diff --git a/project/jni/application/fheroes2/fheroes2-r2050.diff b/project/jni/application/fheroes2/fheroes2-r2050.diff new file mode 100644 index 000000000..e7198fe1f --- /dev/null +++ b/project/jni/application/fheroes2/fheroes2-r2050.diff @@ -0,0 +1,165 @@ +diff -u -r -b -x .svn -x '*.o' -x '*.d' /home/pelya/src/endless_space/fheroes2/src/fheroes2/army/army.cpp src/fheroes2/army/army.cpp +--- /home/pelya/src/endless_space/fheroes2/src/fheroes2/army/army.cpp 2010-11-15 19:17:40.859414020 +0200 ++++ src/fheroes2/army/army.cpp 2010-11-12 16:15:26.000000000 +0200 +@@ -728,12 +728,16 @@ + + void Army::army_t::BattleSetModes(u32 f) + { +- std::for_each(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::BattleSetModes), f)); ++ //std::for_each(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::BattleSetModes), f)); // Cannot call non-const function here ++ for( std::vector ::iterator it = army.begin(); it != army.end(); it++ ) ++ it->BattleSetModes(f); + } + + void Army::army_t::BattleResetModes(u32 f) + { +- std::for_each(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::BattleResetModes), f)); ++ //std::for_each(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::BattleResetModes), f)); // Cannot call non-const function here ++ for( std::vector ::iterator it = army.begin(); it != army.end(); it++ ) ++ it->BattleResetModes(f); + } + + Army::Troop* Army::army_t::BattleFindModes(u32 f) +diff -u -r -b -x .svn -x '*.o' -x '*.d' /home/pelya/src/endless_space/fheroes2/src/fheroes2/game/fheroes2.cpp src/fheroes2/game/fheroes2.cpp +--- /home/pelya/src/endless_space/fheroes2/src/fheroes2/game/fheroes2.cpp 2010-11-15 19:17:40.859414020 +0200 ++++ src/fheroes2/game/fheroes2.cpp 2010-11-22 15:16:37.000000000 +0200 +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + #include "gamedefs.h" + #include "engine.h" +@@ -69,13 +70,18 @@ + + int main(int argc, char **argv) + { ++ VERBOSE("000 - entered SDL_main()"); + Settings & conf = Settings::Get(); + int test = 0; + + std::cout << "Free Heroes II, " + conf.BuildVersion() << std::endl; ++ VERBOSE("Free Heroes II, " + conf.BuildVersion()); + + LoadConfigFiles(conf, GetDirname(argv[0])); + ++ VERBOSE("001"); ++ ++#ifndef ANDROID // Crashes for some reason + // getopt + { + int opt; +@@ -109,13 +115,20 @@ + default: break; + } + } ++#endif ++ ++ VERBOSE("002"); + + if(conf.SelectVideoDriver().size()) SetVideoDriver(conf.SelectVideoDriver()); + ++ VERBOSE("003"); ++ + // random init + Rand::Init(); + if(conf.Music()) SetTimidityEnvPath(conf); + ++ VERBOSE("004"); ++ + u32 subsystem = INIT_VIDEO | INIT_TIMER; + + if(conf.Sound() || conf.Music()) +@@ -128,9 +141,12 @@ + Network::SetProtocolVersion(static_cast((conf.MajorVersion() << 8)) | conf.MinorVersion()); + #endif + ++ VERBOSE("005"); ++ + if(SDL::Init(subsystem)) + try + { ++ VERBOSE("006"); + std::atexit(SDL::Quit); + + if(conf.Unicode()) SetLangEnvPath(conf); +@@ -163,17 +179,23 @@ + //Ensure the mouse position is updated to prevent bad initial values. + LocalEvent::Get().GetMouseCursor(); + ++ VERBOSE("007"); ++ + #ifdef WITH_ZLIB + ZSurface zicons; + if(zicons.Load(FH2_ICONS_WIDTH, FH2_ICONS_HEIGHT, FH2_ICONS_BPP, fh2_icons_pack, FH2_ICONS_SIZE, true)) Display::SetIcons(zicons); + #endif + AGG::Cache & cache = AGG::Cache::Get(); + ++ VERBOSE("008"); ++ + // read data dir + if(! cache.ReadDataDir()) Error::Except("FHeroes2: ", "AGG data files not found."); + + if(IS_DEBUG(DBG_GAME, DBG_INFO)) conf.Dump(); + ++ VERBOSE("009"); ++ + // load palette + cache.LoadPAL(); + +diff -u -r -b -x .svn -x '*.o' -x '*.d' /home/pelya/src/endless_space/fheroes2/src/fheroes2/system/settings.cpp src/fheroes2/system/settings.cpp +--- /home/pelya/src/endless_space/fheroes2/src/fheroes2/system/settings.cpp 2010-11-15 19:17:34.879413999 +0200 ++++ src/fheroes2/system/settings.cpp 2010-11-12 17:31:10.000000000 +0200 +@@ -1424,6 +1419,9 @@ + { + u32 flags = opt_global.Modes(GLOBAL_USESWSURFACE) ? SDL_SWSURFACE : SDL_SWSURFACE | SDL_HWSURFACE; + if(opt_global.Modes(GLOBAL_FULLSCREEN)) flags |= SDL_FULLSCREEN; ++ #ifdef ANDROID ++ flags = SDL_SWSURFACE; ++ #endif + + return flags; + } +diff -u -r -b -x .svn -x '*.o' -x '*.d' /home/pelya/src/endless_space/fheroes2/src/fheroes2/system/settings.h src/fheroes2/system/settings.h +--- /home/pelya/src/endless_space/fheroes2/src/fheroes2/system/settings.h 2010-11-15 19:17:34.869414019 +0200 ++++ src/fheroes2/system/settings.h 2010-11-12 16:09:03.000000000 +0200 +@@ -27,6 +27,7 @@ + #include + #include + #include ++#include + #include "gamedefs.h" + #include "difficulty.h" + #include "race.h" +@@ -35,6 +36,9 @@ + #include "game.h" + #include "game_io.h" + #include "bitmodes.h" ++#ifdef ANDROID ++#include ++#endif + + #define FORMAT_VERSION_2031 0x07EF + #define FORMAT_VERSION_1978 0x07BA +@@ -71,6 +75,9 @@ + #ifdef __SYMBIAN32__ + #define VERBOSE(x) + #define DEBUG(x, y, z) ++#elif defined(ANDROID) ++#define VERBOSE(x) { std::ostringstream osss; osss << x; __android_log_print(ANDROID_LOG_INFO, "FHeroes", "%s", osss.str().c_str()); } ++#define DEBUG(x, y, z) if(IS_DEBUG((x), (y))) VERBOSE(z) + #else + #define VERBOSE(x) std::cout << x << std::endl + #define DEBUG(x, y, z) if(IS_DEBUG((x), (y))) VERBOSE(z) +diff -u -r -b -x .svn -x '*.o' -x '*.d' /home/pelya/src/endless_space/fheroes2/src/xmlccwrap/gzstream.h src/xmlccwrap/gzstream.h +--- /home/pelya/src/endless_space/fheroes2/src/xmlccwrap/gzstream.h 2010-11-15 19:17:31.869414019 +0200 ++++ src/xmlccwrap/gzstream.h 2010-11-12 16:06:58.000000000 +0200 +@@ -33,6 +33,7 @@ + #include + #include + #include ++#include + + #ifdef GZSTREAM_NAMESPACE + namespace GZSTREAM_NAMESPACE { diff --git a/project/jni/application/fheroes2/readme.txt b/project/jni/application/fheroes2/readme.txt index 2481e9b69..8527db977 100644 --- a/project/jni/application/fheroes2/readme.txt +++ b/project/jni/application/fheroes2/readme.txt @@ -1,68 +1,5 @@ -Free Heroes2 Engine (is not playable version.) - -Prerequisites: - -You need to have these libraries (with equivalent devel versions) to build fHeroes2: - -- SDL - -optional library: -- SDL_mixer (play music: internal midi or external ogg tracks) or build WITHOUT_MIXER -- SDL_image (loading external sprites, create screenshot in png format) or build WITHOUT_IMAGE -- SDL_ttf (unicode support) or build WITHOUT_UNICODE -- SDL_net or build WITHOUT_NETWORK -- libogg -- libpng -- gettext - -SDL libraries can be found at http://www.libsdl.org . -Sourcecode you can get it here: http://sourceforge.net/projects/fheroes2/ -And translations: http://translations.launchpad.net/fheroes2 - -Copy origin data/*.agg in to data directory. -Copy maps files (*.mp2) in to maps directory. - -Hot keys: -F4 - switch to fullscreen -PrintScreen - create screenshot -Up - move hero top -Down - move hero bottom -Left - move hero left -Right - move hero right -Ctrl + Up - scroll map top (alt. key ';') -Ctrl + Down - scroll map bottom (alt. key '/') -Ctrl + Left - scroll map left (alt. key ',') -Ctrl + Right - scroll map right (alt. key '.') -e - end turn -t - next town -h - next hero -m - move hero -s - save game to fheroes2.sav -l - load game -i - game info -p - puzzle dialog -d - digging artifact for current hero -space or a - default action -return or n - open dialog -o - system dialog - -1 - show/hide control panel -2 - show/hide radar (only for option: hide interface = on) -3 - show/hide buttons (only for option: hide interface = on) -4 - show/hide status window (only for option: hide interface = on) -5 - show/hide hero/town icons (only for option: hide interface = on) - -Main menu: -n - new game -s - standard game -c - campaign game -m - multi-player game - -Battle: -Esc - fast retreat -space - skip turn (soft: heroes3 version) -s - skip turn (hard) -o - options dialog -a - set auto battle -c - show spell book -h - show heroes dialog +Grab Free Heroes 2 sources with SVN from +https://fheroes2.svn.sourceforge.net/svnroot/fheroes2/trunk/fheroes2 +and put them here, in directory "fheroes2", then apply patch +fheroes2-r2050.diff +and compile with build.sh diff --git a/project/jni/application/fheroes2/src/Makefile b/project/jni/application/fheroes2/src/Makefile deleted file mode 100644 index d7bb894ea..000000000 --- a/project/jni/application/fheroes2/src/Makefile +++ /dev/null @@ -1,94 +0,0 @@ -# makefile -# project: Free Heroes2 -# - -TARGET := fheroes2 -SDL_LIBS := $(shell sdl-config --libs) -SDL_FLAGS := $(shell sdl-config --cflags) - -CFLAGS := $(CFLAGS) -Wall -fsigned-char -DWITH_KEYMAPPING -LDFLAGS := -LIBS := - -ifdef DEBUG -CFLAGS := $(CFLAGS) -O0 -g -pedantic -DWITH_DEBUG -else -CFLAGS := $(CFLAGS) -O2 -endif - -ifndef WITHOUT_MIXER -CFLAGS := $(CFLAGS) -DWITH_MIXER -SDL_LIBS := $(SDL_LIBS) -lSDL_mixer -endif - -ifndef WITHOUT_IMAGE -CFLAGS := $(CFLAGS) -DWITH_IMAGE $(shell libpng12-config --cflags) -DWITH_ZLIB -SDL_LIBS := $(SDL_LIBS) -lSDL_image $(shell libpng12-config --libs) -lz -endif - -ifndef WITHOUT_UNICODE -CFLAGS := $(CFLAGS) -DWITH_TTF -SDL_LIBS := $(SDL_LIBS) -lSDL_ttf -endif - -ifndef WITHOUT_NETWORK -CFLAGS := $(CFLAGS) -DWITH_NET -SDL_LIBS := $(SDL_LIBS) -lSDL_net -endif - -ifndef WITHOUT_XML -CFLAGS := $(CFLAGS) -DWITH_XML -endif - -ifndef WITHOUT_ZLIB -CFLAGS := $(CFLAGS) -DWITH_ZLIB -LIBS := $(LIBS) -lz -endif - -ifndef WITHOUT_EDITOR -CFLAGS := $(CFLAGS) -DWITH_EDITOR -endif - -ifdef RELEASE -CFLAGS := $(CFLAGS) -DBUILD_RELEASE -endif - -CFLAGS := $(SDL_FLAGS) $(CFLAGS) -LIBS := $(SDL_LIBS) $(LIBS) - -ifeq ($(PLATFORM),) -ifeq ($(OS),Windows_NT) -PLATFORM := mingw -else -PLATFORM := unix -endif -endif - -include Makefile.$(PLATFORM) - -export CXX AR LINK WINDRES LDFLAGS CFLAGS LIBS PLATFORM - -.PHONY: clean - -all: -ifndef WITHOUT_XML - $(MAKE) -C xmlccwrap -endif - $(MAKE) -C engine - $(MAKE) -C dist -ifdef WITH_TOOLS - $(MAKE) -C tools -endif -ifndef WITHOUT_UNICODE - $(MAKE) -C dist pot -endif - -clean: -ifndef WITHOUT_XML - $(MAKE) -C xmlccwrap clean -endif -ifdef WITH_TOOLS - $(MAKE) -C tools clean -endif - $(MAKE) -C dist clean - $(MAKE) -C engine clean diff --git a/project/jni/application/fheroes2/src/Makefile.mingw b/project/jni/application/fheroes2/src/Makefile.mingw deleted file mode 100644 index c85a491d4..000000000 --- a/project/jni/application/fheroes2/src/Makefile.mingw +++ /dev/null @@ -1,5 +0,0 @@ -include Makefile.unix - -ifndef WITHOUT_UNICODE -LIBS := $(LIBS) -lintl -liconv -endif diff --git a/project/jni/application/fheroes2/src/Makefile.mingw32 b/project/jni/application/fheroes2/src/Makefile.mingw32 deleted file mode 100644 index c22c5ef9d..000000000 --- a/project/jni/application/fheroes2/src/Makefile.mingw32 +++ /dev/null @@ -1,27 +0,0 @@ -ifndef WITHOUT_MIXER -LIBS := $(LIBS) -lSDL -lmad -lvorbisfile -lvorbis -logg -endif - -ifndef WITHOUT_IMAGE -LIBS := $(LIBS) -lSDL -lpng -ljpeg -endif - -ifndef WITHOUT_UNICODE -LIBS := $(LIBS) -lintl -lfreetype -endif - -ifndef WITHOUT_AUDIOCD -CFLAGS := $(CFLAGS) -DWITH_AUDIOCD -endif - -ifdef WITH_ICONS -IDICON := 1099 -CFLAGS := $(CFLAGS) -DID_ICON=$(IDICON) -export IDICON -endif - -AR := i686-pc-mingw32-ar -CXX := i686-pc-mingw32-g++ -WINDRES := i686-pc-mingw32-windres -CFLAGS := $(CFLAGS) -O2 -static -LIBS := -static -Wl,-Bstatic $(LIBS) -lwinmm diff --git a/project/jni/application/fheroes2/src/Makefile.mingw32ce b/project/jni/application/fheroes2/src/Makefile.mingw32ce deleted file mode 100644 index ee5bf2ea9..000000000 --- a/project/jni/application/fheroes2/src/Makefile.mingw32ce +++ /dev/null @@ -1,20 +0,0 @@ -ifndef WITHOUT_MIXER -LIBS := $(LIBS) -lSDL -lmad -lvorbisfile -lvorbis -logg -endif - -ifndef WITHOUT_UNICODE -LIBS := $(LIBS) -lintl -lfreetype -endif - -ifdef WITH_ICONS -IDICON := 1099 -CFLAGS := $(CFLAGS) -DID_ICON=$(IDICON) -export IDICON -endif - -AR := arm-mingw32ce-ar -CXX := arm-mingw32ce-g++ -WINDRES := arm-mingw32ce-windres -CFLAGS := $(CFLAGS) -ffunction-sections -DWITHOUT_MOUSE -Os -static -LIBS := -Wl,-Bstatic $(LIBS) -lmmtimer -LDFLAGS := -static $(LDFLAGS) -Wl,--gc-sections diff --git a/project/jni/application/fheroes2/src/Makefile.osx b/project/jni/application/fheroes2/src/Makefile.osx deleted file mode 100644 index 84cf22378..000000000 --- a/project/jni/application/fheroes2/src/Makefile.osx +++ /dev/null @@ -1,16 +0,0 @@ -AR := ar -CXX := g++ -LINK := libtool -SIMPLE_LINK_FLAGS := -dynamic -undefined suppress -flat_namespace - -ifndef WITHOUT_UNICODE -LIBS := $(LIBS) -lintl -liconv -endif - -# the config scripts generate link flags like -Wl,-framework which screws up -# libtool on OS X, so we remove the -Wl, prefix and everything works fine. - -search_pattern := -Wl -comma_pattern := , -LINK_FLAGS := $(subst $(search_pattern),,$(LIBS)) -LINK_FLAGS := $(subst $(comma_pattern), ,$(LINK_FLAGS)) $(SIMPLE_LINK_FLAGS) diff --git a/project/jni/application/fheroes2/src/Makefile.unix b/project/jni/application/fheroes2/src/Makefile.unix deleted file mode 100644 index 7dd9f60ae..000000000 --- a/project/jni/application/fheroes2/src/Makefile.unix +++ /dev/null @@ -1,2 +0,0 @@ -AR := ar -CXX := g++ diff --git a/project/jni/application/fheroes2/src/engine/IMG_savepng.cpp b/project/jni/application/fheroes2/src/engine/IMG_savepng.cpp deleted file mode 100644 index 8d461ad24..000000000 --- a/project/jni/application/fheroes2/src/engine/IMG_savepng.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/* - Based on zlib license - see http://www.gzip.org/zlib/zlib_license.html - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - "Philip D. Bober" -*/ - - /* 2010 - support: sdl 1.3 - fheroes2 team */ - /* 2009 - changed: save 16bpp, 24bpp - fheroes2 team */ - /* 2008 - changed: default color - fheroes2 team */ - -/** - * 4/17/04 - IMG_SavePNG & IMG_SavePNG_RW - Philip D. Bober - * 11/08/2004 - Compr fix, levels -1,1-7 now work - Tyler Montbriand - */ -#include -#include "SDL.h" -#include "IMG_savepng.h" - -#ifdef WITH_IMAGE -#include "png.h" - -int IMG_SavePNG(const char *file, SDL_Surface *surf,int compression){ - SDL_RWops *fp; - int ret; - - fp=SDL_RWFromFile(file,"wb"); - - if( fp == NULL ) { - return (-1); - } - - ret=IMG_SavePNG_RW(fp,surf,compression); - SDL_RWclose(fp); - return ret; -} - -static void png_write_data(png_structp png_ptr,png_bytep data, png_size_t length){ - SDL_RWops *rp = (SDL_RWops*) png_get_io_ptr(png_ptr); - SDL_RWwrite(rp,data,1,length); -} - -int IMG_SavePNG_RW(SDL_RWops *src, SDL_Surface *surf,int compression){ - png_structp png_ptr; - png_infop info_ptr; - SDL_PixelFormat *fmt=NULL; - SDL_Surface *tempsurf=NULL; - int ret,funky_format; - unsigned int i; - Uint8 used_alpha, temp_alpha = 0; - png_colorp palette; - Uint8 *palette_alpha=NULL; - png_byte **row_pointers=NULL; - png_ptr=NULL;info_ptr=NULL;palette=NULL;ret=-1; - funky_format=0; - - if( !src || !surf) { - goto savedone; /* Nothing to do. */ - } - - row_pointers=(png_byte **)malloc(surf->h * sizeof(png_byte*)); - if (!row_pointers) { - SDL_SetError("Couldn't allocate memory for rowpointers"); - goto savedone; - } - - png_ptr=png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,NULL,NULL); - if (!png_ptr){ - SDL_SetError("Couldn't allocate memory for PNG file"); - goto savedone; - } - info_ptr= png_create_info_struct(png_ptr); - if (!info_ptr){ - SDL_SetError("Couldn't allocate image information for PNG file"); - goto savedone; - } - /* setup custom writer functions */ - png_set_write_fn(png_ptr,(voidp)src,png_write_data,NULL); - - if (setjmp(png_jmpbuf(png_ptr))){ - SDL_SetError("Unknown error writing PNG"); - goto savedone; - } - - if(compression>Z_BEST_COMPRESSION) - compression=Z_BEST_COMPRESSION; - - if(compression == Z_NO_COMPRESSION) // No compression - { - png_set_filter(png_ptr,0,PNG_FILTER_NONE); - png_set_compression_level(png_ptr,Z_NO_COMPRESSION); - } - else if(compression<0) // Default compression - png_set_compression_level(png_ptr,Z_DEFAULT_COMPRESSION); - else - png_set_compression_level(png_ptr,compression); - - fmt=surf->format; - if(fmt->BitsPerPixel==8){ /* Paletted */ - png_set_IHDR(png_ptr,info_ptr, - surf->w,surf->h,8,PNG_COLOR_TYPE_PALETTE, - PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT); - palette=(png_colorp) malloc(fmt->palette->ncolors * sizeof(png_color)); - if (!palette) { - SDL_SetError("Couldn't create memory for palette"); - goto savedone; - } - for (i=0;(signed int)ipalette->ncolors;i++) { - palette[i].red=fmt->palette->colors[i].r; - palette[i].green=fmt->palette->colors[i].g; - palette[i].blue=fmt->palette->colors[i].b; - } - png_set_PLTE(png_ptr,info_ptr,palette,fmt->palette->ncolors); - if (surf->flags&SDL_SRCCOLORKEY) { - Uint32 colorkey = 0; -#if SDL_VERSION_ATLEAST(1, 3, 0) - SDL_GetColorKey(surf, &colorkey); -#else - colorkey = fmt->colorkey + 1; -#endif - palette_alpha=(Uint8 *)malloc((colorkey+1)*sizeof(Uint8)); - if (!palette_alpha) { - SDL_SetError("Couldn't create memory for palette transparency"); - goto savedone; - } - memset(palette_alpha, 0, (colorkey+1)*sizeof(Uint8)); - palette_alpha[colorkey]=0; - png_set_tRNS(png_ptr,info_ptr,palette_alpha,(colorkey+1),NULL); - } - }else{ /* Truecolor */ - png_set_IHDR(png_ptr,info_ptr, - surf->w,surf->h,8,PNG_COLOR_TYPE_RGB_ALPHA, - PNG_INTERLACE_NONE,PNG_COMPRESSION_TYPE_DEFAULT, - PNG_FILTER_TYPE_DEFAULT); - } - png_write_info(png_ptr, info_ptr); - - if (fmt->BitsPerPixel==8) { /* Paletted */ - for(i=0;(signed int)ih;i++){ - row_pointers[i]= ((png_byte*)surf->pixels) + i*surf->pitch; - } - if(SDL_MUSTLOCK(surf)){ - SDL_LockSurface(surf); - } - png_write_image(png_ptr, row_pointers); - if(SDL_MUSTLOCK(surf)){ - SDL_UnlockSurface(surf); - } - }else{ /* Truecolor */ - if(fmt->BytesPerPixel==3){ - if(fmt->Amask){ /* check for 24 bit with alpha */ - funky_format=1; - }else{ - /* Check for RGB/BGR/GBR/RBG/etc surfaces.*/ -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - if(fmt->Rmask!=0xFF0000 - || fmt->Gmask!=0x00FF00 - || fmt->Bmask!=0x0000FF){ -#else - if(fmt->Rmask!=0x0000FF - || fmt->Gmask!=0x00FF00 - || fmt->Bmask!=0xFF0000){ -#endif - funky_format=1; - } - } - }else if (fmt->BytesPerPixel==4){ - if (!fmt->Amask) { /* check for 32bit but no alpha */ - funky_format=1; - }else{ - /* Check for ARGB/ABGR/GBAR/RABG/etc surfaces.*/ -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - if(fmt->Rmask!=0xFF000000 - || fmt->Gmask!=0x00FF0000 - || fmt->Bmask!=0x0000FF00 - || fmt->Amask!=0x000000FF){ -#else - if(fmt->Rmask!=0x000000FF - || fmt->Gmask!=0x0000FF00 - || fmt->Bmask!=0x00FF0000 - || fmt->Amask!=0xFF000000){ -#endif - funky_format=1; - } - } - }else{ /* 555 or 565 16 bit color */ - funky_format=1; - } - if (funky_format) { - /* Allocate non-funky format, and copy pixeldata in*/ -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 32, - 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff); -#else - tempsurf = SDL_CreateRGBSurface(SDL_SWSURFACE, surf->w, surf->h, 32, - 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); -#endif - if(!tempsurf){ - SDL_SetError("Couldn't allocate temp surface"); - goto savedone; - } - if(surf->flags&SDL_SRCALPHA){ -#if SDL_VERSION_ATLEAST(1, 3, 0) - SDL_GetSurfaceAlphaMod(surf, &temp_alpha); -#else - - temp_alpha=fmt->alpha; -#endif - used_alpha=1; - SDL_SetAlpha(surf,0,255); /* Set for an opaque blit */ - }else{ - used_alpha=0; - } - if(SDL_BlitSurface(surf,NULL,tempsurf,NULL)!=0){ - SDL_SetError("Couldn't blit surface to temp surface"); - SDL_FreeSurface(tempsurf); - goto savedone; - } - if (used_alpha) { - SDL_SetAlpha(surf,SDL_SRCALPHA,(Uint8)temp_alpha); /* Restore alpha settings*/ - } - for(i=0;(signed int)ih;i++){ - row_pointers[i]= ((png_byte*)tempsurf->pixels) + i*tempsurf->pitch; - } - if(SDL_MUSTLOCK(tempsurf)){ - SDL_LockSurface(tempsurf); - } - png_write_image(png_ptr, row_pointers); - if(SDL_MUSTLOCK(tempsurf)){ - SDL_UnlockSurface(tempsurf); - } - SDL_FreeSurface(tempsurf); - } else { - for(i=0;(signed int)ih;i++){ - row_pointers[i]= ((png_byte*)surf->pixels) + i*surf->pitch; - } - if(SDL_MUSTLOCK(surf)){ - SDL_LockSurface(surf); - } - png_write_image(png_ptr, row_pointers); - if(SDL_MUSTLOCK(surf)){ - SDL_UnlockSurface(surf); - } - } - } - - png_write_end(png_ptr, NULL); - ret=0; /* got here, so nothing went wrong. YAY! */ - -savedone: /* clean up and return */ - png_destroy_write_struct(&png_ptr,&info_ptr); - if (palette) { - free(palette); - } - if (palette_alpha) { - free(palette_alpha); - } - if (row_pointers) { - free(row_pointers); - } - return ret; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/IMG_savepng.h b/project/jni/application/fheroes2/src/engine/IMG_savepng.h deleted file mode 100644 index 141f8ece1..000000000 --- a/project/jni/application/fheroes2/src/engine/IMG_savepng.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Based on zlib license - see http://www.gzip.org/zlib/zlib_license.html - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - "Philip D. Bober" - */ -#ifndef __IMG_SAVETOPNG_H__ -#define __IMG_SAVETOPNG_H__ - -/* #include */ - -#ifdef __cplusplus -extern "C" { -#endif - -#define IMG_COMPRESS_OFF 0 -#define IMG_COMPRESS_MAX 9 -#define IMG_COMPRESS_DEFAULT -1 - -#ifdef WITH_IMAGE -/** - * Takes a filename, a surface to save, and a compression level. The - * compression level can be 0(min) through 9(max), or -1(default). - */ -DECLSPEC int SDLCALL IMG_SavePNG(const char *file, - SDL_Surface *surf, - int compression); -/** - * Takes a SDL_RWops pointer, a surface to save, and a compression level. - * compression can be 0(min) through 9(max), or -1(default). - */ -DECLSPEC int SDLCALL IMG_SavePNG_RW(SDL_RWops *src, - SDL_Surface *surf, - int compression); -#endif - -#ifdef __cplusplus -} -#endif - -#endif/*__IMG_SAVETOPNG_H__*/ diff --git a/project/jni/application/fheroes2/src/engine/Makefile b/project/jni/application/fheroes2/src/engine/Makefile deleted file mode 100644 index efec80224..000000000 --- a/project/jni/application/fheroes2/src/engine/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# makefile -# project: Free Heroes2 -# libSDL C++ wrapper engine - -TARGET := libengine - -all: $(TARGET).a - -$(TARGET).a: $(patsubst %.cpp, %.o, $(wildcard *.cpp)) - $(AR) crvs $@ $^ - -%.o: %.cpp - $(CXX) -c -MD $< $(CFLAGS) - -include $(wildcard *.d) - -.PHONY: clean - -clean: - rm -f *.a *.so *.d *.o diff --git a/project/jni/application/fheroes2/src/engine/audio.cpp b/project/jni/application/fheroes2/src/engine/audio.cpp deleted file mode 100644 index 371c11e42..000000000 --- a/project/jni/application/fheroes2/src/engine/audio.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "audio.h" - -namespace Audio -{ - static Spec hardware; -} - -Audio::Spec::Spec() -{ - freq = 0; - format = 0; - channels = 0; - silence = 0; - samples = 0; - size = 0; - callback = NULL; - userdata = NULL; -} - -Audio::CVT::CVT() -{ - needed = 0; - src_format = 0; - dst_format = 0; - rate_incr = 0; - buf = NULL; - len = 0; - len_cvt = 0; - len_mult = 0; - len_ratio = 0; - filters[0] = NULL; - filters[1] = NULL; - filters[2] = NULL; - filters[3] = NULL; - filters[4] = NULL; - filters[5] = NULL; - filters[6] = NULL; - filters[7] = NULL; - filters[8] = NULL; - filters[9] = NULL; - filter_index = 0; -} - -bool Audio::CVT::Build(const Audio::Spec & src, const Audio::Spec & dst) -{ - if(1 == SDL_BuildAudioCVT(this, src.format, src.channels, src.freq, dst.format, dst.channels, dst.freq)) return true; - - std::cerr << "Audio::CVT::Build: " << SDL_GetError() << std::endl; - return false; -} - -bool Audio::CVT::Convert(void) -{ - if(0 == SDL_ConvertAudio(this)) return true; - - std::cerr << "Audio::CVT::Convert: " << SDL_GetError() << std::endl; - return false; -} - -Audio::Spec & Audio::GetHardwareSpec(void) -{ - return hardware; -} diff --git a/project/jni/application/fheroes2/src/engine/audio.h b/project/jni/application/fheroes2/src/engine/audio.h deleted file mode 100644 index d60d2fdf7..000000000 --- a/project/jni/application/fheroes2/src/engine/audio.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2AUDIO_H -#define H2AUDIO_H - -#include "types.h" - -namespace Audio -{ - struct Spec : public SDL_AudioSpec - { - Spec(); - }; - - struct CVT : public SDL_AudioCVT - { - CVT(); - - bool Build(const Spec & src, const Spec & dst); - bool Convert(void); - }; - - Spec & GetHardwareSpec(void); -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/audio_cdrom.cpp b/project/jni/application/fheroes2/src/engine/audio_cdrom.cpp deleted file mode 100644 index bcd136e6b..000000000 --- a/project/jni/application/fheroes2/src/engine/audio_cdrom.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Josh Matthews * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_AUDIOCD -#include -#include "audio_mixer.h" -#include "audio_cdrom.h" - -namespace Cdrom -{ - void Open(void); - void Close(void); - - static SDL_CD *cd = NULL; - static int currentTrack = -1; - static unsigned int startTime = 0; - static unsigned int tickLength; - static SDL_Thread *loopThread; - static SDL_mutex *cdLock; - - int LoopCheck(void *data); -} - -void Cdrom::Open(void) -{ - for(int i = 0; i < SDL_CDNumDrives(); i++) - { - SDL_CD *drive = SDL_CDOpen(i); - - if(drive) - { - if(!CD_INDRIVE(SDL_CDStatus(drive))) - { - SDL_CDClose(drive); - continue; - } - else - if(drive->numtracks > 1 && drive->track[0].type == SDL_DATA_TRACK) - { - cd = drive; - break; - } - } - } - - if(cd) - { - loopThread = SDL_CreateThread(&LoopCheck, NULL); - cdLock = SDL_CreateMutex(); - } - - std::cerr << "Cdrom::Open: " << (cd ? "found CD audio device." : "no CDROM devices available.") << std::endl; -} - -void Cdrom::Close(void) -{ - if(cd) - { - SDL_CDStop(cd); - SDL_KillThread(loopThread); - SDL_DestroyMutex(cdLock); - SDL_CDClose(cd); - cd = NULL; - } -} - -bool Cdrom::isValid(void) -{ - return cd; -} - -int Cdrom::LoopCheck(void *data) -{ - while(1) - { - SDL_Delay(5000); - SDL_LockMutex(cdLock); - if(startTime && SDL_GetTicks() - startTime > tickLength) - Play(currentTrack, true, true); - SDL_UnlockMutex(cdLock); - } - return 0; -} - -void Cdrom::Play(const u8 track, bool loop, bool force) -{ - if(Mixer::isValid() && cd) - { - SDL_LockMutex(cdLock); - - if(currentTrack != track || force) - { - if(SDL_CDPlayTracks(cd, track, 0, 1, 0) < 0) - std::cerr << "Cdrom::Play: Couldn't play track " << static_cast(track) << std::endl; - - currentTrack = track; - if(loop) - { - tickLength = (unsigned int)((cd->track[track].length / CD_FPS) * 0.01f); - startTime = SDL_GetTicks(); - } - else startTime = 0; - - if(SDL_CDStatus(cd) != CD_PLAYING) - std::cerr << "Cdrom::Play: CD is not playing" << SDL_GetError() << std::endl; - } - - SDL_UnlockMutex(cdLock); - } -} - -void Cdrom::Pause(void) -{ - if(cd) SDL_CDPause(cd); -} -#endif diff --git a/project/jni/application/fheroes2/src/engine/audio_cdrom.h b/project/jni/application/fheroes2/src/engine/audio_cdrom.h deleted file mode 100644 index e67759c97..000000000 --- a/project/jni/application/fheroes2/src/engine/audio_cdrom.h +++ /dev/null @@ -1,37 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Josh Matthews * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2AUDIO_CDROM_H -#define H2AUDIO_CDROM_H - -#ifdef WITH_AUDIOCD -#include "types.h" - -namespace Cdrom -{ - bool isValid(void); - void Play(const u8 track, bool loop, bool force = false); - void Pause(void); -} - -#endif -#endif diff --git a/project/jni/application/fheroes2/src/engine/audio_mixer.cpp b/project/jni/application/fheroes2/src/engine/audio_mixer.cpp deleted file mode 100644 index d9d83256a..000000000 --- a/project/jni/application/fheroes2/src/engine/audio_mixer.cpp +++ /dev/null @@ -1,490 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "engine.h" -#include "audio.h" -#include "audio_cdrom.h" -#include "audio_music.h" -#include "audio_mixer.h" - -namespace Mixer -{ - void Init(void); - void Quit(void); - bool valid = false; -} - -bool Mixer::isValid(void) -{ - return valid; -} - -#ifdef WITH_MIXER -#include "SDL_mixer.h" - -void FreeChannel(int channel) -{ - Mixer::chunk_t* sample = Mix_GetChunk(channel); - if(sample) Mix_FreeChunk(sample); -} - -void Mixer::Init(void) -{ - if(SDL::SubSystem(SDL_INIT_AUDIO)) - { - Audio::Spec & hardware = Audio::GetHardwareSpec(); - hardware.freq = 22050; - hardware.format = AUDIO_S16; - hardware.channels = 2; - hardware.samples = 2048; - - if(0 != Mix_OpenAudio(hardware.freq, hardware.format, hardware.channels, hardware.samples)) - { - std::cerr << "Mixer: " << SDL_GetError() << std::endl; - valid = false; - } - else - { - int channels = 0; - Mix_QuerySpec(&hardware.freq, &hardware.format, &channels); - hardware.channels = channels; - - valid = true; - } - } - else - { - std::cerr << "Mixer: audio subsystem not initialize" << std::endl; - valid = false; - } -} - -void Mixer::Quit(void) -{ - if(! SDL::SubSystem(SDL_INIT_AUDIO) || !valid) return; - - Mixer::Reset(); - valid = false; - Mix_CloseAudio(); -} - -void Mixer::SetChannels(u8 num) -{ - Mix_AllocateChannels(num); - Mix_ReserveChannels(1); -} - -void Mixer::FreeChunk(chunk_t *sample) -{ - if(sample) Mix_FreeChunk(sample); -} - - -Mixer::chunk_t* Mixer::LoadWAV(const char* file) -{ - Mix_Chunk *sample = Mix_LoadWAV(file); - if(!sample) std::cerr << "Mixer::LoadWAV: " << Mix_GetError() << std::endl; - return sample; -} - -Mixer::chunk_t* Mixer::LoadWAV(const u8* ptr, u32 size) -{ - Mix_Chunk *sample = Mix_LoadWAV_RW(SDL_RWFromConstMem(ptr, size), 1); - if(!sample) std::cerr << "Mixer::LoadWAV: "<< Mix_GetError() << std::endl; - return sample; -} - -int Mixer::Play(chunk_t* sample, int channel, bool loop) -{ - int res = Mix_PlayChannel(channel, sample, loop ? -1 : 0); - if(res == -1) std::cerr << "Mixer::Play: " << Mix_GetError() << std::endl;; - return res; -} - -int Mixer::Play(const char* file, int channel, bool loop) -{ - if(valid) - { - chunk_t* sample = LoadWAV(file); - if(sample) - { - Mix_ChannelFinished(FreeChannel); - return Play(sample, channel, loop); - } - } - return -1; -} - -int Mixer::Play(const u8* ptr, u32 size, int channel, bool loop) -{ - if(valid && ptr) - { - chunk_t* sample = LoadWAV(ptr, size); - if(sample) - { - Mix_ChannelFinished(FreeChannel); - return Play(sample, channel, loop); - } - } - return -1; -} - -u16 Mixer::MaxVolume(void) -{ - return MIX_MAX_VOLUME; -} - -u16 Mixer::Volume(int channel, s16 vol) -{ - if(!valid) return 0; - return Mix_Volume(channel, vol > MIX_MAX_VOLUME ? MIX_MAX_VOLUME : vol); -} - -void Mixer::Pause(int channel) -{ - Mix_Pause(channel); -} - -void Mixer::Resume(int channel) -{ - Mix_Resume(channel); -} - -void Mixer::Stop(int channel) -{ - Mix_HaltChannel(channel); -} - -void Mixer::Reset(void) -{ - Music::Reset(); -#ifdef WITH_AUDIOCD - if(Cdrom::isValid()) Cdrom::Pause(); -#endif - Mix_HaltChannel(-1); -} - -u8 Mixer::isPlaying(int channel) -{ - return Mix_Playing(channel); -} - -u8 Mixer::isPaused(int channel) -{ - return Mix_Paused(channel); -} - -void Mixer::Reduce(void) -{ -} - -void Mixer::Enhance(void) -{ -} - -#else - -enum { MIX_PLAY = 0x01, MIX_LOOP = 0x02, MIX_REDUCE = 0x04, MIX_ENHANCE = 0x08 }; - -struct chunk_t -{ - chunk_t() : data(NULL), length(0), position(0), volume1(0), state(0) {}; - bool this_ptr(const chunk_t* ch) const{ return ch == this; }; - - const u8 * data; - u32 length; - u32 position; - s16 volume1; - s16 volume2; - u8 state; -}; - - -namespace Mixer -{ - bool PredicateIsFreeSound(const chunk_t &); - void PredicateStopSound(chunk_t &); - void PredicateStartSound(chunk_t &); - void AudioCallBack(void*, u8*, int); - - std::vector chunks; - u8 reserved_channels; -} - -void Mixer::PredicateStopSound(chunk_t & ch) -{ - SDL_LockAudio(); - ch.state &= ~MIX_PLAY; - SDL_UnlockAudio(); -} - -void Mixer::PredicateStartSound(chunk_t & ch) -{ - SDL_LockAudio(); - ch.state |= MIX_PLAY; - SDL_UnlockAudio(); -} - -bool Mixer::PredicateIsFreeSound(const chunk_t & ch) -{ - return !(ch.state & MIX_PLAY); -} - -void Mixer::AudioCallBack(void *unused, u8 *stream, int length) -{ - for(u8 ii = 0; ii < chunks.size(); ++ii) - { - chunk_t & ch = chunks[ii]; - if((ch.state & MIX_PLAY) && ch.volume1) - { - if(ch.state & MIX_REDUCE) - { - ch.volume1 -= 10; - if(ch.volume1 <= 0) - { - ch.volume1 = 0; - ch.state &= ~MIX_REDUCE; - } - } - else - if(ch.state & MIX_ENHANCE) - { - ch.volume1 += 10; - if(ch.volume1 >= ch.volume2) - { - ch.volume1 = ch.volume2; - ch.state &= ~MIX_ENHANCE; - } - } - - SDL_MixAudio(stream, &ch.data[ch.position], (ch.position + length > ch.length ? ch.length - ch.position : length), ch.volume1); - ch.position += length; - if(ch.position >= ch.length) - { - ch.position = 0; - if(!(ch.state & MIX_LOOP)) ch.state &= ~MIX_PLAY; - } - } - } -} - -void Mixer::Init(void) -{ - if(SDL::SubSystem(SDL_INIT_AUDIO)) - { - Audio::Spec spec; - spec.freq = 22050; - spec.format = AUDIO_S16; - spec.channels = 2; - spec.samples = 2048; - spec.callback = AudioCallBack; - - if(0 > SDL_OpenAudio(&spec, &Audio::GetHardwareSpec())) - { - std::cerr << "Mixer::Init: " << SDL_GetError() << std::endl; - valid = false; - } - else - { - SDL_PauseAudio(0); - valid = true; - reserved_channels = 0; - } - } - else - { - std::cerr << "Mixer::Init: audio subsystem not initialize" << std::endl; - valid = false; - } -} - -void Mixer::Quit(void) -{ - if(! SDL::SubSystem(SDL_INIT_AUDIO) || !valid) return; - Music::Reset(); - Mixer::Reset(); - SDL_CloseAudio(); - chunks.clear(); - valid = false; -} - -void Mixer::SetChannels(u8 num) -{ - chunks.resize(num); - reserved_channels = 1; -} - -u16 Mixer::MaxVolume(void) -{ - return SDL_MIX_MAXVOLUME; -} - -u16 Mixer::Volume(int ch, s16 vol) -{ - if(!valid) return 0; - - if(vol > SDL_MIX_MAXVOLUME) vol = SDL_MIX_MAXVOLUME; - - if(ch < 0) - { - for(u8 ii = 0; ii < chunks.size(); ++ii) - { - SDL_LockAudio(); - chunks[ii].volume1 = vol; - chunks[ii].volume2 = vol; - SDL_UnlockAudio(); - } - } - else - if(ch < static_cast(chunks.size())) - { - if(0 > vol) - { - vol = chunks[ch].volume1; - } - else - { - SDL_LockAudio(); - chunks[ch].volume1 = vol; - chunks[ch].volume2 = vol; - SDL_UnlockAudio(); - } - } - return vol; -} - -int Mixer::Play(const u8* ptr, u32 size, int channel, bool loop) -{ - if(valid && ptr) - { - chunk_t* ch = NULL; - - if(0 > channel) - { - std::vector::iterator it = std::find_if(chunks.begin(), chunks.end(), std::bind2nd(std::mem_fun_ref(&chunk_t::this_ptr), ptr)); - if(it == chunks.end()) - { - it = std::find_if(chunks.begin() + reserved_channels, chunks.end(), PredicateIsFreeSound); - if(it == chunks.end()) - { - std::cerr << "Mixer::PlayRAW: mixer is full" << std::endl; - return -1; - } - } - ch = &(*it); - channel = it - chunks.begin(); - } - else - if(channel < static_cast(chunks.size())) - ch = &chunks[channel]; - - if(ch) - { - SDL_LockAudio(); - ch->state |= (loop ? MIX_LOOP | MIX_PLAY : MIX_PLAY); - ch->data = ptr; - ch->length = size; - ch->position = 0; - SDL_UnlockAudio(); - } - return channel; - } - return -1; -} - -void Mixer::Pause(int ch) -{ - if(! valid) return; - if(0 > ch) - std::for_each(chunks.begin(), chunks.end(), PredicateStopSound); - else - if(ch < static_cast(chunks.size())) PredicateStopSound(chunks[ch]); -} - -void Mixer::Resume(int ch) -{ - if(! valid) return; - if(0 > ch) - std::for_each(chunks.begin(), chunks.end(), PredicateStartSound); - else - if(ch < static_cast(chunks.size())) PredicateStartSound(chunks[ch]); -} - -u8 Mixer::isPlaying(int ch) -{ - return 0 <= ch && ch < static_cast(chunks.size()) && (chunks[ch].state & MIX_PLAY); -} - -u8 Mixer::isPaused(int ch) -{ - return 0 <= ch && ch < static_cast(chunks.size()) && !(chunks[ch].state & MIX_PLAY); -} - -void Mixer::Stop(int ch) -{ - Pause(ch); -} - -void Mixer::Reset(void) -{ - Music::Reset(); -#ifdef WITH_AUDIOCD - if(Cdrom::isValid()) Cdrom::Pause(); -#endif - Pause(-1); -} - -void Mixer::Reduce(void) -{ - if(! valid) return; - - std::vector::iterator it = chunks.begin(); - for(; it != chunks.end(); ++it) - { - if((*it).state & MIX_PLAY) - { - SDL_LockAudio(); - (*it).state |= MIX_REDUCE; - SDL_UnlockAudio(); - } - } -} - -void Mixer::Enhance(void) -{ - if(! valid) return; - - std::vector::iterator it = chunks.begin(); - for(; it != chunks.end(); ++it) - { - if((*it).state & MIX_PLAY) - { - SDL_LockAudio(); - (*it).state |= MIX_ENHANCE; - SDL_UnlockAudio(); - } - } -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/audio_mixer.h b/project/jni/application/fheroes2/src/engine/audio_mixer.h deleted file mode 100644 index 05100825a..000000000 --- a/project/jni/application/fheroes2/src/engine/audio_mixer.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2AUDIO_MIXER_H -#define H2AUDIO_MIXER_H - -#include -#include "types.h" - -#ifdef WITH_MIXER -#include "SDL_mixer.h" -#endif - -namespace Mixer -{ -#ifdef WITH_MIXER - typedef Mix_Chunk chunk_t; - - void FreeChunk(chunk_t*); - chunk_t* LoadWAV(const char*); - chunk_t* LoadWAV(const u8*, u32); - - int Play(chunk_t*, int, bool); - int Play(const char*, int = -1, bool = false); -#endif - int Play(const u8*, u32, int = -1, bool = false); - - void SetChannels(u8); - u16 MaxVolume(void); - u16 Volume(int ch, s16 = -1); - - void Pause(int ch = -1); - void Resume(int ch = -1); - void Stop(int ch = -1); - void Reset(void); - - u8 isPlaying(int); - u8 isPaused(int); - bool isValid(void); - - void Reduce(void); - void Enhance(void); -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/audio_music.cpp b/project/jni/application/fheroes2/src/engine/audio_music.cpp deleted file mode 100644 index 03cb9f6d4..000000000 --- a/project/jni/application/fheroes2/src/engine/audio_music.cpp +++ /dev/null @@ -1,213 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "audio_mixer.h" -#include "audio_music.h" - -#ifdef WITH_MIXER -#include "SDL_mixer.h" - -namespace Music -{ - void Play(bool); - - static Mix_Music * music = NULL; - static u16 fadein = 0; - static u16 fadeout = 0; -} - -void Music::Play(bool loop) -{ - if(fadein) - { - if(music && Mix_FadeInMusic(music, loop ? -1 : 0, fadein) == -1) - std::cerr << "Music::Play: " << Mix_GetError() << std::endl; - } - else - { - if(music && Mix_PlayMusic(music, loop ? -1 : 0) == -1) - std::cerr << "Music::Play: " << Mix_GetError() << std::endl; - } -} - -void Music::Play(const u8* ptr, u32 size, bool loop) -{ - if(! Mixer::isValid()) return; - - if(ptr && size) - { - Reset(); - - SDL_RWops *rwops = SDL_RWFromConstMem(ptr, size); - music = Mix_LoadMUS_RW(rwops); - SDL_FreeRW(rwops); - Music::Play(loop); - } -} - -void Music::Play(const char* file, bool loop) -{ - if(! Mixer::isValid()) return; - - Reset(); - music = Mix_LoadMUS(file); - - if(! music) - std::cerr << "Music::Play: " << Mix_GetError() << std::endl; - else - Music::Play(loop); -} - -void Music::SetFadeIn(u16 f) -{ - fadein = f; -} - -void Music::SetFadeOut(u16 f) -{ - fadeout = f; -} - -u16 Music::Volume(s16 vol) -{ - return Mixer::isValid() ? (Mix_VolumeMusic(vol > MIX_MAX_VOLUME ? MIX_MAX_VOLUME : vol)) : 0; -} - -void Music::Pause(void) -{ - if(! Mixer::isValid() && music) Mix_PauseMusic(); -} - -void Music::Resume(void) -{ - if(Mixer::isValid() && music) Mix_ResumeMusic(); -} - -void Music::Reset(void) -{ - if(Mixer::isValid() && music) - { - if(fadeout) - while(!Mix_FadeOutMusic(fadeout) && Mix_PlayingMusic()) SDL_Delay(50); - else - Mix_HaltMusic(); - - Mix_FreeMusic(music); - music = NULL; - } -} - -bool Music::isPlaying(void) -{ - return Mixer::isValid() && Mix_PlayingMusic(); -} - -bool Music::isPaused(void) -{ - return Mixer::isValid() && Mix_PausedMusic(); -} - -#else -#include "thread.h" - -struct info_t -{ - info_t() : loop(false){}; - std::string run; - bool loop; -}; - -namespace Music -{ - SDL::Thread music; - info_t info; -} - -int callbackPlayMusic(void *ptr) -{ - if(ptr && system(NULL)) - { - info_t & info = *reinterpret_cast(ptr); - if(info.loop) - { - while(1){ system(info.run.c_str()); DELAY(10); } - } - else - return system(info.run.c_str()); - } - return -1; -} - -void Music::Play(const u8* ptr, u32 size, bool loop) -{ -} - -void Music::Play(const char* run, bool loop) -{ - if(music.IsRun()) - { - if(info.run == run) return; - music.Kill(); - } - info.run = run; - info.loop = loop; - music.Create(callbackPlayMusic, &info); -} - -void Music::SetFadeIn(u16 f) -{ -} - -void Music::SetFadeOut(u16 f) -{ -} - -u16 Music::Volume(s16 vol) -{ - return 0; -} - -void Music::Pause(void) -{ -} - -void Music::Resume(void) -{ -} - -bool Music::isPlaying(void) -{ - return music.IsRun(); -} - -bool Music::isPaused(void) -{ - return false; -} - -void Music::Reset(void) -{ - if(music.IsRun()) music.Kill(); -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/audio_music.h b/project/jni/application/fheroes2/src/engine/audio_music.h deleted file mode 100644 index c92e94dd5..000000000 --- a/project/jni/application/fheroes2/src/engine/audio_music.h +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2AUDIO_MUSIC_H -#define H2AUDIO_MUSIC_H - -#include "types.h" - -namespace Music -{ - void Play(const u8* ptr, u32 size, bool loop); - void Play(const char* file, bool loop); - u16 Volume(s16 vol); - void SetFadeIn(u16); - void SetFadeOut(u16); - void Pause(void); - void Resume(void); - void Reset(void); - bool isPlaying(void); - bool isPaused(void); -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/background.cpp b/project/jni/application/fheroes2/src/engine/background.cpp deleted file mode 100644 index f7cff67e6..000000000 --- a/project/jni/application/fheroes2/src/engine/background.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "background.h" -#include "display.h" - -Background::Background(const Rect &rt) : Surface(), Rect(rt) -{ -} - -Background::Background(s16 x, s16 y, u16 w, u16 h) : Surface(), Rect(x, y, w, h) -{ -} - -Background::Background(const Point &pt, u16 w, u16 h) : Surface(), Rect(pt, w, h) -{ -} - -bool Background::isValid(void) const -{ - return Surface::isValid(); -} - -void Background::Save(void) -{ - // resize background - if(Surface::isValid() && (Size::w != Surface::w() || Size::h != Surface::h())) FreeSurface(*this); - - if(0 == Rect::w || 0 == Rect::h) return; - - if(! Surface::isValid()) Set(Rect::w, Rect::h, false); - - Blit(Display::Get(), *this, 0, 0); - SetDisplayFormat(); -} - -void Background::Save(s16 ax, s16 ay) -{ - x = ax; - y = ay; - - Save(); -} - -void Background::Save(s16 ax, s16 ay, u16 aw, u16 ah) -{ - x = ax; - y = ay; - Size::w = aw; - Size::h = ah; - - Save(); -} - -void Background::Save(const Point &pt) -{ - x = pt.x; - y = pt.y; - - Save(); -} - -void Background::Save(const Rect &rt) -{ - Save(rt.x, rt.y, rt.w, rt.h); -} - -void Background::Restore(void) -{ - if(Surface::isValid()) - Display::Get().Blit(*this, x, y); -} - -const Rect & Background::GetRect(void) const -{ - return *this; -} - -const Point & Background::GetPos(void) const -{ - return *this; -} - -const Size & Background::GetSize(void) const -{ - return *this; -} diff --git a/project/jni/application/fheroes2/src/engine/background.h b/project/jni/application/fheroes2/src/engine/background.h deleted file mode 100644 index ab6471cdc..000000000 --- a/project/jni/application/fheroes2/src/engine/background.h +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2BACKGROUND_H -#define H2BACKGROUND_H - -#include "types.h" -#include "rect.h" -#include "surface.h" - -class Background : protected Surface, protected Rect -{ -public: - Background(const Rect &rt = Rect()); - Background(s16 x, s16 y, u16 w, u16 h); - Background(const Point &pt, u16 w, u16 h); - - bool isValid(void) const; - - void Save(void); - void Save(s16 ax, s16 ay); - void Save(s16 ax, s16 ay, u16 aw ,u16 ah); - void Save(const Point &pt); - void Save(const Rect &rt); - - void Restore(void); - const Rect & GetRect(void) const; - const Point & GetPos(void) const; - const Size & GetSize(void) const; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/engine/display.cpp b/project/jni/application/fheroes2/src/engine/display.cpp deleted file mode 100644 index 50b8fa555..000000000 --- a/project/jni/application/fheroes2/src/engine/display.cpp +++ /dev/null @@ -1,389 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "rect.h" -#include "types.h" -#include "error.h" -#include "display.h" - -UpdateRects::UpdateRects() : bits(NULL), len(0), bf(0), bw(0) -{ -} - -UpdateRects::~UpdateRects() -{ - delete [] bits; -} - -void UpdateRects::SetVideoMode(u16 dw, u16 dh) -{ - if(dw < 640) - { - bw = 4; - bf = 2; - } - else - if(dw > 640) - { - bw = 16; - bf = 4; - } - else - { - bw = 8; - bf = 3; - } - - // fix bw and bf - while(((dw % bw) || (dh % bw)) && 1 < bf) - { - bw >>= 1; - --bf; - } - - len = (dw >> bf) * (dh >> bf); - len = (len % 8 ? (len >> 3) + 1 : len >> 3); - - if(bits) delete [] bits; - bits = new u8 [len]; - std::fill(bits, bits + len, 0); - - rects.reserve(len / 4); -} - -size_t UpdateRects::Size(void) const -{ - return rects.size(); -} - -void UpdateRects::Clear(void) -{ - std::fill(bits, bits + len, 0); - rects.clear(); -} - -SDL_Rect* UpdateRects::Data(void) -{ - return rects.size() ? &rects[0] : NULL; -} - -void UpdateRects::PushRect(s16 px, s16 py, u16 pw, u16 ph) -{ - Display & display = Display::Get(); - - if(0 != pw && 0 != ph && - px + pw > 0 && py + ph > 0 && - px < display.w() && py < display.h()) - { - if(px < 0) - { - pw += px; - px = 0; - } - - if(py < 0) - { - ph += py; - py = 0; - } - - if(px + pw > display.w()) - pw = display.w() - px; - - if(py + ph > display.h()) - ph = display.h() - py; - - const u16 dw = display.w() >> bf; - s16 xx, yy; - - for(yy = py; yy < py + ph; yy += bw) - for(xx = px; xx < px + pw; xx += bw) - SetBit((yy >> bf) * dw + (xx >> bf), 1); - - yy = py + ph - 1; - for(xx = px; xx < px + pw; xx += bw) - SetBit((yy >> bf) * dw + (xx >> bf), 1); - - xx = px + pw - 1; - for(yy = py; yy < py + ph; yy += bw) - SetBit((yy >> bf) * dw + (xx >> bf), 1); - - yy = py + ph - 1; - xx = px + pw - 1; - SetBit((yy >> bf) * dw + (xx >> bf), 1); - } -} - -bool UpdateRects::BitsToRects(void) -{ - Display & display = Display::Get(); - - const u16 dbf = display.w() >> bf; - const size_t len2 = len << 3; - size_t index; - SDL_Rect rect; - SDL_Rect* prt = NULL; - - for(index = 0; index < len2; ++index) - { - if(GetBit(index)) - { - if(NULL != prt) - { - if(static_cast(rect.y) == (index / dbf) * bw) - rect.w += bw; - else - { - rects.push_back(*prt); - prt = NULL; - } - } - - if(NULL == prt) - { - rect.x = (index % dbf) * bw; - rect.y = (index / dbf) * bw; - rect.w = bw; - rect.h = bw; - prt = ▭ - } - } - else - { - if(prt) - { - rects.push_back(*prt); - prt = NULL; - } - } - } - - if(prt) - { - rects.push_back(*prt); - prt = NULL; - } - - return rects.size(); -} - -void UpdateRects::SetBit(u32 index, bool value) -{ - if(value != GetBit(index)) - bits[index >> 3] ^= (1 << (index % 8)); -} - -bool UpdateRects::GetBit(u32 index) const -{ - return (bits[index >> 3] >> (index % 8)); -} - -Display::Display() -{ -} - -Display::~Display() -{ -} - -Display & Display::operator= (const Display & dp) -{ - surface = SDL_GetVideoSurface(); - - return *this; -} - -void Display::SetVideoMode(const u16 w, const u16 h, u32 flags) -{ - Display & display = Display::Get(); - - if(display.isValid() && display.w() == w && display.h() == h) return; - - if(display.surface && (display.surface->flags & SDL_FULLSCREEN)) flags |= SDL_FULLSCREEN; - display.surface = SDL_SetVideoMode(w, h, 16, flags); - - if(!display.surface) - Error::Except("SDL_SetVideoMode: ", SDL_GetError()); - - display.update_rects.SetVideoMode(display.w(), display.h()); -} - -/* flip */ -void Display::Flip() -{ - Display & display = Display::Get(); - - if(display.surface->flags & SDL_HWSURFACE) - SDL_Flip(display.surface); - else - if(display.update_rects.BitsToRects()) - { - SDL_UpdateRects(display.surface, display.update_rects.Size(), display.update_rects.Data()); - display.update_rects.Clear(); - } -} - -/* full screen */ -void Display::FullScreen(void) -{ - Display & display = Display::Get(); - - SDL_WM_ToggleFullScreen(display.surface); -} - -/* set caption main window */ -void Display::SetCaption(const std::string & caption) -{ - SDL_WM_SetCaption(caption.c_str(), NULL); -} - -/* set icons window */ -void Display::SetIcons(const Surface & icons) -{ - SDL_WM_SetIcon(const_cast(icons.GetSurface()), NULL); -} - -/* hide system cursor */ -void Display::HideCursor(void) -{ - SDL_ShowCursor(SDL_DISABLE); -} - -/* show system cursor */ -void Display::ShowCursor(void) -{ - SDL_ShowCursor(SDL_ENABLE); -} - -bool Display::Fade(u8 fadeTo) -{ - Display & display = Display::Get(); - u8 alpha = display.GetAlpha(); - - if(alpha == fadeTo) return false; - else - if(alpha < fadeTo) return Rise(fadeTo); - if(display.w() != 640 || display.h() != 480) return false; - - Surface temp(display); - temp.SetDisplayFormat(); - temp.Blit(display); - const u32 black = temp.MapRGB(0, 0, 0); - - while(alpha > fadeTo) - { - alpha -= alpha - 10 > fadeTo ? 10 : alpha - fadeTo; - display.Fill(black); - temp.SetAlpha(alpha); - display.Blit(temp); - display.Flip(); - DELAY(10); - } - - return true; -} - -bool Display::Rise(u8 riseTo) -{ - Display & display = Display::Get(); - u8 alpha = display.GetAlpha(); - - if(alpha == riseTo) return false; - else - if(riseTo < alpha) return Fade(riseTo); - if(display.w() != 640 || display.h() != 480) return false; - - Surface temp(display); - temp.SetDisplayFormat(); - temp.Blit(display); - const u32 black = temp.MapRGB(0, 0, 0); - - while(alpha < riseTo) - { - alpha += alpha + 10 < riseTo ? 10 : riseTo - alpha; - display.Fill(black); - temp.SetAlpha(alpha); - display.Blit(temp); - display.Flip(); - DELAY(10); - } - - return true; -} - -/* get video display */ -Display & Display::Get(void) -{ - static Display inside; - return inside; -} - -int Display::GetMaxMode(Size & result, bool rotate) -{ - SDL_Rect** modes = SDL_ListModes(NULL, SDL_ANYFORMAT); - - if(modes == (SDL_Rect **) 0) - { - std::cerr << "Display::GetMaxMode: " << "no modes available" << std::endl; - return 0; - } - else - if(modes == (SDL_Rect **) -1) - { - //std::cout << "Display::GetMaxMode: " << "all modes available" << std::endl; - return -1; - } - else - { - int max = 0; - int cur = 0; - - for(int ii = 0; modes[ii]; ++ii) - { - if(max < modes[ii]->w * modes[ii]->h) - { - max = modes[ii]->w * modes[ii]->h; - cur = ii; - } - } - - result.w = modes[cur]->w; - result.h = modes[cur]->h; - - if(rotate && result.w < result.h) - { - cur = result.w; - result.w = result.h; - result.h = cur; - } - } - return 1; -} - -void Display::AddUpdateRect(s16 px, s16 py, u16 pw, u16 ph) -{ - if(0 == (surface->flags & SDL_HWSURFACE)) - update_rects.PushRect(px, py, pw, ph); -} diff --git a/project/jni/application/fheroes2/src/engine/display.h b/project/jni/application/fheroes2/src/engine/display.h deleted file mode 100644 index 8e73638a4..000000000 --- a/project/jni/application/fheroes2/src/engine/display.h +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2DISPLAY_H -#define H2DISPLAY_H - -#include -#include "surface.h" -#include "rect.h" - -class UpdateRects -{ -public: - UpdateRects(); - ~UpdateRects(); - - void SetVideoMode(u16, u16); - void PushRect(s16, s16, u16, u16); - void Clear(void); - size_t Size(void) const; - SDL_Rect* Data(void); - bool BitsToRects(void); - -protected: - void SetBit(u32, bool); - bool GetBit(u32) const; - - std::vector rects; - u8* bits; - u32 len; - u8 bf; - u8 bw; -}; - -class Display : public Surface -{ -public: - ~Display(); - - static Display & Get(void); - - static void SetVideoMode(const u16 w, const u16 h, u32 flags); - static int GetMaxMode(Size &, bool enable_rotate); - - static void HideCursor(void); - static void ShowCursor(void); - static void SetCaption(const std::string & caption); - static void SetIcons(const Surface & icons); - - void AddUpdateRect(s16, s16, u16, u16); - - static void Flip(); - static void FullScreen(void); - - static bool Fade(u8 fadeTo=0); - static bool Rise(u8 riseTo=255); - - Display & operator= (const Display & dp); - -private: - Display(); - - UpdateRects update_rects; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/engine/engine.cpp b/project/jni/application/fheroes2/src/engine/engine.cpp deleted file mode 100644 index 20741a2e8..000000000 --- a/project/jni/application/fheroes2/src/engine/engine.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "error.h" -#include "engine.h" -#include "font.h" -#include "sdlnet.h" - -namespace Mixer -{ - void Init(void); - void Quit(void); -} - -#ifdef WITH_AUDIOCD -namespace Cdrom -{ - void Open(void); - void Close(void); -} -#endif - -#ifdef _WIN32_WCE -namespace WINCE -{ - bool isRunning(void); - int CreateTrayIcon(void); - void DeleteTrayIcon(void); -} -#endif - -bool SDL::Init(const u32 system) -{ -#ifdef _WIN32_WCE - SDL_putenv("DEBUG_VIDEO=1"); - SDL_putenv("DEBUG_VIDEO_GAPI=1"); - - if(WINCE::isRunning()) return false; -#endif - - if(0 > SDL_Init(system)) - { - std::cerr << "SDL::Init: error: " << SDL_GetError() << std::endl; - return false; - } - - if(SDL_INIT_AUDIO & system) Mixer::Init(); -#ifdef WITH_AUDIOCD - if(SDL_INIT_CDROM & system) Cdrom::Open(); -#endif -#ifdef WITH_TTF - SDL::Font::Init(); -#endif -#ifdef WITH_NET - Network::Init(); -#endif - - SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); - -#ifdef _WIN32_WCE - WINCE::CreateTrayIcon(); -#endif - - return true; -} - -void SDL::Quit(void) -{ -#ifdef _WIN32_WCE - WINCE::DeleteTrayIcon(); -#endif - -#ifdef WITH_NET - Network::Quit(); -#endif -#ifdef WITH_TTF - SDL::Font::Quit(); -#endif -#ifdef WITH_AUDIOCD - if(SubSystem(SDL_INIT_CDROM)) Cdrom::Close(); -#endif - if(SubSystem(SDL_INIT_AUDIO)) Mixer::Quit(); - - SDL_Quit(); -} - -bool SDL::SubSystem(const u32 system) -{ - return system & SDL_WasInit(system); -} - -#ifdef _WIN32_WCE -#include -#include - -#ifdef __MINGW32CE__ -#undef Shell_NotifyIcon -extern "C" { -BOOL WINAPI Shell_NotifyIcon(DWORD, PNOTIFYICONDATAW); -}; -#endif - -// wincommon/SDL_sysevents.c -extern HICON screen_icn; -extern HINSTANCE SDL_Instance; -extern HWND SDL_Window; - -bool WINCE::isRunning(void) -{ - HWND hwnd = FindWindow(NULL, L"SDL_app"); - - if(hwnd) - { - ShowWindow(hwnd, SW_SHOW); - SetForegroundWindow(hwnd); - } - - return hwnd; -} - -int WINCE::CreateTrayIcon(void) -{ -#ifdef ID_ICON - NOTIFYICONDATA nid = {0}; - nid.cbSize = sizeof(nid); - nid.uID = ID_ICON; - nid.uFlags = NIF_ICON | NIF_MESSAGE; - nid.hWnd = SDL_Window; - nid.uCallbackMessage = WM_USER; - nid.hIcon = ::LoadIcon(SDL_Instance, MAKEINTRESOURCE(ID_ICON)); - return Shell_NotifyIcon(NIM_ADD, &nid); -#endif - return 0; -} - -void WINCE::DeleteTrayIcon(void) -{ -#ifdef ID_ICON - NOTIFYICONDATA nid = {0}; - nid.cbSize = sizeof(nid); - nid.uID = ID_ICON; - nid.hWnd = SDL_Window; - Shell_NotifyIcon(NIM_DELETE, &nid); -#endif -} -#endif diff --git a/project/jni/application/fheroes2/src/engine/engine.h b/project/jni/application/fheroes2/src/engine/engine.h deleted file mode 100644 index fe7243ab8..000000000 --- a/project/jni/application/fheroes2/src/engine/engine.h +++ /dev/null @@ -1,54 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2ENGINE_H -#define H2ENGINE_H - -#include "background.h" -#include "display.h" -#include "localevent.h" -#include "error.h" -#include "rect.h" -#include "spritecursor.h" -#include "surface.h" -#include "palette.h" -#include "rand.h" -#include "tools.h" -#include "audio.h" -#include "audio_mixer.h" -#include "audio_music.h" -#include "audio_cdrom.h" -#include "types.h" - -#define INIT_VIDEO SDL_INIT_VIDEO -#define INIT_AUDIO SDL_INIT_AUDIO -#define INIT_TIMER SDL_INIT_TIMER -#define INIT_CDROM SDL_INIT_CDROM - -namespace SDL -{ - bool Init(const u32 system = INIT_VIDEO); - void Quit(void); - - bool SubSystem(const u32 system); -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/error.cpp b/project/jni/application/fheroes2/src/engine/error.cpp deleted file mode 100644 index b23ab4c6f..000000000 --- a/project/jni/application/fheroes2/src/engine/error.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "error.h" - -/* exception */ -void Error::Except(const char* message, const char* cstr) -{ - std::cerr << "Error::Except: " << message << cstr << std::endl; - throw Exception(); -} diff --git a/project/jni/application/fheroes2/src/engine/error.h b/project/jni/application/fheroes2/src/engine/error.h deleted file mode 100644 index 579088838..000000000 --- a/project/jni/application/fheroes2/src/engine/error.h +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2ERROR_H -#define H2ERROR_H - -#include - -class Error -{ - -public: - Error(){}; - ~Error(){}; - - class Exception{}; - static void Except(const char*, const char*); -}; - -#endif diff --git a/project/jni/application/fheroes2/src/engine/font.cpp b/project/jni/application/fheroes2/src/engine/font.cpp deleted file mode 100644 index 160551c75..000000000 --- a/project/jni/application/fheroes2/src/engine/font.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_TTF - -#include -#include "font.h" -#include "engine.h" -#include "surface.h" -#include "SDL_ttf.h" - -bool SDL::Font::init = false; - -SDL::Font::Font() : fnt(NULL) -{ -} - -SDL::Font::~Font() -{ - if(fnt) TTF_CloseFont(fnt); -} - -void SDL::Font::Init(void) -{ - if(0 != TTF_Init()) std::cerr << "Font::Init: error" << std::endl; - else init = true; -} - -void SDL::Font::Quit(void) -{ - TTF_Quit(); - init = false; -} - -bool SDL::Font::isValid(void) const -{ - return fnt; -} - -bool SDL::Font::Open(const std::string & filename, u8 size) -{ - if(init) - { - if(fnt) TTF_CloseFont(fnt); - - fnt = TTF_OpenFont(filename.c_str(), size); - - if(!fnt) std::cerr << "Font::Open: error open: " << filename << std::endl; - } - return fnt; -} - -void SDL::Font::SetStyle(u8 style) -{ - if(fnt) TTF_SetFontStyle(fnt, style); -} - -void SDL::Font::RenderText(Surface & dst, const std::string & msg, const Colors & clr, render_t render) -{ - if(dst.surface) Surface::FreeSurface(dst); - if(fnt) switch(render) - { - case BLENDED: dst.surface = TTF_RenderUTF8_Blended(fnt, msg.c_str(), clr); break; - default: dst.surface = TTF_RenderUTF8_Solid(fnt, msg.c_str(), clr); break; - } -} - -void SDL::Font::RenderChar(Surface & dst, char ch, const Colors & clr, render_t render) -{ - char buf[2] = { '\0', '\0' }; - buf[0] = ch; - - if(dst.surface) Surface::FreeSurface(dst); - if(fnt) switch(render) - { - case BLENDED: dst.surface = TTF_RenderUTF8_Blended(fnt, buf, clr); break; - default: dst.surface = TTF_RenderUTF8_Solid(fnt, buf, clr); break; - } -} - -void SDL::Font::RenderUnicodeText(Surface & dst, const u16 *msg, const Colors & clr, render_t render) -{ - if(dst.surface) Surface::FreeSurface(dst); - if(fnt) switch(render) - { - case BLENDED: dst.surface = TTF_RenderUNICODE_Blended(fnt, msg, clr); break; - default: dst.surface = TTF_RenderUNICODE_Solid(fnt, msg, clr); break; - } -} - -void SDL::Font::RenderUnicodeChar(Surface & dst, u16 ch, const Colors & clr, render_t render) -{ - u16 buf[2] = { L'\0', L'\0' }; - buf[0] = ch; - - if(dst.surface) Surface::FreeSurface(dst); - if(fnt) switch(render) - { - case BLENDED: dst.surface = TTF_RenderUNICODE_Blended(fnt, buf, clr); break; - default: dst.surface = TTF_RenderUNICODE_Solid(fnt, buf, clr); break; - } -} - -int SDL::Font::Height(void) const -{ - return fnt ? TTF_FontHeight(fnt) : 0; -} - -int SDL::Font::Ascent(void) const -{ - return fnt ? TTF_FontAscent(fnt) : 0; -} - -int SDL::Font::Descent(void) const -{ - return fnt ? TTF_FontDescent(fnt) : 0; -} - -int SDL::Font::LineSkip(void) const -{ - return fnt ? TTF_FontLineSkip(fnt) : 0; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/font.h b/project/jni/application/fheroes2/src/engine/font.h deleted file mode 100644 index e07a18dfe..000000000 --- a/project/jni/application/fheroes2/src/engine/font.h +++ /dev/null @@ -1,68 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2FONT_H -#define H2FONT_H - -#ifdef WITH_TTF -#include -#include "types.h" -#include "SDL_ttf.h" - -class Surface; - -namespace SDL -{ - class Font - { - public: - enum render_t { SOLID, BLENDED }; - - Font(); - ~Font(); - - static void Init(void); - static void Quit(void); - - bool Open(const std::string &, u8); - bool isValid(void) const; - void SetStyle(u8); - - int Height(void) const; - int Ascent(void) const; - int Descent(void) const; - int LineSkip(void) const; - - void RenderText(Surface &, const std::string &, const Colors &, render_t = SOLID); - void RenderChar(Surface &, char, const Colors &, render_t = SOLID); - void RenderUnicodeText(Surface &, const u16 *, const Colors &, render_t = SOLID); - void RenderUnicodeChar(Surface &, u16, const Colors &, render_t = SOLID); - - private: - TTF_Font *fnt; - - static bool init; - }; -} -#endif - -#endif diff --git a/project/jni/application/fheroes2/src/engine/localevent.cpp b/project/jni/application/fheroes2/src/engine/localevent.cpp deleted file mode 100644 index ff788707f..000000000 --- a/project/jni/application/fheroes2/src/engine/localevent.cpp +++ /dev/null @@ -1,883 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "error.h" -#include "display.h" -#include "audio_music.h" -#include "audio_mixer.h" -#include "localevent.h" - -#define TAP_DELAY_EMULATE 1050 - -LocalEvent::LocalEvent() : modes(0), key_value(KEY_NONE), mouse_state(0), - mouse_button(0), mouse_st(0, 0), redraw_cursor_func(NULL), keyboard_filter_func(NULL), - clock_delay(TAP_DELAY_EMULATE), loop_delay(1) -{ -#ifdef WITHOUT_MOUSE - emulate_mouse = false; - emulate_mouse_up = KEY_UP; - emulate_mouse_down = KEY_DOWN; - emulate_mouse_left = KEY_LEFT; - emulate_mouse_right = KEY_RIGHT; - emulate_mouse_step = 10; - emulate_press_left = KEY_NONE; - emulate_press_right = KEY_NONE; -#endif -} - -const Point & LocalEvent::GetMousePressLeft(void) const -{ - return mouse_pl; -} - -const Point & LocalEvent::GetMousePressMiddle(void) const -{ - return mouse_pm; -} - -const Point & LocalEvent::GetMousePressRight(void) const -{ - return mouse_pr; -} - -const Point & LocalEvent::GetMouseReleaseLeft(void) const -{ - return mouse_rl; -} - -const Point & LocalEvent::GetMouseReleaseMiddle(void) const -{ - return mouse_rm; -} - -const Point & LocalEvent::GetMouseReleaseRight(void) const -{ - return mouse_rr; -} - -void LocalEvent::SetTapMode(bool f) -{ - if(f) - SetModes(TAP_MODE); - else - { - ResetModes(TAP_MODE); - ResetModes(CLOCK_ON); - clock.Stop(); - } -} - -void LocalEvent::SetTapDelayForRightClickEmulation(u32 d) -{ - clock_delay = d < 200 ? TAP_DELAY_EMULATE : d; -} - -void LocalEvent::SetMouseOffsetX(s16 x) -{ - SetModes(MOUSE_OFFSET); - mouse_st.x = x; -} - -void LocalEvent::SetMouseOffsetY(s16 y) -{ - SetModes(MOUSE_OFFSET); - mouse_st.y = y; -} - -void LocalEvent::SetModes(flag_t f) -{ - modes |= f; -} - -void LocalEvent::ResetModes(flag_t f) -{ - modes &= ~f; -} - -void LocalEvent::SetGlobalFilter(bool f) -{ - f ? SetModes(GLOBAL_FILTER) : ResetModes(GLOBAL_FILTER); -} - -const char* KeySymGetName(KeySym sym) -{ - return SDL_GetKeyName(static_cast(sym)); -} - -KeySym GetKeySym(int key) -{ - switch(key) - { - default: break; - - case SDLK_RETURN: return KEY_RETURN; - case SDLK_LEFT: return KEY_LEFT; - case SDLK_RIGHT: return KEY_RIGHT; - case SDLK_UP: return KEY_UP; - case SDLK_DOWN: return KEY_DOWN; - - case SDLK_ESCAPE: return KEY_ESCAPE; - case SDLK_KP_ENTER: return KEY_RETURN; - case SDLK_BACKSPACE: return KEY_BACKSPACE; - case SDLK_EXCLAIM: return KEY_EXCLAIM; - case SDLK_QUOTEDBL: return KEY_QUOTEDBL; - case SDLK_HASH: return KEY_HASH; - case SDLK_DOLLAR: return KEY_DOLLAR; - case SDLK_AMPERSAND: return KEY_AMPERSAND; - case SDLK_QUOTE: return KEY_QUOTE; - case SDLK_LEFTPAREN: return KEY_LEFTPAREN; - case SDLK_RIGHTPAREN: return KEY_RIGHTPAREN; - case SDLK_ASTERISK: return KEY_ASTERISK; - case SDLK_PLUS: return KEY_PLUS; - case SDLK_COMMA: return KEY_COMMA; - case SDLK_MINUS: return KEY_MINUS; - case SDLK_PERIOD: return KEY_PERIOD; - case SDLK_SLASH: return KEY_SLASH; - case SDLK_COLON: return KEY_COLON; - case SDLK_SEMICOLON: return KEY_SEMICOLON; - case SDLK_LESS: return KEY_LESS; - case SDLK_EQUALS: return KEY_EQUALS; - case SDLK_GREATER: return KEY_GREATER; - case SDLK_QUESTION: return KEY_QUESTION; - case SDLK_AT: return KEY_AT; - case SDLK_LEFTBRACKET: return KEY_LEFTBRACKET; - case SDLK_BACKSLASH: return KEY_BACKSLASH; - case SDLK_RIGHTBRACKET: return KEY_RIGHTBRACKET; - case SDLK_CARET: return KEY_CARET; - case SDLK_UNDERSCORE: return KEY_UNDERSCORE; - case SDLK_LALT: return KEY_ALT; - case SDLK_RALT: return KEY_ALT; - case SDLK_LCTRL: return KEY_CONTROL; - case SDLK_RCTRL: return KEY_CONTROL; - case SDLK_LSHIFT: return KEY_SHIFT; - case SDLK_RSHIFT: return KEY_SHIFT; - case SDLK_TAB: return KEY_TAB; - case SDLK_SPACE: return KEY_SPACE; - case SDLK_DELETE: return KEY_DELETE; - case SDLK_PAGEUP: return KEY_PAGEUP; - case SDLK_PAGEDOWN: return KEY_PAGEDOWN; - case SDLK_F1: return KEY_F1; - case SDLK_F2: return KEY_F2; - case SDLK_F3: return KEY_F3; - case SDLK_F4: return KEY_F4; - case SDLK_F5: return KEY_F5; - case SDLK_F6: return KEY_F6; - case SDLK_F7: return KEY_F7; - case SDLK_F8: return KEY_F8; - case SDLK_F9: return KEY_F9; - case SDLK_F10: return KEY_F10; - case SDLK_F11: return KEY_F11; - case SDLK_F12: return KEY_F12; - case SDLK_PRINT: return KEY_PRINT; - case SDLK_0: return KEY_0; - case SDLK_1: return KEY_1; - case SDLK_2: return KEY_2; - case SDLK_3: return KEY_3; - case SDLK_4: return KEY_4; - case SDLK_5: return KEY_5; - case SDLK_6: return KEY_6; - case SDLK_7: return KEY_7; - case SDLK_8: return KEY_8; - case SDLK_9: return KEY_9; - case SDLK_a: return KEY_a; - case SDLK_b: return KEY_b; - case SDLK_c: return KEY_c; - case SDLK_d: return KEY_d; - case SDLK_e: return KEY_e; - case SDLK_f: return KEY_f; - case SDLK_g: return KEY_g; - case SDLK_h: return KEY_h; - case SDLK_i: return KEY_i; - case SDLK_j: return KEY_j; - case SDLK_k: return KEY_k; - case SDLK_l: return KEY_l; - case SDLK_m: return KEY_m; - case SDLK_n: return KEY_n; - case SDLK_o: return KEY_o; - case SDLK_p: return KEY_p; - case SDLK_q: return KEY_q; - case SDLK_r: return KEY_r; - case SDLK_s: return KEY_s; - case SDLK_t: return KEY_t; - case SDLK_u: return KEY_u; - case SDLK_v: return KEY_v; - case SDLK_w: return KEY_w; - case SDLK_x: return KEY_x; - case SDLK_y: return KEY_y; - case SDLK_z: return KEY_z; - -#ifdef _WIN32_WCE - case 0xC1: return KEY_APP01; - case 0xC2: return KEY_APP02; - case 0xC3: return KEY_APP03; - case 0xC4: return KEY_APP04; - case 0xC5: return KEY_APP05; - case 0xC6: return KEY_APP06; - case 0xC7: return KEY_APP07; - case 0xC8: return KEY_APP08; - case 0xC9: return KEY_APP09; - case 0xCA: return KEY_APP10; - case 0xCB: return KEY_APP11; - case 0xCC: return KEY_APP12; - case 0xCD: return KEY_APP13; - case 0xCE: return KEY_APP14; - case 0xCF: return KEY_APP15; -#endif - } - - return KEY_NONE; -} - -LocalEvent & LocalEvent::Get(void) -{ - static LocalEvent le; - - return le; -} - -bool LocalEvent::HandleEvents(bool delay) -{ - SDL_Event event; - - ResetModes(MOUSE_MOTION); - ResetModes(KEY_PRESSED); - - while(SDL_PollEvent(&event)) - { - switch(event.type) - { - case SDL_ACTIVEEVENT: - if(event.active.state & SDL_APPACTIVE) - { - if(Mixer::isValid()) - { - //iconify - if(0 == event.active.gain) - { - Mixer::Reset(); - Music::Pause(); - loop_delay = 100; - } - else - loop_delay = 1; - } - } - break; - - // keyboard - case SDL_KEYDOWN: - case SDL_KEYUP: - HandleKeyboardEvent(event.key); - break; - - // mouse motion - case SDL_MOUSEMOTION: - HandleMouseMotionEvent(event.motion); - break; - - // mouse button - case SDL_MOUSEBUTTONDOWN: - case SDL_MOUSEBUTTONUP: - HandleMouseButtonEvent(event.button); - break; - - // exit - case SDL_QUIT: - Error::Except("LocalEvent::HandleEvents: ", "quit event: ok."); - return false; - - default: - break; - } - - // need for wheel up/down delay - if(SDL_BUTTON_WHEELDOWN == event.button.button || SDL_BUTTON_WHEELUP == event.button.button) break; - } - - // emulate press right - if((modes & TAP_MODE) && (modes & CLOCK_ON)) - { - clock.Stop(); - if(clock_delay < clock.Get()) - { - ResetModes(CLICK_LEFT); - ResetModes(CLOCK_ON); - mouse_pr = mouse_cu; - SetModes(MOUSE_PRESSED); - mouse_button = SDL_BUTTON_RIGHT; - } - } - - if(delay) SDL_Delay(loop_delay); - - return true; -} - -bool LocalEvent::MouseMotion(void) const -{ - return modes & MOUSE_MOTION; -} - -bool LocalEvent::MouseMotion(const Rect &rt) const -{ - return modes & MOUSE_MOTION ? rt & mouse_cu : false; -} - -bool LocalEvent::MousePressLeft(void) const -{ - return (modes & MOUSE_PRESSED) && SDL_BUTTON_LEFT == mouse_button; -} - -bool LocalEvent::MouseReleaseLeft(void) const -{ - return !(modes & MOUSE_PRESSED) && SDL_BUTTON_LEFT == mouse_button; -} - -bool LocalEvent::MousePressMiddle(void) const -{ - return (modes & MOUSE_PRESSED) && SDL_BUTTON_MIDDLE == mouse_button; -} - -bool LocalEvent::MouseReleaseMiddle(void) const -{ - return !(modes & MOUSE_PRESSED) && SDL_BUTTON_MIDDLE == mouse_button; -} - -bool LocalEvent::MousePressRight(void) const -{ - return (modes & MOUSE_PRESSED) && SDL_BUTTON_RIGHT == mouse_button; -} - -bool LocalEvent::MouseReleaseRight(void) const -{ - return !(modes & MOUSE_PRESSED) && SDL_BUTTON_RIGHT == mouse_button; -} - -void LocalEvent::HandleKeyboardEvent(SDL_KeyboardEvent & event) -{ - if(KEY_NONE != GetKeySym(event.keysym.sym)) - { - (event.type == SDL_KEYDOWN) ? SetModes(KEY_PRESSED) : ResetModes(KEY_PRESSED); - -#ifdef WITHOUT_MOUSE - if(emulate_mouse && EmulateMouseAction(GetKeySym(event.keysym.sym))) return; -#endif - - key_value = GetKeySym(event.keysym.sym); - } -} - -void LocalEvent::HandleMouseMotionEvent(const SDL_MouseMotionEvent & motion) -{ - mouse_state = motion.state; - SetModes(MOUSE_MOTION); - mouse_cu.x = motion.x; - mouse_cu.y = motion.y; - if(modes & MOUSE_OFFSET) mouse_cu += mouse_st; -} - -void LocalEvent::HandleMouseButtonEvent(const SDL_MouseButtonEvent & button) -{ - button.state == SDL_PRESSED ? SetModes(MOUSE_PRESSED) : ResetModes(MOUSE_PRESSED); - mouse_button = button.button; - - mouse_cu.x = button.x; - mouse_cu.y = button.y; - if(modes & MOUSE_OFFSET) mouse_cu += mouse_st; - - if(modes & MOUSE_PRESSED) - switch(button.button) - { - case SDL_BUTTON_WHEELDOWN: - case SDL_BUTTON_WHEELUP: - mouse_pm = mouse_cu; - break; - - case SDL_BUTTON_LEFT: - mouse_pl = mouse_cu; - SetModes(CLICK_LEFT); - - // emulate press right - if(modes & TAP_MODE){ clock.Start(); SetModes(CLOCK_ON); } - break; - - case SDL_BUTTON_MIDDLE: - mouse_pm = mouse_cu; - SetModes(CLICK_MIDDLE); - break; - - - case SDL_BUTTON_RIGHT: - mouse_pr = mouse_cu; - SetModes(CLICK_RIGHT); - break; - - default: - break; - } - else - switch(button.button) - { - case SDL_BUTTON_WHEELDOWN: - case SDL_BUTTON_WHEELUP: - mouse_rm = mouse_cu; - break; - - case SDL_BUTTON_LEFT: - mouse_rl = mouse_cu; - - // emulate press right - if(modes & TAP_MODE){ ResetModes(CLOCK_ON); } - break; - - case SDL_BUTTON_MIDDLE: - mouse_rm = mouse_cu; - break; - - - case SDL_BUTTON_RIGHT: - mouse_rr = mouse_cu; - break; - - default: - break; - } -} - -bool LocalEvent::MouseClickLeft(void) -{ - if(MouseReleaseLeft() && (CLICK_LEFT & modes)) - { - ResetModes(CLICK_LEFT); - return true; - } - - return false; -} - -bool LocalEvent::MouseClickLeft(const Rect &rt) -{ - //if(MouseReleaseLeft() && (rt & mouse_rl) && (CLICK_LEFT & modes) && ((modes & TAP_MODE) || (rt & mouse_pl))) - if(MouseReleaseLeft() && (rt & mouse_pl) && (rt & mouse_rl) && (CLICK_LEFT & modes)) - { - ResetModes(CLICK_LEFT); - return true; - } - - return false; -} - -bool LocalEvent::MouseClickMiddle(void) -{ - if(MouseReleaseMiddle() && (CLICK_MIDDLE & modes)) - { - ResetModes(CLICK_MIDDLE); - return true; - } - - return false; -} - -bool LocalEvent::MouseClickMiddle(const Rect &rt) -{ - if(MouseReleaseMiddle() && (rt & mouse_pm) && (rt & mouse_rm) && (CLICK_MIDDLE & modes)) - { - ResetModes(CLICK_MIDDLE); - return true; - } - - return false; -} - -bool LocalEvent::MouseClickRight(void) -{ - if(MouseReleaseRight() && (CLICK_RIGHT & modes)) - { - ResetModes(CLICK_RIGHT); - return true; - } - - return false; -} - -bool LocalEvent::MouseClickRight(const Rect &rt) -{ - if(MouseReleaseRight() && (rt & mouse_pr) && (rt & mouse_rr) && (CLICK_RIGHT & modes)) - { - ResetModes(CLICK_RIGHT); - return true; - } - - return false; -} - -bool LocalEvent::MouseWheelUp(void) const -{ - return (modes & MOUSE_PRESSED) && SDL_BUTTON_WHEELUP == mouse_button; -} - -bool LocalEvent::MouseWheelDn(void) const -{ - return (modes & MOUSE_PRESSED) && SDL_BUTTON_WHEELDOWN == mouse_button; -} - -bool LocalEvent::MousePressLeft(const Rect &rt) const -{ - return MousePressLeft() && (rt & mouse_pl); -} - -bool LocalEvent::MousePressLeft(const Point &pt, u16 w, u16 h) const -{ - return MousePressLeft() && (Rect(pt.x, pt.y, w, h) & mouse_pl); -} - -bool LocalEvent::MousePressMiddle(const Rect &rt) const -{ - return MousePressMiddle() && (rt & mouse_pm); -} - -bool LocalEvent::MousePressRight(const Rect &rt) const -{ - return MousePressRight() && (rt & mouse_pr); -} - -bool LocalEvent::MouseReleaseLeft(const Rect &rt) const -{ - return MouseReleaseLeft() && (rt & mouse_rl); -} - -bool LocalEvent::MouseReleaseMiddle(const Rect &rt) const -{ - return MouseReleaseMiddle() && (rt & mouse_rm); -} - -bool LocalEvent::MouseReleaseRight(const Rect &rt) const -{ - return MouseReleaseRight() && (rt & mouse_rr); -} - -void LocalEvent::ResetPressLeft(void) -{ - mouse_pl.x = -1; - mouse_pl.y = -1; -} - -void LocalEvent::ResetPressRight(void) -{ - mouse_pr.x = -1; - mouse_pr.y = -1; -} - -void LocalEvent::ResetPressMiddle(void) -{ - mouse_pm.x = -1; - mouse_pm.y = -1; -} - -void LocalEvent::ResetReleaseLeft(void) -{ - mouse_rl.x = -1; - mouse_rl.y = -1; -} - -void LocalEvent::ResetReleaseRight(void) -{ - mouse_rr.x = -1; - mouse_rr.y = -1; -} - -void LocalEvent::ResetReleaseMiddle(void) -{ - mouse_rm.x = -1; - mouse_rm.y = -1; -} - -bool LocalEvent::MouseWheelUp(const Rect &rt) const -{ - return MouseWheelUp() && (rt & mouse_cu); -} - -bool LocalEvent::MouseWheelDn(const Rect &rt) const -{ - return MouseWheelDn() && (rt & mouse_cu); -} - -bool LocalEvent::MouseCursor(const Rect &rt) const -{ - return rt & mouse_cu; -} - -const Point & LocalEvent::GetMouseCursor(void) -{ -#ifdef WITHOUT_MOUSE - if(!emulate_mouse) -#endif - { - int x, y; - - SDL_PumpEvents(); - SDL_GetMouseState(&x, &y); - - mouse_cu.x = x; - mouse_cu.y = y; - } - - if(modes & MOUSE_OFFSET) mouse_cu += mouse_st; - - return mouse_cu; -} - -u16 LocalEvent::KeyMod(void) const -{ - return SDL_GetModState(); -} - -KeySym LocalEvent::KeyValue(void) const -{ - return key_value; -} - -bool LocalEvent::KeyPress(void) const -{ - return modes & KEY_PRESSED; -} - -bool LocalEvent::KeyPress(KeySym key) const -{ - return key == key_value && (modes & KEY_PRESSED); -} - -void LocalEvent::SetGlobalFilterMouseEvents(void (*pf)(u16, u16)) -{ - redraw_cursor_func = pf; -} - -void LocalEvent::SetGlobalFilterKeysEvents(void (*pf)(int, u16)) -{ - keyboard_filter_func = pf; -} - -#if SDL_VERSION_ATLEAST(1, 3, 0) -int LocalEvent::GlobalFilterEvents(void *userdata, SDL_Event *event) -#else -int LocalEvent::GlobalFilterEvents(const SDL_Event *event) -#endif -{ - LocalEvent & le = LocalEvent::Get(); - - // motion - if((le.modes & GLOBAL_FILTER) && SDL_MOUSEMOTION == event->type) - { - // redraw cursor - if(le.redraw_cursor_func) - { - if(le.modes & MOUSE_OFFSET) - (*(le.redraw_cursor_func))(event->motion.x + le.mouse_st.x, event->motion.y + le.mouse_st.y); - else - (*(le.redraw_cursor_func))(event->motion.x, event->motion.y); - } - } - - // key - if((le.modes & GLOBAL_FILTER) && SDL_KEYDOWN == event->type) - - { - // key event - if(le.keyboard_filter_func) - (*(le.keyboard_filter_func))(event->key.keysym.sym, event->key.keysym.mod); - } - - return 1; -} - -void LocalEvent::SetState(u32 type, bool enable) -{ - SDL_EventState(type, enable ? SDL_ENABLE : SDL_IGNORE); -} - -u8 LocalEvent::GetState(u32 type) -{ - return SDL_EventState(type, SDL_QUERY); -} - -void LocalEvent::SetStateDefaults(void) -{ - // enable events - SetState(SDL_ACTIVEEVENT, true); - SetState(SDL_USEREVENT, true); - SetState(SDL_KEYDOWN, true); - SetState(SDL_KEYUP, true); - SetState(SDL_MOUSEMOTION, true); - SetState(SDL_MOUSEBUTTONDOWN, true); - SetState(SDL_MOUSEBUTTONUP, true); - SetState(SDL_QUIT, true); - - // ignore events - SetState(SDL_JOYAXISMOTION, false); - SetState(SDL_JOYBALLMOTION, false); - SetState(SDL_JOYHATMOTION, false); - SetState(SDL_JOYBUTTONUP, false); - SetState(SDL_JOYBUTTONDOWN, false); - SetState(SDL_SYSWMEVENT, false); - SetState(SDL_VIDEORESIZE, false); - SetState(SDL_VIDEOEXPOSE, false); - -#if SDL_VERSION_ATLEAST(1, 3, 0) - SDL_SetEventFilter(GlobalFilterEvents, NULL); -#else - SDL_SetEventFilter(GlobalFilterEvents); -#endif -} - -#ifdef WITHOUT_MOUSE -void LocalEvent::ToggleEmulateMouse(void) -{ - emulate_mouse = emulate_mouse ? false : true; -} - -void LocalEvent::SetEmulateMouse(bool f) -{ - emulate_mouse = f; - if(f) mouse_cu = Point(0, 0); -} - -void LocalEvent::SetEmulateMouseUpKey(KeySym k) -{ - emulate_mouse_up = k; -} - -void LocalEvent::SetEmulateMouseDownKey(KeySym k) -{ - emulate_mouse_down = k; -} - -void LocalEvent::SetEmulateMouseLeftKey(KeySym k) -{ - emulate_mouse_left = k; -} - -void LocalEvent::SetEmulateMouseRightKey(KeySym k) -{ - emulate_mouse_right = k; -} - -void LocalEvent::SetEmulateMouseStep(u8 s) -{ - emulate_mouse_step = s; -} - -void LocalEvent::SetEmulatePressLeftKey(KeySym k) -{ - emulate_press_left = k; -} - -void LocalEvent::SetEmulatePressRightKey(KeySym k) -{ - emulate_press_right = k; -} - -bool LocalEvent::EmulateMouseAction(KeySym key) -{ - if((key == emulate_mouse_up || - key == emulate_mouse_down || - key == emulate_mouse_left || - key == emulate_mouse_right || - key == emulate_press_left || - key == emulate_press_right)) - { - if(emulate_mouse_up == key) - { - mouse_cu.y -= emulate_mouse_step; - SetModes(MOUSE_MOTION); - } - else - if(emulate_mouse_down == key) - { - mouse_cu.y += emulate_mouse_step; - SetModes(MOUSE_MOTION); - } - else - if(emulate_mouse_left == key) - { - mouse_cu.x -= emulate_mouse_step; - SetModes(MOUSE_MOTION); - } - else - if(emulate_mouse_right == key) - { - mouse_cu.x += emulate_mouse_step; - SetModes(MOUSE_MOTION); - } - - if(mouse_cu.x < 0) mouse_cu.x = 0; - if(mouse_cu.y < 0) mouse_cu.y = 0; - if(mouse_cu.x > Display::Get().w()) mouse_cu.x = Display::Get().w(); - if(mouse_cu.y > Display::Get().h()) mouse_cu.y = Display::Get().h(); - - if(emulate_press_left == key) - { - if(modes & KEY_PRESSED) - { - mouse_pl = mouse_cu; - SetModes(MOUSE_PRESSED); - SetModes(CLICK_LEFT); - } - else - { - mouse_rl = mouse_cu; - ResetModes(MOUSE_PRESSED); - } - mouse_button = SDL_BUTTON_LEFT; - } - else - if(emulate_press_right == key) - { - if(modes & KEY_PRESSED) - { - mouse_pr = mouse_cu; - SetModes(MOUSE_PRESSED); - } - else - { - mouse_rr = mouse_cu; - ResetModes(MOUSE_PRESSED); - } - mouse_button = SDL_BUTTON_RIGHT; - } - - if((modes & MOUSE_MOTION) && redraw_cursor_func) - { - if(modes & MOUSE_OFFSET) - (*(redraw_cursor_func))(mouse_cu.x + mouse_st.x, mouse_cu.y + mouse_st.y); - else - (*(redraw_cursor_func))(mouse_cu.x, mouse_cu.y); - } - - ResetModes(KEY_PRESSED); - - return true; - } - - return false; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/localevent.h b/project/jni/application/fheroes2/src/engine/localevent.h deleted file mode 100644 index 5fb859a01..000000000 --- a/project/jni/application/fheroes2/src/engine/localevent.h +++ /dev/null @@ -1,306 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2006 by Andrey Afletdinov * - * Copyright (C) 2008 by Josh Matthews * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2LOCALEVENT_H -#define H2LOCALEVENT_H - -#include "rect.h" -#include "thread.h" -#include "types.h" - -enum KeyMod { MOD_NONE = KMOD_NONE, MOD_CTRL = KMOD_CTRL, MOD_SHIFT = KMOD_SHIFT, MOD_ALT = KMOD_ALT, MOD_CAPS = KMOD_CAPS }; - -enum KeySym -{ - KEY_NONE = -1, - - KEY_UNKNOWN = SDLK_UNKNOWN, - - KEY_BACKSPACE = SDLK_BACKSPACE, - KEY_RETURN = SDLK_RETURN, - KEY_ESCAPE = SDLK_ESCAPE, - KEY_SPACE = SDLK_SPACE, - KEY_EXCLAIM = SDLK_EXCLAIM, - KEY_QUOTEDBL = SDLK_QUOTEDBL, - KEY_HASH = SDLK_HASH, - KEY_DOLLAR = SDLK_DOLLAR, - KEY_AMPERSAND = SDLK_AMPERSAND, - KEY_QUOTE = SDLK_QUOTE, - KEY_LEFTPAREN = SDLK_LEFTPAREN, - KEY_RIGHTPAREN = SDLK_RIGHTPAREN, - KEY_ASTERISK = SDLK_ASTERISK, - KEY_PLUS = SDLK_PLUS, - KEY_COMMA = SDLK_COMMA, - KEY_MINUS = SDLK_MINUS, - KEY_PERIOD = SDLK_PERIOD, - KEY_SLASH = SDLK_SLASH, - KEY_COLON = SDLK_COLON, - KEY_SEMICOLON = SDLK_SEMICOLON, - KEY_LESS = SDLK_LESS, - KEY_EQUALS = SDLK_EQUALS, - KEY_GREATER = SDLK_GREATER, - KEY_QUESTION = SDLK_QUESTION, - KEY_AT = SDLK_AT, - KEY_LEFTBRACKET = SDLK_LEFTBRACKET, - KEY_BACKSLASH = SDLK_BACKSLASH, - KEY_RIGHTBRACKET = SDLK_RIGHTBRACKET, - KEY_CARET = SDLK_CARET, - KEY_UNDERSCORE = SDLK_UNDERSCORE, - KEY_ALT = SDLK_LALT, - KEY_CONTROL = SDLK_LCTRL, - KEY_SHIFT = SDLK_LSHIFT, - KEY_TAB = SDLK_TAB, - KEY_DELETE = SDLK_DELETE, - KEY_PAGEUP = SDLK_PAGEUP, - KEY_PAGEDOWN = SDLK_PAGEDOWN, - KEY_F1 = SDLK_F1, - KEY_F2 = SDLK_F2, - KEY_F3 = SDLK_F3, - KEY_F4 = SDLK_F4, - KEY_F5 = SDLK_F5, - KEY_F6 = SDLK_F6, - KEY_F7 = SDLK_F7, - KEY_F8 = SDLK_F8, - KEY_F9 = SDLK_F9, - KEY_F10 = SDLK_F10, - KEY_F11 = SDLK_F11, - KEY_F12 = SDLK_F12, - KEY_PRINT = SDLK_PRINT, - KEY_LEFT = SDLK_LEFT, - KEY_RIGHT = SDLK_RIGHT, - KEY_UP = SDLK_UP, - KEY_DOWN = SDLK_DOWN, - KEY_0 = SDLK_0, - KEY_1 = SDLK_1, - KEY_2 = SDLK_2, - KEY_3 = SDLK_3, - KEY_4 = SDLK_4, - KEY_5 = SDLK_5, - KEY_6 = SDLK_6, - KEY_7 = SDLK_7, - KEY_8 = SDLK_8, - KEY_9 = SDLK_9, - KEY_a = SDLK_a, - KEY_b = SDLK_b, - KEY_c = SDLK_c, - KEY_d = SDLK_d, - KEY_e = SDLK_e, - KEY_f = SDLK_f, - KEY_g = SDLK_g, - KEY_h = SDLK_h, - KEY_i = SDLK_i, - KEY_j = SDLK_j, - KEY_k = SDLK_k, - KEY_l = SDLK_l, - KEY_m = SDLK_m, - KEY_n = SDLK_n, - KEY_o = SDLK_o, - KEY_p = SDLK_p, - KEY_q = SDLK_q, - KEY_r = SDLK_r, - KEY_s = SDLK_s, - KEY_t = SDLK_t, - KEY_u = SDLK_u, - KEY_v = SDLK_v, - KEY_w = SDLK_w, - KEY_x = SDLK_x, - KEY_y = SDLK_y, - KEY_z = SDLK_z, - -#ifdef _WIN32_WCE - KEY_APP01 = 0xC1, - KEY_APP02 = 0xC2, - KEY_APP03 = 0xC3, - KEY_APP04 = 0xC4, - KEY_APP05 = 0xC5, - KEY_APP06 = 0xC6, - KEY_APP07 = 0xC7, - KEY_APP08 = 0xC8, - KEY_APP09 = 0xC9, - KEY_APP10 = 0xCA, - KEY_APP11 = 0xCB, - KEY_APP12 = 0xCC, - KEY_APP13 = 0xCD, - KEY_APP14 = 0xCE, - KEY_APP15 = 0xCF, -#endif - - KEY_LAST -}; - -const char* KeySymGetName(KeySym); -KeySym GetKeySym(int); - -class LocalEvent -{ -public: - static LocalEvent & Get(void); - - void SetGlobalFilterMouseEvents(void (*pf)(u16, u16)); - void SetGlobalFilterKeysEvents(void (*pf)(int, u16)); - void SetGlobalFilter(bool); - void SetTapMode(bool); - void SetTapDelayForRightClickEmulation(u32); - void SetMouseOffsetX(s16); - void SetMouseOffsetY(s16); - - static void SetStateDefaults(void); - static void SetState(u32 type, bool enable); - static u8 GetState(u32 type); - - bool HandleEvents(bool delay = true); - - bool MouseMotion(void) const; - bool MouseMotion(const Rect &rt) const; - - const Point & GetMouseCursor(void); - const Point & GetMousePressLeft(void) const; - const Point & GetMousePressMiddle(void) const; - const Point & GetMousePressRight(void) const; - const Point & GetMouseReleaseLeft(void) const; - const Point & GetMouseReleaseMiddle(void) const; - const Point & GetMouseReleaseRight(void) const; - - void ResetPressLeft(void); - void ResetPressRight(void); - void ResetPressMiddle(void); - - void ResetReleaseLeft(void); - void ResetReleaseRight(void); - void ResetReleaseMiddle(void); - - bool MouseClickLeft(void); - bool MouseClickMiddle(void); - bool MouseClickRight(void); - - bool MouseClickLeft(const Rect &rt); - bool MouseClickMiddle(const Rect &rt); - bool MouseClickRight(const Rect &rt); - - bool MouseWheelUp(void) const; - bool MouseWheelDn(void) const; - - bool MousePressLeft(void) const; - bool MousePressLeft(const Rect &rt) const; - bool MousePressLeft(const Point &pt, u16 w, u16 h) const; - bool MousePressMiddle(void) const; - bool MousePressMiddle(const Rect &rt) const; - bool MousePressRight(void) const; - bool MousePressRight(const Rect &rt) const; - - bool MouseReleaseLeft(void) const; - bool MouseReleaseLeft(const Rect &rt) const; - bool MouseReleaseMiddle(void) const; - bool MouseReleaseMiddle(const Rect &rt) const; - bool MouseReleaseRight(void) const; - bool MouseReleaseRight(const Rect &rt) const; - - bool MouseWheelUp(const Rect &rt) const; - bool MouseWheelDn(const Rect &rt) const; - - bool MouseCursor(const Rect &rt) const; - - bool KeyPress(void) const; - bool KeyPress(KeySym key) const; - KeySym KeyValue(void) const; - u16 KeyMod(void) const; - -#ifdef WITHOUT_MOUSE - void ToggleEmulateMouse(void); - void SetEmulateMouse(bool); - void SetEmulateMouseUpKey(KeySym); - void SetEmulateMouseDownKey(KeySym); - void SetEmulateMouseLeftKey(KeySym); - void SetEmulateMouseRightKey(KeySym); - void SetEmulateMouseStep(u8); - void SetEmulatePressLeftKey(KeySym); - void SetEmulatePressRightKey(KeySym); - bool EmulateMouseAction(KeySym); -#endif - -private: - LocalEvent(); - - void HandleMouseMotionEvent(const SDL_MouseMotionEvent & motion); - void HandleMouseButtonEvent(const SDL_MouseButtonEvent & button); - void HandleKeyboardEvent(SDL_KeyboardEvent &); - -#if SDL_VERSION_ATLEAST(1, 3, 0) - static int GlobalFilterEvents(void *userdata, SDL_Event *event); -#else - static int GlobalFilterEvents(const SDL_Event *event); -#endif - - enum flag_t - { - KEY_PRESSED = 0x0001, - MOUSE_MOTION = 0x0002, - MOUSE_PRESSED = 0x0004, - GLOBAL_FILTER = 0x0008, - CLICK_LEFT = 0x0010, - CLICK_RIGHT = 0x0020, - CLICK_MIDDLE = 0x0040, - TAP_MODE = 0x0080, - MOUSE_OFFSET = 0x0100, - CLOCK_ON = 0x0200 - }; - - void SetModes(flag_t); - void ResetModes(flag_t); - - u16 modes; - KeySym key_value; - u8 mouse_state; - u8 mouse_button; - - Point mouse_st; // mouse offset for pocketpc - - Point mouse_pl; // press left - Point mouse_pm; // press middle - Point mouse_pr; // press right - - Point mouse_rl; // release left - Point mouse_rm; // release middle - Point mouse_rr; // release right - - Point mouse_cu; // point cursor - - void (*redraw_cursor_func)(u16, u16); - void (*keyboard_filter_func)(int, u16); - - SDL::Time clock; - u32 clock_delay; - u8 loop_delay; - -#ifdef WITHOUT_MOUSE - bool emulate_mouse; - KeySym emulate_mouse_up; - KeySym emulate_mouse_down; - KeySym emulate_mouse_left; - KeySym emulate_mouse_right; - u8 emulate_mouse_step; - KeySym emulate_press_left; - KeySym emulate_press_right; -#endif -}; - -#endif diff --git a/project/jni/application/fheroes2/src/engine/midi.cpp b/project/jni/application/fheroes2/src/engine/midi.cpp deleted file mode 100644 index fa48e35eb..000000000 --- a/project/jni/application/fheroes2/src/engine/midi.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "midi.h" - -u8 MIDI::UnpackDelta(const u8 *p, u32 & d) -{ - const u8 *p2 = p; - d = 0; - - while(*p2 & 0x80) - { - if(4 <= p2 - p) - { - std::cerr << "Event: unpack delta mistake" << std::endl; - break; - } - - d |= 0x0000007F & static_cast(*p2); - d <<= 7; - ++p2; - } - - d += *p2; - - return p2 - p + 1; -} - -u8 MIDI::PackDelta(u8 *p, const u32 & d) -{ - const u8 c1 = static_cast(d & 0x0000007F); - const u8 c2 = static_cast((d & 0x00003F80) >> 7); - const u8 c3 = static_cast((d & 0x001FC000) >> 14); - const u8 c4 = static_cast((d & 0x0FE00000) >> 21); - - if(c4) - { p[0] = c4 | 0x80; p[1] = c3 | 0x80; p[2] = c2 | 0x80; p[3] = c1; } - else - if(c3) - { p[0] = c3 | 0x80; p[1] = c2 | 0x80; p[2] = c1; } - else - if(c2) - { p[0] = c2 | 0x80; p[1] = c1; } - else - { p[0] = c1; } - - return (c4 ? 4 : (c3 ? 3 : (c2 ? 2 : 1))); -} - diff --git a/project/jni/application/fheroes2/src/engine/midi.h b/project/jni/application/fheroes2/src/engine/midi.h deleted file mode 100644 index f4043f946..000000000 --- a/project/jni/application/fheroes2/src/engine/midi.h +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef MIDI_H -#define MIDI_H - -#include "types.h" - -namespace MIDI -{ - u8 UnpackDelta(const u8 *p, u32 & d); - u8 PackDelta(u8 *p, const u32 & d); -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/midi_chunk.cpp b/project/jni/application/fheroes2/src/engine/midi_chunk.cpp deleted file mode 100644 index f9e2969dd..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_chunk.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include - -#include "midi_chunk.h" - -using namespace MIDI; - -Chunk::Chunk() : size(0), data(NULL) -{ - memset(id, '\0', 4); -} - -Chunk::Chunk(const char *i, const u32 s, const u8 *p) : size(s), data(NULL) -{ - i ? memcpy(id, i, 4) : memset(id, '\0', 4); - - if(size) - { - data = new u8[size]; - - if(p) memcpy(data, p, size); else memset(data, '\0', size); - } -} - -Chunk::Chunk(std::istream & i) : size(0), data(NULL) -{ - memset(id, '\0', 4); - Read(i); -} - -Chunk::Chunk(const u8 *p) : size(0), data(NULL) -{ - memset(id, '\0', 4); - Read(p); -} - -Chunk::Chunk(const Chunk & c) : size(c.size), data(NULL) -{ - c.id ? memcpy(id, c.id, 4) : memset(id, '\0', 4); - - if(size) - { - data = new u8 [size]; - memcpy(data, c.data, size); - } -} - -Chunk::~Chunk() -{ - if(data) delete [] data; -} - -Chunk & Chunk::operator= (const Chunk & c) -{ - if(data) delete [] data; - data = NULL; - - c.id ? memcpy(id, c.id, 4) : memset(id, '\0', 4); - size = c.size; - - if(size) - { - data = new u8 [size]; - memcpy(data, c.data, size); - } - - return *this; -} - -bool Chunk::Read(std::istream & i) -{ - if(i.fail()) return false; - - i.read(id, 4); - - i.read(reinterpret_cast(&size), 4); - SwapBE32(size); - - if(data) delete [] data; - data = NULL; - - if(size) - { - data = new u8 [size]; - i.read(reinterpret_cast(data), size); - } - - return true; -} - -bool Chunk::Read(const std::vector & b) -{ - if(8 > b.size()) return false; - - memcpy(id, &b[0], 4); - - size = ReadBE32(&b[4]); - - if(data) delete [] data; - data = NULL; - - if(size + 8 > b.size()) size = b.size() - 8; - - if(size) - { - data = new u8 [size]; - memcpy(data, &b[8], size); - } - - return true; -} - -bool Chunk::Read(const u8 *p) -{ - if(NULL == p) return false; - - memcpy(id, p, 4); - - size = ReadBE32(&p[4]); - - if(data) delete [] data; - data = NULL; - - if(size) - { - data = new u8 [size]; - memcpy(data, &p[8], size); - } - - return true; -} - -bool Chunk::Write(std::ostream & o) const -{ - if(o.fail()) return false; - - o.write(id, 4); - - u32 x = size; - SwapBE32(x); - o.write(reinterpret_cast(&x), 4); - - if(size && data) o.write(reinterpret_cast(data), size); - - return true; -} - -bool Chunk::Write(u8 *p) const -{ - if(NULL == p) return false; - - memcpy(p, id, 4); - - WriteBE32(&p[4], size); - - if(size && data) memcpy(&p[8], data, size); - - return true; -} - -void Chunk::Dump(void) const -{ - std::cerr << "id: "; - std::cerr.write(id, 4); - std::cerr << std::endl << "size: " << std::dec << size << std::endl << "data: " << std::endl; - - u8 endline = 0; - for(u32 ii = 0; ii < size; ++ii) - { - std::cerr << " 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(static_cast(data[ii])) << ":"; - ++endline; - - if(endline > 15) - { - endline = 0; - std::cerr << std::endl; - } - } - std::cerr << std::endl; -} diff --git a/project/jni/application/fheroes2/src/engine/midi_chunk.h b/project/jni/application/fheroes2/src/engine/midi_chunk.h deleted file mode 100644 index c0032a472..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_chunk.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef MIDI_CHUNK_H -#define MIDI_CHUNK_H - -#include -#include -#include -#include "midi.h" - -namespace MIDI -{ - class Chunk - { - public: - char id[4]; - u32 size; - u8* data; - - Chunk(); - Chunk(const char *i, const u32 s, const u8 *p = NULL); - Chunk(std::istream & i); - Chunk(const u8 *p); - Chunk(const Chunk & c); - ~Chunk(); - - Chunk & operator= (const Chunk & c); - - bool Write(std::ostream & o) const; - bool Write(u8 *p) const; - - bool Read(std::istream & i); - bool Read(const u8 *p); - bool Read(const std::vector & b); - - void Dump(void) const; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/midi_event.cpp b/project/jni/application/fheroes2/src/engine/midi_event.cpp deleted file mode 100644 index dc3e3392f..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_event.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "midi_event.h" - -using namespace MIDI; - -Event::Event() : delta(0), status(0), sp(0) -{ -} - -Event::Event(const u32 dl, const u8 st, const u32 sz, const u8 *p) : delta(dl), status(st), data(NULL) -{ - if(sz) - { - data = new u8 [sz]; - size = sz; - memcpy(data, p, size); - } - - SetDelta(dl); -} - -Event::Event(const Event & e) -{ - delta = e.delta; - status = e.status; - - data = NULL; - size = e.size; - - if(size) - { - data = new u8 [size]; - memcpy(data, e.data, size); - } - - memcpy(pack, e.pack, 4); - sp = e.sp; -} - -Event::~Event() -{ - if(data) delete [] data; -} - -Event & Event::operator= (const Event & e) -{ - if(data) delete [] data; - - delta = e.delta; - status = e.status; - - data = NULL; - size = e.size; - - if(size) - { - data = new u8 [size]; - memcpy(data, e.data, size); - } - - memcpy(pack, e.pack, 4); - sp = e.sp; - - return *this; -} - -void Event::SetDelta(const u32 dl) -{ - sp = MIDI::PackDelta(pack, dl); -} - -u32 Event::Size(void) const -{ - return 1 + sp + size; -} - -bool Event::Write(u8 *p) const -{ - if(NULL == p) return false; - - memcpy(p, pack, sp); - p+= sp; - - *p = status; - - if(size) memcpy(p + 1, data, size); - - return true; -} - -bool Event::Write(std::ostream & o) const -{ - if(o.fail()) return false; - - o.write(reinterpret_cast(pack), sp); - o.write(&status, 1); - if(size) o.write(reinterpret_cast(data), size); - - return true; -} - -void Event::Dump(void) const -{ - std::cerr << std::hex << std::setfill('0') \ - << "[dl:0x" << std::setw(4) << delta \ - << ":st:0x" << std::setw(2) << static_cast(static_cast(status)) << ":dt"; - - u8 endline = 0; - for(u32 ii = 0; ii < size; ++ii) - { - std::cerr << " 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(static_cast(data[ii])) << ":"; - ++endline; - - if(endline > 15) - { - endline = 0; - std::cerr << std::endl; - } - } - - std::cerr << "]" << std::endl; -} diff --git a/project/jni/application/fheroes2/src/engine/midi_event.h b/project/jni/application/fheroes2/src/engine/midi_event.h deleted file mode 100644 index b753e6d5a..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_event.h +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef MIDI_EVENT_H -#define MIDI_EVENT_H - -#include -#include "midi.h" - -namespace MIDI -{ - class Event - { - public: - Event(); - Event(const u32 dl, const u8 st, const u32 sz, const u8 *p); - Event(const Event &); - ~Event(); - - Event & operator= (const Event &); - - u32 Size(void) const; - u32 Delta(void) const { return delta; }; - u8 Status(void) const { return status; }; - - void SetDelta(const u32 dl); - - void Dump(void) const; - bool Write(u8 *p) const; - bool Write(std::ostream & o) const; - - protected: - u32 delta; - char status; - - u8* data; - u32 size; - - u8 pack[4]; - u8 sp; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/midi_mid.cpp b/project/jni/application/fheroes2/src/engine/midi_mid.cpp deleted file mode 100644 index a806929a6..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_mid.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "midi_chunk.h" -#include "midi_mid.h" - -using namespace MIDI; - -Mid::Mid() -{ -} - -Mid::Mid(const Mid & m) : mthd(m.mthd) -{ - std::list::const_iterator it1 = m.tracks.begin(); - std::list::const_iterator it2 = m.tracks.end(); - - for(; it1 != it2; ++it1) if(*it1) tracks.push_back(new MTrk(**it1)); -} - -Mid::~Mid() -{ - if(tracks.size()) - { - std::list::const_iterator it1 = tracks.begin(); - std::list::const_iterator it2 = tracks.end(); - - for(; it1 != it2; ++it1) if(*it1) delete *it1; - } -} - -Mid & Mid::operator= (const Mid & m) -{ - mthd = m.mthd; - - if(tracks.size()) - { - std::list::const_iterator it1 = tracks.begin(); - std::list::const_iterator it2 = tracks.end(); - - for(; it1 != it2; ++it1) delete *it1; - } - - std::list::const_iterator it1 = m.tracks.begin(); - std::list::const_iterator it2 = m.tracks.end(); - - for(; it1 != it2; ++it1) if(*it1) tracks.push_back(new MTrk(**it1)); - - return *this; -} - -bool Mid::Read(const std::vector & body) -{ - mthd.Read(body); - - if(! mthd.isValid()) - { - std::cerr << "Mid::Read: " << "error format" << std::endl; - - return false; - } - - const u32 count = mthd.Tracks(); - const u8 *ptr = &body[mthd.Size()]; - - for(u16 ii = 0; ii < count; ++ii) - { - if(ptr >= &body[0] + body.size()) - { - std::cerr << "Mid::Read: " << "error read chunk, total: " << count << ", current: " << ii << std::endl; - - return false; - } - - const Chunk chunk(ptr); - - if(0 == memcmp(ID_MTRK, chunk.id, 4)) tracks.push_back(new MTrk(chunk.data, chunk.size)); - else --ii; - - ptr += 8 + chunk.size; - } - - return true; -} - -bool Mid::Read(const std::string & filename) -{ - std::ifstream fd(filename.c_str(), std::ios::binary); - - if(!fd.is_open()) - { - std::cerr << "Mid::Read: " << "error read: " << filename << std::endl; - - return false; - } - - mthd.Read(fd); - - if(! mthd.isValid()) - { - std::cerr << "Mid::Read: " << "error format: " << filename << std::endl; - - return false; - } - - const u32 count = mthd.Tracks(); - - for(u16 ii = 0; ii < count; ++ii) - { - if(fd.fail()) - { - std::cerr << "Mid::Read: " << "error read chunk, total: " << count << ", current: " << ii << std::endl; - - return false; - } - - const Chunk chunk(fd); - - if(0 == memcmp(ID_MTRK, chunk.id, 4)) tracks.push_back(new MTrk(chunk.data, chunk.size)); - else --ii; - } - - fd.close(); - - return true; -} - -u32 Mid::Size(void) const -{ - u32 total = mthd.Size(); - - if(tracks.size()) - { - std::list::const_iterator it1 = tracks.begin(); - std::list::const_iterator it2 = tracks.end(); - - for(; it1 != it2; ++it1) if(*it1) total += (*it1)->Size(); - } - - return total; -} - -bool Mid::Write(std::vector & body) -{ - body.resize(Size()); - u8 *ptr = &body[0]; - - mthd.Write(ptr); - ptr += mthd.Size(); - - if(tracks.size()) - { - std::list::const_iterator it1 = tracks.begin(); - std::list::const_iterator it2 = tracks.end(); - - for(; it1 != it2; ++it1) if(*it1){ (*it1)->Write(ptr); ptr += (*it1)->Size(); } - } - - return true; -} - -bool Mid::Write(const std::string & filename) -{ - std::ofstream fd(filename.c_str(), std::ios::binary); - - if(!fd.is_open()) - { - std::cerr << "Mid::Write: " << "error write: " << filename << std::endl; - - return false; - } - - mthd.Write(fd); - - if(tracks.size()) - { - std::list::const_iterator it1 = tracks.begin(); - std::list::const_iterator it2 = tracks.end(); - - for(; it1 != it2; ++it1) if(*it1) (*it1)->Write(fd); - } - - fd.close(); - - return true; -} - -void Mid::Dump(void) const -{ - mthd.Dump(); - - if(tracks.size()) - { - std::list::const_iterator it1 = tracks.begin(); - std::list::const_iterator it2 = tracks.end(); - - for(; it1 != it2; ++it1) if(*it1) (*it1)->Dump(); - } -} - -void Mid::AddTrack(MTrk & track) -{ - tracks.push_back(new MTrk(track)); - - mthd.SetTracks(mthd.Tracks() + 1); -} diff --git a/project/jni/application/fheroes2/src/engine/midi_mid.h b/project/jni/application/fheroes2/src/engine/midi_mid.h deleted file mode 100644 index fb8f91e90..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_mid.h +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef MIDI_MID_H -#define MIDI_MID_H - -#include -#include -#include "midi.h" -#include "midi_mthd.h" -#include "midi_mtrk.h" - -namespace MIDI -{ - class Mid - { - public: - Mid(); - Mid(const Mid & m); - ~Mid(); - - Mid & operator= (const Mid & m); - - bool Read(const std::string & filename); - bool Read(const std::vector & body); - - bool Write(const std::string & filename); - bool Write(std::vector & body); - - u32 Size(void) const; - - void SetFormat(const u16 f){ mthd.SetFormat(f); }; - void SetTracks(const u16 t){ mthd.SetTracks(t); }; - void SetPPQN(const u16 p){ mthd.SetPPQN(p); }; - void AddTrack(MTrk & track); - - void Dump(void) const; - - private: - MThd mthd; - std::list tracks; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/midi_mthd.cpp b/project/jni/application/fheroes2/src/engine/midi_mthd.cpp deleted file mode 100644 index 6cd1926f8..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_mthd.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "midi_mthd.h" - -using namespace MIDI; - -void MThd::Dump(void) const -{ - std::cerr << "[MThd] format: " << Format() << ", tracks: " << Tracks() << ", ppqn: " << PPQN() << std::endl; -} - -void MThd::SetFormat(const u16 f) -{ - WriteBE16(reinterpret_cast(&data[0]), f); -} - -void MThd::SetTracks(const u16 t) -{ - WriteBE16(reinterpret_cast(&data[2]), t); -} - -void MThd::SetPPQN(const u16 p) -{ - WriteBE16(reinterpret_cast(&data[4]), p); -} diff --git a/project/jni/application/fheroes2/src/engine/midi_mthd.h b/project/jni/application/fheroes2/src/engine/midi_mthd.h deleted file mode 100644 index c347c8849..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_mthd.h +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef MIDI_MTHD_H -#define MIDI_MTHD_H - -#include -#include -#include -#include "midi.h" -#include "midi_chunk.h" - -#define ID_MTHD "MThd" - -namespace MIDI -{ - class MThd : protected Chunk - { - public: - MThd() : Chunk(ID_MTHD, 6) {}; - MThd(const u8 *p, const u32 s) : Chunk(ID_MTHD, s, p) {}; - MThd(std::istream & i) : Chunk(i) {}; - - bool isValid(void) const{ return 0 == memcmp(Chunk::id, ID_MTHD, 4); }; - bool Read(std::istream & is){ return Chunk::Read(is); }; - bool Read(const std::vector & b){ return Chunk::Read(b); }; - bool Write(std::ostream & os) const{ return Chunk::Write(os); }; - bool Write(u8* b) const{ return Chunk::Write(b); }; - - void SetFormat(const u16 f); - void SetTracks(const u16 t); - void SetPPQN(const u16 p); - - const u8* Data(void) const{ return Chunk::data; }; - u32 Size(void) const{ return 8 + size; }; - u16 Format(void) const{ return ReadBE16(reinterpret_cast(&data[0])); }; - u16 Tracks(void) const{ return ReadBE16(reinterpret_cast(&data[2])); }; - u16 PPQN(void) const{ return ReadBE16(reinterpret_cast(&data[4])); }; - - void Dump(void) const; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/midi_mtrk.cpp b/project/jni/application/fheroes2/src/engine/midi_mtrk.cpp deleted file mode 100644 index fda6f0251..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_mtrk.cpp +++ /dev/null @@ -1,348 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include "midi_mtrk.h" - -using namespace MIDI; - -struct meta_t -{ - meta_t() : command(0), quantity(0), duration(0){} - meta_t(u8 c, u8 q, u32 d) : command(c), quantity(q), duration(d){} - - bool operator< (const meta_t & m) const{ return duration < m.duration; } - void decrease_duration(u32 delta) { duration -= delta; } - - u8 command; - u8 quantity; - u32 duration; -}; - - -MTrk::MTrk(const u8 *p, const u32 s) -{ - const u8 *ptr = p; - bool end = false; - - while(ptr && !end && ptr < (p + s)) - { - u32 delta = 0; - const u8 s = MIDI::UnpackDelta(ptr, delta); - ptr += s; - const u8 status = *ptr; - ptr += 1; - - switch(status >> 4) - { - // meta - case 0x0F: - { - u32 size = 0; - const u8 s = MIDI::UnpackDelta(ptr + 1, size); - if(0xFF == status && 0x2F == *ptr) - { - end = true; - events.push_back(new Event(delta, status, 1 + s + size, ptr)); - } - ptr += 1 + s + size; - } - break; - - // note off - case 0x08: - // note on - case 0x09: - // key pressure - case 0x0A: - // control change - case 0x0B: - // pitch bend - case 0x0E: - { - events.push_back(new Event(delta, status, 2, ptr)); - ptr += 2; - } - break; - - // program change - case 0x0C: - // chanel pressure - case 0x0D: - { - events.push_back(new Event(delta, status, 1, ptr)); - ptr += 1; - } - break; - - // unused command - default: - end = true; - CloseEvents(); - std::cerr << "unknown st: 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(status) << ", ln: " << static_cast(p + s - ptr) << std::endl; - break; - } - } -} - - -MTrk::MTrk(const MTrk & t) -{ - std::list::const_iterator it1 = t.events.begin(); - std::list::const_iterator it2 = t.events.end(); - - for(; it1 != it2; ++it1) if(*it1) events.push_back(new Event(**it1)); -} - -MTrk::~MTrk() -{ - if(events.size()) - { - std::list::const_iterator it1 = events.begin(); - std::list::const_iterator it2 = events.end(); - - for(; it1 != it2; ++it1) if(*it1) delete *it1; - } -} - -u32 MTrk::Size(void) const -{ - u32 result = 8; // id + size - - std::list::const_iterator it1 = events.begin(); - std::list::const_iterator it2 = events.end(); - for(; it1 != it2; ++it1) if(*it1) result += (*it1)->Size(); - - return result; -} - -bool MTrk::Write(std::ostream & o) const -{ - if(o.fail()) return false; - - o.write(ID_MTRK, 4); - - u32 size = 0; - std::list::const_iterator it1 = events.begin(); - std::list::const_iterator it2 = events.end(); - for(; it1 != it2; ++it1) if(*it1) size += (*it1)->Size(); - - u32 x = size; - SwapBE32(x); - o.write(reinterpret_cast(&x), 4); - - if(events.size()) - { - it1 = events.begin(); - it2 = events.end(); - for(; it1 != it2; ++it1) if(*it1) (*it1)->Write(o); - } - - return true; -} - -bool MTrk::Write(u8 *p) const -{ - if(NULL == p) return false; - - memcpy(p, ID_MTRK, 4); - p+= 4; - - u32 size = 0; - std::list::const_iterator it1 = events.begin(); - std::list::const_iterator it2 = events.end(); - for(; it1 != it2; ++it1) if(*it1) size += (*it1)->Size(); - - u32 x = size; - WriteBE32(p, x); - p+= 4; - - if(events.size()) - { - it1 = events.begin(); - it2 = events.end(); - for(; it1 != it2; ++it1) if(*it1){ (*it1)->Write(p); p += (*it1)->Size(); } - } - - return true; -} - -void MTrk::AddEvent(const Event & e) -{ - events.push_back(new Event(e)); -} - -void MTrk::CloseEvents(void) -{ - events.push_back(new Event(0, 0xFF, 2, reinterpret_cast("\057\000"))); -} - -void MTrk::Dump(void) const -{ - std::cerr << "[MTrk]\n"; - - if(events.size()) - { - std::list::const_iterator it1 = events.begin(); - std::list::const_iterator it2 = events.end(); - for(; it1 != it2; ++it1) if(*it1) (*it1)->Dump(); - } - std::cerr << std::endl; -} - -void MTrk::ImportXmiEVNT(const Chunk & evnt) -{ - const u8 *ptr = evnt.data; - - u8 buf[2]; - u32 delta = 0; - u32 delta2 = 0; - - std::list notesoff; - std::list::iterator it1, it2; - - while(ptr && ptr < (evnt.data + evnt.size)) - { - // insert event: note off - if(delta) - { - // sort duration - notesoff.sort(); - - it1 = notesoff.begin(); - it2 = notesoff.end(); - delta2 = 0; - - // apply delta - for(; it1 != it2; ++it1) - { - if((*it1).duration <= delta) - { - buf[0] = (*it1).quantity; - buf[1] = 0x7F; - - // note off - events.push_back(new Event((*it1).duration - delta2, (*it1).command, 2, buf)); - delta2 += ((*it1).duration - delta2); - } - } - - // remove end notes - while(notesoff.size() && notesoff.front().duration <= delta) - notesoff.pop_front(); - - // fixed delta - if(delta2) delta -= delta2; - - // decrease duration - std::for_each(notesoff.begin(), notesoff.end(), std::bind2nd(std::mem_fun_ref(&meta_t::decrease_duration), delta)); - } - - // interval - if(*ptr < 128) - { - delta += *ptr; - ++ptr; - } - else - // command - { - // end - if(0xFF == *ptr && 0x2F == *(ptr + 1)) - { - events.push_back(new Event(delta, *ptr, 2, ptr + 1)); - break; - } - else - switch(*ptr >> 4) - { - // meta - case 0x0F: - { - u32 size = 0; - size += 1 + MIDI::UnpackDelta(ptr + 2, size); - ptr += size + 1; - delta = 0; - } - break; - - // key pressure - case 0x0A: - // control change - case 0x0B: - // pitch bend - case 0x0E: - { - events.push_back(new Event(delta, *ptr, 2, ptr + 1)); - ptr += 3; - delta = 0; - } - break; - - // note off - case 0x08: - { - events.push_back(new Event(delta, *ptr, 2, ptr + 1)); - u32 duration = 0; - const u8 s = MIDI::UnpackDelta(ptr + 3, duration); - notesoff.push_back(meta_t(*ptr - 0x10, *(ptr + 1), duration)); - ptr += 3 + s; - delta = 0; - } - break; - - // note on - case 0x09: - { - events.push_back(new Event(delta, *ptr, 2, ptr + 1)); - u32 duration = 0; - const u8 s = MIDI::UnpackDelta(ptr + 3, duration); - notesoff.push_back(meta_t(*ptr - 0x10, *(ptr + 1), duration)); - ptr += 3 + s; - delta = 0; - } - break; - - // program change - case 0x0C: - // chanel pressure - case 0x0D: - { - events.push_back(new Event(delta, *ptr, 1, ptr + 1)); - ptr += 2; - delta = 0; - } - break; - - // unused command - default: - CloseEvents(); - std::cerr << "unknown st: 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(*ptr) << ", ln: " << static_cast(evnt.data + evnt.size - ptr) << std::endl; - break; - } - } - } -} diff --git a/project/jni/application/fheroes2/src/engine/midi_mtrk.h b/project/jni/application/fheroes2/src/engine/midi_mtrk.h deleted file mode 100644 index f7b28f888..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_mtrk.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef MIDI_TRACK_H -#define MIDI_TRACK_H - -#include -#include -#include "midi.h" -#include "midi_chunk.h" -#include "midi_event.h" - -#define ID_MTRK "MTrk" - -namespace MIDI -{ - u8 UnpackDelta(const char *p, u32 & d); - u8 PackDelta(char *p, const u32 & d); - - class MTrk - { - public: - MTrk() {}; - MTrk(const u8 *p, const u32 s); - MTrk(const MTrk & t); - ~MTrk(); - - bool Write(std::ostream & o) const; - bool Write(u8 *p) const; - u32 Size(void) const; - - void AddEvent(const Event & e); - void ImportXmiEVNT(const Chunk & c); - void CloseEvents(void); - - void Dump(void) const; - - private: - std::list events; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/midi_xmi.cpp b/project/jni/application/fheroes2/src/engine/midi_xmi.cpp deleted file mode 100644 index d67d9e338..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_xmi.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include "midi_xmi.h" - -#define ID_FORM "FORM" -#define ID_CAT "CAT " -#define ID_XMID "XMID" -#define ID_TIMB "TIMB" -#define ID_EVNT "EVNT" - -using namespace MIDI; - -Xmi::Xmi() -{ -} - -bool Xmi::Read(const std::vector & body) -{ - if(0 == body.size()) - { - std::cerr << "Xmi: " << "incorrect size" << std::endl; - return false; - } - - const u8 *ptr = &body[0]; - - if(memcmp(ID_FORM, ptr, 4)) - { - std::cerr << "Xmi: " << "incorrect id: " << ID_FORM << std::endl; - return false; - } - - head.Read(ptr); - ptr += 8 + head.size; - - if(memcmp(ID_CAT, ptr, 4)) - { - std::cerr << "Xmi: " << "incorrect id: " << ID_CAT<< std::endl; - return false; - } - - ptr += 8; - - if(memcmp(ID_XMID, ptr, 4)) - { - std::cerr << "Xmi: " << "incorrect cat id: " << ID_XMID << std::endl; - return false; - } - - ptr += 4; - - if(memcmp(ID_FORM, ptr, 4)) - { - std::cerr << "Xmi: " << "incorrect xmid id: " << ID_FORM << std::endl; - return false; - } - else - ptr += 8; - - if(memcmp(ID_XMID, ptr, 4)) - { - std::cerr << "Xmi: " << "incorrect form id: " << ID_XMID << std::endl; - return false; - } - - ptr += 4; - - if(memcmp(ID_TIMB, ptr, 4)) - { - std::cerr << "Xmi: " << "incorrect id: " << ID_TIMB << std::endl; - return false; - } - - timb.Read(ptr); - ptr += 8 + timb.size; - - if(memcmp(ID_EVNT, ptr, 4)) - { - std::cerr << "Xmi: " << "incorrect id: " << ID_EVNT << std::endl; - return false; - } - - evnt.Read(ptr); - - return true; -} - -bool Xmi::Read(const std::string & filename) -{ - std::ifstream fd(filename.c_str(), std::ios::binary); - - if(!fd.is_open()) - { - std::cerr << "Xmi: " << "error read: " << filename.c_str() << std::endl; - return false; - } - - fd.seekg(0, std::ios_base::end); - const u32 size = fd.tellg(); - fd.seekg(0, std::ios_base::beg); - - std::vector body(size); - fd.read(reinterpret_cast(&body[0]), size); - fd.close(); - - return Read(body); -} - -void Xmi::Dump(void) const -{ - head.Dump(); - timb.Dump(); - evnt.Dump(); -} diff --git a/project/jni/application/fheroes2/src/engine/midi_xmi.h b/project/jni/application/fheroes2/src/engine/midi_xmi.h deleted file mode 100644 index 9515fa3d1..000000000 --- a/project/jni/application/fheroes2/src/engine/midi_xmi.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef MIDI_XMI_H -#define MIDI_XMI_H - -#include -#include "midi.h" -#include "midi_chunk.h" - -namespace MIDI -{ - class Xmi - { - public: - Xmi(); - - bool Read(const std::string & filename); - bool Read(const std::vector & body); - - const Chunk & TIMB(void) const { return timb; } - const Chunk & EVNT(void) const { return evnt; } - - void Dump(void) const; - - private: - Chunk head; - Chunk timb; - Chunk evnt; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/palette.cpp b/project/jni/application/fheroes2/src/engine/palette.cpp deleted file mode 100644 index 4c0107dd3..000000000 --- a/project/jni/application/fheroes2/src/engine/palette.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "SDL.h" -#include "surface.h" -#include "error.h" -#include "palette_h2.h" -#include "palette.h" - -#define PALETTE_SIZE 255 - -Palette::Palette() -{ - sdlpal = new SDL_Palette; - sdlpal->ncolors = PALETTE_SIZE; - sdlpal->colors = new SDL_Color[PALETTE_SIZE]; - - pal = new u32 [PALETTE_SIZE]; - - Surface sfa; - sfa.CreateSurface(1, 1, Surface::GetDefaultDepth(), SDL_SWSURFACE|SDL_SRCALPHA); - const unsigned char *p = kb_pal; - - for(u16 ii = 0; ii < PALETTE_SIZE; ++ii) - { - sdlpal->colors[ii].r = *p++; - sdlpal->colors[ii].g = *p++; - sdlpal->colors[ii].b = *p++; - - sdlpal->colors[ii].r <<= 2; - sdlpal->colors[ii].g <<= 2; - sdlpal->colors[ii].b <<= 2; - - pal[ii] = SDL_MapRGBA(sfa.surface->format, sdlpal->colors[ii].r, sdlpal->colors[ii].g, sdlpal->colors[ii].b, 0xFF); - } -} - -Palette::~Palette() -{ - if(sdlpal) - { - if(sdlpal->colors) delete [] sdlpal->colors; - delete sdlpal; - } - if(pal) delete [] pal; -} - -Palette & Palette::Get(void) -{ - static Palette pal_cache; - - return pal_cache; -} - -u16 Palette::Size(void) const -{ - return PALETTE_SIZE; -} - -u32 Palette::GetColor(u16 index) const -{ - return index < PALETTE_SIZE ? pal[index] : 0; -} - -const SDL_Palette * Palette::SDLPalette(void) const -{ - return sdlpal; -} diff --git a/project/jni/application/fheroes2/src/engine/palette.h b/project/jni/application/fheroes2/src/engine/palette.h deleted file mode 100644 index f9c95583f..000000000 --- a/project/jni/application/fheroes2/src/engine/palette.h +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2PALETTE_H -#define H2PALETTE_H - -#include "types.h" - -struct SDL_Palette; -struct SDL_Color; - -class Palette -{ -public: - ~Palette(); - - static Palette & Get(void); - - u16 Size(void) const; - u32 GetColor(u16) const; - const SDL_Palette * SDLPalette(void) const; - -private: - Palette(); - - u32* pal; - SDL_Palette *sdlpal; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/engine/palette_h2.h b/project/jni/application/fheroes2/src/engine/palette_h2.h deleted file mode 100644 index 6ead61def..000000000 --- a/project/jni/application/fheroes2/src/engine/palette_h2.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef H2KBPAL_H -#define H2KBPAL_H - -static const unsigned char kb_pal[] = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x3f, - 0x3f, 0x3c, 0x3c, 0x3c, 0x3a, 0x3a, 0x3a, 0x37, 0x37, 0x37, 0x35, 0x35, 0x35, 0x32, 0x32, 0x32, - 0x30, 0x30, 0x30, 0x2d, 0x2d, 0x2d, 0x2b, 0x2b, 0x2b, 0x29, 0x29, 0x29, 0x26, 0x26, 0x26, 0x24, - 0x24, 0x24, 0x21, 0x21, 0x21, 0x1f, 0x1f, 0x1f, 0x1c, 0x1c, 0x1c, 0x1a, 0x1a, 0x1a, 0x17, 0x17, - 0x17, 0x15, 0x15, 0x15, 0x12, 0x12, 0x12, 0x10, 0x10, 0x10, 0x0e, 0x0e, 0x0e, 0x0b, 0x0b, 0x0b, - 0x09, 0x09, 0x09, 0x06, 0x06, 0x06, 0x04, 0x04, 0x04, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x3f, - 0x3b, 0x37, 0x3c, 0x37, 0x32, 0x3a, 0x34, 0x2e, 0x38, 0x31, 0x2a, 0x36, 0x2e, 0x26, 0x34, 0x2a, - 0x22, 0x32, 0x28, 0x1e, 0x30, 0x25, 0x1b, 0x2e, 0x22, 0x18, 0x2b, 0x1f, 0x15, 0x29, 0x1c, 0x12, - 0x27, 0x1a, 0x0f, 0x25, 0x18, 0x0d, 0x23, 0x15, 0x0b, 0x21, 0x13, 0x08, 0x1f, 0x11, 0x07, 0x1d, - 0x0f, 0x05, 0x1a, 0x0d, 0x04, 0x18, 0x0c, 0x03, 0x16, 0x0a, 0x02, 0x14, 0x09, 0x01, 0x12, 0x07, - 0x01, 0x0f, 0x06, 0x00, 0x0d, 0x05, 0x00, 0x0b, 0x04, 0x00, 0x09, 0x03, 0x00, 0x30, 0x33, 0x3f, - 0x2b, 0x2e, 0x3c, 0x26, 0x2a, 0x3a, 0x22, 0x26, 0x38, 0x1e, 0x22, 0x36, 0x1a, 0x1e, 0x34, 0x16, - 0x1a, 0x31, 0x13, 0x16, 0x2f, 0x10, 0x13, 0x2d, 0x0d, 0x10, 0x2b, 0x0a, 0x0d, 0x29, 0x08, 0x0c, - 0x26, 0x07, 0x0a, 0x24, 0x05, 0x09, 0x22, 0x04, 0x08, 0x20, 0x03, 0x07, 0x1e, 0x02, 0x06, 0x1c, - 0x01, 0x05, 0x19, 0x01, 0x05, 0x17, 0x00, 0x04, 0x15, 0x00, 0x03, 0x13, 0x00, 0x03, 0x11, 0x2b, - 0x38, 0x27, 0x27, 0x35, 0x23, 0x24, 0x33, 0x20, 0x20, 0x30, 0x1c, 0x1d, 0x2e, 0x19, 0x1a, 0x2c, - 0x17, 0x17, 0x29, 0x14, 0x14, 0x27, 0x11, 0x12, 0x24, 0x0f, 0x0f, 0x22, 0x0c, 0x0d, 0x1f, 0x0a, - 0x0b, 0x1d, 0x09, 0x09, 0x1b, 0x07, 0x08, 0x19, 0x06, 0x06, 0x17, 0x05, 0x05, 0x15, 0x03, 0x03, - 0x13, 0x02, 0x02, 0x10, 0x01, 0x01, 0x0e, 0x01, 0x01, 0x0c, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x08, - 0x00, 0x00, 0x06, 0x00, 0x3f, 0x3d, 0x34, 0x3e, 0x3a, 0x2b, 0x3d, 0x38, 0x23, 0x3c, 0x37, 0x1b, - 0x3b, 0x35, 0x14, 0x3a, 0x33, 0x0d, 0x39, 0x32, 0x05, 0x38, 0x31, 0x00, 0x36, 0x2f, 0x08, 0x34, - 0x2c, 0x07, 0x32, 0x28, 0x06, 0x2f, 0x26, 0x06, 0x2d, 0x23, 0x06, 0x2a, 0x1f, 0x05, 0x27, 0x1c, - 0x04, 0x25, 0x19, 0x03, 0x22, 0x16, 0x03, 0x1f, 0x13, 0x02, 0x1d, 0x11, 0x02, 0x1a, 0x0f, 0x00, - 0x18, 0x0c, 0x00, 0x15, 0x0a, 0x00, 0x13, 0x08, 0x00, 0x39, 0x33, 0x3e, 0x36, 0x2f, 0x3b, 0x32, - 0x2a, 0x39, 0x30, 0x27, 0x36, 0x2d, 0x23, 0x34, 0x2a, 0x1f, 0x31, 0x27, 0x1c, 0x2f, 0x24, 0x19, - 0x2d, 0x21, 0x16, 0x2a, 0x1e, 0x13, 0x28, 0x1c, 0x11, 0x25, 0x19, 0x0e, 0x23, 0x17, 0x0c, 0x20, - 0x14, 0x0a, 0x1e, 0x12, 0x08, 0x1b, 0x10, 0x06, 0x19, 0x0e, 0x05, 0x17, 0x0b, 0x02, 0x14, 0x08, - 0x01, 0x11, 0x06, 0x00, 0x0e, 0x04, 0x00, 0x0b, 0x2d, 0x3d, 0x3f, 0x2a, 0x3a, 0x3c, 0x28, 0x38, - 0x3a, 0x25, 0x36, 0x38, 0x22, 0x33, 0x35, 0x20, 0x31, 0x33, 0x1e, 0x2e, 0x31, 0x1c, 0x2c, 0x2f, - 0x19, 0x2a, 0x2c, 0x17, 0x27, 0x2a, 0x16, 0x25, 0x28, 0x14, 0x23, 0x25, 0x12, 0x20, 0x23, 0x10, - 0x1d, 0x20, 0x0e, 0x1a, 0x1d, 0x0c, 0x18, 0x1b, 0x0a, 0x15, 0x18, 0x08, 0x13, 0x16, 0x07, 0x10, - 0x13, 0x05, 0x0e, 0x10, 0x04, 0x0b, 0x0e, 0x03, 0x09, 0x0b, 0x02, 0x07, 0x09, 0x3f, 0x39, 0x39, - 0x3d, 0x34, 0x34, 0x3c, 0x2f, 0x2f, 0x3a, 0x2b, 0x2b, 0x39, 0x27, 0x27, 0x37, 0x23, 0x23, 0x36, - 0x1f, 0x1f, 0x34, 0x1b, 0x1b, 0x33, 0x17, 0x17, 0x31, 0x14, 0x14, 0x30, 0x11, 0x11, 0x2f, 0x0e, - 0x0e, 0x2e, 0x0b, 0x0b, 0x2d, 0x09, 0x09, 0x2a, 0x08, 0x08, 0x27, 0x06, 0x06, 0x24, 0x04, 0x04, - 0x21, 0x03, 0x03, 0x1e, 0x02, 0x02, 0x1b, 0x01, 0x01, 0x18, 0x00, 0x00, 0x15, 0x00, 0x00, 0x12, - 0x00, 0x00, 0x3f, 0x39, 0x27, 0x3e, 0x36, 0x23, 0x3d, 0x34, 0x1f, 0x3c, 0x31, 0x1c, 0x3b, 0x2e, - 0x18, 0x3a, 0x2b, 0x14, 0x39, 0x28, 0x11, 0x38, 0x24, 0x0e, 0x38, 0x21, 0x0b, 0x33, 0x1d, 0x08, - 0x2e, 0x19, 0x06, 0x29, 0x16, 0x04, 0x25, 0x12, 0x02, 0x20, 0x0f, 0x01, 0x1b, 0x0c, 0x00, 0x17, - 0x0a, 0x00, 0x3f, 0x16, 0x03, 0x37, 0x0d, 0x01, 0x30, 0x05, 0x00, 0x29, 0x00, 0x00, 0x3f, 0x3f, - 0x00, 0x3f, 0x33, 0x00, 0x30, 0x23, 0x00, 0x23, 0x12, 0x00, 0x29, 0x34, 0x00, 0x25, 0x2f, 0x00, - 0x21, 0x2b, 0x00, 0x1e, 0x27, 0x01, 0x1a, 0x23, 0x01, 0x17, 0x1e, 0x01, 0x13, 0x1a, 0x01, 0x10, - 0x16, 0x01, 0x0d, 0x12, 0x01, 0x0a, 0x1e, 0x34, 0x06, 0x1a, 0x31, 0x01, 0x12, 0x2d, 0x00, 0x0e, - 0x2b, 0x03, 0x15, 0x2f, 0x00, 0x0e, 0x2b, 0x00, 0x10, 0x2d, 0x21, 0x38, 0x3f, 0x00, 0x26, 0x3f, - 0x00, 0x14, 0x39, 0x00, 0x00, 0x29, 0x23, 0x23, 0x2f, 0x1c, 0x1c, 0x27, 0x15, 0x15, 0x1f, 0x0f, - 0x0f, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -#endif diff --git a/project/jni/application/fheroes2/src/engine/rand.cpp b/project/jni/application/fheroes2/src/engine/rand.cpp deleted file mode 100644 index 7e93f8592..000000000 --- a/project/jni/application/fheroes2/src/engine/rand.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include "rand.h" - - -void Rand::Init(void){ std::srand((u32) std::time(0)); } - -u32 Rand::Get(u32 min, u32 max){ return max ? min + Get(max - min) : static_cast((min + 1) * (std::rand() / (RAND_MAX + 1.0))); } - -Rand::Queue::Queue(u32 size) -{ - reserve(size); -} - -void Rand::Queue::Reset(void) -{ - clear(); -} - -void Rand::Queue::Push(s32 value, u32 percent) -{ - if(percent) - push_back(std::make_pair(value, percent)); -} - -size_t Rand::Queue::Size(void) const -{ - return size(); -} - -s32 Rand::Queue::Get(void) -{ - std::vector::iterator it; - - // get max - it = begin(); - u32 max = 0; - for(; it != end(); ++it) max += (*it).second; - - // set weight (from 100) - it = begin(); - for(; it != end(); ++it) (*it).second = 100 * (*it).second / max; - - // get max - max = 0; - it = begin(); - for(; it != end(); ++it) max += (*it).second; - - u8 rand = Rand::Get(max); - u8 amount = 0; - - it = begin(); - for(; it != end(); ++it) - { - amount += (*it).second; - if(rand <= amount) return (*it).first; - } - - std::cerr << "Rand::Queue::Get:" << " weight not found, return 0" << std::endl; - return 0; -} diff --git a/project/jni/application/fheroes2/src/engine/rand.h b/project/jni/application/fheroes2/src/engine/rand.h deleted file mode 100644 index 61d62b868..000000000 --- a/project/jni/application/fheroes2/src/engine/rand.h +++ /dev/null @@ -1,69 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2RAND_H -#define H2RAND_H - -#include -#include -#include -#include "types.h" - -namespace Rand -{ - void Init(void); - u32 Get(u32 min, u32 max = 0); - - template< typename T > const T * Get(const std::vector< T > & vec) - { - if(vec.empty()) return NULL; - - return & vec[Rand::Get(vec.size() - 1)]; - } - - template< typename T > const T * Get(const std::list< T > & list) - { - if(list.empty()) return NULL; - - u32 index1 = Rand::Get(list.size() - 1); - u32 index2 = 0; - typename std::list::const_iterator it = list.begin(); - - for(; it != list.end(); ++it) if(index1 == index2++) break; - - return & (*it); - } - - typedef std::pair ValuePercent; - - class Queue : private std::vector - { - public: - Queue(u32 size = 0); - - void Reset(void); - void Push(s32, u32); - size_t Size(void) const; - s32 Get(void); - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/rect.cpp b/project/jni/application/fheroes2/src/engine/rect.cpp deleted file mode 100644 index 212dbbd4e..000000000 --- a/project/jni/application/fheroes2/src/engine/rect.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "rect.h" - -Point::Point(s16 px, s16 py) : x(px), y(py) -{ -} - -bool Point::operator== (const Point & pt) const -{ - return (x == pt.x && y == pt.y); -} - -bool Point::operator!= (const Point & pt) const -{ - return !(*this == pt); -} - -Point & Point::operator+=(const Point & pt) -{ - x += pt.x; - y += pt.y; - - return *this; -} - -Point & Point::operator-=(const Point & pt) -{ - x -= pt.x; - y -= pt.y; - - return *this; -} - -Point operator+(const Point& pt1, const Point& pt2) -{ - return Point(pt1.x + pt2.x, pt1.y + pt2.y); -} - -Point operator-(const Point& pt1, const Point& pt2) -{ - return Point(pt1.x - pt2.x, pt1.y - pt2.y); -} - -Size::Size(u16 sw, u16 sh) : w(sw), h(sh) -{ -} - -bool Size::operator== (const Size & sz) const -{ - return (w == sz.w && h == sz.h); -} - -bool Size::operator!= (const Size & sz) const -{ - return !(*this == sz); -} - -bool Size::isEmpty(void) const -{ - return 0 == w && 0 == h; -} - -Rect::Rect(s16 rx, s16 ry, u16 rw, u16 rh) : Point(rx, ry), Size(rw, rh) -{ -} - -Rect::Rect(const SDL_Rect & rt) : Point(rt.x, rt.y), Size(rt.w, rt.h) -{ -} - -Rect::Rect(const Point & pt, u16 rw, u16 rh) : Point(pt), Size(rw, rh) -{ -} - -Rect::Rect(const Point & pt, const Size & sz) : Point(pt), Size(sz) -{ -} - -Rect::Rect(const Rect & rt1, const Rect & rt2) -{ - x = rt1.x < rt2.x ? rt1.x : rt2.x; - y = rt1.y < rt2.y ? rt1.y : rt2.y; - w = rt1.x + rt1.w > rt2.x + rt2.w ? rt1.x + rt1.w - x : rt2.x + rt2.w - x; - h = rt1.y + rt1.h > rt2.y + rt2.h ? rt1.y + rt1.h - y : rt2.y + rt2.h - y; -} - -Rect::Rect(const std::vector & vect) -{ - int x1 = 32766; - int y1 = 32766; - int x2 = -32766; - int y2 = -32766; - - std::vector::const_iterator it = vect.begin(); - - for(; it != vect.end(); ++it) - { - if((*it).x < x1) x1 = (*it).x; - if((*it).y < y1) y1 = (*it).y; - if((*it).x + (*it).w > x2) x2 = (*it).x + (*it).w; - if((*it).y + (*it).h > y2) y2 = (*it).y + (*it).h; - } - - x = x1; - y = y1; - w = x2 - x1; - h = y2 - y1; -} - -Rect & Rect::operator= (const Point & pt) -{ - x = pt.x; - y = pt.y; - - return *this; -} - -bool Rect::operator== (const Rect & rt) const -{ - return (x == rt.x && y == rt.y && w == rt.w && h == rt.h); -} - -bool Rect::operator!= (const Rect & rt) const -{ - return !(*this == rt); -} - -bool Rect::operator& (const Point & pt) const -{ - return !(pt.x < x || pt.y < y || pt.x >= (x + w) || pt.y >= (y + h)); -} - -bool Rect::operator& (const Rect & rt) const -{ - return - ((rt.x >= x && rt.x < x + w) || - (rt.x + rt.w >= x && rt.x + rt.w < x + w) || - (x >= rt.x && x < rt.x + rt.w) || - (x + w >= rt.x && x + w < rt.x + rt.w)) && - ((rt.y >= y && rt.y < y + h) || - (rt.y + rt.h >= y && rt.y + rt.h < y + h) || - (y >= rt.y && y < rt.y + rt.h) || - (y + h >= rt.y && y + h < rt.y + rt.h)); -} diff --git a/project/jni/application/fheroes2/src/engine/rect.h b/project/jni/application/fheroes2/src/engine/rect.h deleted file mode 100644 index 63e6ece60..000000000 --- a/project/jni/application/fheroes2/src/engine/rect.h +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2RECT_H -#define H2RECT_H - -#include -#include -#include "types.h" - -struct Point -{ - s16 x, y; - - Point(s16 px = 0, s16 py = 0); - - bool operator== (const Point & pt) const; - bool operator!= (const Point & pt) const; - - Point & operator+=(const Point & pt); - Point & operator-=(const Point & pt); -}; - -Point operator+(const Point& pt1, const Point& pt2); - -Point operator-(const Point& pt1, const Point& pt2); - -struct Size -{ - u16 w, h; - - Size(u16 sw = 0, u16 sh = 0); - - bool isEmpty(void) const; - - bool operator== (const Size & sz) const; - bool operator!= (const Size & sz) const; -}; - -struct Rect : Point, Size -{ - Rect(s16 rx = -1, s16 ry = -1, u16 rw = 0, u16 rh = 0); - Rect(const SDL_Rect & rt); - Rect(const Point & pt, u16 rw, u16 rh); - Rect(const Point & pt, const Size & sz); - Rect(const Rect & rt1, const Rect & rt2); - Rect(const std::vector & vect); - - Rect & operator= (const Point & pt); - bool operator== (const Rect & rt) const; - bool operator!= (const Rect & rt) const; - - // rect include point - bool operator& (const Point & pt) const; - - // rect intersects rect - bool operator& (const Rect & rt) const; -}; - -struct RectIncludePoint : std::binary_function -{ - bool operator() (const Rect & r, const Point & p) const { return r & p; }; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/engine/sdlnet.cpp b/project/jni/application/fheroes2/src/engine/sdlnet.cpp deleted file mode 100644 index 48c17391e..000000000 --- a/project/jni/application/fheroes2/src/engine/sdlnet.cpp +++ /dev/null @@ -1,575 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include "sdlnet.h" - -#define BUFSIZE 16 - -QueueMessage::QueueMessage() : type(0), data(NULL), itd1(NULL), itd2(NULL), dtsz(BUFSIZE) -{ - data = new char [dtsz + 1]; - - itd1 = data; - itd2 = itd1; -} - -QueueMessage::QueueMessage(u16 id) : type(id), data(NULL), itd1(NULL), itd2(NULL), dtsz(BUFSIZE) -{ - data = new char [dtsz + 1]; - - itd1 = data; - itd2 = itd1; -} - -QueueMessage::QueueMessage(const QueueMessage & msg) : type(msg.type), data(NULL), itd1(NULL), itd2(NULL), dtsz(msg.dtsz) -{ - data = new char [dtsz + 1]; - - std::memcpy(data, msg.data, dtsz); - itd1 = msg.itd1 > msg.data ? &data[msg.itd1 - msg.data] : data; - itd2 = msg.itd2 > msg.data ? &data[msg.itd2 - msg.data] : itd1; -} - -QueueMessage & QueueMessage::operator= (const QueueMessage & msg) -{ - type = msg.type; - dtsz = msg.dtsz; - data = new char [dtsz + 1]; - - std::memcpy(data, msg.data, dtsz); - itd1 = msg.itd1 > msg.data ? &data[msg.itd1 - msg.data] : data; - itd2 = msg.itd2 > msg.data ? &data[msg.itd2 - msg.data] : itd1; - - return *this; -} - -QueueMessage::~QueueMessage() -{ - if(data) delete [] data; -} - -void QueueMessage::Resize(size_t lack) -{ - const size_t newsize = lack > dtsz ? dtsz + lack + 1 : 2 * dtsz + 1; - char* dat2 = new char [newsize]; - std::memcpy(dat2, data, dtsz); - itd1 = &dat2[itd1 - data]; - itd2 = &dat2[itd2 - data]; - dtsz = newsize - 1; - delete [] data; - data = dat2; -} - -size_t QueueMessage::Size(void) const -{ - return itd2 - data; -} - -u16 QueueMessage::GetID(void) const -{ - return type; -} - -void QueueMessage::SetID(u16 id) -{ - type = id; -} - -void QueueMessage::Reserve(size_t size) -{ - delete [] data; - dtsz = size; - data = new char [dtsz + 1]; - - itd1 = data; - itd2 = itd1; -} - -void QueueMessage::Reset(void) -{ - type = 0; - - if(BUFSIZE != dtsz) - { - delete [] data; - dtsz = BUFSIZE; - data = new char [dtsz + 1]; - } - - itd1 = data; - itd2 = itd1; -} - -void QueueMessage::SoftReset(void) -{ - itd1 = data; -} - -void QueueMessage::Push(s8 byte8) -{ - Push(static_cast(byte8)); -} - -void QueueMessage::Push(u8 byte8) -{ - if(data + dtsz < itd2 + 1) Resize(1); - - *itd2 = byte8; - ++itd2; -} - -void QueueMessage::Push(s16 byte16) -{ - Push(static_cast(byte16)); -} - -void QueueMessage::Push(u16 byte16) -{ - if(data + dtsz < itd2 + 2) Resize(2); - - *itd2 = 0x00FF & (byte16 >> 8); - ++itd2; - - *itd2 = 0x00FF & byte16; - ++itd2; -} - -void QueueMessage::Push(s32 byte32) -{ - Push(static_cast(byte32)); -} - -void QueueMessage::Push(u32 byte32) -{ - if(data + dtsz < itd2 + 4) Resize(4); - - *itd2 = 0x000000FF & (byte32 >> 24); - ++itd2; - - *itd2 = 0x000000FF & (byte32 >> 16); - ++itd2; - - *itd2 = 0x000000FF & (byte32 >> 8); - ++itd2; - - *itd2 = 0x000000FF & byte32; - ++itd2; -} - -void QueueMessage::Push(const std::string & str) -{ - Push(str.c_str()); -} - -void QueueMessage::Push(const char* str) -{ - const size_t len = std::strlen(str); - if(data + dtsz < itd2 + len + 1) Resize(len + 1); - - while(*str) *itd2++ = *str++; - - // end string - *itd2 = 0; - ++itd2; -} - -bool QueueMessage::Pop(s8 & byte8) -{ - u8 tmp; - if(Pop(tmp)) - { - byte8 = tmp; - return true; - } - return false; -} - -bool QueueMessage::Pop(u8 & byte8) -{ - if(itd1 + 1 > itd2) return false; - - byte8 = *itd1; - ++itd1; - - return true; -} - -bool QueueMessage::Pop(s16 & byte16) -{ - u16 tmp; - if(Pop(tmp)) - { - byte16 = tmp; - return true; - } - return false; -} - -bool QueueMessage::Pop(u16 & byte16) -{ - if(itd1 + 2 > itd2) return false; - - byte16 = *itd1; - byte16 <<= 8; - ++itd1; - - byte16 |= (0x00FF & *itd1); - ++itd1; - - return true; -} - -bool QueueMessage::Pop(s32 & byte32) -{ - u32 tmp; - if(Pop(tmp)) - { - byte32 = tmp; - return true; - } - return false; -} - -bool QueueMessage::Pop(u32 & byte32) -{ - if(itd1 + 4 > itd2) return false; - - byte32 = *itd1; - byte32 <<= 8; - ++itd1; - - byte32 |= (0x000000FF & *itd1); - byte32 <<= 8; - ++itd1; - - byte32 |= (0x000000FF & *itd1); - byte32 <<= 8; - ++itd1; - - byte32 |= (0x000000FF & *itd1); - ++itd1; - - return true; -} - -bool QueueMessage::Pop(std::string & str) -{ - if(itd1 >= itd2) return false; - - // find end string - char* end = itd1; - while(*end && end < itd2) ++end; - if(end == itd2) return false; - - str = itd1; - itd1 = end + 1; - - return true; -} - -void QueueMessage::Dump(std::ostream & stream) const -{ - stream << "Network::QueueMessage::Dump: type: 0x" << std::hex << type << ", size: " << std::dec << DtSz(); - - stream << ", data:"; - const char* cur = itd1; - u8 cast; - while(cur < itd2){ cast = *cur; stream << " 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(cast); ++cur; } - - stream << std::endl; -} - -const char* QueueMessage::DtPt(void) const -{ - return itd1; -} - -size_t QueueMessage::DtSz(void) const -{ - return itd2 > itd1 ? itd2 - itd1 : 0; -} - -void QueueMessage::Save(const char* fn) const -{ - std::ofstream fs(fn, std::ios::binary); - - if(fs.is_open()) - { - fs.write(DtPt(), DtSz()); - fs.close(); - } -} - -void QueueMessage::Load(const char* fn) -{ - std::ifstream fs(fn, std::ios::binary); - - if(fs.is_open()) - { - fs.seekg(0, std::ios_base::end); - dtsz = fs.tellg(); - fs.seekg(0, std::ios_base::beg); - - delete [] data; - data = new char [dtsz + 1]; - - fs.read(data, dtsz); - fs.close(); - - itd1 = data; - itd2 = itd1 + dtsz; - } -} - -#ifdef WITH_NET - -namespace Network -{ - static u16 proto = 0xFF01; -} - -void Network::SetProtocolVersion(u16 v) -{ - proto = v; -} - -bool Network::RecvMessage(const Network::Socket & csd, QueueMessage & msg, bool debug) -{ - u16 head; - msg.type = 0; - - if(csd.Recv(reinterpret_cast(&head), sizeof(head))) - { - SwapBE16(head); - - // check id - if((0xFF00 & Network::proto) != (0xFF00 & head)) - { - if(debug) std::cerr << "Network::QueueMessage::Recv: " << "unknown packet id: 0x" << std::hex << head << std::endl; - return false; - } - - // check ver - if((0x00FF & Network::proto) > (0x00FF & head)) - { - if(debug) std::cerr << "Network::QueueMessage::Recv: " << "obsolete protocol ver: 0x" << std::hex << (0x00FF & head) << std::endl; - return false; - } - - u32 size; - - if(csd.Recv(reinterpret_cast(&msg.type), sizeof(msg.type)) && - csd.Recv(reinterpret_cast(&size), sizeof(size))) - { - msg.type = SDL_SwapBE16(msg.type); - size = SDL_SwapBE32(size); - - if(size > msg.dtsz) - { - delete [] msg.data; - msg.data = new char [size + 1]; - msg.dtsz = size; - } - - msg.itd1 = msg.data; - msg.itd2 = msg.itd1 + size; - - return size ? csd.Recv(msg.data, size) : true; - } - } - return false; -} - -bool Network::SendMessage(const Network::Socket & csd, const QueueMessage & msg) -{ - // raw data - if(0 == msg.type) - return msg.Size() ? csd.Send(reinterpret_cast(msg.data), msg.Size()) : false; - - u16 head = Network::proto; - u16 sign = msg.type; - u32 size = msg.Size(); - - SwapBE16(head); - SwapBE16(sign); - SwapBE32(size); - - return csd.Send(reinterpret_cast(&head), sizeof(head)) && - csd.Send(reinterpret_cast(&sign), sizeof(sign)) && - csd.Send(reinterpret_cast(&size), sizeof(size)) && - (size ? csd.Send(msg.data, msg.Size()) : true); -} - -Network::Socket::Socket() : sd(NULL), sdset(NULL) -{ -} - -Network::Socket::Socket(const TCPsocket csd) : sd(NULL), sdset(NULL) -{ - Assign(csd); -} - -Network::Socket::Socket(const Socket &) : sd(NULL), sdset(NULL) -{ -} - -Network::Socket & Network::Socket::operator= (const Socket &) -{ - return *this; -} - -Network::Socket::~Socket() -{ - if(sd) Close(); -} - -void Network::Socket::Assign(const TCPsocket csd) -{ - if(sd) Close(); - - if(csd) - { - sd = csd; - sdset = SDLNet_AllocSocketSet(1); - if(sdset) SDLNet_TCP_AddSocket(sdset, sd); - } -} - - -u32 Network::Socket::Host(void) const -{ - IPaddress* remoteIP = sd ? SDLNet_TCP_GetPeerAddress(sd) : NULL; - if(remoteIP) return SDLNet_Read32(&remoteIP->host); - - std::cerr << "Network::Socket::Host: " << GetError() << std::endl; - return 0; -} - -u16 Network::Socket::Port(void) const -{ - IPaddress* remoteIP = sd ? SDLNet_TCP_GetPeerAddress(sd) : NULL; - if(remoteIP) return SDLNet_Read16(&remoteIP->port); - - std::cerr << "Network::Socket::Host: " << GetError() << std::endl; - return 0; -} - -bool Network::Socket::Ready(void) const -{ - return 0 < SDLNet_CheckSockets(sdset, 1) && 0 < SDLNet_SocketReady(sd); -} - -bool Network::Socket::Recv(char *buf, size_t len) const -{ - if(sd && buf && len) - { - int rcv = 0; - while((rcv = SDLNet_TCP_Recv(sd, buf, len)) > 0 && rcv < static_cast(len)) - { - buf += rcv; - len -= rcv; - } - if(rcv == static_cast(len)) return true; - std::cerr << "Network::Socket::Recv: " << "size: " << std::dec << len << ", receive: " << rcv << ", error: " << GetError() << std::endl; - } - return false; -} - -bool Network::Socket::Send(const char* buf, size_t len) const -{ - return sd && static_cast(len) == SDLNet_TCP_Send(sd, const_cast(reinterpret_cast(buf)), len); -} - -bool Network::Socket::Open(IPaddress & ip) -{ - Assign(SDLNet_TCP_Open(&ip)); - - if(! sd) - std::cerr << "Network::Socket::Open: " << Network::GetError() << std::endl; - - return sd; -} - -bool Network::Socket::IsValid(void) const -{ - return sd; -} - -void Network::Socket::Close(void) -{ - if(sd) - { - if(sdset) - { - SDLNet_TCP_DelSocket(sdset, sd); - SDLNet_FreeSocketSet(sdset); - sdset = NULL; - } - SDLNet_TCP_Close(sd); - sd = NULL; - } -} - -Network::Server::Server() -{ -} - -TCPsocket Network::Server::Accept(void) -{ - return SDLNet_TCP_Accept(sd); -} - -bool Network::Init(void) -{ - if(SDLNet_Init() < 0) - { - std::cerr << "Network::Init: " << GetError() << std::endl; - return false; - } - return true; -} - -void Network::Quit(void) -{ - SDLNet_Quit(); -} - -bool Network::ResolveHost(IPaddress & ip, const char* host, u16 port) -{ - if(SDLNet_ResolveHost(&ip, host, port) < 0) - { - std::cerr << "Network::ResolveHost: " << GetError() << std::endl; - return false; - } - return true; -} - -const char* Network::GetError(void) -{ - return SDLNet_GetError(); -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/sdlnet.h b/project/jni/application/fheroes2/src/engine/sdlnet.h deleted file mode 100644 index c06538841..000000000 --- a/project/jni/application/fheroes2/src/engine/sdlnet.h +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef SDLNET_H -#define SDLNET_H - -#include -#include "types.h" -#include - -#ifdef WITH_NET -#include "SDL_net.h" - -class QueueMessage; - -namespace Network -{ - bool Init(void); - void Quit(void); - bool ResolveHost(IPaddress &, const char*, u16); - const char* GetError(void); - void SetProtocolVersion(u16); - - class Socket - { - public: - Socket(); - Socket(const TCPsocket); - ~Socket(); - - void Assign(const TCPsocket); - - bool Ready(void) const; - - bool Recv(char *, size_t) const; - bool Send(const char*, size_t) const; - - u32 Host(void) const; - u16 Port(void) const; - - bool Open(IPaddress &); - bool IsValid(void) const; - void Close(void); - - protected: - Socket(const Socket &); - Socket & operator= (const Socket &); - - TCPsocket sd; - SDLNet_SocketSet sdset; - }; - - class Server : public Socket - { - public: - Server(); - - TCPsocket Accept(void); - }; - - bool RecvMessage(const Network::Socket &, QueueMessage &, bool = false); - bool SendMessage(const Network::Socket &, const QueueMessage &); -} -#endif - -class QueueMessage -{ -public: - QueueMessage(); - QueueMessage(u16); - QueueMessage(const QueueMessage &); - ~QueueMessage(); - - QueueMessage & operator= (const QueueMessage &); - - u16 GetID(void) const; - void SetID(u16); - - void Push(u8); - void Push(s8); - void Push(u16); - void Push(s16); - void Push(u32); - void Push(s32); - void Push(const std::string &); - void Push(const char*); - - bool Pop(u8 &); - bool Pop(s8 &); - bool Pop(u16 &); - bool Pop(s16 &); - bool Pop(u32 &); - bool Pop(s32 &); - bool Pop(std::string &); - - void SoftReset(void); - void Reset(void); - void Reserve(size_t); - void Dump(std::ostream & = std::cerr) const; - - const char* DtPt(void) const; - size_t DtSz(void) const; - - void Save(const char*) const; - void Load(const char*); - -protected: -#ifdef WITH_NET - friend bool Network::RecvMessage(const Network::Socket &, QueueMessage &, bool); - friend bool Network::SendMessage(const Network::Socket &, const QueueMessage &); -#endif - - void Resize(size_t); - size_t Size(void) const; - - u16 type; - char* data; - char* itd1; - char* itd2; - size_t dtsz; -}; -#endif diff --git a/project/jni/application/fheroes2/src/engine/spritecursor.cpp b/project/jni/application/fheroes2/src/engine/spritecursor.cpp deleted file mode 100644 index 37fcaace6..000000000 --- a/project/jni/application/fheroes2/src/engine/spritecursor.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "rect.h" -#include "surface.h" -#include "display.h" -#include "spritecursor.h" - -SpriteCursor::SpriteCursor() : Background(), sprite(NULL), visible(false) -{ -} - -SpriteCursor::SpriteCursor(const Surface &cursor, const Point & pt) : Background(pt, cursor.w(), cursor.h()), sprite(&cursor), visible(false) -{ -} - -SpriteCursor::SpriteCursor(const Surface &cursor, s16 x, s16 y) : Background(x, y, cursor.w(), cursor.h()), sprite(&cursor), visible(false) -{ -} - -u16 SpriteCursor::w(void) const -{ - return sprite ? sprite->w() : 0; -} - -u16 SpriteCursor::h(void) const -{ - return sprite ? sprite->h() : 0; -} - -void SpriteCursor::SetSprite(const Surface & sf) -{ - if(visible) Restore(); - - Save(Background::x, Background::y, sf.w(), sf.h()); - - sprite = &sf; -} - -const Surface* SpriteCursor::Sprite(void) -{ - return sprite && sprite->isValid() ? sprite : NULL; -} - -void SpriteCursor::Move(const Point &pt) -{ - Move(pt.x, pt.y); -} - -void SpriteCursor::Move(s16 ax, s16 ay) -{ - if(Background::x == ax && Background::y == ay) - { - if(!visible) Show(); - } - else - { - if(visible) Hide(); - Show(ax, ay); - } -} - -void SpriteCursor::Hide(void) -{ - if(!visible) return; - - Restore(); - - visible = false; -} - -void SpriteCursor::Redraw(void) -{ - if(visible) - { - Hide(); - Show(); - } -} - -void SpriteCursor::Show(void) -{ - Show(GetPos()); -} - -void SpriteCursor::Show(const Point &pt) -{ - Show(pt.x, pt.y); -} - -void SpriteCursor::Show(s16 ax, s16 ay) -{ - if(visible) return; - - Save(ax, ay); - - if(sprite) Display::Get().Blit(*sprite, ax, ay); - - visible = true; -} - -bool SpriteCursor::isVisible(void) const -{ - return visible; -} diff --git a/project/jni/application/fheroes2/src/engine/spritecursor.h b/project/jni/application/fheroes2/src/engine/spritecursor.h deleted file mode 100644 index 8779e280a..000000000 --- a/project/jni/application/fheroes2/src/engine/spritecursor.h +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2SPRITECURSOR_H -#define H2SPRITECURSOR_H - -#include "background.h" -#include "types.h" - -class Point; -class Surface; - -class SpriteCursor : public Background -{ -public: - /* sprite cursor */ - SpriteCursor(); - SpriteCursor(const Surface &cursor, const Point & pt = Point()); - SpriteCursor(const Surface &cursor, s16 x, s16 y); - - u16 w(void) const; - u16 h(void) const; - - void SetSprite(const Surface & sf); - const Surface* Sprite(void); - - void Move(s16 ax, s16 ay); - void Move(const Point &pt); - - void Hide(void); - - void Show(s16 ax, s16 ay); - void Show(const Point &pt); - void Show(void); - - void Redraw(void); - - bool isVisible(void) const; - -private: - const Surface* sprite; - bool visible; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/engine/surface.cpp b/project/jni/application/fheroes2/src/engine/surface.cpp deleted file mode 100644 index 5ad7c3117..000000000 --- a/project/jni/application/fheroes2/src/engine/surface.cpp +++ /dev/null @@ -1,940 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "surface.h" -#include "palette.h" -#include "error.h" -#include "localevent.h" -#include "display.h" - -#ifdef WITH_TTF -#include "SDL_ttf.h" -#endif - -#ifdef WITH_IMAGE -#include "SDL_image.h" -#include "IMG_savepng.h" -#endif - -static u8 default_depth = 16; -static SDL_Color* pal_colors = NULL; -#define pal_ncolors 255 - -void SDLFreeSurface(SDL_Surface *sf) -{ - if(sf) - { - // clear static palette - if(sf->format && 8 == sf->format->BitsPerPixel && sf->format->palette && pal_colors == sf->format->palette->colors) - { - sf->format->palette->colors = NULL; - sf->format->palette->ncolors = 0; - } - SDL_FreeSurface(sf); - } -} - -Surface::Surface() : surface(NULL) -{ -} - -Surface::Surface(const void* pixels, unsigned int width, unsigned int height, unsigned char bytes_per_pixel, bool alpha) : surface(NULL) -{ - Set(pixels, width, height, bytes_per_pixel, alpha); -} - -Surface::Surface(u16 sw, u16 sh, u8 depth, u32 fl) : surface(NULL) -{ - Set(sw, sh, depth, fl); -} - -Surface::Surface(u16 sw, u16 sh, bool alpha) : surface(NULL) -{ - Set(sw, sh, alpha); -} - -Surface::Surface(const Surface & bs) : surface(NULL) -{ - Set(bs); -} - -Surface::Surface(SDL_Surface* sf) : surface(NULL) -{ - Set(sf); -} - -Surface::~Surface() -{ - if(! isDisplay()) - FreeSurface(*this); -} - -/* operator = */ -Surface & Surface::operator= (const Surface & bs) -{ - Set(bs); - - return *this; -} - -void Surface::SetDefaultDepth(u8 depth) -{ - switch(depth) - { - case 8: - case 16: - case 24: - case 32: - default_depth = depth; - break; - - default: - break; - } -} - -u8 Surface::GetDefaultDepth(void) -{ - return default_depth; -} - -void Surface::Set(SDL_Surface* sf) -{ - FreeSurface(*this); - - surface = sf ? sf : NULL; - LoadPalette(); -} - -void Surface::Set(const Surface & bs) -{ - FreeSurface(*this); - - if(bs.surface) - { - surface = SDL_ConvertSurface(bs.surface, bs.surface->format, bs.surface->flags); - if(!surface) std::cerr << "Surface: copy constructor, error: " << SDL_GetError() << std::endl; - } -} - -void Surface::Set(u16 sw, u16 sh, bool alpha) -{ - FreeSurface(*this); - - CreateSurface(sw, sh, default_depth, 8 < default_depth && alpha ? SDL_SRCALPHA|SDL_SWSURFACE : SDL_SWSURFACE); - LoadPalette(); -} - -void Surface::Set(u16 sw, u16 sh, u8 depth, u32 fl) -{ - FreeSurface(*this); - - CreateSurface(sw, sh, depth, fl); - LoadPalette(); -} - -void Surface::Set(const void* pixels, unsigned int width, unsigned int height, unsigned char bytes_per_pixel, bool alpha) -{ - FreeSurface(*this); - - switch(bytes_per_pixel) - { - case 1: - Set(width, height, 8, SDL_SWSURFACE); - Lock(); - memcpy(surface->pixels, pixels, width * height); - Unlock(); - break; - - default: - { - u32 rmask = 0; - u32 gmask = 0; - u32 bmask = 0; - u32 amask = 0; - - switch(bytes_per_pixel) - { - case 4: - rmask = RMASK32; - gmask = GMASK32; - bmask = BMASK32; - amask = alpha ? AMASK32 : 0; - break; - case 3: - rmask = alpha ? RMASK24 : RMASK32; - gmask = alpha ? GMASK24 : GMASK32; - bmask = alpha ? BMASK24 : BMASK32; - amask = alpha ? AMASK24 : 0; - break; - case 2: - rmask = RMASK16; - gmask = GMASK16; - bmask = BMASK16; - amask = alpha ? AMASK16 : 0; - break; - default: break; - } - - surface = SDL_CreateRGBSurfaceFrom(const_cast(pixels), width, height, 8 * bytes_per_pixel, width * bytes_per_pixel, - rmask, gmask, bmask, amask); - } - break; - } -} - -bool Surface::isDisplay(void) const -{ - return NULL != surface && Display::Get().surface == surface; -} - -bool Surface::Load(const char* fn) -{ - FreeSurface(*this); - -#ifdef WITH_IMAGE - if(fn) surface = IMG_Load(fn); -#else - if(fn) surface = SDL_LoadBMP(fn); -#endif - return surface; -} - -bool Surface::Load(const std::string & str) -{ - return Load(str.c_str()); -} - -bool Surface::Save(const char *fn) const -{ -#ifdef WITH_IMAGE - return !surface || !fn || IMG_SavePNG(fn, surface, -1) ? false : true; -#else - return !surface || !fn || SDL_SaveBMP(surface, fn) ? false : true; -#endif -} - -bool Surface::Save(const std::string & str) const -{ - return Save(str.c_str()); -} - -u16 Surface::w(void) const -{ - return surface ? surface->w : 0; -} - -u16 Surface::h(void) const -{ - return surface ? surface->h : 0; -} - -u8 Surface::depth(void) const -{ - return surface ? surface->format->BitsPerPixel : 0; -} - -bool Surface::isAlpha(void) const -{ - return SDL_SRCALPHA & surface->flags; -} - -u8 Surface::GetAlpha(void) const -{ -#if SDL_VERSION_ATLEAST(1, 3, 0) - u8 alpha = 0; - if(surface) SDL_GetSurfaceAlphaMod(surface, &alpha); - return alpha; -#else - return surface->format->alpha; -#endif -} - -u32 Surface::MapRGB(u8 r, u8 g, u8 b, u8 a) const -{ - return (SDL_SRCALPHA & surface->flags) ? SDL_MapRGBA(surface->format, r, g, b, a) : SDL_MapRGB(surface->format, r, g, b); -} - -void Surface::GetRGB(u32 pixel, u8 *r, u8 *g, u8 *b, u8 *a) const -{ - return (SDL_SRCALPHA & surface->flags && a) ? SDL_GetRGBA(pixel, surface->format, r, g, b, a) : SDL_GetRGB(pixel, surface->format, r, g, b); -} - -/* create new surface */ -void Surface::CreateSurface(u16 sw, u16 sh, u8 dp, u32 fl) -{ - switch(dp) - { - case 32: - surface = SDL_CreateRGBSurface(fl, sw, sh, dp, RMASK32, GMASK32, BMASK32, (SDL_SRCALPHA & fl ? AMASK32 : 0)); - break; - case 24: - surface = SDL_CreateRGBSurface(fl, sw, sh, dp, RMASK24, GMASK24, BMASK24, (SDL_SRCALPHA & fl ? AMASK24 : 0)); - break; - case 16: - surface = SDL_CreateRGBSurface(fl, sw, sh, dp, RMASK16, GMASK16, BMASK16, (SDL_SRCALPHA & fl ? AMASK16 : 0)); - break; - default: - surface = SDL_CreateRGBSurface(fl, sw, sh, dp, 0, 0, 0, 0); - break; - } - - if(!surface) - { - std::cerr << "w: " << sw << ", h: " << sh << std::endl; - Error::Except("Surface::CreateSurface: empty surface, error:", SDL_GetError()); - } -} - -void Surface::LoadPalette(void) -{ - // only 8bit color - // load static palette (economize 1kb for each surface) - if(surface && 8 == surface->format->BitsPerPixel) - { - if(!pal_colors) - { - pal_colors = Palette::Get().SDLPalette()->colors; - } - - if(surface->format->palette) - { - if(surface->format->palette->colors && pal_colors != surface->format->palette->colors) SDL_free(surface->format->palette->colors); - surface->format->palette->colors = pal_colors; - surface->format->palette->ncolors = pal_ncolors; - } - } -} - -/* format surface */ -void Surface::SetDisplayFormat(void) -{ - SDL_Surface *osurface = surface; - surface = SDL_DisplayFormatAlpha(osurface); - if(osurface) SDLFreeSurface(osurface); -} - -u32 Surface::GetColor(u16 index) const -{ - if(! surface) return 0; - - return 8 == surface->format->BitsPerPixel ? index : Palette::Get().GetColor(index); -} - -u32 Surface::GetColorKey(void) const -{ - if(! surface) return 0; - return SDL_MapRGBA(surface->format, 0xFF, 0x00, 0xFF, 0); -} - -/* set color key */ -void Surface::SetColorKey(void) -{ - if(surface) - { - const u32 clkey = GetColorKey(); - Fill(clkey); - SetColorKey(clkey); - } -} - -void Surface::SetColorKey(u8 r, u8 g, u8 b) -{ -#ifdef _WIN32_WCE - SDL_SetColorKey(surface, SDL_SRCCOLORKEY, MapRGB(r, g, b)); -#else - SDL_SetColorKey(surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, MapRGB(r, g, b)); -#endif -} - -void Surface::SetColorKey(u32 color) -{ -#ifdef _WIN32_WCE - SDL_SetColorKey(surface, SDL_SRCCOLORKEY, color); -#else - SDL_SetColorKey(surface, SDL_SRCCOLORKEY | SDL_RLEACCEL, color); -#endif -} - -/* draw u32 pixel */ -void Surface::SetPixel4(u16 x, u16 y, u32 color) -{ - if(x > surface->w || y > surface->h) return; - - u32 *bufp = static_cast(surface->pixels) + y * surface->pitch / 4 + x; - - *bufp = color; -} - -/* draw u24 pixel */ -void Surface::SetPixel3(u16 x, u16 y, u32 color) -{ - if(x > surface->w || y > surface->h) return; - - u8 *bufp = static_cast(surface->pixels) + y * surface->pitch + x * 3; - - if(SDL_BYTEORDER == SDL_LIL_ENDIAN) - { - bufp[0] = color; - bufp[1] = color >> 8; - bufp[2] = color >> 16; - } - else - { - bufp[2] = color; - bufp[1] = color >> 8; - bufp[0] = color >> 16; - } -} - -/* draw u16 pixel */ -void Surface::SetPixel2(u16 x, u16 y, u32 color) -{ - if(x > surface->w || y > surface->h) return; - - u16 *bufp = static_cast(surface->pixels) + y * surface->pitch / 2 + x; - - *bufp = static_cast(color); -} - -/* draw u8 pixel */ -void Surface::SetPixel1(u16 x, u16 y, u32 color) -{ - if(x > surface->w || y > surface->h) return; - - u8 *bufp = static_cast(surface->pixels) + y * surface->pitch + x; - - *bufp = static_cast(color); -} - -/* draw pixel */ -void Surface::SetPixel(u16 x, u16 y, u32 color) -{ - switch(surface->format->BytesPerPixel) - { - case 1: SetPixel1(x, y, color); break; - case 2: SetPixel2(x, y, color); break; - case 3: SetPixel3(x, y, color); break; - case 4: SetPixel4(x, y, color); break; - default: break; - } - if(isDisplay()) Display::Get().AddUpdateRect(x, y, 1, 1); -} - -u32 Surface::GetPixel4(u16 x, u16 y) const -{ - if(x > surface->w || y > surface->h) return 0; - - u32 *bufp = static_cast(surface->pixels) + y * surface->pitch / 4 + x; - - return *bufp; -} - -u32 Surface::GetPixel3(u16 x, u16 y) const -{ - if(x > surface->w || y > surface->h) return 0; - - u8 *bufp = static_cast(surface->pixels) + y * surface->pitch + x * 3; - - u32 color = 0; - - if(SDL_BYTEORDER == SDL_LIL_ENDIAN) - { - color |= bufp[2]; - color <<= 8; - color |= bufp[1]; - color <<= 8; - color |= bufp[0]; - } - else - { - color |= bufp[0]; - color <<= 8; - color |= bufp[1]; - color <<= 8; - color |= bufp[2]; - } - - return color; -} - -u32 Surface::GetPixel2(u16 x, u16 y) const -{ - if(x > surface->w || y > surface->h) return 0; - u16 *bufp = static_cast(surface->pixels) + y * surface->pitch / 2 + x; - - return static_cast(*bufp); -} - -u32 Surface::GetPixel1(u16 x, u16 y) const -{ - if(x > surface->w || y > surface->h) return 0; - u8 *bufp = static_cast(surface->pixels) + y * surface->pitch + x; - - return static_cast(*bufp); -} - -u32 Surface::GetPixel(u16 x, u16 y) const -{ - switch(surface->format->BytesPerPixel) - { - case 1: return GetPixel1(x, y); - case 2: return GetPixel2(x, y); - case 3: return GetPixel3(x, y); - case 4: return GetPixel4(x, y); - default: break; - } - - return 0; -} - -/* fill colors surface */ -void Surface::Fill(u32 color) -{ - SDL_Rect dstrect = {0, 0, surface->w, surface->h}; - - SDL_FillRect(surface, &dstrect, color); - if(isDisplay()) Display::Get().AddUpdateRect(0, 0, surface->w, surface->h); -} - -/* rect fill colors surface */ -void Surface::FillRect(u32 color, const Rect & rect) -{ - SDL_Rect dstrect = {rect.x, rect.y, rect.w, rect.h}; - SDL_FillRect(surface, &dstrect, color); - if(isDisplay()) Display::Get().AddUpdateRect(rect.x, rect.y, rect.w, rect.h); -} - -/* blit */ -void Surface::Blit(const Surface &src) -{ - SDL_BlitSurface(src.surface, NULL, surface, NULL); - if(isDisplay()) Display::Get().AddUpdateRect(0, 0, src.w(), src.h()); -} - -/* blit */ -void Surface::Blit(const Surface &src, s16 dst_ox, s16 dst_oy) -{ - SDL_Rect dstrect = {dst_ox, dst_oy, src.surface->w, src.surface->h}; - - SDL_BlitSurface(src.surface, NULL, surface, &dstrect); - if(isDisplay()) Display::Get().AddUpdateRect(dst_ox, dst_oy, src.surface->w, src.surface->h); -} - -/* blit */ -void Surface::Blit(const Surface &src, const Rect &src_rt, s16 dst_ox, s16 dst_oy) -{ - SDL_Rect dstrect = {dst_ox, dst_oy, src_rt.w, src_rt.h}; - SDL_Rect srcrect = {src_rt.x, src_rt.y, src_rt.w, src_rt.h}; - - SDL_BlitSurface(src.surface, &srcrect, surface, &dstrect); - if(isDisplay()) Display::Get().AddUpdateRect(dst_ox, dst_oy, src_rt.w, src_rt.h); -} - -void Surface::Blit(const Surface &src, const Point &dst_pt) -{ - Blit(src, dst_pt.x, dst_pt.y); -} - -void Surface::Blit(const Surface &src, const Rect &src_rt, const Point &dst_pt) -{ - Blit(src, src_rt, dst_pt.x, dst_pt.y); -} - -void Surface::SetAlpha(u8 level) -{ -#if SDL_VERSION_ATLEAST(1, 3, 0) - if(surface) - SDL_SetSurfaceAlphaMod(surface, level); -#else - if(surface) - SDL_SetAlpha(surface, SDL_SRCALPHA, level); -#endif -} - -void Surface::ResetAlpha(void) -{ - if(!surface) return; - SDL_SetAlpha(surface, 0, 255); -} - -void Surface::Lock(void) const -{ - if(SDL_MUSTLOCK(surface)) SDL_LockSurface(surface); -} - -void Surface::Unlock(void) const -{ - if(SDL_MUSTLOCK(surface)) SDL_UnlockSurface(surface); -} - -void Surface::FreeSurface(Surface & sf) -{ - if(sf.surface) - { - SDLFreeSurface(sf.surface); - sf.surface = NULL; - } -} - -const SDL_PixelFormat *Surface::GetPixelFormat(void) const -{ - return surface ? surface->format : NULL; -} - -void Surface::ChangeColorIndex(u32 fc, u32 tc) -{ - if(!surface) return; - - if(8 != depth()) return ChangeColor(GetColor(fc), GetColor(tc)); - - Lock(); - if(fc != tc) - for(u16 y = 0; y < surface->h; ++y) - for(u16 x = 0; x < surface->w; ++x) - if(fc == GetPixel(x, y)) SetPixel(x, y, tc); - Unlock(); -} - -void Surface::ChangeColor(u32 fc, u32 tc) -{ - if(!surface) return; - - Lock(); - if(fc != tc) - for(u16 y = 0; y < surface->h; ++y) - for(u16 x = 0; x < surface->w; ++x) - if(fc == GetPixel(x, y)) SetPixel(x, y, tc); - Unlock(); -} - -void Surface::GrayScale(void) -{ - if(!surface) return; - - u8 a, r, g, b, z; - - const u32 colkey = GetColorKey(); - u32 color = 0; - - Lock(); - for(u16 y = 0; y < surface->h; ++y) - for(u16 x = 0; x < surface->w; ++x) - { - color = GetPixel(x, y); - if(color == colkey) continue; - GetRGB(color, &r, &g, &b, &a); - z = static_cast(0.299 * r + 0.587 * g + 0.114 * b); - r = z; - g = z; - b = z; - SetPixel(x, y, MapRGB(r, g, b, a)); - } - Unlock(); -} - -void Surface::Sepia(void) -{ - if(!surface) return; - - Lock(); - for(u16 x = 0; x < surface->w; x++) - for(u16 y = 0; y < surface->h; y++) - { - u32 pixel = GetPixel(x, y); - u8 r, g, b; - GetRGB(pixel, &r, &g, &b); - - //Numbers derived from http://blogs.techrepublic.com.com/howdoi/?p=120 - #define CLAMP255(val) static_cast(std::min((val), 255)) - u8 outR = CLAMP255(static_cast(r * 0.693f + g * 0.769f + b * 0.189f)); - u8 outG = CLAMP255(static_cast(r * 0.449f + g * 0.686f + b * 0.168f)); - u8 outB = CLAMP255(static_cast(r * 0.272f + g * 0.534f + b * 0.131f)); - pixel = MapRGB(outR, outG, outB); - SetPixel(x, y, pixel); - #undef CLAMP255 - } - Unlock(); -} - -void Surface::DrawLine(const Point & p1, const Point & p2, u32 c) -{ - DrawLine(p1.x, p1.y, p2.x, p2.y, c); -} - -void Surface::DrawLine(u16 x1, u16 y1, u16 x2, u16 y2, u32 c) -{ - const u16 dx = std::abs(x2 - x1); - const u16 dy = std::abs(y2 - y1); - - Lock(); - if(dx > dy) - { - s16 ns = std::div(dx, 2).quot; - - for(u16 i = 0; i <= dx; ++i) - { - SetPixel(x1, y1, c); - x1 < x2 ? ++x1 : --x1; - ns -= dy; - if(ns < 0) - { - y1 < y2 ? ++y1 : --y1; - ns += dx; - } - } - } - else - { - s16 ns = std::div(dy, 2).quot; - - for(u16 i = 0; i <= dy; ++i) - { - SetPixel(x1, y1, c); - y1 < y2 ? ++y1 : --y1; - ns -= dx; - if(ns < 0) - { - x1 < x2 ? ++x1 : --x1; - ns += dy; - } - } - } - Unlock(); -} - -void Surface::MakeStencil(Surface & dst, const Surface & src, u32 col) -{ - if(!src.surface) return; - - dst.Set(src.surface->w, src.surface->h); - dst.SetColorKey(); - const u32 clkey = src.GetColorKey(); - u8 r, g, b, a; - - src.Lock(); - dst.Lock(); - for(u16 y = 0; y < src.surface->h; ++y) - for(u16 x = 0; x < src.surface->w; ++x) - { - u32 pixel = src.GetPixel(x, y); - if(clkey != pixel) - { - if(src.isAlpha()) - { - src.GetRGB(pixel, &r, &g, &b, &a); - // skip shadow - if(a < 200) continue; - } - - dst.SetPixel(x, y, col); - } - } - dst.Unlock(); - src.Unlock(); -} - -void Surface::MakeContour(Surface & dst, const Surface & src, u32 col) -{ - if(!src.surface) return; - - dst.Set(src.surface->w + 2, src.surface->h + 2); - dst.SetColorKey(); - - Surface trf; - u32 fake = src.MapRGB(0x00, 0xFF, 0xFF); - - MakeStencil(trf, src, fake); - const u32 clkey = trf.GetColorKey(); - trf.Lock(); - dst.Lock(); - for(u16 y = 0; y < trf.h(); ++y) - for(u16 x = 0; x < trf.w(); ++x) - { - if(fake == trf.GetPixel(x, y)) - { - if(0 == x) dst.SetPixel(x, y, col); - else if(trf.w() - 1 == x) dst.SetPixel(x + 1, y, col); - else if(0 == y) dst.SetPixel(x, y, col); - else if(trf.h() - 1 == y) dst.SetPixel(x, y + 1, col); - else { - if(0 < x && clkey == trf.GetPixel(x - 1, y)) dst.SetPixel(x - 1, y, col); - if(trf.w() - 1 > x && clkey == trf.GetPixel(x + 1, y)) dst.SetPixel(x + 1, y, col); - - if(0 < y && clkey == trf.GetPixel(x, y - 1)) dst.SetPixel(x, y - 1, col); - if(trf.h() - 1 > y && clkey == trf.GetPixel(x, y + 1)) dst.SetPixel(x, y + 1, col); - } - } - } - trf.Unlock(); - dst.Unlock(); -} - -void Surface::TILReflect(Surface & sf_dst, const Surface & sf_src, const u8 shape) -{ - // valid sf_src - if(!sf_src.surface || sf_src.w() != sf_src.h()) - { - std::cerr << "Surface::TILReflect: " << "incorrect size" << std::endl; - return; - } - - if(sf_src.depth() != 8) - { - std::cerr << "Surface::TILReflect: " << "incorrect depth, use only 8 bpp" << std::endl; - return; - } - - const u8 tile_width = sf_src.w(); - const u8 tile_height = sf_src.h(); - - // valid sf_dst - if(!sf_dst.surface || sf_dst.w() != tile_width || sf_dst.h() != tile_height) - { - sf_dst = Surface(tile_width, tile_height, 8, SWSURFACE); - } - - const char* src = static_cast(sf_src.surface->pixels); - char* dst = static_cast(sf_dst.surface->pixels); - - s16 x, y; - - char * dst2 = NULL; - - sf_dst.Lock(); - - // draw tiles - switch(shape % 4) - { - // normal - case 0: - std::memcpy(dst, src, tile_width * tile_height); - break; - - // vertical reflect - case 1: - { - dst2 = dst + tile_width * (tile_height - 1); - - for(int i = 0; i < tile_height; i++) - { - memcpy(dst2, src, tile_width); - - src += tile_width; - dst2 -= tile_width; - } - } - break; - - // horizontal reflect - case 2: - for(y = 0; y < tile_height; ++y) - for(x = tile_width - 1; x >= 0; --x) - { - dst2 = dst + y * tile_width + x; - *dst2 = *src; - ++src; - } - break; - - // any variant - case 3: - for(y = tile_height - 1; y >= 0; --y) - for( x = tile_width - 1; x >= 0; --x) - { - dst2 = dst + y * tile_width + x; - *dst2 = *src; - ++src; - } - break; - } - - sf_dst.Unlock(); -} - -u32 Surface::GetSize(void) const -{ - u32 res = 0; - - if(surface) - { - res = sizeof(SDL_Surface) + sizeof(SDL_PixelFormat) + surface->pitch * surface->h; - - if(surface->format->palette) res += sizeof(SDL_Palette) + surface->format->palette->ncolors * sizeof(SDL_Color); - } - - return res; -} - -u32 AVERAGE(SDL_PixelFormat* fm, u32 c1, u32 c2) -{ - if(c1 == c2) return c1; - if(c1 == SDL_MapRGBA(fm, 0xFF, 0x00, 0xFF, 0)) c1 = 0; - if(c2 == SDL_MapRGBA(fm, 0xFF, 0x00, 0xFF, 0)) c2 = 0; - -#define avr(a, b) ((a + b) >> 1) - u8 r1, g1, b1, a1; - SDL_GetRGBA(c1, fm, &r1, &g1, &b1, &a1); - u8 r2, g2, b2, a2; - SDL_GetRGBA(c2, fm, &r2, &g2, &b2, &a2); - return SDL_MapRGBA(fm, avr(r1, r2), avr(g1, g2), avr(b1, b2), avr(a1, a2)); -} - -/* scale surface */ -void Surface::ScaleMinifyByTwo(Surface & sf_dst, const Surface & sf_src, bool event) -{ - if(!sf_src.isValid()) { std::cerr << "Surface::ScaleMinifyByTwo: " << "invalid surface" << std::endl; return; }; - u16 x, y, x2, y2; - - u8 mul = 2; - u16 w = sf_src.w() / mul; - u16 h = sf_src.h() / mul; - - if(2 > w || 2 > h){ std::cerr << "Surface::ScaleMinifyByTwo: " << "small size" << std::endl; return; }; - - sf_dst.Set(w, h, sf_src.depth(), SWSURFACE); - sf_dst.SetColorKey(); - sf_dst.Lock(); - sf_src.Lock(); - for(y = 0; y < h; y++) - { - y2 = mul * y; - for(x = 0; x < w; x++) - { - x2 = mul * x; - const u32 & p = AVERAGE(sf_src.surface->format, sf_src.GetPixel(x2, y2), sf_src.GetPixel(x2 + 1, y2)); - const u32 & q = AVERAGE(sf_src.surface->format, sf_src.GetPixel(x2, y2 + 1), sf_src.GetPixel(x2 + 1, y2 + 1)); - sf_dst.SetPixel(x, y, AVERAGE(sf_src.surface->format, p, q)); - if(event) LocalEvent::Get().HandleEvents(false); - } - } - sf_src.Unlock(); - sf_dst.Unlock(); -} - -void Surface::Swap(Surface & sf1, Surface & sf2) -{ - std::swap(sf1.surface, sf2.surface); -} diff --git a/project/jni/application/fheroes2/src/engine/surface.h b/project/jni/application/fheroes2/src/engine/surface.h deleted file mode 100644 index f4b94c72d..000000000 --- a/project/jni/application/fheroes2/src/engine/surface.h +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2SURFACE_H -#define H2SURFACE_H - -#include -#include "rect.h" -#include "types.h" - -#define SWSURFACE SDL_SWSURFACE - -class Palette; -class Point; -class Rect; -struct SDL_Surface; -struct SDL_PixelFormat; - -#ifdef WITH_TTF -namespace SDL { class Font; } -#endif - -class Surface -{ -public: - Surface(); - Surface(const void* pixels, unsigned int width, unsigned int height, unsigned char bytes_per_pixel, bool alpha); - Surface(u16 sw, u16 sh, u8 depth, u32 fl); - Surface(u16 sw, u16 sh, bool alpha = false); - Surface(const Surface & bs); - Surface(SDL_Surface * sf); - - ~Surface(); - - Surface & operator= (const Surface & bs); - void Set(const Surface &); - void Set(SDL_Surface * sf); - void Set(u16 sw, u16 sh, bool alpha = false); - void Set(u16 sw, u16 sh, u8 depth, u32 fl); - void Set(const void* pixels, unsigned int width, unsigned int height, unsigned char bytes_per_pixel, bool alpha); - - bool Load(const char*); - bool Load(const std::string &); - - bool Save(const char *) const; - bool Save(const std::string &) const; - - u16 w(void) const; - u16 h(void) const; - u8 depth(void) const; - - bool isValid(void) const{ return surface ? true : false; }; - bool isDisplay(void) const; - bool isAlpha(void) const; - u8 GetAlpha(void) const; - u32 MapRGB(u8 r, u8 g, u8 b, u8 a = 0) const; - void GetRGB(u32 pixel, u8 *r, u8 *g, u8 *b, u8 *a = NULL) const; - - void Blit(const Surface &src); - void Blit(const Surface &src, s16 dst_ox, s16 dst_oy); - void Blit(const Surface &src, const Point &dst_pt); - void Blit(const Surface &src, const Rect &src_rt, s16 dst_ox, s16 dst_oy); - void Blit(const Surface &src, const Rect &src_rt, const Point &dst_pt); - - - const SDL_Surface *GetSurface(void) const{ return surface; }; - - void Fill(u32 color); - void Fill(u8 r, u8 g, u8 b){ Fill(MapRGB(r, g, b)); }; - - void FillRect(u32 color, const Rect & src); - void FillRect(u8 r, u8 g, u8 b, const Rect & src){ FillRect(MapRGB(r, g, b), src); }; - - void SetDisplayFormat(void); - void SetColorKey(void); - void SetColorKey(u8 r, u8 g, u8 b); - void SetColorKey(u32 color); - void SetAlpha(u8 level); - void ResetAlpha(void); - void SetPixel(u16 x, u16 y, u32 color); - - void LoadPalette(void); - u32 GetColorKey(void) const; - u32 GetColor(u16) const; - u32 GetPixel(u16 x, u16 y) const; - - void DrawLine(const Point &, const Point &, u32); - void DrawLine(u16, u16, u16, u16, u32); - - - void ChangeColor(u32, u32); - void ChangeColorIndex(u32, u32); - void GrayScale(void); - void Sepia(void); - - void Lock(void) const; - void Unlock(void) const; - - u32 GetSize(void) const; - - static void TILReflect(Surface & sf_dst, const Surface & sf_src, const u8 shape); - - static void MakeStencil(Surface &, const Surface &, u32); - static void MakeContour(Surface &, const Surface &, u32); - - static void ScaleMinifyByTwo(Surface & sf_dst, const Surface & sf_src, bool event = false); - static void SetDefaultDepth(u8); - static u8 GetDefaultDepth(void); - static void FreeSurface(Surface &); - static void Swap(Surface &, Surface &); - -protected: - void SetPixel4(u16 x, u16 y, u32 color); - void SetPixel3(u16 x, u16 y, u32 color); - void SetPixel2(u16 x, u16 y, u32 color); - void SetPixel1(u16 x, u16 y, u32 color); - u32 GetPixel4(u16 x, u16 y) const; - u32 GetPixel3(u16 x, u16 y) const; - u32 GetPixel2(u16 x, u16 y) const; - u32 GetPixel1(u16 x, u16 y) const; -#ifdef WITH_TTF - friend class SDL::Font; -#endif - friend class Palette; - - void CreateSurface(const Rect &sz, u8 dp, u32 fl){ CreateSurface(sz.w, sz.h, dp, fl); }; - void CreateSurface(u16 sw, u16 sh, u8 dp, u32 fl); - const SDL_PixelFormat *GetPixelFormat(void) const; - - SDL_Surface *surface; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/engine/thread.cpp b/project/jni/application/fheroes2/src/engine/thread.cpp deleted file mode 100644 index 5e1d3188b..000000000 --- a/project/jni/application/fheroes2/src/engine/thread.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "thread.h" - -using namespace SDL; - -Thread::Thread() : thread(NULL) -{ -} - -Thread::~Thread() -{ - Kill(); -} - -void Thread::Create(int (*fn)(void *), void *param) -{ - thread = SDL_CreateThread(fn, param); -} - -int Thread::Wait(void) -{ - int status = 0; - if(thread) SDL_WaitThread(thread, &status); - thread = NULL; - return status; -} - -void Thread::Kill(void) -{ - if(thread) SDL_KillThread(thread); - thread = NULL; -} - -bool Thread::IsRun(void) const -{ - return thread; -} - -u32 Thread::GetID(void) const -{ - return thread ? SDL_GetThreadID(thread) : 0; -} - -Mutex::Mutex() : mutex(SDL_CreateMutex()) -{ -} - -Mutex::~Mutex() -{ - if(mutex) SDL_DestroyMutex(mutex); -} - -bool Mutex::Lock(void) const -{ - return mutex ? 0 == SDL_mutexP(mutex) : false; -} - -bool Mutex::Unlock(void) const -{ - return mutex ? 0 == SDL_mutexV(mutex) : false; -} - -Timer::Timer() : id(0) -{ -} - -void Timer::Run(Timer & timer, u32 interval, u32 (*fn)(u32, void *), void *param) -{ - if(timer.id) Remove(timer); - - timer.id = SDL_AddTimer(interval, fn, param); -} - -void Timer::Remove(Timer & timer) -{ - if(timer.id) - { - SDL_RemoveTimer(timer.id); - timer.id = 0; - } -} - -bool Timer::IsValid(void) const -{ - return id; -} - -Time::Time() -{ -} - -void Time::Start(void) -{ - tick2 = tick1 = SDL_GetTicks(); -} - -void Time::Stop(void) -{ - tick2 = SDL_GetTicks(); -} - -u32 Time::Get(void) const -{ - return tick2 > tick1 ? tick2 - tick1 : 0; -} - -void Time::Print(const char* header) const -{ - std::cerr << (header ? header : "time: ") << Get() << " ms" << std::endl; -} diff --git a/project/jni/application/fheroes2/src/engine/thread.h b/project/jni/application/fheroes2/src/engine/thread.h deleted file mode 100644 index 280b6c651..000000000 --- a/project/jni/application/fheroes2/src/engine/thread.h +++ /dev/null @@ -1,95 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef SDLTHREAD_H -#define SDLTHREAD_H - -#include -#include "SDL_thread.h" -#include "types.h" - -namespace SDL -{ - -class Thread -{ -public: - Thread(); - ~Thread(); - - void Create(int (*)(void *), void *param = NULL); - int Wait(void); - void Kill(void); - - bool IsRun(void) const; - - u32 GetID(void) const; - -private: - SDL_Thread *thread; -}; - -class Mutex -{ -public: - Mutex(); - ~Mutex(); - - bool Lock(void) const; - bool Unlock(void) const; - -private: - SDL_mutex *mutex; -}; - -class Timer -{ -public: - Timer(); - - bool IsValid(void) const; - - static void Run(Timer &, u32, u32 (*)(u32, void *), void *param = NULL); - static void Remove(Timer &); - -private: - SDL_TimerID id; -}; - -class Time -{ -public: - Time(); - - void Start(void); - void Stop(void); - u32 Get(void) const; - void Print(const char* header = NULL) const; - -private: - u32 tick1; - u32 tick2; -}; - -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/tinyconfig.cpp b/project/jni/application/fheroes2/src/engine/tinyconfig.cpp deleted file mode 100644 index 62bc94689..000000000 --- a/project/jni/application/fheroes2/src/engine/tinyconfig.cpp +++ /dev/null @@ -1,269 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of SDL++ Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include - -#include "tinyconfig.h" -#include "tools.h" - -bool SpaceCompare(char a, char b) -{ - return std::isspace(a) && std::isspace(b); -} - -void ModifyKey(std::string & key) -{ - String::Lower(key); - String::Trim(key); - - // remove multiple space - std::string::iterator it = std::unique(key.begin(), key.end(), SpaceCompare); - key.resize(it - key.begin()); - - // change space - std::replace_if(key.begin(), key.end(), ::isspace, 0x20); -} - -Tiny::Value::Value() : ival(0) -{ -} - -Tiny::Value::Value(int val) -{ - ival = val; - sval = val; -} - -Tiny::Value::Value(const char* val) -{ - sval = val; - ival = String::ToInt(sval); -} - -void Tiny::Value::operator= (int val) -{ - ival = val; - sval.clear(); - String::AddInt(sval, val); -} - -void Tiny::Value::operator= (const char* val) -{ - sval = val; - ival = String::ToInt(sval); -} - -std::ostream & Tiny::operator<< (std::ostream & os, const Tiny::Entry & en) -{ - os << en.first << " = " << en.second.sval << std::endl; - return os; -} - -Tiny::Entry::Entry() -{ -} - -Tiny::Entry::Entry(const char* key, const char* val) : - std::pair(key, val) -{ - ModifyKey(first); -} - -Tiny::Entry::Entry(const char* key, int val) : - std::pair(key, val) -{ - ModifyKey(first); -} - -const std::string & Tiny::Entry::StrParams(void) const -{ - return second.sval; -} - -int Tiny::Entry::IntParams(void) const -{ - return second.ival; -} - -bool Tiny::Entry::IsKey(const char* key) const -{ - return key && key == first; -} - -bool Tiny::Entry::IsValue(const char* val) const -{ - return val && val == second.sval; -} - -bool Tiny::Entry::IsValue(int val) const -{ - return val == second.ival; -} - -Tiny::Config::Config() : separator('='), comment(';') -{ -} - -Tiny::Config::~Config() -{ -} - -void Tiny::Config::SetSeparator(char c) -{ - separator = c; -} - -void Tiny::Config::SetComment(char c) -{ - comment = c; -} - -bool Tiny::Config::Load(const char* cfile) -{ - if(!cfile) return false; - - std::ifstream fs(cfile); - if(!fs.is_open()) return false; - - std::string str; - while(std::getline(fs, str)) - { - String::Trim(str); - if(str.empty() || str[0] == comment) continue; - - size_t pos = str.find(separator); - if(std::string::npos != pos) - { - std::string left(str.substr(0, pos)); - std::string right(str.substr(pos + 1, str.length() - pos - 1)); - - String::Trim(left); - String::Trim(right); - - AddEntry(left.c_str(), right.c_str(), false); - } - } - fs.close(); - - return true; -} - -bool Tiny::Config::Save(const char* cfile) -{ - if(!cfile) return false; - - std::ofstream fs(cfile); - if(!fs.is_open()) return false; - - Dump(fs); - fs.close(); - - return true; -} - -void Tiny::Config::Dump(std::ostream & os) -{ - std::copy(entries.begin(), entries.end(), std::ostream_iterator(os, "")); -} - -Tiny::EntryIterator Tiny::Config::FindEntry(std::string key) -{ - ModifyKey(key); - return std::find_if(entries.begin(), entries.end(), std::bind2nd(std::mem_fun_ref(&Entry::IsKey), key.c_str())); -} - -Tiny::EntryConstIterator Tiny::Config::FindEntry(std::string key) const -{ - ModifyKey(key); - return std::find_if(entries.begin(), entries.end(), std::bind2nd(std::mem_fun_ref(&Entry::IsKey), key.c_str())); -} - -int Tiny::Config::IntParams(const char* key) const -{ - EntryConstIterator it = FindEntry(key); - return it != entries.end() ? (*it).second.ival : 0; -} - -const char* Tiny::Config::StrParams(const char* key) const -{ - EntryConstIterator it = FindEntry(key); - return it != entries.end() ? (*it).second.sval.c_str() : NULL; -} - -void Tiny::Config::GetParams(const char* ckey, std::list & res) const -{ - std::string key(ckey); - ModifyKey(key); - - for(EntryConstIterator it = entries.begin(); it != entries.end(); ++it) - if((*it).IsKey(ckey)) res.push_back((*it).second.sval); -} - -const Tiny::Entry* Tiny::Config::Find(const char* key) const -{ - EntryConstIterator it = FindEntry(key); - return it != entries.end() ? &(*it) : NULL; -} - -void Tiny::Config::AddEntry(const char* key, const char* val, bool uniq) -{ - if(uniq) - { - EntryIterator it = FindEntry(key); - - if(it != entries.end()) - (*it).second = val; - else - entries.push_back(Entry(key, val)); - } - else - entries.push_back(Entry(key, val)); -} - -void Tiny::Config::AddEntry(const char* key, int val, bool uniq) -{ - if(uniq) - { - EntryIterator it = FindEntry(key); - - if(it != entries.end()) - (*it).second = val; - else - entries.push_back(Entry(key, val)); - } - else - entries.push_back(Entry(key, val)); -} - -void Tiny::Config::Clear(void) -{ - entries.clear(); -} - -const Tiny::Entries & Tiny::Config::GetEntries(void) const -{ - return entries; -} diff --git a/project/jni/application/fheroes2/src/engine/tinyconfig.h b/project/jni/application/fheroes2/src/engine/tinyconfig.h deleted file mode 100644 index 63a2d1cb5..000000000 --- a/project/jni/application/fheroes2/src/engine/tinyconfig.h +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of SDL++ Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef TINYCONFIG_H -#define TINYCONFIG_H - -#include -#include -#include -#include -#include -#include - -namespace Tiny -{ - struct Value - { - Value(); - Value(int); - Value(const char*); - - void operator= (int); - void operator= (const char*); - - int ival; - std::string sval; - }; - - struct Entry : public std::pair - { - Entry(); - Entry(const char*, const char*); - Entry(const char*, int); - - const std::string & StrParams(void) const; - int IntParams(void) const; - - bool IsKey(const char*) const; - bool IsValue(const char*) const; - bool IsValue(int) const; - }; - - std::ostream & operator<< (std::ostream &, const Entry &); - - typedef std::list Entries; - typedef std::list::iterator EntryIterator; - typedef std::list::const_iterator EntryConstIterator; - - class Config - { - public: - Config(); - ~Config(); - - bool Load(const char*); - bool Save(const char*); - void Dump(std::ostream &); - void Clear(void); - - void SetSeparator(char); - void SetComment(char); - - int IntParams(const char*) const; - const char* StrParams(const char*) const; - void GetParams(const char*, std::list &) const; - - void AddEntry(const char*, const char*, bool uniq = true); - void AddEntry(const char*, int, bool uniq = true); - - const Entry* Find(const char*) const; - const Entries & GetEntries(void) const; - - protected: - EntryIterator FindEntry(std::string); - EntryConstIterator FindEntry(std::string) const; - - char separator; - char comment; - Entries entries; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/tools.cpp b/project/jni/application/fheroes2/src/engine/tools.cpp deleted file mode 100644 index d21f9e8a7..000000000 --- a/project/jni/application/fheroes2/src/engine/tools.cpp +++ /dev/null @@ -1,530 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include "error.h" -#include "types.h" -#include "tools.h" - -/* trim left right space */ -void String::Trim(std::string & str) -{ - std::string::iterator iter; - - // left - iter = str.begin(); - while(iter != str.end() && std::isspace(*iter)) ++iter; - if(iter != str.begin()) str.erase(str.begin(), iter); - - // right - iter = str.end() - 1; - while(iter != str.begin() && std::isspace(*iter)) --iter; - if(iter != str.end() - 1) str.erase(iter + 1, str.end()); -} - -/* convert to lower case */ -void String::Lower(std::string & str) -{ - std::transform(str.begin(), str.end(), str.begin(), ::tolower); -} - -/* convert to upper case */ -void String::Upper(std::string & str) -{ - std::transform(str.begin(), str.end(), str.begin(), ::toupper); -} - -/* int to string */ -void String::AddInt(std::string &str, int value) -{ - std::ostringstream stream; - stream << value; - - str += stream.str(); -} - -int String::ToInt(const std::string & str) -{ - int res = 0; - - // decimal - if(str.end() == std::find_if(str.begin(), str.end(), std::not1(std::ptr_fun(std::isdigit)))) - { - std::istringstream ss(str); - ss >> res; - } - else - // hex - if(str.size() > 3 && str.at(0) == '0' && std::tolower(str.at(1)) == 'x' && - str.end() == std::find_if(str.begin() + 2, str.end(), std::not1(std::ptr_fun(std::isxdigit)))) - { - std::istringstream ss(str); - ss >> std::hex >> res; - } - else - // str - { - std::string lower(str); - String::Lower(lower); - - if(lower == "on") return 1; - else - if(lower == "one") return 1; - else - if(lower == "two") return 2; - else - if(lower == "three") return 3; - else - if(lower == "four") return 4; - else - if(lower == "five") return 5; - else - if(lower == "six") return 6; - else - if(lower == "seven") return 7; - else - if(lower == "eight") return 8; - else - if(lower == "nine") return 9; - } - - return res; -} - -/* string compare */ -bool String::Compare(const std::string &str1, const std::string &str2, bool sensitive) -{ - if(str1.size() != str2.size()) return false; - if(sensitive) return str1 == str2; - - std::string strl1(str1); - std::string strl2(str2); - Lower(strl1); - Lower(strl2); - - return str1 == str2; -} - -void String::Replace(std::string & dst, const char* pred, const char* src) -{ - size_t pos = std::string::npos; - - while(std::string::npos != (pos = dst.find(pred))) dst.replace(pos, std::strlen(pred), src); -} - -void String::Replace(std::string & dst, const char* pred, const std::string & src) -{ - size_t pos = std::string::npos; - - while(std::string::npos != (pos = dst.find(pred))) dst.replace(pos, std::strlen(pred), src); -} - -void String::Replace(std::string & dst, const char* pred, int value) -{ - if(std::string::npos != dst.find(pred)) - { - std::ostringstream stream; - stream << value; - Replace(dst, pred, stream.str()); - } -} - -// from SDL_ttf -void String::UTF8_to_UNICODE(u16 *unicode, const char *utf8, int len) -{ - int i, j; - u16 ch; - - for ( i=0, j=0; i < len; ++i, ++j ) - { - ch = ((const unsigned char *)utf8)[i]; - if ( ch >= 0xF0 ) - { - ch = (u16)(utf8[i]&0x07) << 18; - ch |= (u16)(utf8[++i]&0x3F) << 12; - ch |= (u16)(utf8[++i]&0x3F) << 6; - ch |= (u16)(utf8[++i]&0x3F); - } - else - if ( ch >= 0xE0 ) - { - ch = (u16)(utf8[i]&0x0F) << 12; - ch |= (u16)(utf8[++i]&0x3F) << 6; - ch |= (u16)(utf8[++i]&0x3F); - } - else - if ( ch >= 0xC0 ) - { - ch = (u16)(utf8[i]&0x1F) << 6; - ch |= (u16)(utf8[++i]&0x3F); - } - unicode[j] = ch; - } - unicode[j] = 0; -} - -void String::UNICODE_to_UTF8(std::string & utf8, const u16 *unicode, size_t len) -{ - utf8.reserve(2 * len); - - for(size_t ii = 0; ii < len; ++ii) - { - if(unicode[ii] < 128) - { - utf8.append(1, static_cast(unicode[ii])); - } - else - if(unicode[ii] < 2048) - { - utf8.append(1, static_cast(192 + ((unicode[ii] - (unicode[ii] % 64)) / 64))); - utf8.append(1, static_cast(128 + (unicode[ii] % 64))); - } - else - { - utf8.append(1, static_cast(224 + ((unicode[ii] - (unicode[ii] % 4096)) / 4096))); - utf8.append(1, static_cast(128 + (((unicode[ii] % 4096) - (unicode[ii] % 64)) / 64))); - utf8.append(1, static_cast(128 + (unicode[ii] % 64))); - } - } -} - -void String::AppendKey(std::string & res, KeySym sym, u16 mod) -{ - switch(sym) - { - case KEY_1: res += (MOD_SHIFT & mod ? '!' : '1'); break; - case KEY_2: res += (MOD_SHIFT & mod ? '@' : '2'); break; - case KEY_3: res += (MOD_SHIFT & mod ? '#' : '3'); break; - case KEY_4: res += (MOD_SHIFT & mod ? '$' : '4'); break; - case KEY_5: res += (MOD_SHIFT & mod ? '%' : '5'); break; - case KEY_6: res += (MOD_SHIFT & mod ? '^' : '6'); break; - case KEY_7: res += (MOD_SHIFT & mod ? '&' : '7'); break; - case KEY_8: res += (MOD_SHIFT & mod ? '*' : '8'); break; - case KEY_9: res += (MOD_SHIFT & mod ? '(' : '9'); break; - case KEY_0: res += (MOD_SHIFT & mod ? ')' : '0'); break; - - case KEY_MINUS: res += (MOD_SHIFT & mod ? '_' : '-'); break; - case KEY_EQUALS: res += (MOD_SHIFT & mod ? '+' : '='); break; - case KEY_BACKSLASH: res += (MOD_SHIFT & mod ? '|' : '\\'); break; - case KEY_LEFTBRACKET: res += (MOD_SHIFT & mod ? '{' : '['); break; - case KEY_RIGHTBRACKET: res += (MOD_SHIFT & mod ? '}' : ']'); break; - case KEY_SEMICOLON: res += (MOD_SHIFT & mod ? ':' : ';'); break; - case KEY_QUOTE: res += (MOD_SHIFT & mod ? '"' : '\''); break; - case KEY_COMMA: res += (MOD_SHIFT & mod ? '<' : ','); break; - case KEY_PERIOD: res += (MOD_SHIFT & mod ? '>' : '.'); break; - case KEY_SLASH: res += (MOD_SHIFT & mod ? '?' : '/'); break; - - case KEY_EXCLAIM: res += '!'; break; - case KEY_AT: res += '@'; break; - case KEY_HASH: res += '#'; break; - case KEY_DOLLAR: res += '$'; break; - case KEY_AMPERSAND: res += '&'; break; - case KEY_ASTERISK: res += '*'; break; - case KEY_LEFTPAREN: res += '('; break; - case KEY_RIGHTPAREN: res += ')'; break; - case KEY_QUOTEDBL: res += '"'; break; - case KEY_PLUS: res += '+'; break; - case KEY_COLON: res += ':'; break; - case KEY_LESS: res += '<'; break; - case KEY_GREATER: res += '>'; break; - case KEY_QUESTION: res += '?'; break; - case KEY_CARET: res += '^'; break; - case KEY_UNDERSCORE: res += '_'; break; - - case KEY_SPACE: res += ' '; break; - - case KEY_a: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'A' : 'a'); break; - case KEY_b: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'B' : 'b'); break; - case KEY_c: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'C' : 'c'); break; - case KEY_d: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'D' : 'd'); break; - case KEY_e: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'E' : 'e'); break; - case KEY_f: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'F' : 'f'); break; - case KEY_g: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'G' : 'g'); break; - case KEY_h: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'H' : 'h'); break; - case KEY_i: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'I' : 'i'); break; - case KEY_j: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'J' : 'j'); break; - case KEY_k: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'K' : 'k'); break; - case KEY_l: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'L' : 'l'); break; - case KEY_m: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'M' : 'm'); break; - case KEY_n: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'N' : 'n'); break; - case KEY_o: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'O' : 'o'); break; - case KEY_p: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'P' : 'p'); break; - case KEY_q: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'Q' : 'q'); break; - case KEY_r: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'R' : 'r'); break; - case KEY_s: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'S' : 's'); break; - case KEY_t: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'T' : 't'); break; - case KEY_u: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'U' : 'u'); break; - case KEY_v: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'V' : 'v'); break; - case KEY_w: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'W' : 'w'); break; - case KEY_x: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'X' : 'x'); break; - case KEY_y: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'Y' : 'y'); break; - case KEY_z: res += ((MOD_SHIFT | MOD_CAPS) & mod ? 'Z' : 'z'); break; - - - case KEY_BACKSPACE: if(res.size()) res.resize(res.size() - 1); break; - default: break; - } -} - -int Sign(int s) -{ - return (s < 0 ? -1 : (s > 0 ? 1 : 0)); -} - -std::string GetDirname(const std::string & str) -{ - if(str.size()) - { - size_t pos = str.rfind(SEPARATOR); - - if(std::string::npos == pos) - return std::string("."); - else - if(pos == 0) - return str; - else - if(pos == str.size() - 1) - return GetDirname(str.substr(0, str.size() - 1)); - else - return str.substr(0, pos); - } - - return str; -} - -std::string GetBasename(const std::string & str) -{ - if(str.size()) - { - size_t pos = str.rfind(SEPARATOR); - - if(std::string::npos == pos || - pos == 0) return str; - else - if(pos == str.size() - 1) - return GetBasename(str.substr(0, str.size() - 1)); - else - return str.substr(pos + 1); - } - - return str; -} - -#if defined __SYMBIAN32__ -u32 GetMemoryUsage(void) -{ - return 0; -} -#elif defined __WIN32__ -#include "windows.h" -u32 GetMemoryUsage(void) -{ - static MEMORYSTATUS ms; - ZeroMemory(&ms, sizeof(ms)); - ms.dwLength = sizeof(MEMORYSTATUS); - GlobalMemoryStatus(&ms); - return (ms.dwTotalVirtual - ms.dwAvailVirtual); -} -#elif defined __LINUX__ -#include "unistd.h" -u32 GetMemoryUsage(void) -{ - unsigned int size = 0; - std::ostringstream os; - os << "/proc/" << getpid() << "/statm"; - - std::ifstream fs(os.str().c_str()); - if(fs.is_open()) - { - fs >> size; - fs.close(); - } - - return size * getpagesize(); -} -#else -u32 GetMemoryUsage(void) -{ - return 0; -} -#endif - -KeySym KeySymFromChar(char c) -{ - switch(c) - { - case '!': return KEY_EXCLAIM; - case '"': return KEY_QUOTEDBL; - case '#': return KEY_HASH; - case '$': return KEY_DOLLAR; - case '&': return KEY_AMPERSAND; - case '\'': return KEY_QUOTE; - case '(': return KEY_LEFTPAREN; - case ')': return KEY_RIGHTPAREN; - case '*': return KEY_ASTERISK; - case '+': return KEY_PLUS; - case ',': return KEY_COMMA; - case '-': return KEY_MINUS; - case '.': return KEY_PERIOD; - case '/': return KEY_SLASH; - case ':': return KEY_COLON; - case ';': return KEY_SEMICOLON; - case '<': return KEY_LESS; - case '=': return KEY_EQUALS; - case '>': return KEY_GREATER; - case '?': return KEY_QUESTION; - case '@': return KEY_AT; - case '[': return KEY_LEFTBRACKET; - case '\\': return KEY_BACKSLASH; - case ']': return KEY_RIGHTBRACKET; - case '^': return KEY_CARET; - case '_': return KEY_UNDERSCORE; - case ' ': return KEY_SPACE; - - case 'a': return KEY_a; - case 'b': return KEY_b; - case 'c': return KEY_c; - case 'd': return KEY_d; - case 'e': return KEY_e; - case 'f': return KEY_f; - case 'g': return KEY_g; - case 'h': return KEY_h; - case 'i': return KEY_i; - case 'j': return KEY_j; - case 'k': return KEY_k; - case 'l': return KEY_l; - case 'm': return KEY_m; - case 'n': return KEY_n; - case 'o': return KEY_o; - case 'p': return KEY_p; - case 'q': return KEY_q; - case 'r': return KEY_r; - case 's': return KEY_s; - case 't': return KEY_t; - case 'u': return KEY_u; - case 'v': return KEY_v; - case 'w': return KEY_w; - case 'x': return KEY_x; - case 'y': return KEY_y; - case 'z': return KEY_z; - - case '0': return KEY_0; - case '1': return KEY_1; - case '2': return KEY_2; - case '3': return KEY_3; - case '4': return KEY_4; - case '5': return KEY_5; - case '6': return KEY_6; - case '7': return KEY_7; - case '8': return KEY_8; - case '9': return KEY_9; - - default: break; - } - return KEY_NONE; -} - -bool FilePresent(const std::string & file) -{ - std::ifstream fs; - // check file - fs.open(file.c_str(), std::ios::binary); - if(fs.is_open()) - { - fs.close(); - return true; - } - return false; -} - -bool StoreMemToFile(const std::vector & data, const std::string & file) -{ - std::ofstream fs; - fs.open(file.c_str(), std::ios::binary); - if(fs.is_open() && data.size()) - { - fs.write(reinterpret_cast(&data[0]), data.size()); - fs.close(); - return true; - } - return false; -} - -bool StoreFileToMem(std::vector & data, const std::string & file) -{ - std::ifstream fs; - fs.open(file.c_str(), std::ios::binary); - if(fs.is_open()) - { - fs.seekg(0, std::ios_base::end); - data.resize(fs.tellg()); - fs.seekg(0, std::ios_base::beg); - fs.read(reinterpret_cast(&data[0]), data.size()); - fs.close(); - return true; - } - return false; -} - -bool PressIntKey(u32 min, u32 max, u32 & result) -{ - LocalEvent & le = LocalEvent::Get(); - - if(le.KeyPress(KEY_BACKSPACE)) - { - if(min < result) - { - result /= 10; - if(result < min) result = min; - } - return true; - } - else - if(le.KeyPress() && KEY_0 <= le.KeyValue() && KEY_9 >= le.KeyValue()) - { - if(max > result) - { - result *= 10; - switch(le.KeyValue()) - { - case KEY_1: result += 1; break; - case KEY_2: result += 2; break; - case KEY_3: result += 3; break; - case KEY_4: result += 4; break; - case KEY_5: result += 5; break; - case KEY_6: result += 6; break; - case KEY_7: result += 7; break; - case KEY_8: result += 8; break; - case KEY_9: result += 9; break; - default: break; - } - if(result > max) result = max; - } - return true; - } - return false; -} diff --git a/project/jni/application/fheroes2/src/engine/tools.h b/project/jni/application/fheroes2/src/engine/tools.h deleted file mode 100644 index 206f115f0..000000000 --- a/project/jni/application/fheroes2/src/engine/tools.h +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2TOOLS_H -#define H2TOOLS_H - -#include -#include "localevent.h" -#include "types.h" - -namespace String -{ - void Trim(std::string &str); - void Lower(std::string &str); - void Upper(std::string &str); - void AddInt(std::string &str, int value); - int ToInt(const std::string &str); - bool Compare(const std::string &str1, const std::string &str2, bool sensitive = true); - - void Replace(std::string &, const char*, const char *); - void Replace(std::string &, const char*, const std::string &); - void Replace(std::string &, const char*, int); - - void AppendKey(std::string &, KeySym, u16); - - // from SDL_ttf - void UTF8_to_UNICODE(u16 *unicode, const char *utf8, int len); - void UNICODE_to_UTF8(std::string & utf8, const u16 *unicode, size_t len); - -} - -int Sign(int); -KeySym KeySymFromChar(char); -bool PressIntKey(u32 min, u32 max, u32 & result); - -std::string GetDirname(const std::string &); -std::string GetBasename(const std::string &); - -u32 GetMemoryUsage(void); - -bool StoreMemToFile(const std::vector &, const std::string &); -bool StoreFileToMem(std::vector &, const std::string &); -bool FilePresent(const std::string &); - -#endif diff --git a/project/jni/application/fheroes2/src/engine/types.cpp b/project/jni/application/fheroes2/src/engine/types.cpp deleted file mode 100644 index c3196c5a7..000000000 --- a/project/jni/application/fheroes2/src/engine/types.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "types.h" - -u32 ReadBE32(const u8 *p) -{ - return ((((u32) *p) << 24) | (((u32) *(p + 1)) << 16) | (((u32) *(p + 2)) << 8) | ((u32) *(p + 3))); -} - -u32 ReadLE32(const u8 *p) -{ - return ((((u32) *(p + 3)) << 24) | (((u32) *(p + 2)) << 16) | (((u32) *(p + 1)) << 8) | ((u32) *p)); -} - -u16 ReadBE16(const u8 *p) -{ - return((((u16) *p) << 8) | ((u16) *(p + 1))); -} - -u16 ReadLE16(const u8 *p) -{ - return((((u16) *(p + 1)) << 8) | ((u16) *p)); -} - -void WriteBE32(u8 *p, u32 x) -{ - *p = static_cast(x >> 24); - *(p + 1) = static_cast((x & 0x00FF0000) >> 16); - *(p + 2) = static_cast((x & 0x0000FF00) >> 8); - *(p + 3) = static_cast(x & 0x000000FF); -} - -void WriteBE16(u8 *p, u16 x) -{ - *p = static_cast(x >> 8); - *(p + 1) = static_cast(x & 0x00FF); -} - -void WriteLE32(u8 *p, u32 x) -{ - *(p + 3) = static_cast(x >> 24); - *(p + 2) = static_cast((x & 0x00FF0000) >> 16); - *(p + 1) = static_cast((x & 0x0000FF00) >> 8); - *p = static_cast(x & 0x000000FF); -} - -void WriteLE16(u8 *p, u16 x) -{ - *(p + 1) = static_cast(x >> 8); - *p = static_cast(x & 0x00FF); -} diff --git a/project/jni/application/fheroes2/src/engine/types.h b/project/jni/application/fheroes2/src/engine/types.h deleted file mode 100644 index 56a8fb8d6..000000000 --- a/project/jni/application/fheroes2/src/engine/types.h +++ /dev/null @@ -1,137 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2TYPES_H -#define H2TYPES_H - -#include "SDL.h" - -typedef Sint8 s8; -typedef Uint8 u8; -typedef Sint16 s16; -typedef Uint16 u16; -typedef Sint32 s32; -typedef Uint32 u32; - -typedef SDL_Color Colors; - -#define MAXU16 0xFFFF -#define MAXU32 0xFFFFFFFF - -#if defined __SYMBIAN32__ -#define MKDIR(X) mkdir(X, S_IRWXU) -#define SEPARATOR '\\' -#elif defined __WIN32__ -#include -#define MKDIR(X) mkdir(X) -#define SEPARATOR '\\' -#else -#define MKDIR(X) mkdir(X, S_IRWXU) -#define SEPARATOR '/' -#endif - -#define DELAY(X) SDL_Delay(X) - -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - -#define RMASK16 0x0000f000 -#define GMASK16 0x00000f00 -#define BMASK16 0x000000f0 -#define AMASK16 0x0000000f - -#define RMASK24 0x00fc0000 -#define GMASK24 0x0003f000 -#define BMASK24 0x00000fc0 -#define AMASK24 0x0000003f - -#define RMASK32 0xff000000 -#define GMASK32 0x00ff0000 -#define BMASK32 0x0000ff00 -#define AMASK32 0x000000ff - -#else - -#define RMASK16 0x0000000f -#define GMASK16 0x000000f0 -#define BMASK16 0x00000f00 -#define AMASK16 0x0000f000 - -#define RMASK24 0x0000003f -#define GMASK24 0x00000fc0 -#define BMASK24 0x0003f000 -#define AMASK24 0x00fc0000 - -#define RMASK32 0x000000ff -#define GMASK32 0x0000ff00 -#define BMASK32 0x00ff0000 -#define AMASK32 0xff000000 - -#endif - -#define Swap16(X) X=SDL_Swap16(X) -#define Swap32(X) X=SDL_Swap32(X) -#define SwapLE16(X) X=SDL_SwapLE16(X) -#define SwapLE32(X) X=SDL_SwapLE32(X) -#define SwapBE16(X) X=SDL_SwapBE16(X) -#define SwapBE32(X) X=SDL_SwapBE32(X) - -u32 ReadBE32(const u8 *p); -u32 ReadLE32(const u8 *p); -u16 ReadBE16(const u8 *p); -u16 ReadLE16(const u8 *p); - -void WriteBE32(u8 *p, u32 x); -void WriteBE16(u8 *p, u16 x); -void WriteLE32(u8 *p, u32 x); -void WriteLE16(u8 *p, u16 x); - -#if defined __SYMBIAN32__ -#define PATH_MAX FILENAME_MAX -namespace std -{ - int c_abs(int x); - float c_abs(float x); - double c_abs(double x); - int c_isspace(char c); - -#define isspace(c) c_isspace(c) -#define abs(x) c_abs(x) -} -using namespace std; -#endif - -#if defined __MINGW32CE__ -#include -#ifndef PATH_MAX -#define PATH_MAX 255 -#endif -#define setlocale(x,y) 0 -#define system(x) 0 -#define putenv(x) SDL_putenv(x) -#define getenv(x) SDL_getenv(x) -#define getopt(x, y, z) -1 -#define optarg 0 -#else -#include -#endif - -#endif diff --git a/project/jni/application/fheroes2/src/engine/zzlib.cpp b/project/jni/application/fheroes2/src/engine/zzlib.cpp deleted file mode 100644 index d9f082ddb..000000000 --- a/project/jni/application/fheroes2/src/engine/zzlib.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "zzlib.h" - -#ifdef WITH_ZLIB -#include -#include - -bool ZLib::UnCompress(std::vector & dst, const char* src, size_t srcsz, bool debug) -{ - if(src && srcsz) - { - uLong dstsz = srcsz * 20; - dst.resize(dstsz); - int res = 0; - while(Z_BUF_ERROR == (res = uncompress(reinterpret_cast(&dst[0]), &dstsz, reinterpret_cast(src), srcsz))) - { dstsz = dst.size() * 2; dst.resize(dstsz); } - dst.resize(dstsz); - - switch(res) - { - case Z_OK: return true; - case Z_MEM_ERROR: if(debug) std::cerr << "ZLib::UnCompress: " << "Z_MEM_ERROR" << std::endl; return false; - case Z_BUF_ERROR: if(debug) std::cerr << "ZLib::UnCompress: " << "Z_BUF_ERROR" << std::endl; return false; - case Z_DATA_ERROR:if(debug) std::cerr << "ZLib::UnCompress: " << "Z_DATA_ERROR"<< std::endl; return false; - default: break; - } - - return Z_OK == res; - } - return false; -} - -bool ZLib::UnCompress(std::vector & dst, const std::vector & src, bool debug) -{ - return src.size() && UnCompress(dst, &src[0], src.size(), debug); -} - -bool ZLib::UnCompress(std::vector & dst, const std::string & src, bool debug) -{ - return src.size() && UnCompress(dst, src.c_str(), src.size(), debug); -} - -bool ZLib::Compress(std::vector & dst, const char* src, size_t srcsz) -{ - if(src && srcsz) - { - dst.resize(compressBound(srcsz)); - uLong dstsz = dst.size(); - int res = compress(reinterpret_cast(&dst[0]), &dstsz, reinterpret_cast(src), srcsz); - dst.resize(dstsz); - return Z_OK == res; - } - return false; -} - -bool ZLib::Compress(std::vector & dst, const std::vector & src) -{ - return src.size() && Compress(dst, &src[0], src.size()); -} - -bool ZLib::Compress(std::vector & dst, const std::string & src) -{ - return src.size() && Compress(dst, src.c_str(), src.size()); -} - -bool ZSurface::Load(u16 w, u16 h, u8 b, const u8* p, size_t s, bool a) -{ - if(!ZLib::UnCompress(buf, reinterpret_cast(p), s)) return false; - Set(&buf[0], w, h, b, a); - return true; -} - -#endif diff --git a/project/jni/application/fheroes2/src/engine/zzlib.h b/project/jni/application/fheroes2/src/engine/zzlib.h deleted file mode 100644 index b05ed9c62..000000000 --- a/project/jni/application/fheroes2/src/engine/zzlib.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2ZLIB_H -#define H2ZLIB_H - -#ifdef WITH_ZLIB - -#include -#include -#include "types.h" -#include "surface.h" - -namespace ZLib -{ - bool UnCompress(std::vector &, const char*, size_t, bool debug = false); - bool UnCompress(std::vector &, const std::vector &, bool debug = false); - bool UnCompress(std::vector &, const std::string &, bool debug = false); - - bool Compress(std::vector &, const char*, size_t); - bool Compress(std::vector &, const std::vector &); - bool Compress(std::vector &, const std::string &); -} - -class ZSurface : public Surface -{ -public: - ZSurface(){} - - bool Load(u16 w, u16 h, u8 b, const u8* p, size_t s, bool a); - -private: - std::vector buf; -}; - -#endif -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/agg.cpp b/project/jni/application/fheroes2/src/fheroes2/agg/agg.cpp deleted file mode 100644 index 1b7f2cc96..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/agg.cpp +++ /dev/null @@ -1,1284 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include - -#include "settings.h" -#include "text.h" -#include "engine.h" -#include "midi_xmi.h" -#include "midi_mid.h" -#include "dir.h" -#include "agg.h" - -#ifdef WITH_XML -#include "xmlccwrap.h" -#endif - -#define FATSIZENAME 15 - -/*AGG::File constructor */ -AGG::File::File(void) : count_items(0), stream(NULL) -{ -} - -bool AGG::File::Open(const std::string & fname) -{ - filename = fname; - stream = new std::ifstream(filename.c_str(), std::ios::binary); - - if(!stream || !stream->is_open()) - { - DEBUG(DBG_ENGINE , DBG_WARN, "AGG::File: error read file: " << filename << ", skipping..."); - return false; - } - - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::File: load: " << filename); - - stream->read(reinterpret_cast(&count_items), sizeof(u16)); - SwapLE16(count_items); - - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::File: count items: " << count_items); - - char buf[FATSIZENAME + 1]; - buf[FATSIZENAME] = 0; - - for(u16 ii = 0; ii < count_items; ++ii) - { - const u32 pos = stream->tellg(); - - stream->seekg(-FATSIZENAME * (count_items - ii), std::ios_base::end); - stream->read(buf, FATSIZENAME); - - const std::string key(buf); - - FAT & f = fat[key]; - - stream->seekg(pos, std::ios_base::beg); - - stream->read(reinterpret_cast(&f.crc), sizeof(u32)); - SwapLE32(f.crc); - - stream->read(reinterpret_cast(&f.offset), sizeof(u32)); - SwapLE32(f.offset); - - stream->read(reinterpret_cast(&f.size), sizeof(u32)); - SwapLE32(f.size); - } - return true; -} - -AGG::File::~File() -{ - if(stream) - { - stream->close(); - delete stream; - } -} - -bool AGG::File::isGood(void) const -{ - return stream && stream->good() && count_items; -} - -/* get AGG file name */ -const std::string & AGG::File::Name(void) const -{ - return filename; -} - -/* get FAT element */ -const AGG::FAT & AGG::File::Fat(const std::string & key) -{ - return fat[key]; -} - -/* get count elements */ -u16 AGG::File::CountItems(void) -{ - return count_items; -} - -/* dump FAT */ -void AGG::FAT::Dump(const std::string & n) const -{ - printf("%s\t%lX\t%lX\t%lX\n", n.c_str(), static_cast(crc), static_cast(offset), static_cast(size)); -} - -/* read element to body */ -bool AGG::File::Read(const std::string & key, std::vector & body) -{ - const FAT & f = fat[key]; - - if(IS_DEBUG(DBG_ENGINE, DBG_TRACE)) f.Dump(key); - - if(f.size) - { - DEBUG(DBG_ENGINE , DBG_TRACE, "AGG::File::Read: " << key); - - body.resize(f.size); - - stream->seekg(f.offset, std::ios_base::beg); - - stream->read(reinterpret_cast(&body[0]), f.size); - - return true; - } - - return false; -} - -/* dump AGG file */ -void AGG::File::Dump(void) const -{ - std::map::const_iterator it1 = fat.begin(); - std::map::const_iterator it2 = fat.end(); - - for(; it1 != it2; ++it1) - { - const std::string & n = (*it1).first; - const FAT & f = (*it1).second; - - f.Dump(n); - } -} - -/* AGG::Cache constructor */ -AGG::Cache::Cache() -{ -#ifdef WITH_TTF - Settings & conf = Settings::Get(); - const std::string font1(conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "fonts" + SEPARATOR + conf.FontsNormal()); - const std::string font2(conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "fonts" + SEPARATOR + conf.FontsSmall()); - - if(conf.Unicode()) - { - if(!font_medium.Open(font1, conf.FontsNormalSize()) || - !font_small.Open(font2, conf.FontsSmallSize())) conf.SetUnicode(false); - } -#endif - icn_cache = new icn_cache_t [ICN::UNKNOWN + 1]; - til_cache = new til_cache_t [TIL::UNKNOWN + 1]; - - icn_cache[ICN::UNKNOWN].count = 1; - icn_cache[ICN::UNKNOWN].sprites = new Sprite [1]; - icn_cache[ICN::UNKNOWN].reflect = new Sprite [1]; - - icn_registry_enable = false; - icn_registry.reserve(250); -} - -AGG::Cache::~Cache() -{ - if(icn_cache) - { - for(u16 ii = 0; ii < ICN::UNKNOWN + 1; ++ii) - { - if(icn_cache[ii].sprites) delete [] icn_cache[ii].sprites; - if(icn_cache[ii].reflect) delete [] icn_cache[ii].reflect; - } - delete [] icn_cache; - } - - if(til_cache) - { - for(u16 ii = 0; ii < TIL::UNKNOWN + 1; ++ii) - { - if(til_cache[ii].sprites) delete [] til_cache[ii].sprites; - } - delete [] til_cache; - } -} - -void AGG::Cache::ClearAllICN(void) -{ - if(icn_cache) - { - for(u16 ii = 0; ii < ICN::UNKNOWN; ++ii) - { - if(icn_cache[ii].sprites) delete [] icn_cache[ii].sprites; - icn_cache[ii].sprites = NULL; - if(icn_cache[ii].reflect) delete [] icn_cache[ii].reflect; - icn_cache[ii].reflect = NULL; - } - } -} - -void AGG::Cache::ClearAllWAV(void) -{ - loop_sounds.clear(); - - std::map >::iterator it1 = wav_cache.begin(); - std::map >::iterator it2 = wav_cache.end(); - - for(; it1 != it2; ++it1) if((*it1).second.size()) (*it1).second.clear(); -} - -void AGG::Cache::ClearAllMID(void) -{ - std::map >::iterator it1 = mid_cache.begin(); - std::map >::iterator it2 = mid_cache.end(); - - for(; it1 != it2; ++it1) if((*it1).second.size()) (*it1).second.clear(); -} - -/* get AGG::Cache object */ -AGG::Cache & AGG::Cache::Get(void) -{ - static Cache agg_cache; - - return agg_cache; -} - -/* read data directory */ -bool AGG::Cache::ReadDataDir(void) -{ - const Settings & conf = Settings::Get(); - Dir dir; - - dir.Read(conf.DataDirectory(), ".agg", false); - dir.Read(conf.LocalPrefix() + SEPARATOR + conf.DataDirectory(), ".agg", false); - - // not found agg, exit - if(0 == dir.size()) return false; - - // attach agg files - for(Dir::const_iterator itd = dir.begin(); itd != dir.end(); ++itd) - { - std::string lower = *itd; - String::Lower(lower); - if(std::string::npos != lower.find("heroes2.agg") && !heroes2_agg.isGood()) heroes2_agg.Open(*itd); - if(std::string::npos != lower.find("heroes2x.agg") && !heroes2x_agg.isGood()) heroes2x_agg.Open(*itd); - } - - if(heroes2x_agg.isGood()) Settings::Get().SetPriceLoyaltyVersion(); - - return heroes2_agg.isGood(); -} - -bool AGG::Cache::ReadChunk(const std::string & key, std::vector & body) -{ - if(heroes2x_agg.isGood() && heroes2x_agg.Read(key, body)) return true; - - return heroes2_agg.isGood() && heroes2_agg.Read(key, body); -} - -/* load manual ICN object */ -void AGG::Cache::LoadExtICN(icn_cache_t & v, const ICN::icn_t icn, const u16 index, bool reflect) -{ - DEBUG(DBG_ENGINE, DBG_TRACE, "AGG::Cache::LoadExtICN: " << ICN::GetString(icn) << ", " << index); - - u8 count = 0; // for animation sprite need update count for ICN::AnimationFrame - - switch(icn) - { - case ICN::TELEPORT1: - case ICN::TELEPORT2: - case ICN::TELEPORT3: count = 8; break; - case ICN::FOUNTAIN: count = 2; break; - case ICN::TREASURE: count = 2; break; - case ICN::ROUTERED: count = 145; break; - case ICN::YELLOW_FONT: - case ICN::YELLOW_SMALFONT: count = 96; break; - - default: break; - } - - if(NULL == v.sprites) - { - v.sprites = new Sprite [count]; - v.reflect = new Sprite [count]; - v.count = count; - } - - for(u8 ii = 0; ii < count; ++ii) - { - Sprite & sprite = reflect ? v.reflect[ii] : v.sprites[ii]; - - switch(icn) - { - case ICN::TELEPORT1: - LoadOrgICN(sprite, ICN::OBJNMUL2, 116, false); - sprite.ChangeColorIndex(0xEE, 0xEE + ii / 2); - break; - - case ICN::TELEPORT2: - LoadOrgICN(sprite, ICN::OBJNMUL2, 119, false); - sprite.ChangeColorIndex(0xEE, 0xEE + ii); - break; - - case ICN::TELEPORT3: - LoadOrgICN(sprite, ICN::OBJNMUL2, 122, false); - sprite.ChangeColorIndex(0xEE, 0xEE + ii); - break; - - case ICN::FOUNTAIN: - LoadOrgICN(sprite, ICN::OBJNMUL2, 15, false); - sprite.ChangeColorIndex(0xE8, 0xE8 - ii); - sprite.ChangeColorIndex(0xE9, 0xE9 - ii); - sprite.ChangeColorIndex(0xEA, 0xEA - ii); - sprite.ChangeColorIndex(0xEB, 0xEB - ii); - sprite.ChangeColorIndex(0xEC, 0xEC - ii); - sprite.ChangeColorIndex(0xED, 0xED - ii); - sprite.ChangeColorIndex(0xEE, 0xEE - ii); - sprite.ChangeColorIndex(0xEF, 0xEF - ii); - break; - - case ICN::TREASURE: - LoadOrgICN(sprite, ICN::OBJNRSRC, 19, false); - sprite.ChangeColorIndex(0x0A, ii ? 0x00 : 0x0A); - sprite.ChangeColorIndex(0xC2, ii ? 0xD6 : 0xC2); - sprite.ChangeColorIndex(0x64, ii ? 0xDA : 0x64); - break; - - case ICN::ROUTERED: - LoadOrgICN(sprite, ICN::ROUTE, ii, false); - sprite.ChangeColorIndex(0x55, 0xB0); - sprite.ChangeColorIndex(0x5C, 0xB7); - sprite.ChangeColorIndex(0x60, 0xBB); - break; - - case ICN::YELLOW_FONT: - LoadOrgICN(sprite, ICN::FONT, ii, false); - sprite.ChangeColorIndex(0x0A, 0xDA); - sprite.ChangeColorIndex(0x0B, 0xDA); - sprite.ChangeColorIndex(0x0C, 0xDA); - sprite.ChangeColorIndex(0x0D, 0xDA); - sprite.ChangeColorIndex(0x0E, 0xDB); - sprite.ChangeColorIndex(0x0F, 0xDB); - sprite.ChangeColorIndex(0x10, 0xDB); - sprite.ChangeColorIndex(0x11, 0xDB); - sprite.ChangeColorIndex(0x12, 0xDB); - sprite.ChangeColorIndex(0x13, 0xDB); - sprite.ChangeColorIndex(0x14, 0xDB); - break; - - case ICN::YELLOW_SMALFONT: - LoadOrgICN(sprite, ICN::SMALFONT, ii, false); - sprite.ChangeColorIndex(0x0A, 0xDA); - sprite.ChangeColorIndex(0x0B, 0xDA); - sprite.ChangeColorIndex(0x0C, 0xDA); - sprite.ChangeColorIndex(0x0D, 0xDA); - sprite.ChangeColorIndex(0x0E, 0xDB); - sprite.ChangeColorIndex(0x0F, 0xDB); - sprite.ChangeColorIndex(0x10, 0xDB); - sprite.ChangeColorIndex(0x11, 0xDB); - sprite.ChangeColorIndex(0x12, 0xDB); - sprite.ChangeColorIndex(0x13, 0xDB); - sprite.ChangeColorIndex(0x14, 0xDB); - break; - - default: break; - } - } -} - -bool AGG::Cache::LoadAltICN(icn_cache_t & v, const std::string & spec, const u16 index, bool reflect) -{ -#ifdef WITH_XML - // parse spec.xml - TiXmlDocument doc; - const TiXmlElement* xml_icn = NULL; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_icn = doc.FirstChildElement("icn"))) - { - int count, ox, oy; - xml_icn->Attribute("count", &count); - - if(NULL == v.sprites) - { - v.count = count; - v.sprites = new Sprite [v.count]; - v.reflect = new Sprite [v.count]; - } - - // find current image - const TiXmlElement *xml_sprite = xml_icn->FirstChildElement("sprite"); - u16 ii = 0; - for(; ii != index && xml_sprite; xml_sprite = xml_sprite->NextSiblingElement("sprite"), ++ii); - - if(xml_sprite && ii == index) - { - xml_sprite->Attribute("ox", &ox); - xml_sprite->Attribute("oy", &oy); - std::string name(spec); - String::Replace(name, "spec.xml", xml_sprite->Attribute("name")); - Sprite & sp = reflect ? v.reflect[index] : v.sprites[index]; - // good load - if(sp.Load(name.c_str()) && sp.isValid()) - { - sp.SetOffset(ox, oy); - DEBUG(DBG_ENGINE, DBG_TRACE, "AGG::Cache::LoadAltICN: " << spec << ", " << index); - - return true; - } - } - DEBUG(DBG_ENGINE , DBG_WARN, "AGG::Cache::LoadAltICN: broken xml file: " << spec); - } -#endif - - return false; -} - -void AGG::Cache::LoadOrgICN(Sprite & sp, const ICN::icn_t icn, const u16 index, bool reflect) -{ - std::vector body; - - if(ReadChunk(ICN::GetString(icn), body)) - { - // hard fix artifact "ultimate stuff" sprite for loyalty version - if(Settings::Get().PriceLoyaltyVersion() && - ICN::ARTIFACT == icn && - Artifact::IndexSprite64(Artifact::ULTIMATE_STAFF) == index) - { - body.clear(); - heroes2_agg.Read(ICN::GetString(icn), body); - } - - // loading original - DEBUG(DBG_ENGINE, DBG_TRACE, "AGG::Cache::LoadOrgICN: " << ICN::GetString(icn) << ", " << index); - - const u16 count = ReadLE16(&body[0]); - ICN::Header header1, header2; - - header1.Load(&body[6 + index * ICN::Header::SizeOf()]); - if(index + 1 != count) header2.Load(&body[6 + (index + 1) * ICN::Header::SizeOf()]); - - const u32 size_data = (index + 1 != count ? header2.OffsetData() - header1.OffsetData() : - // total size - ReadLE32(&body[2]) - header1.OffsetData()); - - sp.Set(header1.Width(), header1.Height(), ICN::RequiresAlpha(icn)); - sp.SetOffset(header1.OffsetX(), header1.OffsetY()); - sp.SetColorKey(); - Sprite::DrawICN(sp, &body[6 + header1.OffsetData()], size_data, reflect); - Sprite::AddonExtensionModify(sp, icn, index); - } - else - Error::Except("AGG::Cache::LoadOrgICN: ReadChunk: ", ICN::GetString(icn)); -} - -void AGG::Cache::LoadOrgICN(icn_cache_t & v, const ICN::icn_t icn, const u16 index, bool reflect) -{ - if(NULL == v.sprites) - { - std::vector body; - ReadChunk(ICN::GetString(icn), body); - - v.count = ReadLE16(&body[0]); - v.sprites = new Sprite [v.count]; - v.reflect = new Sprite [v.count]; - } - - Sprite & sp = reflect ? v.reflect[index] : v.sprites[index]; - - LoadOrgICN(sp, icn, index, reflect); - // set display format - if(8 != sp.depth() && - !(Settings::Get().QVGA() && ICN::NeedMinify4PocketPC(icn, index))) sp.SetDisplayFormat(); -} - -/* load ICN object to AGG::Cache */ -void AGG::Cache::LoadICN(const ICN::icn_t icn, u16 index, bool reflect) -{ - icn_cache_t & v = icn_cache[icn]; - - if(reflect) - { - if(v.reflect && (index >= v.count || v.reflect[index].isValid())) return; - } - else - { - if(v.sprites && (index >= v.count || v.sprites[index].isValid())) return; - } - - const Settings & conf = Settings::Get(); - bool skip_origin = false; - - // load modify sprite - if(ICN::isModifiedSprite(icn)) - { - LoadExtICN(v, icn, index, reflect); - skip_origin = true; - } - else - // load from images dir - if(conf.UseAltResource()) - { - Dir dir; - std::string name(ICN::GetString(icn)); - String::Lower(name); - const std::string xml_spec(conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "images" + SEPARATOR + name + SEPARATOR + "spec.xml"); - - if(FilePresent(xml_spec) && - LoadAltICN(v, xml_spec, index, reflect)) skip_origin = true; - } - - //load origin sprite - if(!skip_origin) LoadOrgICN(v, icn, index, reflect); - - // pocketpc: scale sprites - if(Settings::Get().QVGA() && ICN::NeedMinify4PocketPC(icn, index)) - { - Sprite & sp = reflect ? v.reflect[index] : v.sprites[index]; - sp.ScaleMinifyByTwo(); - //sp.SetDisplayFormat(); - } - - // registry icn - if(icn_registry_enable && - icn_registry.end() == std::find(icn_registry.begin(), icn_registry.end(), icn)) - icn_registry.push_back(icn); -} - -/* load TIL object to AGG::Cache */ -void AGG::Cache::LoadTIL(const TIL::til_t til) -{ - til_cache_t & v = til_cache[til]; - - if(v.sprites) return; - - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadTIL: " << TIL::GetString(til)); - - std::vector body; - - if(ReadChunk(TIL::GetString(til), body)) - { - const u16 count = ReadLE16(&body.at(0)); - const u16 width = ReadLE16(&body.at(2)); - const u16 height= ReadLE16(&body.at(4)); - - const u32 tile_size = width * height; - const u32 body_size = 6 + count * tile_size; - - // check size - if(body.size() != body_size) - { - DEBUG(DBG_ENGINE , DBG_WARN, "AGG::Cache::LoadTIL: size mismach, skipping..."); - return; - } - - v.count = count * 4; // rezerve for rotate sprites - v.sprites = new Surface [v.count]; - - for(u16 ii = 0; ii < count; ++ii) - v.sprites[ii].Set(&body[6 + ii * tile_size], width, height, 1, false); - } -} - -/* load 82M object to AGG::Cache in Audio::CVT */ -void AGG::Cache::LoadWAV(const M82::m82_t m82) -{ - std::vector & v = wav_cache[m82]; - - if(v.size() || !Mixer::isValid()) return; - -#ifdef WITH_MIXER - const Settings & conf = Settings::Get(); - - if(conf.UseAltResource()) - { - std::string name(M82::GetString(m82)); - String::Lower(name); - // ogg - String::Replace(name, ".82m", ".ogg"); - std::string sound = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "sounds" + SEPARATOR + name; - - if(StoreFileToMem(v, sound)) - { - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadWAV: " << sound); - return; - } - - // mp3 - String::Replace(name, ".82m", ".mp3"); - sound = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "sounds" + SEPARATOR + name; - - if(StoreFileToMem(v, sound)) - { - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadWAV: " << sound); - return; - } - } -#endif - - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadWAV: " << M82::GetString(m82)); - std::vector body; - -#ifdef WITH_MIXER - if(ReadChunk(M82::GetString(m82), body)) - { - // create WAV format - v.resize(body.size() + 44); - - WriteLE32(&v[0], 0x46464952); // RIFF - WriteLE32(&v[4], body.size() + 0x24); // size - WriteLE32(&v[8], 0x45564157); // WAVE - WriteLE32(&v[12], 0x20746D66); // FMT - WriteLE32(&v[16], 0x10); // size_t - WriteLE16(&v[20], 0x01); // format - WriteLE16(&v[22], 0x01); // channels - WriteLE32(&v[24], 22050); // samples - WriteLE32(&v[28], 22050); // byteper - WriteLE16(&v[32], 0x01); // align - WriteLE16(&v[34], 0x08); // bitsper - WriteLE32(&v[36], 0x61746164); // DATA - WriteLE32(&v[40], body.size()); // size - - std::copy(body.begin(), body.end(), &v[44]); - } -#else - Audio::Spec wav_spec; - wav_spec.format = AUDIO_U8; - wav_spec.channels = 1; - wav_spec.freq = 22050; - - const Audio::Spec & hardware = Audio::GetHardwareSpec(); - - Audio::CVT cvt; - - if(cvt.Build(wav_spec, hardware) && - ReadChunk(M82::GetString(m82), body)) - { - const u32 size = cvt.len_mult * body.size(); - - cvt.buf = new u8[size]; - cvt.len = body.size(); - - memcpy(cvt.buf, &body[0], body.size()); - - cvt.Convert(); - - v.assign(cvt.buf, cvt.buf + size - 1); - - delete [] cvt.buf; - cvt.buf = NULL; - } -#endif -} - -/* load XMI object to AGG::Cache */ -void AGG::Cache::LoadMID(const XMI::xmi_t xmi) -{ - std::vector & v = mid_cache[xmi]; - - if(v.size()) return; - - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadMID: " << XMI::GetString(xmi)); - - if(! Mixer::isValid()) return; - - std::vector body; - - if(ReadChunk(XMI::GetString(xmi), body)) - { - MIDI::Xmi x; - MIDI::Mid m; - MIDI::MTrk track; - - x.Read(body); - track.ImportXmiEVNT(x.EVNT()); - - m.AddTrack(track); - m.SetPPQN(64); - - m.Write(v); - } -} - -void AGG::Cache::LoadPAL(void) -{ - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::LoadPAL: " << Palette::Get().Size()); -} - -void AGG::Cache::LoadFNT(void) -{ -#ifdef WITH_TTF - const Settings & conf = Settings::Get(); - - if(conf.Unicode()) - { - if(fnt_cache.size()) return; - - const char *letters = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"; - const u8 letters_size = std::strlen(letters); - u16 *unicode = new u16[letters_size + 1]; - - String::UTF8_to_UNICODE(unicode, letters, letters_size); - - for(u8 ii = 0; ii < letters_size; ++ii) LoadFNT(unicode[ii]); - - delete [] unicode; - - if(fnt_cache.size()) - { - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::LoadFonts: normal fonts " << conf.FontsNormal()); - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::LoadFonts: small fonts " << conf.FontsSmall()); - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::LoadFonts: preload english charsets"); - } - else - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::LoadFonts: internal."); - } - else -#endif - { - PreloadObject(ICN::SMALFONT); - PreloadObject(ICN::FONT); - - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::LoadFonts: internal."); - } -} - -#ifdef WITH_TTF -void AGG::Cache::LoadFNT(u16 ch) -{ - const Settings & conf = Settings::Get(); - - if(conf.Unicode()) - { - const Colors white = { 0xFF, 0xFF, 0xFF, 0x00 }; - const Colors yellow= { 0xFF, 0xFF, 0x00, 0x00 }; - - // small - font_small.RenderUnicodeChar(fnt_cache[ch].small_white, ch, white, conf.FontsRenderBlended() ? SDL::Font::BLENDED : SDL::Font::SOLID); - font_small.RenderUnicodeChar(fnt_cache[ch].small_yellow, ch, yellow, conf.FontsRenderBlended() ? SDL::Font::BLENDED : SDL::Font::SOLID); - - // medium - if(!(conf.QVGA() && !conf.Unicode())) - { - font_medium.RenderUnicodeChar(fnt_cache[ch].medium_white, ch, white, conf.FontsRenderBlended() ? SDL::Font::BLENDED : SDL::Font::SOLID); - font_medium.RenderUnicodeChar(fnt_cache[ch].medium_yellow, ch, yellow, conf.FontsRenderBlended() ? SDL::Font::BLENDED : SDL::Font::SOLID); - } - - DEBUG(DBG_ENGINE , DBG_TRACE, "AGG::LoadChar: 0x" << std::hex << static_cast(ch)); - } -} -#endif - -/* free ICN object in AGG::Cache */ -void AGG::Cache::FreeICN(const ICN::icn_t icn) -{ - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::FreeICN: " << ICN::GetString(icn)); - if(icn_cache[icn].sprites){ delete [] icn_cache[icn].sprites; icn_cache[icn].sprites = NULL; } - if(icn_cache[icn].reflect){ delete [] icn_cache[icn].reflect; icn_cache[icn].reflect = NULL; } - icn_cache[icn].count = 0; -} - -/* free TIL object in AGG::Cache */ -void AGG::Cache::FreeTIL(const TIL::til_t til) -{ - if(til_cache[til].sprites){ delete [] til_cache[til].sprites; til_cache[til].sprites = NULL; } - til_cache[til].count = 0; -} - -/* free 82M object in AGG::Cache */ -void AGG::Cache::FreeWAV(const M82::m82_t m82) -{ - std::vector & v = wav_cache[m82]; - - if(v.size()) v.clear(); -} - -/* free XMI object in AGG::Cache */ -void AGG::Cache::FreeMID(const XMI::xmi_t xmi) -{ - std::vector & v = mid_cache[xmi]; - - if(v.size()) v.clear(); -} - -/* return ICN sprite from AGG::Cache */ -const Sprite & AGG::Cache::GetICN(const ICN::icn_t icn, u16 index, bool reflect) -{ - icn_cache_t & v = icn_cache[icn]; - - // out of range? - if(v.count && index >= v.count) - { - DEBUG(DBG_ENGINE , DBG_WARN, "AGG::GetICN: " << ICN::GetString(icn) << ", index out of range: " << index); - index = 0; - } - - // need load? - if(0 == v.count || ((reflect && (!v.reflect || !v.reflect[index].isValid())) || (!v.sprites || !v.sprites[index].isValid()))) - LoadICN(icn, index, reflect); - - // invalid sprite? - if((reflect && !v.reflect[index].isValid()) || (!reflect && !v.sprites[index].isValid())) - { - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::Cache::GetICN: return invalid sprite: " << ICN::GetString(icn) << ", index: " << index << ", reflect: " << (reflect ? "true" : "false")); - } - - return reflect ? v.reflect[index] : v.sprites[index]; -} - -/* return count of sprites from specific ICN */ -int AGG::Cache::GetICNCount(const ICN::icn_t icn) -{ - if(icn_cache[icn].count == 0) AGG::GetICN(icn, 0); - return icn_cache[icn].count; -} - -/* return TIL surface from AGG::Cache */ -const Surface & AGG::Cache::GetTIL(const TIL::til_t til, u16 index, u8 shape) -{ - til_cache_t & v = til_cache[til]; - - if(0 == v.count) LoadTIL(til); - - u16 index2 = index; - - if(shape) - { - switch(til) - { - case TIL::STON: index2 += 36 * (shape % 4); break; - case TIL::CLOF32: index2 += 4 * (shape % 4); break; - case TIL::GROUND32: index2 += 432 * (shape % 4); break; - default: break; - } - } - - if(index2 >= v.count) - { - DEBUG(DBG_ENGINE , DBG_WARN, "AGG::GetTIL: " << TIL::GetString(til) << ", index out of range: " << index); - index2 = 0; - } - - Surface & surface = v.sprites[index2]; - - if(shape && ! surface.isValid()) - { - const Surface & src = v.sprites[index]; - - if(src.isValid()) - { - surface.Set(src.w(), src.h(), 8, SDL_SWSURFACE); - TIL::Reflect(surface, src, shape); - } - else - DEBUG(DBG_ENGINE , DBG_WARN, "AGG::GetTIL: src surface is NULL"); - } - - if(! surface.isValid()) - { - DEBUG(DBG_ENGINE , DBG_WARN, "AGG::GetTIL: invalid sprite: " << TIL::GetString(til) << ", index: " << index); - } - - return surface; -} - -/* return CVT from AGG::Cache */ -const std::vector & AGG::Cache::GetWAV(const M82::m82_t m82) -{ - const std::vector & v = wav_cache[m82]; - - if(v.empty()) LoadWAV(m82); - - return v; -} - -/* return MID from AGG::Cache */ -const std::vector & AGG::Cache::GetMID(const XMI::xmi_t xmi) -{ - const std::vector & v = mid_cache[xmi]; - - if(v.empty()) LoadMID(xmi); - - return v; -} - -#ifdef WITH_TTF -/* return FNT cache */ -const Surface & AGG::Cache::GetFNT(u16 c, u8 f) -{ - if(!fnt_cache[c].small_white.isValid()) LoadFNT(c); - - switch(f) - { - case Font::YELLOW_SMALL: return fnt_cache[c].small_yellow; - case Font::BIG: return fnt_cache[c].medium_white; - case Font::YELLOW_BIG: return fnt_cache[c].medium_yellow; - default: break; - } - - return fnt_cache[c].small_white; -} - -const SDL::Font & AGG::Cache::GetMediumFont(void) const -{ - return font_medium; -} - -const SDL::Font & AGG::Cache::GetSmallFont(void) const -{ - return font_small; -} -#endif - -bool AGG::Cache::isValidFonts(void) const -{ -#ifdef WITH_TTF - return Settings::Get().Unicode() ? font_small.isValid() && font_medium.isValid() : false; -#endif - return false; -} - -void AGG::Cache::ICNRegistryEnable(bool f) -{ - icn_registry_enable = f; -} - -void AGG::Cache::ICNRegistryFreeObjects(void) -{ - std::vector::const_iterator it1 = icn_registry.begin(); - std::vector::const_iterator it2 = icn_registry.end(); - for(; it1 != it2; ++it1) if(!ICN::SkipRegistryFree(*it1)) FreeICN(*it1); -} - -void AGG::Cache::Dump(void) const -{ - std::cout << "AGG::Cache::Dump:" << std::endl; - u32 total1 = 0; - u32 total2 = 0; - - if(icn_cache) - { - total1 = 0; - for(u16 ii = 0; ii < ICN::UNKNOWN; ++ii) - { - total2 = 0; - if(icn_cache[ii].sprites) - for(u16 jj = 0; jj < icn_cache[ii].count; ++jj) - total2 += (icn_cache[ii].sprites[jj].GetSize() + icn_cache[ii].reflect[jj].GetSize()); - if(icn_cache[ii].count) - std::cout << "ICN: " << ICN::GetString((ICN::icn_t) ii) << ", count: " << icn_cache[ii].count << ", total: " << total2 << std::endl; - total1 += total2; - } - std::cout << "ICN: " << " total: " << total1 << std::endl; - } - - if(til_cache) - { - total1 = 0; - for(u16 ii = 0; ii < TIL::UNKNOWN; ++ii) - { - total2 = 0; - if(til_cache[ii].sprites) - for(u16 jj = 0; jj < til_cache[ii].count; ++jj) - total2 += til_cache[ii].sprites[jj].GetSize(); - if(til_cache[ii].count) - std::cout << "TIL: " << TIL::GetString((TIL::til_t) ii) << ", count: " << til_cache[ii].count << ", total: " << total2 << std::endl; - total1 += total2; - } - std::cout << "TIL: " << " total: " << total1 << std::endl; - } - - if(wav_cache.size()) - { - total1 = 0; - std::map >::const_iterator it1 = wav_cache.begin(); - std::map >::const_iterator it2 = wav_cache.end(); - for(; it1 != it2; ++it1) - { - if((*it1).second.size()) - std::cout << "M82: " << M82::GetString((*it1).first) << ", size: " << (*it1).second.size() << std::endl; - total1 += (*it1).second.size(); - } - std::cout << "M82: " << " total: " << total1 << std::endl; - } - - if(mid_cache.size()) - { - total1 = 0; - std::map >::const_iterator it1 = mid_cache.begin(); - std::map >::const_iterator it2 = mid_cache.end(); - for(; it1 != it2; ++it1) - { - if((*it1).second.size()) - std::cout << "XMI: " << XMI::GetString((*it1).first) << ", size: " << (*it1).second.size() << std::endl; - total1 += (*it1).second.size(); - } - std::cout << "XMI: " << " total: " << total1 << std::endl; - } - -#ifdef WITH_TTF - if(fnt_cache.size()) - { - total1 = 0; - std::map::const_iterator it1 = fnt_cache.begin(); - std::map::const_iterator it2 = fnt_cache.end(); - for(; it1 != it2; ++it1) - total1 += ((*it1).second.medium_white.GetSize() + (*it1).second.medium_yellow.GetSize() + (*it1).second.small_white.GetSize() + (*it1).second.small_yellow.GetSize()); - - std::cout << "FNT: " << " total: " << total1 << std::endl; - } -#endif -} - -// wrapper AGG::PreloadObject -void AGG::PreloadObject(const ICN::icn_t icn, bool reflect) -{ - // deprecated - // or loading all sprites? AGG::Cache::Get().LoadICN(icn, index, reflect); -} - -void AGG::PreloadObject(const TIL::til_t til) -{ - return AGG::Cache::Get().LoadTIL(til); -} - -void AGG::ICNRegistryEnable(bool f) -{ - AGG::Cache::Get().ICNRegistryEnable(f); -} - -void AGG::ICNRegistryFreeObjects(void) -{ - AGG::Cache::Get().ICNRegistryFreeObjects(); -} - -// wrapper AGG::FreeObject -void AGG::FreeObject(const ICN::icn_t icn) -{ - return AGG::Cache::Get().FreeICN(icn); -} - -void AGG::FreeObject(const TIL::til_t til) -{ - return AGG::Cache::Get().FreeTIL(til); -} - -// wrapper AGG::GetXXX -int AGG::GetICNCount(const ICN::icn_t icn) -{ - return AGG::Cache::Get().GetICNCount(icn); -} - -const Sprite & AGG::GetICN(const ICN::icn_t icn, const u16 index, bool reflect) -{ - return AGG::Cache::Get().GetICN(icn, index, reflect); -} - -const Surface & AGG::GetTIL(const TIL::til_t til, const u16 index, const u8 shape) -{ - return AGG::Cache::Get().GetTIL(til, index, shape); -} - -void AGG::Cache::ResetMixer(void) -{ - Mixer::Reset(); - loop_sounds.clear(); - loop_sounds.reserve(7); -} - -void AGG::Cache::LoadLOOPXXSounds(const u16* vols) -{ - const Settings & conf = Settings::Get(); - - if(conf.Sound() && vols) - { - // set volume loop sounds - for(u8 channel = 0; channel != LOOPXX_COUNT; ++channel) - { - u16 vol = vols[channel]; - M82::m82_t m82 = M82::GetLOOP00XX(channel); - if(M82::UNKNOWN == m82) continue; - - // find loops - std::vector::iterator it = std::find_if(loop_sounds.begin(), loop_sounds.end(), - std::bind2nd(std::mem_fun_ref(&loop_sound_t::isM82), m82)); - - if(it != loop_sounds.end()) - { - // unused and free - if(0 == vol) - { - if(Mixer::isPlaying((*it).channel)) - { - Mixer::Pause((*it).channel); - Mixer::Volume((*it).channel, Mixer::MaxVolume() * conf.SoundVolume() / 10); - Mixer::Stop((*it).channel); - } - (*it).sound = M82::UNKNOWN; - } - // used and set vols - else - if(Mixer::isPlaying((*it).channel)) - { - Mixer::Pause((*it).channel); - Mixer::Volume((*it).channel, vol * conf.SoundVolume() / 10); - Mixer::Resume((*it).channel); - } - } - else - // new sound - if(0 != vol) - { - const std::vector & v = AGG::Cache::Get().GetWAV(m82); - int ch = Mixer::Play(&v[0], v.size(), -1, true); - - if(0 <= ch) - { - Mixer::Pause(ch); - Mixer::Volume(ch, vol * conf.SoundVolume() / 10); - Mixer::Resume(ch); - - // find unused - std::vector::iterator it = std::find_if(loop_sounds.begin(), loop_sounds.end(), - std::bind2nd(std::mem_fun_ref(&loop_sound_t::isM82), M82::UNKNOWN)); - - if(it != loop_sounds.end()) - { - (*it).sound = m82; - (*it).channel = ch; - } - else - loop_sounds.push_back(loop_sound_t(m82, ch)); - - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::PlayLOOPSound: " << M82::GetString(m82)); - } - } - } - } -} - -/* wrapper Audio::Play */ -void AGG::PlaySound(const M82::m82_t m82) -{ - const Settings & conf = Settings::Get(); - - if(conf.Sound()) - { - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::PlaySound: " << M82::GetString(m82)); - const std::vector & v = AGG::Cache::Get().GetWAV(m82); - int ch = Mixer::Play(&v[0], v.size(), -1, false); - Mixer::Pause(ch); - Mixer::Volume(ch, Mixer::MaxVolume() * conf.SoundVolume() / 10); - Mixer::Resume(ch); - } -} - -/* wrapper Audio::Play */ -void AGG::PlayMusic(const MUS::mus_t mus, bool loop) -{ - static MUS::mus_t old = MUS::UNKNOWN; - const Settings & conf = Settings::Get(); - - if(!conf.Music() || MUS::UNUSED == mus || MUS::UNKNOWN == mus || (old == mus && Music::isPlaying())) return; - - old = mus; - - if(conf.MusicExt()) - { - const std::string musname(conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "music" + SEPARATOR + MUS::GetString(mus)); -#ifdef WITH_MIXER - std::string shortname(conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "music" + SEPARATOR + MUS::GetString(mus, true)); - const char* filename = NULL; - - if(FilePresent(musname)) filename = musname.c_str(); - else - if(FilePresent(shortname)) filename = shortname.c_str(); - else - { - String::Replace(shortname, ".ogg", ".mp3"); - if(FilePresent(shortname)) filename = shortname.c_str(); - else - DEBUG(DBG_ENGINE , DBG_WARN, "AGG::PlayMusic: error read file: " << musname << ", skipping..."); - } - - if(filename) Music::Play(filename, loop); -#else - if(FilePresent(musname) && conf.PlayMusCommand().size()) - { - const std::string run = conf.PlayMusCommand() + " " + musname; - Music::Play(run.c_str(), loop); - } -#endif - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::PlayMusic: " << MUS::GetString(mus)); - } - else -#ifdef WITH_AUDIOCD - if(conf.MusicCD() && Cdrom::isValid()) - { - Cdrom::Play(mus, loop); - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::PlayMusic: cd track " << static_cast(mus)); - } - else -#endif - if(conf.MusicMIDI()) - { - XMI::xmi_t xmi = XMI::FromMUS(mus); - if(XMI::UNKNOWN != xmi) - { -#ifdef WITH_MIXER - const std::vector & v = AGG::Cache::Get().GetMID(xmi); - if(v.size()) Music::Play(&v[0], v.size(), loop); -#else - if(conf.PlayMusCommand().size()) - { - const std::string file = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "music" + SEPARATOR + XMI::GetString(xmi); - if(FilePresent(file)) - { - const std::string run = conf.PlayMusCommand() + " " + file; - Music::Play(run.c_str(), loop); - } - else - StoreMemToFile(AGG::Cache::Get().GetMID(xmi), file); - } -#endif - } - DEBUG(DBG_ENGINE , DBG_INFO, "AGG::PlayMusic: " << XMI::GetString(xmi)); - } -} - -#ifdef WITH_TTF -/* return letter sprite */ -const Surface & AGG::GetUnicodeLetter(u16 ch, u8 ft) -{ - if(AGG::Cache::Get().isValidFonts()) - return AGG::Cache::Get().GetFNT(ch, ft); - else - return AGG::GetLetter(ch, ft); -} -#endif - -const Surface & AGG::GetLetter(char ch, u8 ft) -{ - if(ch < 0x21) DEBUG(DBG_ENGINE , DBG_WARN, "AGG::GetLetter: unknown letter"); - - switch(ft) - { - case Font::YELLOW_BIG: return AGG::GetICN(ICN::YELLOW_FONT, ch - 0x20); - case Font::YELLOW_SMALL:return AGG::GetICN(ICN::YELLOW_SMALFONT, ch - 0x20); - case Font::BIG: return AGG::GetICN(ICN::FONT, ch - 0x20); - case Font::SMALL: return AGG::GetICN(ICN::SMALFONT, ch - 0x20); - - default: break; - } - - return AGG::GetICN(ICN::SMALFONT, ch - 0x20); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/agg.h b/project/jni/application/fheroes2/src/fheroes2/agg/agg.h deleted file mode 100644 index b600ee1ca..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/agg.h +++ /dev/null @@ -1,208 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2AGG_H -#define H2AGG_H - -#include -#include -#include -#include - -#include "gamedefs.h" -#include "icn.h" -#include "til.h" -#include "xmi.h" -#include "m82.h" -#include "mus.h" -#include "sprite.h" -#include "font.h" - -namespace AGG -{ - class FAT - { - public: - FAT() : crc(0), offset(0), size(0) {} - - u32 crc; - u32 offset; - u32 size; - - void Dump(const std::string & n) const; - }; - - class File - { - public: - File(); - ~File(); - - bool Open(const std::string &); - bool isGood(void) const; - const std::string & Name(void) const; - const FAT & Fat(const std::string & key); - u16 CountItems(void); - - bool Read(const std::string & key, std::vector & body); - - void Dump(void) const; - - private: - std::string filename; - std::map fat; - u16 count_items; - std::ifstream* stream; - }; - - struct icn_cache_t - { - icn_cache_t() : sprites(NULL), reflect(NULL), count(0) {} - Sprite *sprites; - Sprite *reflect; - u16 count; - }; - - struct til_cache_t - { - til_cache_t() : sprites(NULL), count(0) {} - Surface *sprites; - u16 count; - }; - - struct fnt_cache_t - { - fnt_cache_t() : medium_white(NULL), medium_yellow(NULL), small_white(NULL), small_yellow(NULL) {} - Surface medium_white; - Surface medium_yellow; - Surface small_white; - Surface small_yellow; - }; - - struct loop_sound_t - { - loop_sound_t(M82::m82_t w, int c) : sound(w), channel(c) {} - bool isM82(const M82::m82_t wav) const{ return wav == sound; } - - M82::m82_t sound; - int channel; - }; - - class Cache - { - public: - ~Cache(); - - static Cache & Get(void); - - bool ReadDataDir(void); - bool ReadChunk(const std::string & key, std::vector & body); - - int GetICNCount(const ICN::icn_t icn); - const Sprite & GetICN(const ICN::icn_t icn, u16 index, bool reflect = false); - const Surface & GetTIL(const TIL::til_t til, u16 index, u8 shape); - const std::vector & GetWAV(const M82::m82_t m82); - const std::vector & GetMID(const XMI::xmi_t xmi); -#ifdef WITH_TTF - const Surface & GetFNT(u16, u8); - const SDL::Font & GetMediumFont(void) const; - const SDL::Font & GetSmallFont(void) const; - void LoadFNT(u16); -#endif - - void LoadExtICN(icn_cache_t &, const ICN::icn_t, const u16, bool); - bool LoadAltICN(icn_cache_t &, const std::string &, const u16, bool); - void LoadOrgICN(Sprite &, const ICN::icn_t, const u16, bool); - void LoadOrgICN(icn_cache_t &, const ICN::icn_t, const u16, bool); - void LoadICN(const ICN::icn_t icn, u16 index, bool reflect = false); - void LoadTIL(const TIL::til_t til); - void LoadWAV(const M82::m82_t m82); - void LoadMID(const XMI::xmi_t xmi); - - void LoadLOOPXXSounds(const u16*); - void ResetMixer(void); - - void LoadPAL(void); - void LoadFNT(void); - bool isValidFonts(void) const; - - void FreeICN(const ICN::icn_t icn); - void FreeTIL(const TIL::til_t til); - void FreeWAV(const M82::m82_t m82); - void FreeMID(const XMI::xmi_t xmi); - - void ClearAllICN(void); - void ClearAllWAV(void); - void ClearAllMID(void); - - void ICNRegistryEnable(bool); - void ICNRegistryFreeObjects(void); - - void Dump(void) const; - - private: - Cache(); - - File heroes2_agg; - File heroes2x_agg; - - icn_cache_t* icn_cache; - til_cache_t* til_cache; - - std::vector loop_sounds; - std::map > wav_cache; - std::map > mid_cache; - -#ifdef WITH_TTF - std::map fnt_cache; - SDL::Font font_medium; - SDL::Font font_small; -#endif - std::vector icn_registry; - bool icn_registry_enable; - }; - - // wrapper AGG::PreloadObject - void PreloadObject(const ICN::icn_t icn, bool reflect = false); - void PreloadObject(const TIL::til_t til); - - // wrapper AGG::FreeObject - void FreeObject(const ICN::icn_t icn); - void FreeObject(const TIL::til_t til); - - // wrapper AGG::GetXXX - void ICNRegistryEnable(bool); - void ICNRegistryFreeObjects(void); - int GetICNCount(const ICN::icn_t icn); - const Sprite & GetICN(const ICN::icn_t icn, const u16 index, bool reflect = false); - const Surface & GetTIL(const TIL::til_t til, const u16 index, const u8 shape); - - const Surface & GetLetter(char ch, u8 ft); -#ifdef WITH_TTF - const Surface & GetUnicodeLetter(u16 ch, u8 ft); -#endif - // wrapper Audio - void PlaySound(const M82::m82_t m82); - void PlayMusic(const MUS::mus_t mus, bool loop = true); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/icn.cpp b/project/jni/application/fheroes2/src/fheroes2/agg/icn.cpp deleted file mode 100644 index 9d7b43c2d..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/icn.cpp +++ /dev/null @@ -1,2050 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "settings.h" -#include "heroes.h" -#include "spell.h" -#include "objcrck.h" -#include "objdirt.h" -#include "objdsrt.h" -#include "objgras.h" -#include "objlava.h" -#include "objsnow.h" -#include "objswmp.h" -#include "icn.h" - -namespace ICN -{ - struct icnmap_t - { - icn_t type; - const char* string; - }; - - static const icnmap_t icnmap[] = { - { ADVBORDE, "ADVBORDE.ICN" }, - { ADVBORD, "ADVBORD.ICN" }, - { ADVBTNS, "ADVBTNS.ICN" }, - { ADVEBTNS, "ADVEBTNS.ICN" }, - { ADVMCO, "ADVMCO.ICN" }, - { AELEM, "AELEM.ICN" }, - { APANBKGE, "APANBKGE.ICN" }, - { APANBKG, "APANBKG.ICN" }, - { APANELE, "APANELE.ICN" }, - { APANEL, "APANEL.ICN" }, - { ARCHER2, "ARCHER2.ICN" }, - { ARCHER, "ARCHER.ICN" }, - { ARCH_MSL, "ARCH_MSL.ICN" }, - { ART32, "ART32.ICN" }, - { ARTFX, "ARTFX.ICN" }, - { ARTIFACT, "ARTIFACT.ICN" }, - { BARB32, "BARB32.ICN" }, - { B_BFLG32, "B-BFLG32.ICN" }, - { BERZERK, "BERZERK.ICN" }, - { B_FLAG32, "B-FLAG32.ICN" }, - { BIGBAR, "BIGBAR.ICN" }, - { BLDGXTRA, "BLDGXTRA.ICN" }, - { BLESS, "BLESS.ICN" }, - { BLIND, "BLIND.ICN" }, - { BLUEFIRE, "BLUEFIRE.ICN" }, - { BOAR, "BOAR.ICN" }, - { BOAT32, "BOAT32.ICN" }, - { BOATSHAD, "BOATSHAD.ICN" }, - { BOATWIND, "BOATWIND.ICN" }, - { BOOK, "BOOK.ICN" }, - { BORDEDIT, "BORDEDIT.ICN" }, - { BOULDER, "BOULDER.ICN" }, - { BRCREST, "BRCREST.ICN" }, - { BROTHERS, "BROTHERS.ICN" }, - { BTNBAUD, "BTNBAUD.ICN" }, - { BTNCMPGN, "BTNCMPGN.ICN" }, - { BTNCOM, "BTNCOM.ICN" }, - { BTNDCCFG, "BTNDCCFG.ICN" }, - { BTNDC, "BTNDC.ICN" }, - { BTNEMAIN, "BTNEMAIN.ICN" }, - { BTNENEW, "BTNENEW.ICN" }, - { BTNESIZE, "BTNESIZE.ICN" }, - { BTNHOTST, "BTNHOTST.ICN" }, - { BTNMCFG, "BTNMCFG.ICN" }, - { BTNMODEM, "BTNMODEM.ICN" }, - { BTNMP, "BTNMP.ICN" }, - { BTNNET2, "BTNNET2.ICN" }, - { BTNNET, "BTNNET.ICN" }, - { BTNNEWGM, "BTNNEWGM.ICN" }, - { BTNSHNGL, "BTNSHNGL.ICN" }, - { BUILDING, "BUILDING.ICN" }, - { BUYBUILD, "BUYBUILD.ICN" }, - { BUYBUILE, "BUYBUILE.ICN" }, - { CAMPBKGE, "CAMPBKGE.ICN" }, - { CAMPBKGG, "CAMPBKGG.ICN" }, - { CAMPXTRE, "CAMPXTRE.ICN" }, - { CAMPXTRG, "CAMPXTRG.ICN" }, - { CAPTCOVR, "CAPTCOVR.ICN" }, - { CASLBAR, "CASLBAR.ICN" }, - { CASLWIND, "CASLWIND.ICN" }, - { CASLXTRA, "CASLXTRA.ICN" }, - { CASTBKGB, "CASTBKGB.ICN" }, - { CASTBKGK, "CASTBKGK.ICN" }, - { CASTBKGN, "CASTBKGN.ICN" }, - { CASTBKGS, "CASTBKGS.ICN" }, - { CASTBKGW, "CASTBKGW.ICN" }, - { CASTBKGZ, "CASTBKGZ.ICN" }, - { CASTLEB, "CASTLEB.ICN" }, - { CASTLEK, "CASTLEK.ICN" }, - { CASTLEN, "CASTLEN.ICN" }, - { CASTLES, "CASTLES.ICN" }, - { CASTLEW, "CASTLEW.ICN" }, - { CASTLEZ, "CASTLEZ.ICN" }, - { CATAPULT, "CATAPULT.ICN" }, - { CAVALRYB, "CAVALRYB.ICN" }, - { CAVALRYR, "CAVALRYR.ICN" }, - { CBKGBEAC, "CBKGBEAC.ICN" }, - { CBKGCRCK, "CBKGCRCK.ICN" }, - { CBKGDIMT, "CBKGDIMT.ICN" }, - { CBKGDITR, "CBKGDITR.ICN" }, - { CBKGDSRT, "CBKGDSRT.ICN" }, - { CBKGGRAV, "CBKGGRAV.ICN" }, - { CBKGGRMT, "CBKGGRMT.ICN" }, - { CBKGGRTR, "CBKGGRTR.ICN" }, - { CBKGLAVA, "CBKGLAVA.ICN" }, - { CBKGSNMT, "CBKGSNMT.ICN" }, - { CBKGSNTR, "CBKGSNTR.ICN" }, - { CBKGSWMP, "CBKGSWMP.ICN" }, - { CBKGWATR, "CBKGWATR.ICN" }, - { CELLWIN, "CELLWIN.ICN" }, - { CENTAUR, "CENTAUR.ICN" }, - { CFLGSMAL, "CFLGSMAL.ICN" }, - { CLOP32, "CLOP32.ICN" }, - { CLOUDLUK, "CLOUDLUK.ICN" }, - { CMBTCAPB, "CMBTCAPB.ICN" }, - { CMBTCAPK, "CMBTCAPK.ICN" }, - { CMBTCAPN, "CMBTCAPN.ICN" }, - { CMBTCAPS, "CMBTCAPS.ICN" }, - { CMBTCAPW, "CMBTCAPW.ICN" }, - { CMBTCAPZ, "CMBTCAPZ.ICN" }, - { CMBTFLE1, "CMBTFLE1.ICN" }, - { CMBTFLE2, "CMBTFLE2.ICN" }, - { CMBTFLE3, "CMBTFLE3.ICN" }, - { CMBTHROB, "CMBTHROB.ICN" }, - { CMBTHROK, "CMBTHROK.ICN" }, - { CMBTHRON, "CMBTHRON.ICN" }, - { CMBTHROS, "CMBTHROS.ICN" }, - { CMBTHROW, "CMBTHROW.ICN" }, - { CMBTHROZ, "CMBTHROZ.ICN" }, - { CMBTLOS1, "CMBTLOS1.ICN" }, - { CMBTLOS2, "CMBTLOS2.ICN" }, - { CMBTLOS3, "CMBTLOS3.ICN" }, - { CMBTMISC, "CMBTMISC.ICN" }, - { CMBTSURR, "CMBTSURR.ICN" }, - { CMSECO, "CMSECO.ICN" }, - { COBJ0000, "COBJ0000.ICN" }, - { COBJ0001, "COBJ0001.ICN" }, - { COBJ0002, "COBJ0002.ICN" }, - { COBJ0003, "COBJ0003.ICN" }, - { COBJ0004, "COBJ0004.ICN" }, - { COBJ0005, "COBJ0005.ICN" }, - { COBJ0006, "COBJ0006.ICN" }, - { COBJ0007, "COBJ0007.ICN" }, - { COBJ0008, "COBJ0008.ICN" }, - { COBJ0009, "COBJ0009.ICN" }, - { COBJ0010, "COBJ0010.ICN" }, - { COBJ0011, "COBJ0011.ICN" }, - { COBJ0012, "COBJ0012.ICN" }, - { COBJ0013, "COBJ0013.ICN" }, - { COBJ0014, "COBJ0014.ICN" }, - { COBJ0015, "COBJ0015.ICN" }, - { COBJ0016, "COBJ0016.ICN" }, - { COBJ0017, "COBJ0017.ICN" }, - { COBJ0018, "COBJ0018.ICN" }, - { COBJ0019, "COBJ0019.ICN" }, - { COBJ0020, "COBJ0020.ICN" }, - { COBJ0021, "COBJ0021.ICN" }, - { COBJ0022, "COBJ0022.ICN" }, - { COBJ0023, "COBJ0023.ICN" }, - { COBJ0024, "COBJ0024.ICN" }, - { COBJ0025, "COBJ0025.ICN" }, - { COBJ0026, "COBJ0026.ICN" }, - { COBJ0027, "COBJ0027.ICN" }, - { COBJ0028, "COBJ0028.ICN" }, - { COBJ0029, "COBJ0029.ICN" }, - { COBJ0030, "COBJ0030.ICN" }, - { COBJ0031, "COBJ0031.ICN" }, - { COLDRAY, "COLDRAY.ICN" }, - { COLDRING, "COLDRING.ICN" }, - { CONGRATS, "CONGRATS.ICN" }, - { COVR0001, "COVR0001.ICN" }, - { COVR0002, "COVR0002.ICN" }, - { COVR0003, "COVR0003.ICN" }, - { COVR0004, "COVR0004.ICN" }, - { COVR0005, "COVR0005.ICN" }, - { COVR0006, "COVR0006.ICN" }, - { COVR0007, "COVR0007.ICN" }, - { COVR0008, "COVR0008.ICN" }, - { COVR0009, "COVR0009.ICN" }, - { COVR0010, "COVR0010.ICN" }, - { COVR0011, "COVR0011.ICN" }, - { COVR0012, "COVR0012.ICN" }, - { COVR0013, "COVR0013.ICN" }, - { COVR0014, "COVR0014.ICN" }, - { COVR0015, "COVR0015.ICN" }, - { COVR0016, "COVR0016.ICN" }, - { COVR0017, "COVR0017.ICN" }, - { COVR0018, "COVR0018.ICN" }, - { COVR0019, "COVR0019.ICN" }, - { COVR0020, "COVR0020.ICN" }, - { COVR0021, "COVR0021.ICN" }, - { COVR0022, "COVR0022.ICN" }, - { COVR0023, "COVR0023.ICN" }, - { COVR0024, "COVR0024.ICN" }, - { CPANBKGE, "CPANBKGE.ICN" }, - { CPANBKG, "CPANBKG.ICN" }, - { CPANELE, "CPANELE.ICN" }, - { CPANEL, "CPANEL.ICN" }, - { CREST, "CREST.ICN" }, - { CSPANBKE, "CSPANBKE.ICN" }, - { CSPANBKG, "CSPANBKG.ICN" }, - { CSPANBTE, "CSPANBTE.ICN" }, - { CSPANBTN, "CSPANBTN.ICN" }, - { CSPANEL, "CSPANEL.ICN" }, - { CSTLBARB, "CSTLBARB.ICN" }, - { CSTLCAPB, "CSTLCAPB.ICN" }, - { CSTLCAPK, "CSTLCAPK.ICN" }, - { CSTLCAPN, "CSTLCAPN.ICN" }, - { CSTLCAPS, "CSTLCAPS.ICN" }, - { CSTLCAPW, "CSTLCAPW.ICN" }, - { CSTLCAPZ, "CSTLCAPZ.ICN" }, - { CSTLKNGT, "CSTLKNGT.ICN" }, - { CSTLNECR, "CSTLNECR.ICN" }, - { CSTLSORC, "CSTLSORC.ICN" }, - { CSTLWRLK, "CSTLWRLK.ICN" }, - { CSTLWZRD, "CSTLWZRD.ICN" }, - { CTRACK00, "CTRACK00.ICN" }, - { CTRACK01, "CTRACK01.ICN" }, - { CTRACK02, "CTRACK02.ICN" }, - { CTRACK03, "CTRACK03.ICN" }, - { CTRACK04, "CTRACK04.ICN" }, - { CTRACK05, "CTRACK05.ICN" }, - { CTRACK06, "CTRACK06.ICN" }, - { CURSE, "CURSE.ICN" }, - { CYCLOPS, "CYCLOPS.ICN" }, - { DISRRAY, "DISRRAY.ICN" }, - { DRAGBLAK, "DRAGBLAK.ICN" }, - { DRAGBONE, "DRAGBONE.ICN" }, - { DRAGGREE, "DRAGGREE.ICN" }, - { DRAGRED, "DRAGRED.ICN" }, - { DRAGSLAY, "DRAGSLAY.ICN" }, - { DROPLISL, "DROPLISL.ICN" }, - { DROPLIST, "DROPLIST.ICN" }, - { DRUID2, "DRUID2.ICN" }, - { DRUID, "DRUID.ICN" }, - { DRUIDMSL, "DRUIDMSL.ICN" }, - { DUMMY, "DUMMY.ICN" }, - { DWARF2, "DWARF2.ICN" }, - { DWARF, "DWARF.ICN" }, - { ECPANEL, "ECPANEL.ICN" }, - { EDITBTNS, "EDITBTNS.ICN" }, - { EDITOR, "EDITOR.ICN" }, - { EDITPANL, "EDITPANL.ICN" }, - { EELEM, "EELEM.ICN" }, - { ELECTRIC, "ELECTRIC.ICN" }, - { ELF2, "ELF2.ICN" }, - { ELF, "ELF.ICN" }, - { ELF__MSL, "ELF__MSL.ICN" }, - { ESCROLL, "ESCROLL.ICN" }, - { ESPANBKG, "ESPANBKG.ICN" }, - { ESPANBTN, "ESPANBTN.ICN" }, - { ESPANEL, "ESPANEL.ICN" }, - { EVIW_ALL, "EVIW_ALL.ICN" }, - { EVIWDDOR, "EVIWDDOR.ICN" }, - { EVIWHROS, "EVIWHROS.ICN" }, - { EVIWMINE, "EVIWMINE.ICN" }, - { EVIWPUZL, "EVIWPUZL.ICN" }, - { EVIWRSRC, "EVIWRSRC.ICN" }, - { EVIWRTFX, "EVIWRTFX.ICN" }, - { EVIWTWNS, "EVIWTWNS.ICN" }, - { EVIWWRLD, "EVIWWRLD.ICN" }, - { EXPMRL, "EXPMRL.ICN" }, - { EXTRAOVR, "EXTRAOVR.ICN" }, - { FELEM, "FELEM.ICN" }, - { FIREBAL2, "FIREBAL2.ICN" }, - { FIREBALL, "FIREBALL.ICN" }, - { FLAG32, "FLAG32.ICN" }, - { FONT, "FONT.ICN" }, - { FRNG0001, "FRNG0001.ICN" }, - { FRNG0002, "FRNG0002.ICN" }, - { FRNG0003, "FRNG0003.ICN" }, - { FRNG0004, "FRNG0004.ICN" }, - { FRNG0005, "FRNG0005.ICN" }, - { FRNG0006, "FRNG0006.ICN" }, - { FRNG0007, "FRNG0007.ICN" }, - { FRNG0008, "FRNG0008.ICN" }, - { FRNG0009, "FRNG0009.ICN" }, - { FRNG0010, "FRNG0010.ICN" }, - { FRNG0011, "FRNG0011.ICN" }, - { FRNG0012, "FRNG0012.ICN" }, - { FRNG0013, "FRNG0013.ICN" }, - { FROTH, "FROTH.ICN" }, - { GARGOYLE, "GARGOYLE.ICN" }, - { G_BFLG32, "G-BFLG32.ICN" }, - { GENIE, "GENIE.ICN" }, - { G_FLAG32, "G-FLAG32.ICN" }, - { GHOST, "GHOST.ICN" }, - { GOBLIN, "GOBLIN.ICN" }, - { GOLEM2, "GOLEM2.ICN" }, - { GOLEM, "GOLEM.ICN" }, - { GRIFFIN, "GRIFFIN.ICN" }, - { GROUND12, "GROUND12.ICN" }, - { GROUND4, "GROUND4.ICN" }, - { GROUND6, "GROUND6.ICN" }, - { HALFLING, "HALFLING.ICN" }, - { HALFLMSL, "HALFLMSL.ICN" }, - { HASTE, "HASTE.ICN" }, - { HEROBKG, "HEROBKG.ICN" }, - { HEROES, "HEROES.ICN" }, - { HEROEXTE, "HEROEXTE.ICN" }, - { HEROEXTG, "HEROEXTG.ICN" }, - { HEROFL00, "HEROFL00.ICN" }, - { HEROFL01, "HEROFL01.ICN" }, - { HEROFL02, "HEROFL02.ICN" }, - { HEROFL03, "HEROFL03.ICN" }, - { HEROFL04, "HEROFL04.ICN" }, - { HEROFL05, "HEROFL05.ICN" }, - { HEROFL06, "HEROFL06.ICN" }, - { HEROLOGE, "HEROLOGE.ICN" }, - { HEROLOGO, "HEROLOGO.ICN" }, - { HISCORE, "HISCORE.ICN" }, - { HOURGLAS, "HOURGLAS.ICN" }, - { HSBKG, "HSBKG.ICN" }, - { HSBTNS, "HSBTNS.ICN" }, - { HSICONS, "HSICONS.ICN" }, - { HYDRA, "HYDRA.ICN" }, - { HYPNOTIZ, "HYPNOTIZ.ICN" }, - { ICECLOUD, "ICECLOUD.ICN" }, - { KEEP, "KEEP.ICN" }, - { KNGT32, "KNGT32.ICN" }, - { LETTER12, "LETTER12.ICN" }, - { LETTER4, "LETTER4.ICN" }, - { LETTER6, "LETTER6.ICN" }, - { LGNDXTRA, "LGNDXTRA.ICN" }, - { LGNDXTRE, "LGNDXTRE.ICN" }, - { LICH2, "LICH2.ICN" }, - { LICHCLOD, "LICHCLOD.ICN" }, - { LICH, "LICH.ICN" }, - { LICH_MSL, "LICH_MSL.ICN" }, - { LISTBOX, "LISTBOX.ICN" }, - { LISTBOXS, "LISTBOXS.ICN" }, - { LOCATORE, "LOCATORE.ICN" }, - { LOCATORS, "LOCATORS.ICN" }, - { MAGE1, "MAGE1.ICN" }, - { MAGE2, "MAGE2.ICN" }, - { MAGEGLDB, "MAGEGLDB.ICN" }, - { MAGEGLDK, "MAGEGLDK.ICN" }, - { MAGEGLDN, "MAGEGLDN.ICN" }, - { MAGEGLDS, "MAGEGLDS.ICN" }, - { MAGEGLDW, "MAGEGLDW.ICN" }, - { MAGEGLDZ, "MAGEGLDZ.ICN" }, - { MAGIC01, "MAGIC01.ICN" }, - { MAGIC02, "MAGIC02.ICN" }, - { MAGIC03, "MAGIC03.ICN" }, - { MAGIC04, "MAGIC04.ICN" }, - { MAGIC06, "MAGIC06.ICN" }, - { MAGIC07, "MAGIC07.ICN" }, - { MAGIC08, "MAGIC08.ICN" }, - { MANA, "MANA.ICN" }, - { MEDUSA, "MEDUSA.ICN" }, - { METEOR, "METEOR.ICN" }, - { MINICAPT, "MINICAPT.ICN" }, - { MINIHERO, "MINIHERO.ICN" }, - { MINILKMR, "MINILKMR.ICN" }, - { MINIMON, "MINIMON.ICN" }, - { MINIPORT, "MINIPORT.ICN" }, - { MINISS, "MINISS.ICN" }, - { MINITOWN, "MINITOWN.ICN" }, - { MINOTAU2, "MINOTAU2.ICN" }, - { MINOTAUR, "MINOTAUR.ICN" }, - { MISC12, "MISC12.ICN" }, - { MISC4, "MISC4.ICN" }, - { MISC6, "MISC6.ICN" }, - { MOATPART, "MOATPART.ICN" }, - { MOATWHOL, "MOATWHOL.ICN" }, - { MOBILITY, "MOBILITY.ICN" }, - { MONH0000, "MONH0000.ICN" }, - { MONH0001, "MONH0001.ICN" }, - { MONH0002, "MONH0002.ICN" }, - { MONH0003, "MONH0003.ICN" }, - { MONH0004, "MONH0004.ICN" }, - { MONH0005, "MONH0005.ICN" }, - { MONH0006, "MONH0006.ICN" }, - { MONH0007, "MONH0007.ICN" }, - { MONH0008, "MONH0008.ICN" }, - { MONH0009, "MONH0009.ICN" }, - { MONH0010, "MONH0010.ICN" }, - { MONH0011, "MONH0011.ICN" }, - { MONH0012, "MONH0012.ICN" }, - { MONH0013, "MONH0013.ICN" }, - { MONH0014, "MONH0014.ICN" }, - { MONH0015, "MONH0015.ICN" }, - { MONH0016, "MONH0016.ICN" }, - { MONH0017, "MONH0017.ICN" }, - { MONH0018, "MONH0018.ICN" }, - { MONH0019, "MONH0019.ICN" }, - { MONH0020, "MONH0020.ICN" }, - { MONH0021, "MONH0021.ICN" }, - { MONH0022, "MONH0022.ICN" }, - { MONH0023, "MONH0023.ICN" }, - { MONH0024, "MONH0024.ICN" }, - { MONH0025, "MONH0025.ICN" }, - { MONH0026, "MONH0026.ICN" }, - { MONH0027, "MONH0027.ICN" }, - { MONH0028, "MONH0028.ICN" }, - { MONH0029, "MONH0029.ICN" }, - { MONH0030, "MONH0030.ICN" }, - { MONH0031, "MONH0031.ICN" }, - { MONH0032, "MONH0032.ICN" }, - { MONH0033, "MONH0033.ICN" }, - { MONH0034, "MONH0034.ICN" }, - { MONH0035, "MONH0035.ICN" }, - { MONH0036, "MONH0036.ICN" }, - { MONH0037, "MONH0037.ICN" }, - { MONH0038, "MONH0038.ICN" }, - { MONH0039, "MONH0039.ICN" }, - { MONH0040, "MONH0040.ICN" }, - { MONH0041, "MONH0041.ICN" }, - { MONH0042, "MONH0042.ICN" }, - { MONH0043, "MONH0043.ICN" }, - { MONH0044, "MONH0044.ICN" }, - { MONH0045, "MONH0045.ICN" }, - { MONH0046, "MONH0046.ICN" }, - { MONH0047, "MONH0047.ICN" }, - { MONH0048, "MONH0048.ICN" }, - { MONH0049, "MONH0049.ICN" }, - { MONH0050, "MONH0050.ICN" }, - { MONH0051, "MONH0051.ICN" }, - { MONH0052, "MONH0052.ICN" }, - { MONH0053, "MONH0053.ICN" }, - { MONH0054, "MONH0054.ICN" }, - { MONH0055, "MONH0055.ICN" }, - { MONH0056, "MONH0056.ICN" }, - { MONH0057, "MONH0057.ICN" }, - { MONH0058, "MONH0058.ICN" }, - { MONH0059, "MONH0059.ICN" }, - { MONH0060, "MONH0060.ICN" }, - { MONH0061, "MONH0061.ICN" }, - { MONH0062, "MONH0062.ICN" }, - { MONH0063, "MONH0063.ICN" }, - { MONH0064, "MONH0064.ICN" }, - { MONH0065, "MONH0065.ICN" }, - { MONS32, "MONS32.ICN" }, - { MORALEB, "MORALEB.ICN" }, - { MORALEG, "MORALEG.ICN" }, - { MTNCRCK, "MTNCRCK.ICN" }, - { MTNDIRT, "MTNDIRT.ICN" }, - { MTNDSRT, "MTNDSRT.ICN" }, - { MTNGRAS, "MTNGRAS.ICN" }, - { MTNLAVA, "MTNLAVA.ICN" }, - { MTNMULT, "MTNMULT.ICN" }, - { MTNSNOW, "MTNSNOW.ICN" }, - { MTNSWMP, "MTNSWMP.ICN" }, - { MUMMY2, "MUMMY2.ICN" }, - { MUMMYW, "MUMMYW.ICN" }, - { NECR32, "NECR32.ICN" }, - { NETBOX, "NETBOX.ICN" }, - { NGEXTRA, "NGEXTRA.ICN" }, - { NGHSBKG, "NGHSBKG.ICN" }, - { NGMPBKG, "NGMPBKG.ICN" }, - { NGSPBKG, "NGSPBKG.ICN" }, - { NOMAD, "NOMAD.ICN" }, - { O_BFLG32, "O-BFLG32.ICN" }, - { OBJNARTI, "OBJNARTI.ICN" }, - { OBJNCRCK, "OBJNCRCK.ICN" }, - { OBJNDIRT, "OBJNDIRT.ICN" }, - { OBJNDSRT, "OBJNDSRT.ICN" }, - { OBJNGRA2, "OBJNGRA2.ICN" }, - { OBJNGRAS, "OBJNGRAS.ICN" }, - { OBJNHAUN, "OBJNHAUN.ICN" }, - { OBJNLAV2, "OBJNLAV2.ICN" }, - { OBJNLAV3, "OBJNLAV3.ICN" }, - { OBJNLAVA, "OBJNLAVA.ICN" }, - { OBJNMUL2, "OBJNMUL2.ICN" }, - { OBJNMULT, "OBJNMULT.ICN" }, - { OBJNRSRC, "OBJNRSRC.ICN" }, - { OBJNSNOW, "OBJNSNOW.ICN" }, - { OBJNSWMP, "OBJNSWMP.ICN" }, - { OBJNTOWN, "OBJNTOWN.ICN" }, - { OBJNTWBA, "OBJNTWBA.ICN" }, - { OBJNTWRD, "OBJNTWRD.ICN" }, - { OBJNTWSH, "OBJNTWSH.ICN" }, - { OBJNWAT2, "OBJNWAT2.ICN" }, - { OBJNWATR, "OBJNWATR.ICN" }, - { OBJNXTRA, "OBJNXTRA.ICN" }, - { OBJPALET, "OBJPALET.ICN" }, - { O_FLAG32, "O-FLAG32.ICN" }, - { OGRE2, "OGRE2.ICN" }, - { OGRE, "OGRE.ICN" }, - { ORC2, "ORC2.ICN" }, - { ORC, "ORC.ICN" }, - { ORC__MSL, "ORC__MSL.ICN" }, - { OVERBACK, "OVERBACK.ICN" }, - { OVERLAY, "OVERLAY.ICN" }, - { OVERVIEW, "OVERVIEW.ICN" }, - { PALADIN2, "PALADIN2.ICN" }, - { PALADIN, "PALADIN.ICN" }, - { PARALYZE, "PARALYZE.ICN" }, - { P_BFLG32, "P-BFLG32.ICN" }, - { PEASANT, "PEASANT.ICN" }, - { P_FLAG32, "P-FLAG32.ICN" }, - { PHOENIX, "PHOENIX.ICN" }, - { PHYSICAL, "PHYSICAL.ICN" }, - { PIKEMAN2, "PIKEMAN2.ICN" }, - { PIKEMAN, "PIKEMAN.ICN" }, - { PORT0000, "PORT0000.ICN" }, - { PORT0001, "PORT0001.ICN" }, - { PORT0002, "PORT0002.ICN" }, - { PORT0003, "PORT0003.ICN" }, - { PORT0004, "PORT0004.ICN" }, - { PORT0005, "PORT0005.ICN" }, - { PORT0006, "PORT0006.ICN" }, - { PORT0007, "PORT0007.ICN" }, - { PORT0008, "PORT0008.ICN" }, - { PORT0009, "PORT0009.ICN" }, - { PORT0010, "PORT0010.ICN" }, - { PORT0011, "PORT0011.ICN" }, - { PORT0012, "PORT0012.ICN" }, - { PORT0013, "PORT0013.ICN" }, - { PORT0014, "PORT0014.ICN" }, - { PORT0015, "PORT0015.ICN" }, - { PORT0016, "PORT0016.ICN" }, - { PORT0017, "PORT0017.ICN" }, - { PORT0018, "PORT0018.ICN" }, - { PORT0019, "PORT0019.ICN" }, - { PORT0020, "PORT0020.ICN" }, - { PORT0021, "PORT0021.ICN" }, - { PORT0022, "PORT0022.ICN" }, - { PORT0023, "PORT0023.ICN" }, - { PORT0024, "PORT0024.ICN" }, - { PORT0025, "PORT0025.ICN" }, - { PORT0026, "PORT0026.ICN" }, - { PORT0027, "PORT0027.ICN" }, - { PORT0028, "PORT0028.ICN" }, - { PORT0029, "PORT0029.ICN" }, - { PORT0030, "PORT0030.ICN" }, - { PORT0031, "PORT0031.ICN" }, - { PORT0032, "PORT0032.ICN" }, - { PORT0033, "PORT0033.ICN" }, - { PORT0034, "PORT0034.ICN" }, - { PORT0035, "PORT0035.ICN" }, - { PORT0036, "PORT0036.ICN" }, - { PORT0037, "PORT0037.ICN" }, - { PORT0038, "PORT0038.ICN" }, - { PORT0039, "PORT0039.ICN" }, - { PORT0040, "PORT0040.ICN" }, - { PORT0041, "PORT0041.ICN" }, - { PORT0042, "PORT0042.ICN" }, - { PORT0043, "PORT0043.ICN" }, - { PORT0044, "PORT0044.ICN" }, - { PORT0045, "PORT0045.ICN" }, - { PORT0046, "PORT0046.ICN" }, - { PORT0047, "PORT0047.ICN" }, - { PORT0048, "PORT0048.ICN" }, - { PORT0049, "PORT0049.ICN" }, - { PORT0050, "PORT0050.ICN" }, - { PORT0051, "PORT0051.ICN" }, - { PORT0052, "PORT0052.ICN" }, - { PORT0053, "PORT0053.ICN" }, - { PORT0054, "PORT0054.ICN" }, - { PORT0055, "PORT0055.ICN" }, - { PORT0056, "PORT0056.ICN" }, - { PORT0057, "PORT0057.ICN" }, - { PORT0058, "PORT0058.ICN" }, - { PORT0059, "PORT0059.ICN" }, - { PORT0060, "PORT0060.ICN" }, - { PORT0061, "PORT0061.ICN" }, - { PORT0062, "PORT0062.ICN" }, - { PORT0063, "PORT0063.ICN" }, - { PORT0064, "PORT0064.ICN" }, - { PORT0065, "PORT0065.ICN" }, - { PORT0066, "PORT0066.ICN" }, - { PORT0067, "PORT0067.ICN" }, - { PORT0068, "PORT0068.ICN" }, - { PORT0069, "PORT0069.ICN" }, - { PORT0070, "PORT0070.ICN" }, - { PORT0090, "PORT0090.ICN" }, - { PORT0091, "PORT0091.ICN" }, - { PORT0092, "PORT0092.ICN" }, - { PORT0093, "PORT0093.ICN" }, - { PORT0094, "PORT0094.ICN" }, - { PORT0095, "PORT0095.ICN" }, - { PORTCFLG, "PORTCFLG.ICN" }, - { PORTMEDI, "PORTMEDI.ICN" }, - { PORTXTRA, "PORTXTRA.ICN" }, - { PRIMSKIL, "PRIMSKIL.ICN" }, - { PUZZLE, "PUZZLE.ICN" }, - { QWIKHERO, "QWIKHERO.ICN" }, - { QWIKINFO, "QWIKINFO.ICN" }, - { QWIKTOWN, "QWIKTOWN.ICN" }, - { RADAR, "RADAR.ICN" }, - { R_BFLG32, "R-BFLG32.ICN" }, - { RECR2BKG, "RECR2BKG.ICN" }, - { RECRBKG, "RECRBKG.ICN" }, - { RECRUIT, "RECRUIT.ICN" }, - { REDBACK, "REDBACK.ICN" }, - { REDDEATH, "REDDEATH.ICN" }, - { REDFIRE, "REDFIRE.ICN" }, - { REQBKG, "REQBKG.ICN" }, - { REQSBKG, "REQSBKG.ICN" }, - { REQUEST, "REQUEST.ICN" }, - { REQUESTS, "REQUESTS.ICN" }, - { RESOURCE, "RESOURCE.ICN" }, - { RESSMALL, "RESSMALL.ICN" }, - { R_FLAG32, "R-FLAG32.ICN" }, - { ROAD, "ROAD.ICN" }, - { ROC, "ROC.ICN" }, - { ROGUE, "ROGUE.ICN" }, - { ROUTE, "ROUTE.ICN" }, - { SCENIBKG, "SCENIBKG.ICN" }, - { SCROLL2, "SCROLL2.ICN" }, - { SCROLLCN, "SCROLLCN.ICN" }, - { SCROLLE, "SCROLLE.ICN" }, - { SCROLL, "SCROLL.ICN" }, - { SECSKILL, "SECSKILL.ICN" }, - { SHADOW32, "SHADOW32.ICN" }, - { SHIELD, "SHIELD.ICN" }, - { SHNGANIM, "SHNGANIM.ICN" }, - { SKELETON, "SKELETON.ICN" }, - { SMALCLOD, "SMALCLOD.ICN" }, - { SMALFONT, "SMALFONT.ICN" }, - { SMALLBAR, "SMALLBAR.ICN" }, - { SORC32, "SORC32.ICN" }, - { SPANBKGE, "SPANBKGE.ICN" }, - { SPANBKG, "SPANBKG.ICN" }, - { SPANBTNE, "SPANBTNE.ICN" }, - { SPANBTN, "SPANBTN.ICN" }, - { SPANEL, "SPANEL.ICN" }, - { SPARKS, "SPARKS.ICN" }, - { SPELCO, "SPELCO.ICN" }, - { SPELLINF, "SPELLINF.ICN" }, - { SPELLINL, "SPELLINL.ICN" }, - { SPELLS, "SPELLS.ICN" }, - { SPRITE, "SPRITE.ICN" }, - { STELSKIN, "STELSKIN.ICN" }, - { STONBACK, "STONBACK.ICN" }, - { STONBAKE, "STONBAKE.ICN" }, - { STONEBAK, "STONEBAK.ICN" }, - { STONEBK2, "STONEBK2.ICN" }, - { STONSKIN, "STONSKIN.ICN" }, - { STORM, "STORM.ICN" }, - { STREAM, "STREAM.ICN" }, - { STRIP, "STRIP.ICN" }, - { SUNMOONE, "SUNMOONE.ICN" }, - { SUNMOON, "SUNMOON.ICN" }, - { SURDRBKE, "SURDRBKE.ICN" }, - { SURDRBKG, "SURDRBKG.ICN" }, - { SURRENDE, "SURRENDE.ICN" }, - { SURRENDR, "SURRENDR.ICN" }, - { SWAPBTN, "SWAPBTN.ICN" }, - { SWAPWIN, "SWAPWIN.ICN" }, - { SWORDSM2, "SWORDSM2.ICN" }, - { SWORDSMN, "SWORDSMN.ICN" }, - { SYSTEME, "SYSTEME.ICN" }, - { SYSTEM, "SYSTEM.ICN" }, - { TAVWIN, "TAVWIN.ICN" }, - { TENT, "TENT.ICN" }, - { TERRAINS, "TERRAINS.ICN" }, - { TEXTBACK, "TEXTBACK.ICN" }, - { TEXTBAK2, "TEXTBAK2.ICN" }, - { TEXTBAR, "TEXTBAR.ICN" }, - { TITANBLA, "TITANBLA.ICN" }, - { TITANBLU, "TITANBLU.ICN" }, - { TITANMSL, "TITANMSL.ICN" }, - { TOWNBKG0, "TOWNBKG0.ICN" }, - { TOWNBKG1, "TOWNBKG1.ICN" }, - { TOWNBKG2, "TOWNBKG2.ICN" }, - { TOWNBKG3, "TOWNBKG3.ICN" }, - { TOWNBKG4, "TOWNBKG4.ICN" }, - { TOWNBKG5, "TOWNBKG5.ICN" }, - { TOWNFIX, "TOWNFIX.ICN" }, - { TOWNNAME, "TOWNNAME.ICN" }, - { TOWNWIND, "TOWNWIND.ICN" }, - { TRADPOSE, "TRADPOSE.ICN" }, - { TRADPOST, "TRADPOST.ICN" }, - { TREASURY, "TREASURY.ICN" }, - { TREDECI, "TREDECI.ICN" }, - { TREEVIL, "TREEVIL.ICN" }, - { TREFALL, "TREFALL.ICN" }, - { TREFIR, "TREFIR.ICN" }, - { TREJNGL, "TREJNGL.ICN" }, - { TRESNOW, "TRESNOW.ICN" }, - { TROLL2, "TROLL2.ICN" }, - { TROLL, "TROLL.ICN" }, - { TROLLMSL, "TROLLMSL.ICN" }, - { TWNBBOAT, "TWNBBOAT.ICN" }, - { TWNBCAPT, "TWNBCAPT.ICN" }, - { TWNBCSTL, "TWNBCSTL.ICN" }, - { TWNBDOCK, "TWNBDOCK.ICN" }, - { TWNBDW_0, "TWNBDW_0.ICN" }, - { TWNBDW_1, "TWNBDW_1.ICN" }, - { TWNBDW_2, "TWNBDW_2.ICN" }, - { TWNBDW_3, "TWNBDW_3.ICN" }, - { TWNBDW_4, "TWNBDW_4.ICN" }, - { TWNBDW_5, "TWNBDW_5.ICN" }, - { TWNBEXT0, "TWNBEXT0.ICN" }, - { TWNBEXT1, "TWNBEXT1.ICN" }, - { TWNBEXT2, "TWNBEXT2.ICN" }, - { TWNBEXT3, "TWNBEXT3.ICN" }, - { TWNBLTUR, "TWNBLTUR.ICN" }, - { TWNBMAGE, "TWNBMAGE.ICN" }, - { TWNBMARK, "TWNBMARK.ICN" }, - { TWNBMOAT, "TWNBMOAT.ICN" }, - { TWNBRTUR, "TWNBRTUR.ICN" }, - { TWNBSPEC, "TWNBSPEC.ICN" }, - { TWNBSTAT, "TWNBSTAT.ICN" }, - { TWNBTENT, "TWNBTENT.ICN" }, - { TWNBTHIE, "TWNBTHIE.ICN" }, - { TWNBTVRN, "TWNBTVRN.ICN" }, - { TWNBUP_1, "TWNBUP_1.ICN" }, - { TWNBUP_3, "TWNBUP_3.ICN" }, - { TWNBUP_4, "TWNBUP_4.ICN" }, - { TWNBWEL2, "TWNBWEL2.ICN" }, - { TWNBWELL, "TWNBWELL.ICN" }, - { TWNKBOAT, "TWNKBOAT.ICN" }, - { TWNKCAPT, "TWNKCAPT.ICN" }, - { TWNKCSTL, "TWNKCSTL.ICN" }, - { TWNKDOCK, "TWNKDOCK.ICN" }, - { TWNKDW_0, "TWNKDW_0.ICN" }, - { TWNKDW_1, "TWNKDW_1.ICN" }, - { TWNKDW_2, "TWNKDW_2.ICN" }, - { TWNKDW_3, "TWNKDW_3.ICN" }, - { TWNKDW_4, "TWNKDW_4.ICN" }, - { TWNKDW_5, "TWNKDW_5.ICN" }, - { TWNKEXT0, "TWNKEXT0.ICN" }, - { TWNKEXT1, "TWNKEXT1.ICN" }, - { TWNKEXT2, "TWNKEXT2.ICN" }, - { TWNKLTUR, "TWNKLTUR.ICN" }, - { TWNKMAGE, "TWNKMAGE.ICN" }, - { TWNKMARK, "TWNKMARK.ICN" }, - { TWNKMOAT, "TWNKMOAT.ICN" }, - { TWNKRTUR, "TWNKRTUR.ICN" }, - { TWNKSPEC, "TWNKSPEC.ICN" }, - { TWNKSTAT, "TWNKSTAT.ICN" }, - { TWNKTENT, "TWNKTENT.ICN" }, - { TWNKTHIE, "TWNKTHIE.ICN" }, - { TWNKTVRN, "TWNKTVRN.ICN" }, - { TWNKUP_1, "TWNKUP_1.ICN" }, - { TWNKUP_2, "TWNKUP_2.ICN" }, - { TWNKUP_3, "TWNKUP_3.ICN" }, - { TWNKUP_4, "TWNKUP_4.ICN" }, - { TWNKUP_5, "TWNKUP_5.ICN" }, - { TWNKWEL2, "TWNKWEL2.ICN" }, - { TWNKWELL, "TWNKWELL.ICN" }, - { TWNNBOAT, "TWNNBOAT.ICN" }, - { TWNNCAPT, "TWNNCAPT.ICN" }, - { TWNNCSTL, "TWNNCSTL.ICN" }, - { TWNNDOCK, "TWNNDOCK.ICN" }, - { TWNNDW_0, "TWNNDW_0.ICN" }, - { TWNNDW_1, "TWNNDW_1.ICN" }, - { TWNNDW_2, "TWNNDW_2.ICN" }, - { TWNNDW_3, "TWNNDW_3.ICN" }, - { TWNNDW_4, "TWNNDW_4.ICN" }, - { TWNNDW_5, "TWNNDW_5.ICN" }, - { TWNNEXT0, "TWNNEXT0.ICN" }, - { TWNNLTUR, "TWNNLTUR.ICN" }, - { TWNNMAGE, "TWNNMAGE.ICN" }, - { TWNNMARK, "TWNNMARK.ICN" }, - { TWNNMOAT, "TWNNMOAT.ICN" }, - { TWNNRTUR, "TWNNRTUR.ICN" }, - { TWNNSPEC, "TWNNSPEC.ICN" }, - { TWNNSTAT, "TWNNSTAT.ICN" }, - { TWNNTENT, "TWNNTENT.ICN" }, - { TWNNTHIE, "TWNNTHIE.ICN" }, - { TWNNTVRN, "TWNNTVRN.ICN" }, - { TWNNUP_1, "TWNNUP_1.ICN" }, - { TWNNUP_2, "TWNNUP_2.ICN" }, - { TWNNUP_3, "TWNNUP_3.ICN" }, - { TWNNUP_4, "TWNNUP_4.ICN" }, - { TWNNWEL2, "TWNNWEL2.ICN" }, - { TWNNWELL, "TWNNWELL.ICN" }, - { TWNSBOAT, "TWNSBOAT.ICN" }, - { TWNSCAPT, "TWNSCAPT.ICN" }, - { TWNSCSTL, "TWNSCSTL.ICN" }, - { TWNSDOCK, "TWNSDOCK.ICN" }, - { TWNSDW_0, "TWNSDW_0.ICN" }, - { TWNSDW_1, "TWNSDW_1.ICN" }, - { TWNSDW_2, "TWNSDW_2.ICN" }, - { TWNSDW_3, "TWNSDW_3.ICN" }, - { TWNSDW_4, "TWNSDW_4.ICN" }, - { TWNSDW_5, "TWNSDW_5.ICN" }, - { TWNSEXT0, "TWNSEXT0.ICN" }, - { TWNSEXT1, "TWNSEXT1.ICN" }, - { TWNSLTUR, "TWNSLTUR.ICN" }, - { TWNSMAGE, "TWNSMAGE.ICN" }, - { TWNSMARK, "TWNSMARK.ICN" }, - { TWNSMOAT, "TWNSMOAT.ICN" }, - { TWNSRTUR, "TWNSRTUR.ICN" }, - { TWNSSPEC, "TWNSSPEC.ICN" }, - { TWNSSTAT, "TWNSSTAT.ICN" }, - { TWNSTENT, "TWNSTENT.ICN" }, - { TWNSTHIE, "TWNSTHIE.ICN" }, - { TWNSTVRN, "TWNSTVRN.ICN" }, - { TWNSUP_1, "TWNSUP_1.ICN" }, - { TWNSUP_2, "TWNSUP_2.ICN" }, - { TWNSUP_3, "TWNSUP_3.ICN" }, - { TWNSWEL2, "TWNSWEL2.ICN" }, - { TWNSWELL, "TWNSWELL.ICN" }, - { TWNWBOAT, "TWNWBOAT.ICN" }, - { TWNWCAPT, "TWNWCAPT.ICN" }, - { TWNWCSTL, "TWNWCSTL.ICN" }, - { TWNWDOCK, "TWNWDOCK.ICN" }, - { TWNWDW_0, "TWNWDW_0.ICN" }, - { TWNWDW_1, "TWNWDW_1.ICN" }, - { TWNWDW_2, "TWNWDW_2.ICN" }, - { TWNWDW_3, "TWNWDW_3.ICN" }, - { TWNWDW_4, "TWNWDW_4.ICN" }, - { TWNWDW_5, "TWNWDW_5.ICN" }, - { TWNWEXT0, "TWNWEXT0.ICN" }, - { TWNWLTUR, "TWNWLTUR.ICN" }, - { TWNWMAGE, "TWNWMAGE.ICN" }, - { TWNWMARK, "TWNWMARK.ICN" }, - { TWNWMOAT, "TWNWMOAT.ICN" }, - { TWNWRTUR, "TWNWRTUR.ICN" }, - { TWNWSPEC, "TWNWSPEC.ICN" }, - { TWNWSTAT, "TWNWSTAT.ICN" }, - { TWNWTENT, "TWNWTENT.ICN" }, - { TWNWTHIE, "TWNWTHIE.ICN" }, - { TWNWTVRN, "TWNWTVRN.ICN" }, - { TWNWUP_3, "TWNWUP_3.ICN" }, - { TWNWUP5B, "TWNWUP5B.ICN" }, - { TWNWUP_5, "TWNWUP_5.ICN" }, - { TWNWWEL2, "TWNWWEL2.ICN" }, - { TWNWWELL, "TWNWWELL.ICN" }, - { TWNZBOAT, "TWNZBOAT.ICN" }, - { TWNZCAPT, "TWNZCAPT.ICN" }, - { TWNZCSTL, "TWNZCSTL.ICN" }, - { TWNZDOCK, "TWNZDOCK.ICN" }, - { TWNZDW_0, "TWNZDW_0.ICN" }, - { TWNZDW_1, "TWNZDW_1.ICN" }, - { TWNZDW_2, "TWNZDW_2.ICN" }, - { TWNZDW_3, "TWNZDW_3.ICN" }, - { TWNZDW_4, "TWNZDW_4.ICN" }, - { TWNZDW_5, "TWNZDW_5.ICN" }, - { TWNZEXT0, "TWNZEXT0.ICN" }, - { TWNZLTUR, "TWNZLTUR.ICN" }, - { TWNZMAGE, "TWNZMAGE.ICN" }, - { TWNZMARK, "TWNZMARK.ICN" }, - { TWNZMOAT, "TWNZMOAT.ICN" }, - { TWNZRTUR, "TWNZRTUR.ICN" }, - { TWNZSPEC, "TWNZSPEC.ICN" }, - { TWNZSTAT, "TWNZSTAT.ICN" }, - { TWNZTENT, "TWNZTENT.ICN" }, - { TWNZTHIE, "TWNZTHIE.ICN" }, - { TWNZTVRN, "TWNZTVRN.ICN" }, - { TWNZUP_2, "TWNZUP_2.ICN" }, - { TWNZUP_4, "TWNZUP_4.ICN" }, - { TWNZUP_5, "TWNZUP_5.ICN" }, - { TWNZWEL2, "TWNZWEL2.ICN" }, - { TWNZWELL, "TWNZWELL.ICN" }, - { UNICORN, "UNICORN.ICN" }, - { VAMPIRE2, "VAMPIRE2.ICN" }, - { VAMPIRE, "VAMPIRE.ICN" }, - { VGENBKGE, "VGENBKGE.ICN" }, - { VGENBKG, "VGENBKG.ICN" }, - { VIEW_ALL, "VIEW_ALL.ICN" }, - { VIEWARME, "VIEWARME.ICN" }, - { VIEWARMY, "VIEWARMY.ICN" }, - { VIEWARSM, "VIEWARSM.ICN" }, - { VIEWDDOR, "VIEWDDOR.ICN" }, - { VIEWGEN, "VIEWGEN.ICN" }, - { VIEWHROS, "VIEWHROS.ICN" }, - { VIEWMINE, "VIEWMINE.ICN" }, - { VIEWPUZL, "VIEWPUZL.ICN" }, - { VIEWRSRC, "VIEWRSRC.ICN" }, - { VIEWRTFX, "VIEWRTFX.ICN" }, - { VIEWTWNS, "VIEWTWNS.ICN" }, - { VIEWWRLD, "VIEWWRLD.ICN" }, - { VWFLAG12, "VWFLAG12.ICN" }, - { VWFLAG4, "VWFLAG4.ICN" }, - { VWFLAG6, "VWFLAG6.ICN" }, - { WELEM, "WELEM.ICN" }, - { WELLBKG, "WELLBKG.ICN" }, - { WELLXTRA, "WELLXTRA.ICN" }, - { WINCMBBE, "WINCMBBE.ICN" }, - { WINCMBTB, "WINCMBTB.ICN" }, - { WINCMBT, "WINCMBT.ICN" }, - { WINLOSEB, "WINLOSEB.ICN" }, - { WINLOSEE, "WINLOSEE.ICN" }, - { WINLOSE, "WINLOSE.ICN" }, - { WOLF, "WOLF.ICN" }, - { WRLK32, "WRLK32.ICN" }, - { WZRD32, "WZRD32.ICN" }, - { X_LOC1, "X_LOC1.ICN" }, - { X_LOC2, "X_LOC2.ICN" }, - { X_LOC3, "X_LOC3.ICN" }, - { XPRIMARY, "XPRIMARY.ICN" }, - { Y_BFLG32, "Y-BFLG32.ICN" }, - { Y_FLAG32, "Y-FLAG32.ICN" }, - { YINYANG, "YINYANG.ICN" }, - { ZOMBIE2, "ZOMBIE2.ICN" }, - { ZOMBIE, "ZOMBIE.ICN" }, - - { ROUTERED, "MANUAL.ICN" }, - { TELEPORT1, "MANUAL.ICN" }, - { TELEPORT2, "MANUAL.ICN" }, - { TELEPORT3, "MANUAL.ICN" }, - { FOUNTAIN, "MANUAL.ICN" }, - { TREASURE, "MANUAL.ICN" }, - { YELLOW_FONT, "MANUAL.ICN" }, - { YELLOW_SMALFONT,"MANUAL.ICN" }, - - { UNKNOWN, "UNKNOWN.ICN" }, - }; - - u8 missile9(float, float); - u8 missile7(float, float); -} - -const char* ICN::GetString(const icn_t icn) -{ - return icnmap[icn].string; -} - -ICN::Header::Header() : offset_x(0), offset_y(0), width(0), height(0), type(0), offset_data(0) -{ -} - -void ICN::Header::Load(const u8* p) -{ - offset_x = ReadLE16(&p[0]); - offset_y = ReadLE16(&p[2]); - width = ReadLE16(&p[4]); - height= ReadLE16(&p[6]); - type = p[8]; - offset_data = ReadLE32(&p[9]); -} - -u16 ICN::AnimationFrame(const icn_t icn, const u16 start, const u32 ticket, const u8 quantity) -{ - switch(icn) - { - case TELEPORT1: - case TELEPORT2: - case TELEPORT3: return start + ticket % 8; - - case FOUNTAIN: - case TREASURE: return start + ticket % 2; - - case TWNBBOAT: - case TWNKBOAT: - case TWNNBOAT: - case TWNSBOAT: - case TWNWBOAT: - case TWNZBOAT: return 1 + ticket % 9; - - case CMBTCAPB: - case CMBTCAPK: - case CMBTCAPN: - case CMBTCAPS: - case CMBTCAPW: - case CMBTCAPZ: return 1 + ticket % 10; - - case CMBTHROB: return 1 + ticket % 18; - case CMBTHROK: return 1 + ticket % 19; - case CMBTHRON: return 1 + ticket % 19; - case CMBTHROS: return 1 + ticket % 16; - case CMBTHROW: return 1 + ticket % 16; - case CMBTHROZ: return 1 + ticket % 18; - - case HEROFL00: - case HEROFL01: - case HEROFL02: - case HEROFL03: - case HEROFL04: - case HEROFL05: return ticket % 5; - - case TWNBDOCK: - case TWNKDOCK: - case TWNNDOCK: - case TWNSDOCK: - case TWNWDOCK: - case TWNZDOCK: - - case TWNBEXT0: - case TWNKEXT0: - case TWNNEXT0: - case TWNSEXT0: - case TWNWEXT0: - case TWNZEXT0: - - case TWNBCAPT: - case TWNBDW_3: - case TWNBDW_4: - case TWNBDW_5: - case TWNBEXT1: - case TWNBMOAT: - case TWNBUP_3: - case TWNBUP_4: - case TWNKCSTL: - case TWNKDW_0: - case TWNKLTUR: - case TWNKRTUR: - case TWNKTHIE: - case TWNKTVRN: - case TWNNCSTL: - case TWNNDW_2: - case TWNNUP_2: - case TWNSCAPT: - case TWNSCSTL: - case TWNSDW_0: - case TWNSDW_1: - case TWNSEXT1: - case TWNSTHIE: - case TWNSTVRN: - case TWNSUP_1: - case TWNSWEL2: - case TWNWCAPT: - case TWNWCSTL: - case TWNWMOAT: - case TWNZCSTL: - case TWNZDW_0: - case TWNZDW_2: - case TWNZTHIE: - case TWNZUP_2: return 1 + ticket % 5; - - case TWNBCSTL: - case TWNKDW_2: - case TWNKUP_2: - case TWNNDW_5: - case TWNNWEL2: - case TWNWDW_0: - case TWNWWEL2: - case TWNZTVRN: return 1 + ticket % 6; - - case TWNKDW_4: - case TWNKUP_4: return 1 + ticket % 7; - - case TAVWIN: return 2 + ticket % 20; - - case CMBTLOS1: return 1 + ticket % 30; - case CMBTLOS2: return 1 + ticket % 29; - case CMBTLOS3: return 1 + ticket % 22; - case CMBTFLE1: return 1 + ticket % 43; - case CMBTFLE2: return 1 + ticket % 26; - case CMBTFLE3: return 1 + ticket % 25; - case CMBTSURR: return 1 + ticket % 20; - - case WINCMBT: return 1 + ticket % 20; - - case MINIMON: return start + 1 + ticket % 6; - - case TWNNMAGE: return start + 1 + ticket % 5; - - case TWNBMAGE: return 4 == start ? start + 1 + ticket % 8 : 0; - - case SHNGANIM: return 1 + ticket % 39; - - case BTNSHNGL: return start + ticket % 4; - - case OBJNHAUN: return ticket % 15; - - case OBJNWATR: - - switch(start) - { - // buttle - case 0x00: - return start + (ticket % 11) + 1; - - // shadow - case 0x0C: - // chest - case 0x13: - // shadow - case 0x26: - // flotsam - case 0x2D: - // unkn - case 0x37: - // boat - case 0x3E: - // waves - case 0x45: - // seaweed - case 0x4C: - case 0x53: - case 0x5A: - case 0x61: - case 0x68: - // sailor-man - case 0x6F: - // shadow - case 0xBC: - // buoy - case 0xC3: - // broken ship (right) - case 0xE2: - case 0xE9: - case 0xF1: - case 0xF8: - return start + (ticket % 6) + 1; - - // seagull on stones - case 0x76: - case 0x86: - case 0x96: - return start + (ticket % 15) + 1; - - // whirlpool - case 0xCA: - case 0xCE: - case 0xD2: - case 0xD6: - case 0xDA: - case 0xDE: - return start + (ticket % 3) + 1; - - default: - return 0; - } - break; - - case OBJNWAT2: - - switch(start) - { - // sail broken ship (left) - case 0x03: - case 0x0C: - return start + (ticket % 6) + 1; - - default: - return 0; - } - break; - - case OBJNCRCK: - - switch(start) - { - // pool of oil - case 0x50: - case 0x5B: - case 0x66: - case 0x71: - case 0x7C: - case 0x89: - case 0x94: - case 0x9F: - case 0xAA: - // smoke from chimney - case 0xBE: - // shadow smoke - case 0xCA: - return start + (ticket % 10) + 1; - - default: - return 0; - } - break; - - case OBJNDIRT: - - switch(start) - { - // mill - case 0x99: - case 0x9D: - case 0xA1: - case 0xA5: - case 0xA9: - case 0xAD: - case 0xB1: - case 0xB5: - case 0xB9: - case 0xBD: - return start + (ticket % 3) + 1; - - default: - return 0; - } - break; - - case OBJNDSRT: - - switch(start) - { - // campfire - case 0x36: - case 0x3D: - return start + (ticket % 6) + 1; - - default: - return 0; - } - break; - - case OBJNGRA2: - - switch(start) - { - // mill - case 0x17: - case 0x1B: - case 0x1F: - case 0x23: - case 0x27: - case 0x2B: - case 0x2F: - case 0x33: - case 0x37: - case 0x3B: - return start + (ticket % 3) + 1; - - // smoke from chimney - case 0x3F: - case 0x46: - case 0x4D: - // archerhouse - case 0x54: - // smoke from chimney - case 0x5D: - case 0x64: - // shadow smoke - case 0x6B: - // peasanthunt - case 0x72: - return start + (ticket % 6) + 1; - - default: - return 0; - } - break; - - case OBJNLAV2: - - switch(start) - { - // middle volcano - case 0x00: - // shadow - case 0x07: - case 0x0E: - // lava - case 0x15: - return start + (ticket % 6) + 1; - - // small volcano - // shadow - case 0x21: - case 0x2C: - // lava - case 0x37: - case 0x43: - return start + (ticket % 10) + 1; - - default: - return 0; - } - break; - - case OBJNLAV3: - - // big volcano - switch(start) - { - // smoke - case 0x00: - case 0x0F: - case 0x1E: - case 0x2D: - case 0x3C: - case 0x4B: - case 0x5A: - case 0x69: - case 0x87: - case 0x96: - case 0xA5: - // shadow - case 0x78: - case 0xB4: - case 0xC3: - case 0xD2: - case 0xE1: - return start + (ticket % 14) + 1; - - default: - return 0; - } - break; - - case OBJNLAVA: - - switch(start) - { - // shadow of lava - case 0x4F: - case 0x58: - case 0x62: - return start + (ticket % 9) + 1; - - default: - return 0; - } - break; - - case OBJNMUL2: - - switch(start) - { - // lighthouse - case 0x3D: - return start + (ticket % 9) + 1; - - // alchemytower - case 0x1B: - // watermill - case 0x53: - case 0x5A: - case 0x62: - case 0x69: - // fire in wagoncamp - case 0x81: - // smoke smithy (2 chimney) - case 0xA6: - // smoke smithy (1 chimney) - case 0xAD: - // shadow smoke - case 0xB4: - return start + (ticket % 6) + 1; - - // magic garden - case 0xBE: - return quantity ? start + (ticket % 6) + 1 : start + 7; - - default: - return 0; - } - break; - - case OBJNMULT: - - switch(start) - { - // smoke - case 0x05: - // shadow - case 0x0F: - case 0x19: - return start + (ticket % 9) + 1; - - // smoke - case 0x24: - // shadow - case 0x2D: - return start + (ticket % 8) + 1; - - // smoke - case 0x5A: - // shadow - case 0x61: - case 0x68: - case 0x7C: - // campfire - case 0x83: - return start + (ticket % 6) + 1; - - default: - return 0; - } - break; - - case OBJNSNOW: - - switch(start) - { - // firecamp - case 0x04: - // alchemytower - case 0x97: - // watermill - case 0xA2: - case 0xA9: - case 0xB1: - case 0xB8: - return start + (ticket % 6) + 1; - - // mill - case 0x60: - case 0x64: - case 0x68: - case 0x6C: - case 0x70: - case 0x74: - case 0x78: - case 0x7C: - case 0x80: - case 0x84: - return start + (ticket % 3) + 1; - - default: - return 0; - } - break; - - case OBJNSWMP: - - switch(start) - { - // shadow - case 0x00: - case 0x0E: - case 0x2B: - // smoke - case 0x07: - case 0x22: - case 0x33: - // light in window - case 0x16: - case 0x3A: - case 0x43: - case 0x4A: - return start + (ticket % 6) + 1; - - default: - return 0; - } - break; - - // extra objects for loyalty version - case X_LOC1: - - if(Settings::Get().PriceLoyaltyVersion()) - switch(start) - { - // alchemist tower - case 0x04: - case 0x0D: - case 0x16: - // arena - case 0x1F: - case 0x28: - case 0x32: - case 0x3B: - // earth altar - case 0x55: - case 0x5E: - case 0x67: - return start + (ticket % 8) + 1; - - default: - return 0; - } - break; - - // extra objects for loyalty version - case X_LOC2: - - if(Settings::Get().PriceLoyaltyVersion()) - switch(start) - { - // mermaid - case 0x0A: - case 0x13: - case 0x1C: - case 0x25: - // sirens - case 0x2F: - case 0x38: - case 0x41: - case 0x4A: - case 0x53: - case 0x5C: - case 0x66: - return start + (ticket % 8) + 1; - - default: - return 0; - } - break; - - // extra objects for loyalty version - case X_LOC3: - - if(Settings::Get().PriceLoyaltyVersion()) - switch(start) - { - // hut magi - case 0x00: - case 0x0A: - case 0x14: - // eye magi - case 0x20: - case 0x29: - case 0x32: - return start + (ticket % 8) + 1; - - // barrier - case 0x3C: - case 0x42: - case 0x48: - case 0x4E: - case 0x54: - case 0x5A: - case 0x60: - case 0x66: - return start + (ticket % 4) + 1; - - default: - return 0; - } - break; - - - - - - default: break; - } - - return 0; -} - -bool ICN::RequiresAlpha(const ICN::icn_t icn) -{ - switch(icn) - { - case ICN::SYSTEM: - case ICN::SYSTEME: - case ICN::BUYBUILD: - case ICN::BUYBUILE: - case ICN::BOOK: - return false; - default: - break; - } - - return true; -} - -ICN::icn_t ICN::PORTxxxx(u8 id) -{ - switch(id) - { - case Heroes::LORDKILBURN: return ICN::PORT0000; - case Heroes::SIRGALLANTH: return ICN::PORT0001; - case Heroes::ECTOR: return ICN::PORT0002; - case Heroes::GVENNETH: return ICN::PORT0003; - case Heroes::TYRO: return ICN::PORT0004; - case Heroes::AMBROSE: return ICN::PORT0005; - case Heroes::RUBY: return ICN::PORT0006; - case Heroes::MAXIMUS: return ICN::PORT0007; - case Heroes::DIMITRY: return ICN::PORT0008; - case Heroes::THUNDAX: return ICN::PORT0009; - case Heroes::FINEOUS: return ICN::PORT0010; - case Heroes::JOJOSH: return ICN::PORT0011; - case Heroes::CRAGHACK: return ICN::PORT0012; - case Heroes::JEZEBEL: return ICN::PORT0013; - case Heroes::JACLYN: return ICN::PORT0014; - case Heroes::ERGON: return ICN::PORT0015; - case Heroes::TSABU: return ICN::PORT0016; - case Heroes::ATLAS: return ICN::PORT0017; - case Heroes::ASTRA: return ICN::PORT0018; - case Heroes::NATASHA: return ICN::PORT0019; - case Heroes::TROYAN: return ICN::PORT0020; - case Heroes::VATAWNA: return ICN::PORT0021; - case Heroes::REBECCA: return ICN::PORT0022; - case Heroes::GEM: return ICN::PORT0023; - case Heroes::ARIEL: return ICN::PORT0024; - case Heroes::CARLAWN: return ICN::PORT0025; - case Heroes::LUNA: return ICN::PORT0026; - case Heroes::ARIE: return ICN::PORT0027; - case Heroes::ALAMAR: return ICN::PORT0028; - case Heroes::VESPER: return ICN::PORT0029; - case Heroes::CRODO: return ICN::PORT0030; - case Heroes::BAROK: return ICN::PORT0031; - case Heroes::KASTORE: return ICN::PORT0032; - case Heroes::AGAR: return ICN::PORT0033; - case Heroes::FALAGAR: return ICN::PORT0034; - case Heroes::WRATHMONT: return ICN::PORT0035; - case Heroes::MYRA: return ICN::PORT0036; - case Heroes::FLINT: return ICN::PORT0037; - case Heroes::DAWN: return ICN::PORT0038; - case Heroes::HALON: return ICN::PORT0039; - case Heroes::MYRINI: return ICN::PORT0040; - case Heroes::WILFREY: return ICN::PORT0041; - case Heroes::SARAKIN: return ICN::PORT0042; - case Heroes::KALINDRA: return ICN::PORT0043; - case Heroes::MANDIGAL: return ICN::PORT0044; - case Heroes::ZOM: return ICN::PORT0045; - case Heroes::DARLANA: return ICN::PORT0046; - case Heroes::ZAM: return ICN::PORT0047; - case Heroes::RANLOO: return ICN::PORT0048; - case Heroes::CHARITY: return ICN::PORT0049; - case Heroes::RIALDO: return ICN::PORT0050; - case Heroes::ROXANA: return ICN::PORT0051; - case Heroes::SANDRO: return ICN::PORT0052; - case Heroes::CELIA: return ICN::PORT0053; - case Heroes::ROLAND: return ICN::PORT0054; - case Heroes::CORLAGON: return ICN::PORT0055; - case Heroes::ELIZA: return ICN::PORT0056; - case Heroes::ARCHIBALD: return ICN::PORT0057; - case Heroes::HALTON: return ICN::PORT0058; - case Heroes::BAX: return ICN::PORT0059; - - case Heroes::SOLMYR: return ICN::PORT0060; - case Heroes::DAINWIN: return ICN::PORT0061; - case Heroes::MOG: return ICN::PORT0062; - case Heroes::UNCLEIVAN: return ICN::PORT0063; - case Heroes::JOSEPH: return ICN::PORT0064; - case Heroes::GALLAVANT: return ICN::PORT0065; - case Heroes::ELDERIAN: return ICN::PORT0066; - case Heroes::CEALLACH: return ICN::PORT0067; - case Heroes::DRAKONIA: return ICN::PORT0068; - case Heroes::MARTINE: return ICN::PORT0069; - case Heroes::JARKONAS: return ICN::PORT0070; - - case Heroes::SANDYSANDY: return ICN::PORT0059; - - default: break; - } - - return ICN::UNKNOWN; -} - -bool ICN::NeedMinify4PocketPC(icn_t icn, u16 index) -{ - switch(icn) - { - case TOWNWIND: - return index == 0 || index == 1; - // - case PUZZLE: - case HSBKG: - case BOOK: - //case STONEBAK: - // battle - case CBKGDSRT: - case CBKGSNTR: - case CBKGSNMT: - case CBKGSWMP: - case CBKGCRCK: - case CBKGBEAC: - case CBKGLAVA: - case CBKGDITR: - case CBKGDIMT: - case CBKGGRTR: - case CBKGGRMT: - case CBKGWATR: - case CBKGGRAV: - - // missile - case ARCH_MSL: - case ORC__MSL: - case TROLLMSL: - case ELF__MSL: - case DRUIDMSL: - case HALFLMSL: - case TITANMSL: - case LICH_MSL: - case LICHCLOD: - case KEEP: - - //catapult - case BOULDER: - case CATAPULT: - case SMALCLOD: - - // spells - case FIREBALL: - case FIREBAL2: - case SPARKS: - case MAGIC01: - case HASTE: - case MAGIC02: - case BLIND: - case BLESS: - case STONSKIN: - case STELSKIN: - case CURSE: - case MAGIC06: - case MAGIC07: - case STORM: - case METEOR: - case PARALYZE: - case HYPNOTIZ: - case ICECLOUD: - case COLDRING: - case REDDEATH: - case DRAGSLAY: - case SHIELD: - case BERZERK: - case COLDRAY: - case DISRRAY: - case MORALEG: - case MORALEB: - - // castle - case CASTBKGB: - case CASTBKGK: - case CASTBKGN: - case CASTBKGS: - case CASTBKGW: - case CASTBKGZ: - case CASTLEB: - case CASTLEK: - case CASTLEN: - case CASTLES: - case CASTLEW: - case CASTLEZ: - case MOATWHOL: - - // objects - case COVR0001: - case COVR0002: - case COVR0003: - case COVR0004: - case COVR0005: - case COVR0006: - case COVR0007: - case COVR0008: - case COVR0009: - case COVR0010: - case COVR0011: - case COVR0012: - case COVR0013: - case COVR0014: - case COVR0015: - case COVR0016: - case COVR0017: - case COVR0018: - case COVR0019: - case COVR0020: - case COVR0021: - case COVR0022: - case COVR0023: - case COVR0024: - - case COBJ0000: - case COBJ0001: - case COBJ0002: - case COBJ0003: - case COBJ0004: - case COBJ0005: - case COBJ0006: - case COBJ0007: - case COBJ0008: - case COBJ0009: - case COBJ0010: - case COBJ0011: - case COBJ0012: - case COBJ0013: - case COBJ0014: - case COBJ0015: - case COBJ0016: - case COBJ0017: - case COBJ0018: - case COBJ0019: - case COBJ0020: - case COBJ0021: - case COBJ0022: - case COBJ0023: - case COBJ0024: - case COBJ0025: - case COBJ0026: - case COBJ0027: - case COBJ0028: - case COBJ0029: - case COBJ0030: - case COBJ0031: - - return true; - - case TEXTBAR: - if(index < 10) return true; - break; - - default: break; - } - - if(isBattleMonsterICN(icn)) return true; - - return false; -} - -bool ICN::SkipBottomForRedrawHeroes(icn_t icn, u16 index) -{ - switch(icn) - { - case ICN::OBJNTWBA: - case ICN::ROAD: - case ICN::STREAM: - return true; - - case ICN::OBJNCRCK: return ObjWasteLand::isPassable(icn, index); - case ICN::OBJNDIRT: return ObjDirt::isPassable(icn, index); - case ICN::OBJNDSRT: return ObjDesert::isPassable(icn, index); - case ICN::OBJNGRA2: - case ICN::OBJNGRAS: return ObjGrass::isPassable(icn, index); - case ICN::OBJNLAVA: return ObjLava::isPassable(icn, index); - case ICN::OBJNSNOW: return ObjSnow::isPassable(icn, index); - case ICN::OBJNSWMP: return ObjSwamp::isPassable(icn, index); - default: break; - } - return false; -} - -u8 ICN::missile9(float dx, float dy) -{ - if(0 == dx) return dy > 0 ? 0 : 8; - else - if(0 == dy) return 4; - - const float tan = std::fabs(dy / dx); - - // tan 30: 0 - 30 - if(0.577 >= tan) return dy > 0 ? 3 : 5; - else - // tan 60: 90 - 60 - if(1.732 <= tan) return dy > 0 ? 1 : 7; - - // tan 45: 30 - 60 - return dy > 0 ? 2 : 6; -} - -u8 ICN::missile7(float dx, float dy) -{ - if(0 == dx) return dy > 0 ? 0 : 6; - else - if(0 == dy) return 3; - - const float tan = std::fabs(dy / dx); - - // tan 45: 0 - 45 - if(1 >= tan) return dy > 0 ? 2 : 4; - - // 45 - 90 - return dy > 0 ? 1 : 5; -} - -u8 ICN::GetMissIndex(icn_t icn, s16 dx, s16 dy) -{ - switch(icn) - { - case KEEP: - case ARCH_MSL: - case ORC__MSL: return missile9(dx, dy); - - case ELF__MSL: - case DRUIDMSL: - case HALFLMSL: - case TITANMSL: return missile7(dx, dy); - - case TROLLMSL: - case LICH_MSL: - default: break; - } - - return 0; -} - -bool ICN::isModifiedSprite(const ICN::icn_t icn) -{ - switch(icn) - { - case YELLOW_FONT: - case YELLOW_SMALFONT: - case ROUTERED: - case TELEPORT1: - case TELEPORT2: - case TELEPORT3: - case FOUNTAIN: - case TREASURE: - return true; - - default: break; - } - return false; -} - -bool ICN::isBattleMonsterICN(u16 icn) -{ - switch(icn) - { - case PEASANT: - case ARCHER: - case ARCHER2: - case PIKEMAN: - case PIKEMAN2: - case SWORDSMN: - case SWORDSM2: - case CAVALRYR: - case CAVALRYB: - case PALADIN: - case PALADIN2: - case GOBLIN: - case ORC: - case ORC2: - case WOLF: - case OGRE: - case OGRE2: - case TROLL: - case TROLL2: - case CYCLOPS: - case SPRITE: - case DWARF: - case DWARF2: - case ELF: - case ELF2: - case DRUID: - case DRUID2: - case UNICORN: - case PHOENIX: - case CENTAUR: - case GARGOYLE: - case GRIFFIN: - case MINOTAUR: - case MINOTAU2: - case HYDRA: - case DRAGGREE: - case DRAGRED: - case DRAGBLAK: - case HALFLING: - case BOAR: - case GOLEM: - case GOLEM2: - case ROC: - case MAGE1: - case MAGE2: - case TITANBLU: - case TITANBLA: - case SKELETON: - case ZOMBIE: - case ZOMBIE2: - case MUMMYW: - case MUMMY2: - case VAMPIRE: - case VAMPIRE2: - case LICH: - case LICH2: - case DRAGBONE: - case ROGUE: - case NOMAD: - case GHOST: - case GENIE: - case MEDUSA: - case EELEM: - case AELEM: - case FELEM: - case WELEM: - return true; - - default: break; - } - - return false; -} - -bool ICN::SkipRegistryFree(ICN::icn_t icn) -{ - switch(icn) - { - case SPELCO: - case CMSECO: - case ADVMCO: - return true; - - default: break; - } - - return false; -} - -ICN::icn_t ICN::FromString(const char* str) -{ - const icnmap_t* ptr = &icnmap[0]; - while(ptr->type != ICN::UNKNOWN && str && 0 != std::strcmp(str, ptr->string)) ++ptr; - return ptr->type; -} - -bool ICN::HighlyObjectSprite(ICN::icn_t icn, u16 index) -{ - switch(icn) - { - case OBJNDIRT: - // wind mill - if(154 <= index && index <= 160) return true; - break; - - case OBJNGRA2: - // wind mill - if(24 <= index && index <= 30) return true; - break; - - case OBJNLAV2: - case OBJNLAV3: - // fog lava - return true; - - case OBJNMUL2: - // dragon city - if(35 == index || 37 == index || 38 == index || 40 == index || 41 == index) return true; - // ligth - if(59 == index) return true; - // water mill - if(82 == index) return true; - break; - - case OBJNMULT: - // fort - if(36 <= index && index <= 44) return true; - // tree - if(117 == index || 118 == index) return true; - break; - - case OBJNSNOW: - // wind mill - if(97 <= index && index <= 103) return true; - // water mill - if(161 == index) return true; - break; - - case OBJNSWMP: - // - if(35 <= index && index <= 42) return true; - break; - - case OBJNTOWN: - if(1 <= index && index <= 5) return true; - if(32 <= index && index <= 37) return true; - if(64 <= index && index <= 69) return true; - if(96 <= index && index <= 101) return true; - if(128 <= index && index <= 133) return true; - if(160 <= index && index <= 165) return true; - break; - - case FLAG32: - return true; - - default: break; - } - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/icn.h b/project/jni/application/fheroes2/src/fheroes2/agg/icn.h deleted file mode 100644 index a17156bac..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/icn.h +++ /dev/null @@ -1,950 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2ICN_H -#define H2ICN_H - -#include "gamedefs.h" - -namespace ICN -{ - enum icn_t - { - ADVBORDE, - ADVBORD, - ADVBTNS, - ADVEBTNS, - ADVMCO, - AELEM, - APANBKGE, - APANBKG, - APANELE, - APANEL, - ARCHER2, - ARCHER, - ARCH_MSL, - ART32, - ARTFX, - ARTIFACT, - BARB32, - B_BFLG32, - BERZERK, - B_FLAG32, - BIGBAR, - BLDGXTRA, - BLESS, - BLIND, - BLUEFIRE, - BOAR, - BOAT32, - BOATSHAD, - BOATWIND, - BOOK, - BORDEDIT, - BOULDER, - BRCREST, - BROTHERS, - BTNBAUD, - BTNCMPGN, - BTNCOM, - BTNDCCFG, - BTNDC, - BTNEMAIN, - BTNENEW, - BTNESIZE, - BTNHOTST, - BTNMCFG, - BTNMODEM, - BTNMP, - BTNNET2, - BTNNET, - BTNNEWGM, - BTNSHNGL, - BUILDING, - BUYBUILD, - BUYBUILE, - CAMPBKGE, - CAMPBKGG, - CAMPXTRE, - CAMPXTRG, - CAPTCOVR, - CASLBAR, - CASLWIND, - CASLXTRA, - CASTBKGB, - CASTBKGK, - CASTBKGN, - CASTBKGS, - CASTBKGW, - CASTBKGZ, - CASTLEB, - CASTLEK, - CASTLEN, - CASTLES, - CASTLEW, - CASTLEZ, - CATAPULT, - CAVALRYB, - CAVALRYR, - CBKGBEAC, - CBKGCRCK, - CBKGDIMT, - CBKGDITR, - CBKGDSRT, - CBKGGRAV, - CBKGGRMT, - CBKGGRTR, - CBKGLAVA, - CBKGSNMT, - CBKGSNTR, - CBKGSWMP, - CBKGWATR, - CELLWIN, - CENTAUR, - CFLGSMAL, - CLOP32, - CLOUDLUK, - CMBTCAPB, - CMBTCAPK, - CMBTCAPN, - CMBTCAPS, - CMBTCAPW, - CMBTCAPZ, - CMBTFLE1, - CMBTFLE2, - CMBTFLE3, - CMBTHROB, - CMBTHROK, - CMBTHRON, - CMBTHROS, - CMBTHROW, - CMBTHROZ, - CMBTLOS1, - CMBTLOS2, - CMBTLOS3, - CMBTMISC, - CMBTSURR, - CMSECO, - COBJ0000, - COBJ0001, - COBJ0002, - COBJ0003, - COBJ0004, - COBJ0005, - COBJ0006, - COBJ0007, - COBJ0008, - COBJ0009, - COBJ0010, - COBJ0011, - COBJ0012, - COBJ0013, - COBJ0014, - COBJ0015, - COBJ0016, - COBJ0017, - COBJ0018, - COBJ0019, - COBJ0020, - COBJ0021, - COBJ0022, - COBJ0023, - COBJ0024, - COBJ0025, - COBJ0026, - COBJ0027, - COBJ0028, - COBJ0029, - COBJ0030, - COBJ0031, - COLDRAY, - COLDRING, - CONGRATS, - COVR0001, - COVR0002, - COVR0003, - COVR0004, - COVR0005, - COVR0006, - COVR0007, - COVR0008, - COVR0009, - COVR0010, - COVR0011, - COVR0012, - COVR0013, - COVR0014, - COVR0015, - COVR0016, - COVR0017, - COVR0018, - COVR0019, - COVR0020, - COVR0021, - COVR0022, - COVR0023, - COVR0024, - CPANBKGE, - CPANBKG, - CPANELE, - CPANEL, - CREST, - CSPANBKE, - CSPANBKG, - CSPANBTE, - CSPANBTN, - CSPANEL, - CSTLBARB, - CSTLCAPB, - CSTLCAPK, - CSTLCAPN, - CSTLCAPS, - CSTLCAPW, - CSTLCAPZ, - CSTLKNGT, - CSTLNECR, - CSTLSORC, - CSTLWRLK, - CSTLWZRD, - CTRACK00, - CTRACK01, - CTRACK02, - CTRACK03, - CTRACK04, - CTRACK05, - CTRACK06, - CURSE, - CYCLOPS, - DISRRAY, - DRAGBLAK, - DRAGBONE, - DRAGGREE, - DRAGRED, - DRAGSLAY, - DROPLISL, - DROPLIST, - DRUID2, - DRUID, - DRUIDMSL, - DUMMY, - DWARF2, - DWARF, - ECPANEL, - EDITBTNS, - EDITOR, - EDITPANL, - EELEM, - ELECTRIC, - ELF2, - ELF, - ELF__MSL, - ESCROLL, - ESPANBKG, - ESPANBTN, - ESPANEL, - EVIW_ALL, - EVIWDDOR, - EVIWHROS, - EVIWMINE, - EVIWPUZL, - EVIWRSRC, - EVIWRTFX, - EVIWTWNS, - EVIWWRLD, - EXPMRL, - EXTRAOVR, - FELEM, - FIREBAL2, - FIREBALL, - FLAG32, - FONT, - FRNG0001, - FRNG0002, - FRNG0003, - FRNG0004, - FRNG0005, - FRNG0006, - FRNG0007, - FRNG0008, - FRNG0009, - FRNG0010, - FRNG0011, - FRNG0012, - FRNG0013, - FROTH, - GARGOYLE, - G_BFLG32, - GENIE, - G_FLAG32, - GHOST, - GOBLIN, - GOLEM2, - GOLEM, - GRIFFIN, - GROUND12, - GROUND4, - GROUND6, - HALFLING, - HALFLMSL, - HASTE, - HEROBKG, - HEROES, - HEROEXTE, - HEROEXTG, - HEROFL00, - HEROFL01, - HEROFL02, - HEROFL03, - HEROFL04, - HEROFL05, - HEROFL06, - HEROLOGE, - HEROLOGO, - HISCORE, - HOURGLAS, - HSBKG, - HSBTNS, - HSICONS, - HYDRA, - HYPNOTIZ, - ICECLOUD, - KEEP, - KNGT32, - LETTER12, - LETTER4, - LETTER6, - LGNDXTRA, - LGNDXTRE, - LICH2, - LICHCLOD, - LICH, - LICH_MSL, - LISTBOX, - LISTBOXS, - LOCATORE, - LOCATORS, - MAGE1, - MAGE2, - MAGEGLDB, - MAGEGLDK, - MAGEGLDN, - MAGEGLDS, - MAGEGLDW, - MAGEGLDZ, - MAGIC01, - MAGIC02, - MAGIC03, - MAGIC04, - MAGIC06, - MAGIC07, - MAGIC08, - MANA, - MEDUSA, - METEOR, - MINICAPT, - MINIHERO, - MINILKMR, - MINIMON, - MINIPORT, - MINISS, - MINITOWN, - MINOTAU2, - MINOTAUR, - MISC12, - MISC4, - MISC6, - MOATPART, - MOATWHOL, - MOBILITY, - MONH0000, - MONH0001, - MONH0002, - MONH0003, - MONH0004, - MONH0005, - MONH0006, - MONH0007, - MONH0008, - MONH0009, - MONH0010, - MONH0011, - MONH0012, - MONH0013, - MONH0014, - MONH0015, - MONH0016, - MONH0017, - MONH0018, - MONH0019, - MONH0020, - MONH0021, - MONH0022, - MONH0023, - MONH0024, - MONH0025, - MONH0026, - MONH0027, - MONH0028, - MONH0029, - MONH0030, - MONH0031, - MONH0032, - MONH0033, - MONH0034, - MONH0035, - MONH0036, - MONH0037, - MONH0038, - MONH0039, - MONH0040, - MONH0041, - MONH0042, - MONH0043, - MONH0044, - MONH0045, - MONH0046, - MONH0047, - MONH0048, - MONH0049, - MONH0050, - MONH0051, - MONH0052, - MONH0053, - MONH0054, - MONH0055, - MONH0056, - MONH0057, - MONH0058, - MONH0059, - MONH0060, - MONH0061, - MONH0062, - MONH0063, - MONH0064, - MONH0065, - MONS32, - MORALEB, - MORALEG, - MTNCRCK, - MTNDIRT, - MTNDSRT, - MTNGRAS, - MTNLAVA, - MTNMULT, - MTNSNOW, - MTNSWMP, - MUMMY2, - MUMMYW, - NECR32, - NETBOX, - NGEXTRA, - NGHSBKG, - NGMPBKG, - NGSPBKG, - NOMAD, - O_BFLG32, - OBJNARTI, - OBJNCRCK, - OBJNDIRT, - OBJNDSRT, - OBJNGRA2, - OBJNGRAS, - OBJNHAUN, - OBJNLAV2, - OBJNLAV3, - OBJNLAVA, - OBJNMUL2, - OBJNMULT, - OBJNRSRC, - OBJNSNOW, - OBJNSWMP, - OBJNTOWN, - OBJNTWBA, - OBJNTWRD, - OBJNTWSH, - OBJNWAT2, - OBJNWATR, - OBJNXTRA, - OBJPALET, - O_FLAG32, - OGRE2, - OGRE, - ORC2, - ORC, - ORC__MSL, - OVERBACK, - OVERLAY, - OVERVIEW, - PALADIN2, - PALADIN, - PARALYZE, - P_BFLG32, - PEASANT, - P_FLAG32, - PHOENIX, - PHYSICAL, - PIKEMAN2, - PIKEMAN, - PORT0000, - PORT0001, - PORT0002, - PORT0003, - PORT0004, - PORT0005, - PORT0006, - PORT0007, - PORT0008, - PORT0009, - PORT0010, - PORT0011, - PORT0012, - PORT0013, - PORT0014, - PORT0015, - PORT0016, - PORT0017, - PORT0018, - PORT0019, - PORT0020, - PORT0021, - PORT0022, - PORT0023, - PORT0024, - PORT0025, - PORT0026, - PORT0027, - PORT0028, - PORT0029, - PORT0030, - PORT0031, - PORT0032, - PORT0033, - PORT0034, - PORT0035, - PORT0036, - PORT0037, - PORT0038, - PORT0039, - PORT0040, - PORT0041, - PORT0042, - PORT0043, - PORT0044, - PORT0045, - PORT0046, - PORT0047, - PORT0048, - PORT0049, - PORT0050, - PORT0051, - PORT0052, - PORT0053, - PORT0054, - PORT0055, - PORT0056, - PORT0057, - PORT0058, - PORT0059, - PORT0060, - PORT0061, - PORT0062, - PORT0063, - PORT0064, - PORT0065, - PORT0066, - PORT0067, - PORT0068, - PORT0069, - PORT0070, - PORT0090, - PORT0091, - PORT0092, - PORT0093, - PORT0094, - PORT0095, - PORTCFLG, - PORTMEDI, - PORTXTRA, - PRIMSKIL, - PUZZLE, - QWIKHERO, - QWIKINFO, - QWIKTOWN, - RADAR, - R_BFLG32, - RECR2BKG, - RECRBKG, - RECRUIT, - REDBACK, - REDDEATH, - REDFIRE, - REQBKG, - REQSBKG, - REQUEST, - REQUESTS, - RESOURCE, - RESSMALL, - R_FLAG32, - ROAD, - ROC, - ROGUE, - ROUTE, - SCENIBKG, - SCROLL2, - SCROLLCN, - SCROLLE, - SCROLL, - SECSKILL, - SHADOW32, - SHIELD, - SHNGANIM, - SKELETON, - SMALCLOD, - SMALFONT, - SMALLBAR, - SORC32, - SPANBKGE, - SPANBKG, - SPANBTNE, - SPANBTN, - SPANEL, - SPARKS, - SPELCO, - SPELLINF, - SPELLINL, - SPELLS, - SPRITE, - STELSKIN, - STONBACK, - STONBAKE, - STONEBAK, - STONEBK2, - STONSKIN, - STORM, - STREAM, - STRIP, - SUNMOONE, - SUNMOON, - SURDRBKE, - SURDRBKG, - SURRENDE, - SURRENDR, - SWAPBTN, - SWAPWIN, - SWORDSM2, - SWORDSMN, - SYSTEME, - SYSTEM, - TAVWIN, - TENT, - TERRAINS, - TEXTBACK, - TEXTBAK2, - TEXTBAR, - TITANBLA, - TITANBLU, - TITANMSL, - TOWNBKG0, - TOWNBKG1, - TOWNBKG2, - TOWNBKG3, - TOWNBKG4, - TOWNBKG5, - TOWNFIX, - TOWNNAME, - TOWNWIND, - TRADPOSE, - TRADPOST, - TREASURY, - TREDECI, - TREEVIL, - TREFALL, - TREFIR, - TREJNGL, - TRESNOW, - TROLL2, - TROLL, - TROLLMSL, - TWNBBOAT, - TWNBCAPT, - TWNBCSTL, - TWNBDOCK, - TWNBDW_0, - TWNBDW_1, - TWNBDW_2, - TWNBDW_3, - TWNBDW_4, - TWNBDW_5, - TWNBEXT0, - TWNBEXT1, - TWNBEXT2, - TWNBEXT3, - TWNBLTUR, - TWNBMAGE, - TWNBMARK, - TWNBMOAT, - TWNBRTUR, - TWNBSPEC, - TWNBSTAT, - TWNBTENT, - TWNBTHIE, - TWNBTVRN, - TWNBUP_1, - TWNBUP_3, - TWNBUP_4, - TWNBWEL2, - TWNBWELL, - TWNKBOAT, - TWNKCAPT, - TWNKCSTL, - TWNKDOCK, - TWNKDW_0, - TWNKDW_1, - TWNKDW_2, - TWNKDW_3, - TWNKDW_4, - TWNKDW_5, - TWNKEXT0, - TWNKEXT1, - TWNKEXT2, - TWNKLTUR, - TWNKMAGE, - TWNKMARK, - TWNKMOAT, - TWNKRTUR, - TWNKSPEC, - TWNKSTAT, - TWNKTENT, - TWNKTHIE, - TWNKTVRN, - TWNKUP_1, - TWNKUP_2, - TWNKUP_3, - TWNKUP_4, - TWNKUP_5, - TWNKWEL2, - TWNKWELL, - TWNNBOAT, - TWNNCAPT, - TWNNCSTL, - TWNNDOCK, - TWNNDW_0, - TWNNDW_1, - TWNNDW_2, - TWNNDW_3, - TWNNDW_4, - TWNNDW_5, - TWNNEXT0, - TWNNLTUR, - TWNNMAGE, - TWNNMARK, - TWNNMOAT, - TWNNRTUR, - TWNNSPEC, - TWNNSTAT, - TWNNTENT, - TWNNTHIE, - TWNNTVRN, - TWNNUP_1, - TWNNUP_2, - TWNNUP_3, - TWNNUP_4, - TWNNWEL2, - TWNNWELL, - TWNSBOAT, - TWNSCAPT, - TWNSCSTL, - TWNSDOCK, - TWNSDW_0, - TWNSDW_1, - TWNSDW_2, - TWNSDW_3, - TWNSDW_4, - TWNSDW_5, - TWNSEXT0, - TWNSEXT1, - TWNSLTUR, - TWNSMAGE, - TWNSMARK, - TWNSMOAT, - TWNSRTUR, - TWNSSPEC, - TWNSSTAT, - TWNSTENT, - TWNSTHIE, - TWNSTVRN, - TWNSUP_1, - TWNSUP_2, - TWNSUP_3, - TWNSWEL2, - TWNSWELL, - TWNWBOAT, - TWNWCAPT, - TWNWCSTL, - TWNWDOCK, - TWNWDW_0, - TWNWDW_1, - TWNWDW_2, - TWNWDW_3, - TWNWDW_4, - TWNWDW_5, - TWNWEXT0, - TWNWLTUR, - TWNWMAGE, - TWNWMARK, - TWNWMOAT, - TWNWRTUR, - TWNWSPEC, - TWNWSTAT, - TWNWTENT, - TWNWTHIE, - TWNWTVRN, - TWNWUP_3, - TWNWUP5B, - TWNWUP_5, - TWNWWEL2, - TWNWWELL, - TWNZBOAT, - TWNZCAPT, - TWNZCSTL, - TWNZDOCK, - TWNZDW_0, - TWNZDW_1, - TWNZDW_2, - TWNZDW_3, - TWNZDW_4, - TWNZDW_5, - TWNZEXT0, - TWNZLTUR, - TWNZMAGE, - TWNZMARK, - TWNZMOAT, - TWNZRTUR, - TWNZSPEC, - TWNZSTAT, - TWNZTENT, - TWNZTHIE, - TWNZTVRN, - TWNZUP_2, - TWNZUP_4, - TWNZUP_5, - TWNZWEL2, - TWNZWELL, - UNICORN, - VAMPIRE2, - VAMPIRE, - VGENBKGE, - VGENBKG, - VIEW_ALL, - VIEWARME, - VIEWARMY, - VIEWARSM, - VIEWDDOR, - VIEWGEN, - VIEWHROS, - VIEWMINE, - VIEWPUZL, - VIEWRSRC, - VIEWRTFX, - VIEWTWNS, - VIEWWRLD, - VWFLAG12, - VWFLAG4, - VWFLAG6, - WELEM, - WELLBKG, - WELLXTRA, - WINCMBBE, - WINCMBTB, - WINCMBT, - WINLOSEB, - WINLOSEE, - WINLOSE, - WOLF, - WRLK32, - WZRD32, - X_LOC1, - X_LOC2, - X_LOC3, - XPRIMARY, - Y_BFLG32, - Y_FLAG32, - YINYANG, - ZOMBIE2, - ZOMBIE, - - // system - ROUTERED, - TELEPORT1, - TELEPORT2, - TELEPORT3, - FOUNTAIN, - TREASURE, - YELLOW_FONT, - YELLOW_SMALFONT, - - UNKNOWN - - }; - - class Header - { - public: - Header(); - - void Load(const u8* p); - - u16 OffsetX(void) const{ return offset_x; } - u16 OffsetY(void) const{ return offset_y; } - u16 Width(void) const{ return width; } - u16 Height(void) const{ return height; } - u8 Type(void) const{ return type; } - u32 OffsetData(void) const{ return offset_data; } - - inline static u8 SizeOf(void){ return 13; } - - private: - u16 offset_x; - u16 offset_y; - u16 width; - u16 height; - u8 type; - u32 offset_data; - }; - - const char* GetString(const icn_t icn); - icn_t FromString(const char*); - u16 AnimationFrame(const icn_t icn, const u16 start, const u32 ticket = 0, const u8 quantity = 0); - bool RequiresAlpha(const icn_t icn); - bool isModifiedSprite(const icn_t icn); - bool NeedMinify4PocketPC(icn_t, u16); - bool SkipBottomForRedrawHeroes(icn_t, u16); - icn_t PORTxxxx(u8); - u8 GetMissIndex(icn_t, s16, s16); - - bool isBattleMonsterICN(u16); - bool HighlyObjectSprite(icn_t, u16); - - bool SkipRegistryFree(icn_t); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/m82.cpp b/project/jni/application/fheroes2/src/fheroes2/agg/m82.cpp deleted file mode 100644 index 2d3df1cd1..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/m82.cpp +++ /dev/null @@ -1,485 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "spell.h" -#include "mp2.h" -#include "m82.h" - -namespace M82 -{ - static const struct - { - m82_t type; - const char* string; - } m82map[] = { - { AELMATTK, "AELMATTK.82M" }, - { AELMKILL, "AELMKILL.82M" }, - { AELMMOVE, "AELMMOVE.82M" }, - { AELMWNCE, "AELMWNCE.82M" }, - { ANTIMAGK, "ANTIMAGK.82M" }, - { ARCHATTK, "ARCHATTK.82M" }, - { ARCHKILL, "ARCHKILL.82M" }, - { ARCHMOVE, "ARCHMOVE.82M" }, - { ARCHSHOT, "ARCHSHOT.82M" }, - { ARCHWNCE, "ARCHWNCE.82M" }, - { ARMGEDN, "ARMGEDN.82M" }, - { BADLUCK, "BADLUCK.82M" }, - { BADMRLE, "BADMRLE.82M" }, - { BERZERK, "BERZERK.82M" }, - { BLESS, "BLESS.82M" }, - { BLIND, "BLIND.82M" }, - { BLOODLUS, "BLOODLUS.82M" }, - { BOARATTK, "BOARATTK.82M" }, - { BOARKILL, "BOARKILL.82M" }, - { BOARMOVE, "BOARMOVE.82M" }, - { BOARWNCE, "BOARWNCE.82M" }, - { BONEATTK, "BONEATTK.82M" }, - { BONEKILL, "BONEKILL.82M" }, - { BONEMOVE, "BONEMOVE.82M" }, - { BONEWNCE, "BONEWNCE.82M" }, - { BUILDTWN, "BUILDTWN.82M" }, - { CATSND00, "CATSND00.82M" }, - { CATSND02, "CATSND02.82M" }, - { CAVLATTK, "CAVLATTK.82M" }, - { CAVLKILL, "CAVLKILL.82M" }, - { CAVLMOVE, "CAVLMOVE.82M" }, - { CAVLWNCE, "CAVLWNCE.82M" }, - { CHAINLTE, "CHAINLTE.82M" }, - { CNTRATTK, "CNTRATTK.82M" }, - { CNTRKILL, "CNTRKILL.82M" }, - { CNTRMOVE, "CNTRMOVE.82M" }, - { CNTRSHOT, "CNTRSHOT.82M" }, - { CNTRWNCE, "CNTRWNCE.82M" }, - { COLDRAY, "COLDRAY.82M" }, - { COLDRING, "COLDRING.82M" }, - { CURE, "CURE.82M" }, - { CURSE, "CURSE.82M" }, - { CYCLATTK, "CYCLATTK.82M" }, - { CYCLKILL, "CYCLKILL.82M" }, - { CYCLMOVE, "CYCLMOVE.82M" }, - { CYCLWNCE, "CYCLWNCE.82M" }, - { DIGSOUND, "DIGSOUND.82M" }, - { DIPMAGK, "DIPMAGK.82M" }, - { DISRUPTR, "DISRUPTR.82M" }, - { DRAWBRG, "DRAWBRG.82M" }, - { DRGNATTK, "DRGNATTK.82M" }, - { DRGNKILL, "DRGNKILL.82M" }, - { DRGNMOVE, "DRGNMOVE.82M" }, - { DRGNSLAY, "DRGNSLAY.82M" }, - { DRGNWNCE, "DRGNWNCE.82M" }, - { DRUIATTK, "DRUIATTK.82M" }, - { DRUIKILL, "DRUIKILL.82M" }, - { DRUIMOVE, "DRUIMOVE.82M" }, - { DRUISHOT, "DRUISHOT.82M" }, - { DRUIWNCE, "DRUIWNCE.82M" }, - { DWRFATTK, "DWRFATTK.82M" }, - { DWRFKILL, "DWRFKILL.82M" }, - { DWRFMOVE, "DWRFMOVE.82M" }, - { DWRFWNCE, "DWRFWNCE.82M" }, - { EELMATTK, "EELMATTK.82M" }, - { EELMKILL, "EELMKILL.82M" }, - { EELMMOVE, "EELMMOVE.82M" }, - { EELMWNCE, "EELMWNCE.82M" }, - { ELF_ATTK, "ELF_ATTK.82M" }, - { ELF_KILL, "ELF_KILL.82M" }, - { ELF_MOVE, "ELF_MOVE.82M" }, - { ELF_SHOT, "ELF_SHOT.82M" }, - { ELF_WNCE, "ELF_WNCE.82M" }, - { ERTHQUAK, "ERTHQUAK.82M" }, - { EXPERNCE, "EXPERNCE.82M" }, - { FELMATTK, "FELMATTK.82M" }, - { FELMKILL, "FELMKILL.82M" }, - { FELMMOVE, "FELMMOVE.82M" }, - { FELMWNCE, "FELMWNCE.82M" }, - { FIREBALL, "FIREBALL.82M" }, - { GARGATTK, "GARGATTK.82M" }, - { GARGKILL, "GARGKILL.82M" }, - { GARGMOVE, "GARGMOVE.82M" }, - { GARGWNCE, "GARGWNCE.82M" }, - { GBLNATTK, "GBLNATTK.82M" }, - { GBLNKILL, "GBLNKILL.82M" }, - { GBLNMOVE, "GBLNMOVE.82M" }, - { GBLNWNCE, "GBLNWNCE.82M" }, - { GENIATTK, "GENIATTK.82M" }, - { GENIKILL, "GENIKILL.82M" }, - { GENIMOVE, "GENIMOVE.82M" }, - { GENIWNCE, "GENIWNCE.82M" }, - { GHSTATTK, "GHSTATTK.82M" }, - { GHSTKILL, "GHSTKILL.82M" }, - { GHSTMOVE, "GHSTMOVE.82M" }, - { GHSTWNCE, "GHSTWNCE.82M" }, - { GOLMATTK, "GOLMATTK.82M" }, - { GOLMKILL, "GOLMKILL.82M" }, - { GOLMMOVE, "GOLMMOVE.82M" }, - { GOLMWNCE, "GOLMWNCE.82M" }, - { GOODLUCK, "GOODLUCK.82M" }, - { GOODMRLE, "GOODMRLE.82M" }, - { GRIFATTK, "GRIFATTK.82M" }, - { GRIFKILL, "GRIFKILL.82M" }, - { GRIFMOVE, "GRIFMOVE.82M" }, - { GRIFWNCE, "GRIFWNCE.82M" }, - { H2MINE, "H2MINE.82M" }, - { HALFATTK, "HALFATTK.82M" }, - { HALFKILL, "HALFKILL.82M" }, - { HALFMOVE, "HALFMOVE.82M" }, - { HALFSHOT, "HALFSHOT.82M" }, - { HALFWNCE, "HALFWNCE.82M" }, - { HASTE, "HASTE.82M" }, - { HYDRATTK, "HYDRATTK.82M" }, - { HYDRKILL, "HYDRKILL.82M" }, - { HYDRMOVE, "HYDRMOVE.82M" }, - { HYDRWNCE, "HYDRWNCE.82M" }, - { HYPNOTIZ, "HYPNOTIZ.82M" }, - { KEEPSHOT, "KEEPSHOT.82M" }, - { KILLFADE, "KILLFADE.82M" }, - { LICHATTK, "LICHATTK.82M" }, - { LICHEXPL, "LICHEXPL.82M" }, - { LICHKILL, "LICHKILL.82M" }, - { LICHMOVE, "LICHMOVE.82M" }, - { LICHSHOT, "LICHSHOT.82M" }, - { LICHWNCE, "LICHWNCE.82M" }, - { LIGHTBLT, "LIGHTBLT.82M" }, - { LOOP0000, "LOOP0000.82M" }, - { LOOP0001, "LOOP0001.82M" }, - { LOOP0002, "LOOP0002.82M" }, - { LOOP0003, "LOOP0003.82M" }, - { LOOP0004, "LOOP0004.82M" }, - { LOOP0005, "LOOP0005.82M" }, - { LOOP0006, "LOOP0006.82M" }, - { LOOP0007, "LOOP0007.82M" }, - { LOOP0008, "LOOP0008.82M" }, - { LOOP0009, "LOOP0009.82M" }, - { LOOP0010, "LOOP0010.82M" }, - { LOOP0011, "LOOP0011.82M" }, - { LOOP0012, "LOOP0012.82M" }, - { LOOP0013, "LOOP0013.82M" }, - { LOOP0014, "LOOP0014.82M" }, - { LOOP0015, "LOOP0015.82M" }, - { LOOP0016, "LOOP0016.82M" }, - { LOOP0017, "LOOP0017.82M" }, - { LOOP0018, "LOOP0018.82M" }, - { LOOP0019, "LOOP0019.82M" }, - { LOOP0020, "LOOP0020.82M" }, - { LOOP0021, "LOOP0021.82M" }, - { LOOP0022, "LOOP0022.82M" }, - { LOOP0023, "LOOP0023.82M" }, - { LOOP0024, "LOOP0024.82M" }, - { LOOP0025, "LOOP0025.82M" }, - { LOOP0026, "LOOP0026.82M" }, - { LOOP0027, "LOOP0027.82M" }, - { MAGCAROW, "MAGCAROW.82M" }, - { MAGEATTK, "MAGEATTK.82M" }, - { MAGEKILL, "MAGEKILL.82M" }, - { MAGEMOVE, "MAGEMOVE.82M" }, - { MAGESHOT, "MAGESHOT.82M" }, - { MAGEWNCE, "MAGEWNCE.82M" }, - { MASSBLES, "MASSBLES.82M" }, - { MASSCURE, "MASSCURE.82M" }, - { MASSCURS, "MASSCURS.82M" }, - { MASSHAST, "MASSHAST.82M" }, - { MASSSHIE, "MASSSHIE.82M" }, - { MASSSLOW, "MASSSLOW.82M" }, - { MEDSATTK, "MEDSATTK.82M" }, - { MEDSKILL, "MEDSKILL.82M" }, - { MEDSMOVE, "MEDSMOVE.82M" }, - { MEDSWNCE, "MEDSWNCE.82M" }, - { METEOR, "METEOR~1.82M" }, - { MINOATTK, "MINOATTK.82M" }, - { MINOKILL, "MINOKILL.82M" }, - { MINOMOVE, "MINOMOVE.82M" }, - { MINOWNCE, "MINOWNCE.82M" }, - { MIRRORIM, "MIRRORIM.82M" }, - { MNRDEATH, "MNRDEATH.82M" }, - { MUMYATTK, "MUMYATTK.82M" }, - { MUMYKILL, "MUMYKILL.82M" }, - { MUMYMOVE, "MUMYMOVE.82M" }, - { MUMYWNCE, "MUMYWNCE.82M" }, - { NMADATTK, "NMADATTK.82M" }, - { NMADKILL, "NMADKILL.82M" }, - { NMADMOVE, "NMADMOVE.82M" }, - { NMADWNCE, "NMADWNCE.82M" }, - { NWHEROLV, "NWHEROLV.82M" }, - { OGREATTK, "OGREATTK.82M" }, - { OGREKILL, "OGREKILL.82M" }, - { OGREMOVE, "OGREMOVE.82M" }, - { OGREWNCE, "OGREWNCE.82M" }, - { ORC_ATTK, "ORC_ATTK.82M" }, - { ORC_KILL, "ORC_KILL.82M" }, - { ORC_MOVE, "ORC_MOVE.82M" }, - { ORC_SHOT, "ORC_SHOT.82M" }, - { ORC_WNCE, "ORC_WNCE.82M" }, - { PARALIZE, "PARALIZE.82M" }, - { PHOEATTK, "PHOEATTK.82M" }, - { PHOEKILL, "PHOEKILL.82M" }, - { PHOEMOVE, "PHOEMOVE.82M" }, - { PHOEWNCE, "PHOEWNCE.82M" }, - { PICKUP01, "PICKUP01.82M" }, - { PICKUP02, "PICKUP02.82M" }, - { PICKUP03, "PICKUP03.82M" }, - { PICKUP04, "PICKUP04.82M" }, - { PICKUP05, "PICKUP05.82M" }, - { PICKUP06, "PICKUP06.82M" }, - { PICKUP07, "PICKUP07.82M" }, - { PIKEATTK, "PIKEATTK.82M" }, - { PIKEKILL, "PIKEKILL.82M" }, - { PIKEMOVE, "PIKEMOVE.82M" }, - { PIKEWNCE, "PIKEWNCE.82M" }, - { PLDNATTK, "PLDNATTK.82M" }, - { PLDNKILL, "PLDNKILL.82M" }, - { PLDNMOVE, "PLDNMOVE.82M" }, - { PLDNWNCE, "PLDNWNCE.82M" }, - { PREBATTL, "PREBATTL.82M" }, - { PROTECT, "PROTECT.82M" }, - { PSNTATTK, "PSNTATTK.82M" }, - { PSNTKILL, "PSNTKILL.82M" }, - { PSNTMOVE, "PSNTMOVE.82M" }, - { PSNTWNCE, "PSNTWNCE.82M" }, - { RESURECT, "RESURECT.82M" }, - { RESURTRU, "RESURTRU.82M" }, - { ROC_ATTK, "ROC_ATTK.82M" }, - { ROC_KILL, "ROC_KILL.82M" }, - { ROC_MOVE, "ROC_MOVE.82M" }, - { ROC_WNCE, "ROC_WNCE.82M" }, - { ROGUATTK, "ROGUATTK.82M" }, - { ROGUKILL, "ROGUKILL.82M" }, - { ROGUMOVE, "ROGUMOVE.82M" }, - { ROGUWNCE, "ROGUWNCE.82M" }, - { RSBRYFZL, "RSBRYFZL.82M" }, - { SHIELD, "SHIELD.82M" }, - { SKELATTK, "SKELATTK.82M" }, - { SKELKILL, "SKELKILL.82M" }, - { SKELMOVE, "SKELMOVE.82M" }, - { SKELWNCE, "SKELWNCE.82M" }, - { SLOW, "SLOW.82M" }, - { SPRTATTK, "SPRTATTK.82M" }, - { SPRTKILL, "SPRTKILL.82M" }, - { SPRTMOVE, "SPRTMOVE.82M" }, - { SPRTWNCE, "SPRTWNCE.82M" }, - { STELSKIN, "STELSKIN.82M" }, - { STONESKI, "STONESKI.82M" }, - { STONSKIN, "STONSKIN.82M" }, - { STORM, "STORM.82M" }, - { SUMNELM, "SUMNELM.82M" }, - { SWDMATTK, "SWDMATTK.82M" }, - { SWDMKILL, "SWDMKILL.82M" }, - { SWDMMOVE, "SWDMMOVE.82M" }, - { SWDMWNCE, "SWDMWNCE.82M" }, - { TELEIN, "TELEIN.82M" }, - { TELPTIN, "TELPTIN.82M" }, - { TELPTOUT, "TELPTOUT.82M" }, - { TITNATTK, "TITNATTK.82M" }, - { TITNKILL, "TITNKILL.82M" }, - { TITNMOVE, "TITNMOVE.82M" }, - { TITNSHOT, "TITNSHOT.82M" }, - { TITNWNCE, "TITNWNCE.82M" }, - { TREASURE, "TREASURE.82M" }, - { TRLLATTK, "TRLLATTK.82M" }, - { TRLLKILL, "TRLLKILL.82M" }, - { TRLLMOVE, "TRLLMOVE.82M" }, - { TRLLSHOT, "TRLLSHOT.82M" }, - { TRLLWNCE, "TRLLWNCE.82M" }, - { UNICATTK, "UNICATTK.82M" }, - { UNICKILL, "UNICKILL.82M" }, - { UNICMOVE, "UNICMOVE.82M" }, - { UNICWNCE, "UNICWNCE.82M" }, - { VAMPATTK, "VAMPATTK.82M" }, - { VAMPEXT1, "VAMPEXT1.82M" }, - { VAMPEXT2, "VAMPEXT2.82M" }, - { VAMPKILL, "VAMPKILL.82M" }, - { VAMPMOVE, "VAMPMOVE.82M" }, - { VAMPWNCE, "VAMPWNCE.82M" }, - { WELMATTK, "WELMATTK.82M" }, - { WELMKILL, "WELMKILL.82M" }, - { WELMMOVE, "WELMMOVE.82M" }, - { WELMWNCE, "WELMWNCE.82M" }, - { WOLFATTK, "WOLFATTK.82M" }, - { WOLFKILL, "WOLFKILL.82M" }, - { WOLFMOVE, "WOLFMOVE.82M" }, - { WOLFWNCE, "WOLFWNCE.82M" }, - { WSND00, "WSND00.82M" }, - { WSND01, "WSND01.82M" }, - { WSND02, "WSND02.82M" }, - { WSND03, "WSND03.82M" }, - { WSND04, "WSND04.82M" }, - { WSND05, "WSND05.82M" }, - { WSND06, "WSND06.82M" }, - { WSND10, "WSND10.82M" }, - { WSND11, "WSND11.82M" }, - { WSND12, "WSND12.82M" }, - { WSND13, "WSND13.82M" }, - { WSND14, "WSND14.82M" }, - { WSND15, "WSND15.82M" }, - { WSND16, "WSND16.82M" }, - { WSND20, "WSND20.82M" }, - { WSND21, "WSND21.82M" }, - { WSND22, "WSND22.82M" }, - { WSND23, "WSND23.82M" }, - { WSND24, "WSND24.82M" }, - { WSND25, "WSND25.82M" }, - { WSND26, "WSND26.82M" }, - { ZOMBATTK, "ZOMBATTK.82M" }, - { ZOMBKILL, "ZOMBKILL.82M" }, - { ZOMBMOVE, "ZOMBMOVE.82M" }, - { ZOMBWNCE, "ZOMBWNCE.82M" }, - - }; -} - -const char* M82::GetString(const m82_t m82) -{ - return m82map[m82].string; -} - -M82::m82_t M82::FromSpell(u8 spell) -{ - switch(spell) - { - case Spell::FIREBALL: return FIREBALL; - case Spell::FIREBLAST: return FIREBALL; - case Spell::LIGHTNINGBOLT: return LIGHTBLT; - case Spell::CHAINLIGHTNING: return CHAINLTE; - case Spell::TELEPORT: return TELEIN; - case Spell::CURE: return CURE; - case Spell::MASSCURE: return MASSCURE; - case Spell::RESURRECT: return RESURECT; - case Spell::RESURRECTTRUE: return RESURTRU; - case Spell::HASTE: return HASTE; - case Spell::MASSHASTE: return MASSHAST; - case Spell::SLOW: return SLOW; - case Spell::MASSSLOW: return MASSSLOW; - case Spell::BLIND: return BLIND; - case Spell::BLESS: return BLESS; - case Spell::MASSBLESS: return MASSBLES; - case Spell::STONESKIN: return STONSKIN; - case Spell::STEELSKIN: return STELSKIN; - case Spell::CURSE: return CURSE; - case Spell::MASSCURSE: return MASSCURS; - case Spell::ANTIMAGIC: return ANTIMAGK; - case Spell::DISPEL: return DIPMAGK; - case Spell::MASSDISPEL: return DIPMAGK; - case Spell::ARROW: return MAGCAROW; - case Spell::BERSERKER: return BERZERK; - case Spell::ARMAGEDDON: return ARMGEDN; - case Spell::ELEMENTALSTORM: return STORM; - case Spell::METEORSHOWER: return METEOR; - case Spell::PARALYZE: return PARALIZE; - case Spell::HYPNOTIZE: return HYPNOTIZ; - case Spell::COLDRAY: return COLDRAY; - case Spell::COLDRING: return COLDRING; - case Spell::DISRUPTINGRAY: return DISRUPTR; - case Spell::DEATHRIPPLE: return MNRDEATH; - case Spell::DRAGONSLAYER: return DRGNSLAY; - case Spell::BLOODLUST: return BLOODLUS; - case Spell::ANIMATEDEAD: return RESURECT; - case Spell::MIRRORIMAGE: return MIRRORIM; - case Spell::SHIELD: return SHIELD; - case Spell::MASSSHIELD: return MASSSHIE; - case Spell::SUMMONEELEMENT: return SUMNELM; - case Spell::SUMMONAELEMENT: return SUMNELM; - case Spell::SUMMONFELEMENT: return SUMNELM; - case Spell::SUMMONWELEMENT: return SUMNELM; - case Spell::EARTHQUAKE: return ERTHQUAK; - case Spell::HAUNT: return H2MINE; - case Spell::STONE: return PARALIZE; - - default: break; - } - - return UNKNOWN; -} - -u8 M82::GetIndexLOOP00XXFromObject(u8 obj) -{ - switch(obj) - { - case MP2::OBJ_BUOY: return 0; - case MP2::OBJ_SHIPWRECK: - case MP2::OBJ_DERELICTSHIP: return 1; - case MP2::OBJ_COAST: return 2; - case MP2::OBJ_ORACLE: return 3; - case MP2::OBJ_STONELIGHTS: return 4; - case MP2::OBJ_LAVAPOOL: return 5; - case MP2::OBJ_ALCHEMYLAB: return 6; - case MP2::OBJ_WATERWHEEL: return 9; - case MP2::OBJ_CAMPFIRE: return 10; - case MP2::OBJ_WINDMILL: return 11; - case MP2::OBJ_ARTESIANSPRING: - case MP2::OBJ_FOUNTAIN: return 12; - case MP2::OBJ_WATERLAKE: - case MP2::OBJ_WATERINGHOLE: return 13; - case MP2::OBJ_MINES: return 15; - case MP2::OBJ_SAWMILL: return 16; - case MP2::OBJ_DAEMONCAVE: return 17; - case MP2::OBJ_SHRINE1: - case MP2::OBJ_SHRINE2: - case MP2::OBJ_SHRINE3: return 18; - case MP2::OBJ_TARPIT: return 21; - case MP2::OBJ_TRADINGPOST: return 22; - case MP2::OBJ_RUINS: return 24; - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_DWARFCOTT: - case MP2::OBJ_ARCHERHOUSE: return 25; - case MP2::OBJ_VOLCANO: return 27; - - default: break; - } - - return 0xFF; -} - -M82::m82_t M82::GetLOOP00XX(u8 index) -{ - switch(index) - { - case 0: return LOOP0000; - case 1: return LOOP0001; - case 2: return LOOP0002; - case 3: return LOOP0003; - case 4: return LOOP0004; - case 5: return LOOP0005; - case 6: return LOOP0006; - case 7: return LOOP0007; - case 8: return LOOP0008; - case 9: return LOOP0009; - case 10: return LOOP0010; - case 11: return LOOP0011; - case 12: return LOOP0012; - case 13: return LOOP0013; - case 14: return LOOP0014; - case 15: return LOOP0015; - case 16: return LOOP0016; - case 17: return LOOP0017; - case 18: return LOOP0018; - case 19: return LOOP0019; - case 20: return LOOP0020; - case 21: return LOOP0021; - case 22: return LOOP0022; - case 23: return LOOP0023; - case 24: return LOOP0024; - case 25: return LOOP0025; - case 26: return LOOP0026; - case 27: return LOOP0027; - default: break; - } - - return UNKNOWN; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/m82.h b/project/jni/application/fheroes2/src/fheroes2/agg/m82.h deleted file mode 100644 index 1900601d7..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/m82.h +++ /dev/null @@ -1,354 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2M82_H -#define H2M82_H - -#include "gamedefs.h" - -#define LOOPXX_COUNT 28 - -namespace M82 -{ - enum m82_t - { - AELMATTK, - AELMKILL, - AELMMOVE, - AELMWNCE, - ANTIMAGK, - ARCHATTK, - ARCHKILL, - ARCHMOVE, - ARCHSHOT, - ARCHWNCE, - ARMGEDN, - BADLUCK, - BADMRLE, - BERZERK, - BLESS, - BLIND, - BLOODLUS, - BOARATTK, - BOARKILL, - BOARMOVE, - BOARWNCE, - BONEATTK, - BONEKILL, - BONEMOVE, - BONEWNCE, - BUILDTWN, - CATSND00, - CATSND02, - CAVLATTK, - CAVLKILL, - CAVLMOVE, - CAVLWNCE, - CHAINLTE, - CNTRATTK, - CNTRKILL, - CNTRMOVE, - CNTRSHOT, - CNTRWNCE, - COLDRAY, - COLDRING, - CURE, - CURSE, - CYCLATTK, - CYCLKILL, - CYCLMOVE, - CYCLWNCE, - DIGSOUND, - DIPMAGK, - DISRUPTR, - DRAWBRG, - DRGNATTK, - DRGNKILL, - DRGNMOVE, - DRGNSLAY, - DRGNWNCE, - DRUIATTK, - DRUIKILL, - DRUIMOVE, - DRUISHOT, - DRUIWNCE, - DWRFATTK, - DWRFKILL, - DWRFMOVE, - DWRFWNCE, - EELMATTK, - EELMKILL, - EELMMOVE, - EELMWNCE, - ELF_ATTK, - ELF_KILL, - ELF_MOVE, - ELF_SHOT, - ELF_WNCE, - ERTHQUAK, - EXPERNCE, - FELMATTK, - FELMKILL, - FELMMOVE, - FELMWNCE, - FIREBALL, - GARGATTK, - GARGKILL, - GARGMOVE, - GARGWNCE, - GBLNATTK, - GBLNKILL, - GBLNMOVE, - GBLNWNCE, - GENIATTK, - GENIKILL, - GENIMOVE, - GENIWNCE, - GHSTATTK, - GHSTKILL, - GHSTMOVE, - GHSTWNCE, - GOLMATTK, - GOLMKILL, - GOLMMOVE, - GOLMWNCE, - GOODLUCK, - GOODMRLE, - GRIFATTK, - GRIFKILL, - GRIFMOVE, - GRIFWNCE, - H2MINE, - HALFATTK, - HALFKILL, - HALFMOVE, - HALFSHOT, - HALFWNCE, - HASTE, - HYDRATTK, - HYDRKILL, - HYDRMOVE, - HYDRWNCE, - HYPNOTIZ, - KEEPSHOT, - KILLFADE, - LICHATTK, - LICHEXPL, - LICHKILL, - LICHMOVE, - LICHSHOT, - LICHWNCE, - LIGHTBLT, - LOOP0000, - LOOP0001, - LOOP0002, - LOOP0003, - LOOP0004, - LOOP0005, - LOOP0006, - LOOP0007, - LOOP0008, - LOOP0009, - LOOP0010, - LOOP0011, - LOOP0012, - LOOP0013, - LOOP0014, - LOOP0015, - LOOP0016, - LOOP0017, - LOOP0018, - LOOP0019, - LOOP0020, - LOOP0021, - LOOP0022, - LOOP0023, - LOOP0024, - LOOP0025, - LOOP0026, - LOOP0027, - MAGCAROW, - MAGEATTK, - MAGEKILL, - MAGEMOVE, - MAGESHOT, - MAGEWNCE, - MASSBLES, - MASSCURE, - MASSCURS, - MASSHAST, - MASSSHIE, - MASSSLOW, - MEDSATTK, - MEDSKILL, - MEDSMOVE, - MEDSWNCE, - METEOR, - MINOATTK, - MINOKILL, - MINOMOVE, - MINOWNCE, - MIRRORIM, - MNRDEATH, - MUMYATTK, - MUMYKILL, - MUMYMOVE, - MUMYWNCE, - NMADATTK, - NMADKILL, - NMADMOVE, - NMADWNCE, - NWHEROLV, - OGREATTK, - OGREKILL, - OGREMOVE, - OGREWNCE, - ORC_ATTK, - ORC_KILL, - ORC_MOVE, - ORC_SHOT, - ORC_WNCE, - PARALIZE, - PHOEATTK, - PHOEKILL, - PHOEMOVE, - PHOEWNCE, - PICKUP01, - PICKUP02, - PICKUP03, - PICKUP04, - PICKUP05, - PICKUP06, - PICKUP07, - PIKEATTK, - PIKEKILL, - PIKEMOVE, - PIKEWNCE, - PLDNATTK, - PLDNKILL, - PLDNMOVE, - PLDNWNCE, - PREBATTL, - PROTECT, - PSNTATTK, - PSNTKILL, - PSNTMOVE, - PSNTWNCE, - RESURECT, - RESURTRU, - ROC_ATTK, - ROC_KILL, - ROC_MOVE, - ROC_WNCE, - ROGUATTK, - ROGUKILL, - ROGUMOVE, - ROGUWNCE, - RSBRYFZL, - SHIELD, - SKELATTK, - SKELKILL, - SKELMOVE, - SKELWNCE, - SLOW, - SPRTATTK, - SPRTKILL, - SPRTMOVE, - SPRTWNCE, - STELSKIN, - STONESKI, - STONSKIN, - STORM, - SUMNELM, - SWDMATTK, - SWDMKILL, - SWDMMOVE, - SWDMWNCE, - TELEIN, - TELPTIN, - TELPTOUT, - TITNATTK, - TITNKILL, - TITNMOVE, - TITNSHOT, - TITNWNCE, - TREASURE, - TRLLATTK, - TRLLKILL, - TRLLMOVE, - TRLLSHOT, - TRLLWNCE, - UNICATTK, - UNICKILL, - UNICMOVE, - UNICWNCE, - VAMPATTK, - VAMPEXT1, - VAMPEXT2, - VAMPKILL, - VAMPMOVE, - VAMPWNCE, - WELMATTK, - WELMKILL, - WELMMOVE, - WELMWNCE, - WOLFATTK, - WOLFKILL, - WOLFMOVE, - WOLFWNCE, - WSND00, - WSND01, - WSND02, - WSND03, - WSND04, - WSND05, - WSND06, - WSND10, - WSND11, - WSND12, - WSND13, - WSND14, - WSND15, - WSND16, - WSND20, - WSND21, - WSND22, - WSND23, - WSND24, - WSND25, - WSND26, - ZOMBATTK, - ZOMBKILL, - ZOMBMOVE, - ZOMBWNCE, - - UNKNOWN - - }; - - const char* GetString(const m82_t m82); - m82_t FromSpell(u8); - u8 GetIndexLOOP00XXFromObject(u8); - m82_t GetLOOP00XX(u8); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/mus.cpp b/project/jni/application/fheroes2/src/fheroes2/agg/mus.cpp deleted file mode 100644 index 9d3a3ed76..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/mus.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Josh Matthews * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "race.h" -#include "ground.h" -#include "mus.h" -#include "settings.h" -#include "mp2.h" - -namespace MUS -{ - static const struct - { - mus_t type; - const char* string; - } musmap[] = { - { UNUSED, "" }, - { DATATRACK, "" }, - { BATTLE1, "Battle (1)" }, - { BATTLE2, "Battle (2)" }, - { BATTLE3, "Battle (3)" }, - { BARBARIAN, "Barbarian Castle" }, - { SORCERESS, "Sorceress Castle" }, - { WARLOCK, "Warlock Castle" }, - { WIZARD, "Wizard Castle" }, - { NECROMANCER, "Necromancer Castle" }, - { KNIGHT, "Knight Castle" }, - { LAVA, "Lava Theme" }, - { WASTELAND, "Wasteland Theme" }, - { DESERT, "Desert Theme" }, - { SNOW, "Snow Theme" }, - { SWAMP, "Swamp Theme" }, - { BEACH, "Ocean Theme" }, - { DIRT, "Dirt Theme" }, - { GRASS, "Grass Theme" }, - { LOSTGAME, "Lost Game" }, - { WEEK1, "Week (1)" }, - { WEEK2_MONTH1, "Week (2) Month (1)" }, - { MONTH2, "Month (2)" }, - { PUZZLE, "Map Puzzle" }, - { ROLAND, "Roland's Campaign" }, - { CARAVANS, "25" }, - { CARAVANS_2, "26" }, - { CARAVANS_3, "27" }, - { COMPUTER, "28" }, - { BATTLEWIN, "29" }, - { BATTLELOSE, "30" }, - { DEATH, "31" }, - { WATERSPRING, "32" }, - { ARABIAN, "33" }, - { NOMADTENTS, "34" }, - { TREEHOUSE, "35" }, - { DEMONCAVE, "36" }, - { EXPERIENCE, "37" }, - { SKILL, "38" }, - { WATCHTOWER, "39" }, - { EVENT15, "40" }, - { NEWS, "41" }, - { MAINMENU, "Main Menu" }, - { VICTORY, "Scenario Victory" }, - { UNKNOWN, "???" } - }; - - const std::string GetString(const mus_t mus, bool shortname) - { - std::stringstream sstream; - sstream << std::setw(2) << std::setfill('0') << (int)mus; - if(shortname) - sstream << ".ogg"; - else - sstream << " " << musmap[mus].string << ".ogg"; - return sstream.str(); - } -} - -MUS::mus_t MUS::FromGround(const u16 ground) -{ - switch(ground) - { - case Maps::Ground::DESERT: return DESERT; - case Maps::Ground::SNOW: return SNOW; - case Maps::Ground::SWAMP: return SWAMP; - case Maps::Ground::WASTELAND: return WASTELAND; - case Maps::Ground::BEACH: return BEACH; - case Maps::Ground::LAVA: return LAVA; - case Maps::Ground::DIRT: return DIRT; - case Maps::Ground::GRASS: return GRASS; - default: break; - } - - return UNKNOWN; -} - -MUS::mus_t MUS::FromRace(const u8 race) -{ - switch(race) - { - case Race::KNGT: return KNIGHT; - case Race::BARB: return BARBARIAN; - case Race::SORC: return SORCERESS; - case Race::WRLK: return WARLOCK; - case Race::WZRD: return WIZARD; - case Race::NECR: return NECROMANCER; - default: break; - } - - return UNKNOWN; -} - -MUS::mus_t MUS::FromMapObject(u8 object) -{ - if(!Settings::Get().CDMusic()) - return MUS::UNKNOWN; - - switch(object) - { - case MP2::OBJ_WITCHSHUT: - case MP2::OBJ_FORT: - case MP2::OBJ_MERCENARYCAMP: - case MP2::OBJ_DOCTORHUT: - case MP2::OBJ_STANDINGSTONES: - return MUS::SKILL; - - case MP2::OBJ_GAZEBO: - case MP2::OBJ_TREEKNOWLEDGE: - return MUS::EXPERIENCE; - - case MP2::OBJ_DAEMONCAVE: - return MUS::DEMONCAVE; - - case MP2::OBJ_TREEHOUSE: - case MP2::OBJ_TREECITY: - return MUS::TREEHOUSE; - - case MP2::OBJ_WATCHTOWER: - return MUS::WATCHTOWER; - - case MP2::OBJ_DESERTTENT: - return MUS::NOMADTENTS; - - case MP2::OBJ_ARTESIANSPRING: - return MUS::WATERSPRING; - - case MP2::OBJ_SPHINX: - return MUS::ARABIAN; - - case MP2::OBJ_EVENT: - return MUS::NEWS; - - default: - return MUS::UNKNOWN; - } -} - -MUS::mus_t MUS::GetBattleRandom(void) -{ - switch(Rand::Get(1, 3)) - { - case 1: return BATTLE1; - case 2: return BATTLE2; - case 3: return BATTLE3; - default: break; - } - return UNKNOWN; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/mus.h b/project/jni/application/fheroes2/src/fheroes2/agg/mus.h deleted file mode 100644 index db6db377f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/mus.h +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Josh Matthews * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2MUS_H -#define H2MUS_H - -#include "gamedefs.h" - -namespace MUS -{ - enum mus_t - { - UNUSED, - DATATRACK, - BATTLE1, - BATTLE2, - BATTLE3, - BARBARIAN, - SORCERESS, - WARLOCK, - WIZARD, - NECROMANCER, - KNIGHT, - LAVA, - WASTELAND, - DESERT, - SNOW, - SWAMP, - BEACH, - DIRT, - GRASS, - LOSTGAME, - WEEK1, - WEEK2_MONTH1, - MONTH2, - PUZZLE, - ROLAND, - CARAVANS, - CARAVANS_2, - CARAVANS_3, - COMPUTER, - BATTLEWIN, - BATTLELOSE, - DEATH, - WATERSPRING, - ARABIAN, - NOMADTENTS, - TREEHOUSE, - DEMONCAVE, - EXPERIENCE, - SKILL, - WATCHTOWER, - EVENT15, - NEWS, - MAINMENU, - VICTORY, - - UNKNOWN - }; - - const std::string GetString(const mus_t mus, bool shortname = false); - - mus_t FromGround(const u16 ground); - mus_t FromRace(const u8 race); - mus_t FromMapObject(u8 object); - - mus_t GetBattleRandom(void); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/sprite.cpp b/project/jni/application/fheroes2/src/fheroes2/agg/sprite.cpp deleted file mode 100644 index 4bce2b307..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/sprite.cpp +++ /dev/null @@ -1,189 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "settings.h" -#include "icn.h" -#include "cursor.h" -#include "display.h" -#include "sprite.h" - -Sprite::Sprite() : offsetX(0), offsetY(0) -{ -} - -void Sprite::SetOffset(s16 ox, s16 oy) -{ - offsetX = ox; - offsetY = oy; -} - -void Sprite::DrawICN(Surface & sf, const u8* cur, const u32 size, bool reflect) -{ - if(NULL == cur || 0 == size) return; - - const u8 *max = cur + size; - - u8 c = 0; - u16 x = reflect ? sf.w() - 1 : 0; - u16 y = 0; - - const u32 shadow = sf.isAlpha() ? sf.MapRGB(0, 0, 0, 0x40) : sf.GetColorKey(); - - // lock surface - sf.Lock(); - - while(1) - { - // 0x00 - end line - if(0 == *cur) - { - ++y; - x = reflect ? sf.w() - 1 : 0; - ++cur; - } - else - // 0x7F - count data - if(0x80 > *cur) - { - c = *cur; - ++cur; - while(c-- && cur < max) - { - sf.SetPixel(x, y, sf.GetColor(*cur)); - reflect ? x-- : x++; - ++cur; - } - } - else - // 0x80 - end data - if(0x80 == *cur) - { - break; - } - else - // 0xBF - skip data - if(0xC0 > *cur) - { - reflect ? x -= *cur - 0x80 : x += *cur - 0x80; - ++cur; - } - else - // 0xC0 - shadow - if(0xC0 == *cur) - { - ++cur; - c = *cur % 4 ? *cur % 4 : *(++cur); - while(c--){ if(sf.isAlpha()) sf.SetPixel(x, y, shadow); reflect ? x-- : x++; } - ++cur; - } - else - // 0xC1 - if(0xC1 == *cur) - { - ++cur; - c = *cur; - ++cur; - while(c--){ sf.SetPixel(x, y, sf.GetColor(*cur)); reflect ? x-- : x++; } - ++cur; - } - else - { - c = *cur - 0xC0; - ++cur; - while(c--){ sf.SetPixel(x, y, sf.GetColor(*cur)); reflect ? x-- : x++; } - ++cur; - } - - if(cur >= max) - { - DEBUG(DBG_ENGINE , DBG_WARN, "Sprite: index out of range"); - break; - } - } - - // unlock surface - sf.Unlock(); -} - -u32 Sprite::GetSize(void) const -{ - return Surface::GetSize() + sizeof(offsetX) + sizeof(offsetY); -} - -void Sprite::ScaleMinifyByTwo(void) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - - if(w() > 3 && h() > 3) - { - u16 theme = 0; - if(cursor.isVisible() && Cursor::WAIT != cursor.Themes()) - { - theme = cursor.Themes(); - cursor.SetThemes(Cursor::WAIT); - cursor.Show(); - display.Flip(); - } - - Surface sf; - Surface::ScaleMinifyByTwo(sf, *this, cursor.isVisible()); - Surface::Swap(sf, *this); - - if(theme) - { - cursor.SetThemes(theme); - cursor.Show(); - display.Flip(); - } - } - - offsetX /= 2; - offsetY /= 2; -} - -void Sprite::AddonExtensionModify(Sprite & sp, u16 icn, u16 index) -{ - switch(icn) - { - case ICN::AELEM: - if(sp.w() > 3 && sp.h() > 3) - { - Surface sf; - Surface::MakeContour(sf, sp, sp.GetColor(0xEF)); - sp.Blit(sf, -1, -1); - } - break; - - default: break; - } -} - -void Sprite::BlitSpriteWithAlpha(Surface & dst, u8 alpha, s16 dstx, s16 dsty) const -{ - Surface sf(w(), h()); - sf.SetColorKey(); - sf.Blit(*this); - sf.SetAlpha(alpha); - - dst.Blit(sf, dstx, dsty); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/sprite.h b/project/jni/application/fheroes2/src/fheroes2/agg/sprite.h deleted file mode 100644 index a5a4f3255..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/sprite.h +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2SPRITE_H -#define H2SPRITE_H - -#include "surface.h" -#include "gamedefs.h" - -class Sprite : public Surface -{ -public: - Sprite(); - - void SetOffset(s16, s16); - - s16 x(void) const{ return offsetX; } - s16 y(void) const{ return offsetY; } - - u32 GetSize(void) const; - void ScaleMinifyByTwo(void); - void BlitSpriteWithAlpha(Surface &, u8, s16, s16) const; - - static void DrawICN(Surface & sf, const u8* buf, const u32 size, bool reflect); - static void AddonExtensionModify(Sprite & sp, u16 icn, u16 index); - -private: - - s16 offsetX; - s16 offsetY; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/til.cpp b/project/jni/application/fheroes2/src/fheroes2/agg/til.cpp deleted file mode 100644 index 82c7f4d48..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/til.cpp +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "surface.h" -#include "til.h" - -namespace TIL -{ - static const struct - { - til_t type; - const char* string; - } tilmap[] = { - { CLOF32, "CLOF32.TIL" }, - { GROUND32, "GROUND32.TIL" }, - { STON, "STON.TIL" }, - }; -} - -const char* TIL::GetString(const til_t til) -{ - return tilmap[til].string; -} - -void TIL::Reflect(Surface & sf_dst, const Surface & sf_src, const u8 shape) -{ - Surface::TILReflect(sf_dst, sf_src, shape); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/til.h b/project/jni/application/fheroes2/src/fheroes2/agg/til.h deleted file mode 100644 index 0c9f6ce00..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/til.h +++ /dev/null @@ -1,45 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2TIL_H -#define H2TIL_H - -#include "gamedefs.h" - -class Surface; - -namespace TIL -{ - enum til_t - { - CLOF32, - GROUND32, - STON, - - UNKNOWN - }; - - const char* GetString(const til_t til); - void Reflect(Surface & sf_dst, const Surface & sf_src, const u8 shape); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/xmi.cpp b/project/jni/application/fheroes2/src/fheroes2/agg/xmi.cpp deleted file mode 100644 index 82e696144..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/xmi.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "xmi.h" - -namespace XMI -{ - static const struct - { - xmi_t type; - const char* string; - } xmimap[] = { - { UNKNOWN, "???" }, - { MIDI0002, "MIDI0002.XMI" }, - { MIDI0003, "MIDI0003.XMI" }, - { MIDI0004, "MIDI0004.XMI" }, - { MIDI0005, "MIDI0005.XMI" }, - { MIDI0006, "MIDI0006.XMI" }, - { MIDI0007, "MIDI0007.XMI" }, - { MIDI0008, "MIDI0008.XMI" }, - { MIDI0009, "MIDI0009.XMI" }, - { MIDI0010, "MIDI0010.XMI" }, - { MIDI0011, "MIDI0011.XMI" }, - { MIDI0013, "MIDI0013.XMI" }, - { MIDI0014, "MIDI0014.XMI" }, - { MIDI0015, "MIDI0015.XMI" }, - { MIDI0017, "MIDI0017.XMI" }, - { MIDI0018, "MIDI0018.XMI" }, - { MIDI0042, "MIDI0042.XMI" }, - { MIDI0043, "MIDI0043.XMI" }, - }; -} - -const char* XMI::GetString(const xmi_t xmi) -{ - return xmimap[xmi].string; -} - -XMI::xmi_t XMI::FromMUS(const MUS::mus_t mus) -{ - switch(mus) - { - case MUS::BATTLE1: return MIDI0002; - case MUS::BATTLE2: return MIDI0003; - case MUS::BATTLE3: return MIDI0004; - case MUS::SORCERESS: return MIDI0005; - case MUS::WARLOCK: return MIDI0006; - case MUS::NECROMANCER: return MIDI0007; - case MUS::KNIGHT: return MIDI0008; - case MUS::BARBARIAN: return MIDI0009; - case MUS::WIZARD: return MIDI0010; - case MUS::LAVA: return MIDI0011; - case MUS::DESERT: return MIDI0013; - case MUS::SNOW: return MIDI0014; - case MUS::SWAMP: return MIDI0015; - case MUS::DIRT: return MIDI0017; - case MUS::GRASS: return MIDI0018; - case MUS::MAINMENU: return MIDI0042; - case MUS::VICTORY: return MIDI0043; - default: break; - } - - return UNKNOWN; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/agg/xmi.h b/project/jni/application/fheroes2/src/fheroes2/agg/xmi.h deleted file mode 100644 index 378c6ff09..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/agg/xmi.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2XMI_H -#define H2XMI_H - -#include "mus.h" - -namespace XMI -{ - enum xmi_t - { - UNKNOWN, - MIDI0002, - MIDI0003, - MIDI0004, - MIDI0005, - MIDI0006, - MIDI0007, - MIDI0008, - MIDI0009, - MIDI0010, - MIDI0011, - MIDI0013, - MIDI0014, - MIDI0015, - MIDI0017, - MIDI0018, - MIDI0042, - MIDI0043 - }; - - const char* GetString(const xmi_t xmi); - xmi_t FromMUS(const MUS::mus_t mus); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/algorithm/algorithm.cpp b/project/jni/application/fheroes2/src/fheroes2/algorithm/algorithm.cpp deleted file mode 100644 index fc6853d2d..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/algorithm/algorithm.cpp +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "algorithm.h" - diff --git a/project/jni/application/fheroes2/src/fheroes2/algorithm/algorithm.h b/project/jni/application/fheroes2/src/fheroes2/algorithm/algorithm.h deleted file mode 100644 index 01ee84e29..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/algorithm/algorithm.h +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2ALGORITHM_H -#define H2ALGORITHM_H - -#include -#include "gamedefs.h" -#include "skill.h" -#include "mp2.h" - -namespace Route { class Step; } -class Heroes; - -namespace Algorithm -{ - bool PathFind(std::list *result, const s32 from, const s32 to, const u16 limit = MAXU16, const Heroes * = NULL); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/algorithm/pathfind.cpp b/project/jni/application/fheroes2/src/fheroes2/algorithm/pathfind.cpp deleted file mode 100644 index d94956a8c..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/algorithm/pathfind.cpp +++ /dev/null @@ -1,229 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "maps.h" -#include "world.h" -#include "direction.h" -#include "settings.h" -#include "object.h" -#include "heroes.h" -#include "route.h" -#include "algorithm.h" - -struct cell_t -{ - cell_t() : cost_g(MAXU16), cost_t(MAXU16), cost_d(MAXU16), parent(-1), open(true){}; - - u16 cost_g; - u16 cost_t; - u16 cost_d; - s32 parent; - bool open; -}; - -bool ImpassableCorners(const s32 from, const Direction::vector_t to, const Heroes *hero) -{ - if( to & (Direction::TOP | Direction::BOTTOM | Direction::LEFT | Direction::RIGHT)) return false; - - if(to & (Direction::TOP_LEFT | Direction::BOTTOM_LEFT)) - { - if(Maps::isValidDirection(from, Direction::LEFT) && - !world.GetTiles(Maps::GetDirectionIndex(from, Direction::LEFT)).isPassable(hero)) return true; - } - - if(to & (Direction::TOP_RIGHT | Direction::BOTTOM_RIGHT)) - { - if(Maps::isValidDirection(from, Direction::RIGHT) && - !world.GetTiles(Maps::GetDirectionIndex(from, Direction::RIGHT)).isPassable(hero)) return true; - } - - if(to & (Direction::TOP_LEFT | Direction::TOP_RIGHT)) - { - if(Maps::isValidDirection(from, Direction::TOP) && - !world.GetTiles(Maps::GetDirectionIndex(from, Direction::TOP)).isPassable(hero)) return true; - } - - if(to & (Direction::BOTTOM_LEFT | Direction::BOTTOM_RIGHT)) - { - if(Maps::isValidDirection(from, Direction::BOTTOM) && - !world.GetTiles(Maps::GetDirectionIndex(from, Direction::BOTTOM)).isPassable(hero)) return true; - } - - return false; -} - -u32 GetCurrentLength(std::map & list, s32 cur) -{ - u32 res = 0; - const cell_t* cell = &list[cur]; - while(-1 != cell->parent){ cell = &list[cell->parent]; ++res; }; - return res; -} - -bool MonsterDestination(const s32 from, const u16 around, const s32 dst) -{ - for(Direction::vector_t dir = Direction::TOP_LEFT; dir < Direction::CENTER; ++dir) - if((around & dir) && dst == Maps::GetDirectionIndex(from, dir)) - return true; - - return false; -} - -bool Algorithm::PathFind(std::list *result, const s32 from, const s32 to, const u16 limit, const Heroes *hero) -{ - const u8 pathfinding = (hero ? hero->GetLevelSkill(Skill::Secondary::PATHFINDING) : Skill::Level::NONE); - const u8 under = (hero ? hero->GetUnderObject() : MP2::OBJ_ZERO); - - s32 cur = from; - s32 alt = 0; - s32 tmp = 0; - std::map list; - std::map::iterator it1 = list.begin(); - std::map::iterator it2 = list.end(); - Direction::vector_t direct = Direction::CENTER; - - list[cur].cost_g = 0; - list[cur].cost_t = 0; - list[cur].parent = -1; - list[cur].open = false; - - u16 mons = 0; - cell_t cell; - - while(cur != to) - { - LocalEvent::Get().HandleEvents(false); - - for(direct = Direction::TOP_LEFT; direct != Direction::CENTER; ++direct) - { - if(Maps::isValidDirection(cur, direct)) - { - tmp = Maps::GetDirectionIndex(cur, direct); - - if(list[tmp].open) - { - // new - if(-1 == list[tmp].parent) - { - cell.cost_g = Maps::Ground::GetPenalty(tmp, direct, pathfinding); - cell.parent = cur; - cell.open = true; - cell.cost_t = cell.cost_g + list[cur].cost_t; - cell.cost_d = 50 * Maps::GetApproximateDistance(tmp, to); - - if(MAXU16 == cell.cost_g) continue; - - // check monster protection - if(tmp != to && (mons = Maps::TileUnderProtection(tmp)) && ! MonsterDestination(tmp, mons, to)) continue; - - // check direct from object - const Maps::Tiles & tile1 = world.GetTiles(cur); - if(MP2::OBJ_ZERO != under && MP2::OBJ_HEROES == tile1.GetObject() && ! Object::AllowDirect(under, direct)) continue; - - // check obstacles as corners - //if(ImpassableCorners(cur, direct, hero)) continue; // disable, need fix more objects with passable option - - // check direct to object - const Maps::Tiles & tile2 = world.GetTiles(tmp); - if(! Object::AllowDirect(tile2.GetObject(), Direction::Reflect(direct))) continue; - - if(tile2.isPassable(hero) || tmp == to) list[tmp] = cell; - } - // check alt - else - { - alt = Maps::Ground::GetPenalty(cur, direct, pathfinding); - if(list[tmp].cost_t > list[cur].cost_t + alt) - { - list[tmp].parent = cur; - list[tmp].cost_g = alt; - list[tmp].cost_t = list[cur].cost_t + alt; - } - } - } - } - } - - if(cur == to) break; - else - list[cur].open = false; - - DEBUG(DBG_GAME , DBG_TRACE, "Algorithm::PathFind: route, from: " << cur); - - it1 = list.begin(); - alt = -1; - tmp = MAXU16; - - // find minimal cost - for(; it1 != it2; ++it1) if((*it1).second.open) - { - const cell_t & cell2 = (*it1).second; - - if(IS_DEBUG(DBG_GAME, DBG_TRACE) && cell2.cost_g != MAXU16) - { - direct = Direction::Get(cur, (*it1).first); - if(Direction::UNKNOWN != direct) - { - std::cout << " direct: " << Direction::String(direct); - std::cout << ", index: " << (*it1).first; - std::cout << ", cost g: " << cell2.cost_g; - std::cout << ", cost t: " << cell2.cost_t; - std::cout << ", cost d: " << cell2.cost_d << std::endl; - } - } - - - if(cell2.cost_t + cell2.cost_d < tmp) - { - tmp = cell2.cost_t + cell2.cost_d; - alt = (*it1).first; - } - } - - // not found, and exception - if(MAXU16 == tmp || -1 == alt || (limit && GetCurrentLength(list, cur) > limit)) break; - else - DEBUG(DBG_GAME , DBG_TRACE, "Algorithm::PathFind: select: " << alt); - - cur = alt; - } - - // save path - if(cur == to) - { - while(cur != from) - { - if(-1 == list[cur].parent) break; - alt = cur; - cur = list[alt].parent; - if(result) result->push_front(Route::Step(Direction::Get(cur, alt), list[alt].cost_g)); - } - return true; - } - - DEBUG(DBG_GAME , DBG_TRACE, "Algorithm::PathFind: not found, from:" << from << ", to: " << to); - list.clear(); - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/army/army.cpp b/project/jni/application/fheroes2/src/fheroes2/army/army.cpp deleted file mode 100644 index 8a8aca7fd..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/army/army.cpp +++ /dev/null @@ -1,1290 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "settings.h" -#include "payment.h" -#include "world.h" -#include "kingdom.h" -#include "maps_tiles.h" -#include "text.h" -#include "luck.h" -#include "morale.h" -#include "speed.h" -#include "castle.h" -#include "heroes.h" -#include "battle_stats.h" -#include "tools.h" -#include "army.h" - -std::vector::iterator MaxElement(std::vector::iterator first, std::vector::iterator last, bool (*pf)(const Army::Troop &, const Army::Troop &)) -{ - while(first != last) if(Army::isValidTroop(*first)) break; else ++first; - std::vector::iterator largest = first; - if(first == last) return last; - while(++first != last) if(Army::isValidTroop(*first) && pf(*first, *largest)) largest = first; - return largest; -} - -std::vector::const_iterator MaxElement(std::vector::const_iterator first, std::vector::const_iterator last, bool (*pf)(const Army::Troop &, const Army::Troop &)) -{ - while(first != last) if(Army::isValidTroop(*first)) break; else ++first; - std::vector::const_iterator largest = first; - if(first == last) return last; - while(++first != last) if(Army::isValidTroop(*first) && pf(*first, *largest)) largest = first; - return largest; -} - -std::vector::iterator MinElement(std::vector::iterator first, std::vector::iterator last, bool (*pf)(const Army::Troop &, const Army::Troop &)) -{ - while(first != last) if(Army::isValidTroop(*first)) break; else ++first; - std::vector::iterator lowest = first; - if(first == last) return last; - while(++first != last) if(Army::isValidTroop(*first) && pf(*first, *lowest)) lowest = first; - return lowest; -} - -std::vector::const_iterator MinElement(std::vector::const_iterator first, std::vector::const_iterator last, bool (*pf)(const Army::Troop &, const Army::Troop &)) -{ - while(first != last) if(Army::isValidTroop(*first)) break; else ++first; - std::vector::const_iterator lowest = first; - if(first == last) return last; - while(++first != last) if(Army::isValidTroop(*first) && pf(*first, *lowest)) lowest = first; - return lowest; -} - -const char* Army::String(u32 size) -{ - const char* str_size[] = { _("army|Few"), _("army|Several"), _("army|Pack"), _("army|Lots"), _("army|Horde"), _("army|Throng"), _("army|Swarm"), _("army|Zounds"), _("army|Legion") }; - - switch(GetSize(size)) - { - case FEW: return str_size[0]; - case SEVERAL: return str_size[1]; - case PACK: return str_size[2]; - case LOTS: return str_size[3]; - case HORDE: return str_size[4]; - case THRONG: return str_size[5]; - case SWARM: return str_size[6]; - case ZOUNDS: return str_size[7]; - case LEGION: return str_size[8]; - } - - return str_size[0]; -} - -Army::armysize_t Army::GetSize(u32 count) -{ - if(LEGION <= count) return LEGION; - else - if(ZOUNDS <= count) return ZOUNDS; - else - if(SWARM <= count) return SWARM; - else - if(THRONG <= count) return THRONG; - else - if(HORDE <= count) return HORDE; - else - if(LOTS <= count) return LOTS; - else - if(PACK <= count) return PACK; - else - if(SEVERAL <= count) return SEVERAL; - - return FEW; -} - -Army::army_t::army_t(HeroBase* s) : army(ARMYMAXTROOPS), commander(s), combat_format(FORMAT_SPREAD), color(Color::GRAY) -{ - std::vector::iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - for(; it1 != it2; ++it1) (*it1).army = this; -} - -Army::army_t::army_t(const army_t & a) : army(ARMYMAXTROOPS), commander(NULL), combat_format(FORMAT_SPREAD), color(Color::GRAY) -{ - std::vector::iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - for(; it1 != it2; ++it1) (*it1).army = this; - - Import(a.army); -} - -void Army::army_t::FromGuardian(const Maps::Tiles & t) -{ - Reset(); - - if(MP2::isCaptureObject(t.GetObject())) - color = world.ColorCapturedObject(t.GetIndex()); - - u8 obj = t.GetObject(); - - if(MP2::OBJ_HEROES == obj) - { - const Heroes* hero = world.GetHeroes(t.GetIndex()); - if(hero) obj = hero->GetUnderObject(); - } - - switch(obj) - { - case MP2::OBJ_PYRAMID: - army[0].Set(Monster::ROYAL_MUMMY, 10); - army[1].Set(Monster::VAMPIRE_LORD, 10); - army[2].Set(Monster::ROYAL_MUMMY, 10); - army[3].Set(Monster::VAMPIRE_LORD, 10); - army[4].Set(Monster::ROYAL_MUMMY, 10); - break; - - case MP2::OBJ_GRAVEYARD: - army[0].Set(Monster::MUTANT_ZOMBIE, 100); - ArrangeForBattle(); - break; - - case MP2::OBJ_SHIPWRECK: - army[0].Set(Monster::GHOST, t.GetQuantity2()); - ArrangeForBattle(); - break; - - case MP2::OBJ_DERELICTSHIP: - army[0].Set(Monster::SKELETON, 200); - ArrangeForBattle(); - break; - - case MP2::OBJ_ARTIFACT: - switch(t.GetQuantity2()) - { - case 6: army[0].Set(Monster::ROGUE, 50); break; - case 7: army[0].Set(Monster::GENIE, 1); break; - case 8: army[0].Set(Monster::PALADIN, 1); break; - case 9: army[0].Set(Monster::CYCLOPS, 1); break; - case 10:army[0].Set(Monster::PHOENIX, 1); break; - case 11:army[0].Set(Monster::GREEN_DRAGON, 1); break; - case 12:army[0].Set(Monster::TITAN, 1); break; - case 13:army[0].Set(Monster::BONE_DRAGON, 1); break; - default: break; - } - ArrangeForBattle(); - break; - - //case MP2::OBJ_ABANDONEDMINE: - // army[0] = Troop(t); - // ArrangeForBattle(); - // break; - - case MP2::OBJ_CITYDEAD: - army[0].Set(Monster::ZOMBIE, 20); - army[1].Set(Monster::VAMPIRE_LORD, 5); - army[2].Set(Monster::POWER_LICH, 5); - army[3].Set(Monster::VAMPIRE_LORD, 5); - army[4].Set(Monster::ZOMBIE, 20); - break; - - case MP2::OBJ_TROLLBRIDGE: - army[0].Set(Monster::TROLL, 4); - army[1].Set(Monster::WAR_TROLL, 4); - army[2].Set(Monster::TROLL, 4); - army[3].Set(Monster::WAR_TROLL, 4); - army[4].Set(Monster::TROLL, 4); - break; - - case MP2::OBJ_DRAGONCITY: - army[0].Set(Monster::GREEN_DRAGON, 3); - army[1].Set(Monster::RED_DRAGON, 2); - army[2].Set(Monster::BLACK_DRAGON, 1); - break; - - case MP2::OBJ_DAEMONCAVE: - army[0].Set(Monster::EARTH_ELEMENT, 2); - army[1].Set(Monster::EARTH_ELEMENT, 2); - army[2].Set(Monster::EARTH_ELEMENT, 2); - army[3].Set(Monster::EARTH_ELEMENT, 2); - break; - - default: - army[0] = Troop(t); - ArrangeForBattle(); - break; - } -} - -Army::army_t & Army::army_t::operator= (const army_t & a) -{ - commander = NULL; - - Import(a.army); - combat_format = a.combat_format; - color = a.color; - - return *this; -} - -void Army::army_t::SetCombatFormat(format_t f) -{ - combat_format = f; -} - -u8 Army::army_t::GetCombatFormat(void) const -{ - return combat_format; -} - -void Army::army_t::Import(const std::vector & v) -{ - for(u8 ii = 0; ii < Size(); ++ii) - { - if(ii < v.size()) - army[ii] = v[ii]; - else - army[ii].Reset(); - } -} - -void Army::army_t::UpgradeMonsters(const Monster & m) -{ - UpgradeMonsters(m()); -} - -void Army::army_t::UpgradeMonsters(const Monster::monster_t m) -{ - for(u8 ii = 0; ii < Size(); ++ii) if(army[ii].isValid() && army[ii] == m) army[ii].Upgrade(); -} - -u8 Army::army_t::Size(void) const -{ - return army.size() > ARMYMAXTROOPS ? army.size() : ARMYMAXTROOPS; -} - -Army::Troop & Army::army_t::FirstValid(void) -{ - std::vector::iterator it = std::find_if(army.begin(), army.end(), Army::isValidTroop); - - if(it == army.end()) - { - DEBUG(DBG_GAME , DBG_WARN, "Army::FirstValid: not found, return first.."); - it = army.begin(); - } - - return *it; -} - -s8 Army::army_t::GetTroopIndex(const Troop & t) const -{ - for(u8 ii = 0; ii < Size(); ++ii) if(&army[ii] == &t) return ii; - return -1; -} - -Army::Troop & Army::army_t::At(u8 index) -{ - return index < Size() ? army[index] : army[Size() - 1]; -} - -const Army::Troop & Army::army_t::At(u8 index) const -{ - return index < Size() ? army[index] : army[Size() - 1]; -} - -u8 Army::army_t::GetCount(void) const -{ - return std::count_if(army.begin(), army.end(), Army::isValidTroop); -} - -u8 Army::army_t::GetUniqCount(void) const -{ - std::vector troops; - troops.reserve(ARMYMAXTROOPS); - - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - for(; it1 != it2; ++it1) if((*it1).isValid()) troops.push_back((*it1).GetID()); - troops.resize(std::unique(troops.begin(), troops.end()) - troops.begin()); - - return troops.size(); -} - -u32 Army::army_t::GetCountMonsters(const Monster & m) const -{ - return GetCountMonsters(m()); -} - -u32 Army::army_t::GetCountMonsters(const Monster::monster_t m) const -{ - u32 c = 0; - - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - for(; it1 != it2; ++it1) if((*it1).isValid() && (*it1) == m) c += (*it1).GetCount(); - - return c; -} - -bool Army::army_t::JoinTroop(const Monster & mon, const u32 count) -{ - return JoinTroop(Troop(mon.GetID(), count)); -} - -bool Army::army_t::JoinTroop(const Monster::monster_t mon, const u32 count) -{ - return JoinTroop(Troop(mon, count)); -} - -bool Army::army_t::JoinTroop(const Troop & troop) -{ - if(!troop.isValid()) return false; - - std::vector::iterator it; - it = std::find_if(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::HasMonster), troop())); - - if(it == army.end()) it = std::find_if(army.begin(), army.end(), std::not1(std::mem_fun_ref(&Troop::isValid))); - - if(it != army.end()) - { - if((*it).isValid()) - (*it).SetCount((*it).GetCount() + troop.GetCount()); - else - (*it).Set(troop, troop.GetCount()); - DEBUG(DBG_GAME , DBG_INFO, "Army::JoinTroop: monster: " << troop.GetName() << ", count: " << std::dec << troop.GetCount() << ", commander: " << (commander ? commander->GetName() : "unknown")); - return true; - } - - return false; -} - -bool Army::army_t::isValid(void) const -{ - return army.end() != std::find_if(army.begin(),army.end(), Army::isValidTroop); -} - -bool Army::army_t::HasMonster(const Monster & mons) const -{ - return HasMonster(mons()); -} - -bool Army::army_t::HasMonster(const Monster::monster_t mons) const -{ - return army.end() != std::find_if(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::HasMonster), mons)); -} - -Color::color_t Army::army_t::GetColor(void) const -{ - return commander ? commander->GetColor() : color; -} - -void Army::army_t::SetColor(Color::color_t cl) -{ - color = cl; -} - -Race::race_t Army::army_t::GetRace(void) const -{ - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - std::vector races; - races.reserve(ARMYMAXTROOPS); - - for(; it1 != it2; ++it1) if((*it1).isValid()) races.push_back((*it1).GetRace()); - races.resize(std::unique(races.begin(), races.end()) - races.begin()); - - if(races.empty()) - { - DEBUG(DBG_GAME , DBG_WARN, "Army::GetRaceArmy: empty"); - return Race::MULT; - } - - return 1 < races.size() ? Race::MULT : races.at(0); -} - -s8 Army::army_t::GetLuck(void) const -{ - return commander ? commander->GetLuck() : GetLuckModificator(NULL); -} - -s8 Army::army_t::GetLuckModificator(std::string *strs) const -{ - return Luck::NORMAL; -} - -bool Army::army_t::AllTroopsIsRace(u8 race) const -{ - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - for(; it1 != it2; ++it1) if((*it1).isValid() && (*it1).GetRace() != race) return false; - - return true; -} - -s8 Army::army_t::GetMorale(void) const -{ - return commander ? commander->GetMorale() : GetMoraleModificator(NULL); -} - -// TODO:: need optimize -s8 Army::army_t::GetMoraleModificator(std::string *strs) const -{ - s8 result(Morale::NORMAL); - - // different race penalty - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - u8 count = 0; - u8 count_kngt = 0; - u8 count_barb = 0; - u8 count_sorc = 0; - u8 count_wrlk = 0; - u8 count_wzrd = 0; - u8 count_necr = 0; - u8 count_bomg = 0; - bool ghost_present = false; - for(; it1 != it2; ++it1) if((*it1).isValid()) - { - switch((*it1).GetRace()) - { - case Race::KNGT: ++count_kngt; break; - case Race::BARB: ++count_barb; break; - case Race::SORC: ++count_sorc; break; - case Race::WRLK: ++count_wrlk; break; - case Race::WZRD: ++count_wzrd; break; - case Race::NECR: ++count_necr; break; - case Race::BOMG: ++count_bomg; break; - default: break; - } - if(*it1 == Monster::GHOST) ghost_present = true; - } - - Race::race_t r = Race::MULT; - if(count_kngt){ ++count; r = Race::KNGT; } - if(count_barb){ ++count; r = Race::BARB; } - if(count_sorc){ ++count; r = Race::SORC; } - if(count_wrlk){ ++count; r = Race::WRLK; } - if(count_wzrd){ ++count; r = Race::WZRD; } - if(count_necr){ ++count; r = Race::NECR; } - if(count_bomg){ ++count; r = Race::BOMG; } - const u8 uniq_count = GetUniqCount(); - - switch(count) - { - case 2: - case 0: break; - case 1: - if(0 == count_necr && !ghost_present) - { - if(1 < uniq_count) - { - ++result; - if(strs) - { - std::string str = _("All %{race} troops +1"); - String::Replace(str, "%{race}", Race::String(r)); - strs->append(str); - strs->append("\n"); - } - } - } - else - { - if(strs) - { - strs->append(_("Entire unit is undead, so morale does not apply.")); - strs->append("\n"); - } - return 0; - } - break; - case 3: - result -= 1; - if(strs) - { - strs->append(_("Troops of 3 alignments -1")); - strs->append("\n"); - } - break; - case 4: - result -= 2; - if(strs) - { - strs->append(_("Troops of 4 alignments -2")); - strs->append("\n"); - } - break; - default: - result -= 3; - if(strs) - { - strs->append(_("Troops of 5 alignments -3")); - strs->append("\n"); - } - break; - } - - // undead in life group - if((1 < uniq_count && (count_necr || ghost_present) && (count_kngt || count_barb || count_sorc || count_wrlk || count_wzrd || count_bomg)) || - // or artifact Arm Martyr - (commander && commander->HasArtifact(Artifact::ARM_MARTYR))) - { - result -= 1; - if(strs) - { - strs->append(_("Some undead in groups -1")); - strs->append("\n"); - } - } - - return result; -} - -Army::Troop & Army::army_t::GetWeakestTroop(void) -{ - return *MinElement(army.begin(), army.end(), WeakestTroop); -} - -const Army::Troop & Army::army_t::GetSlowestTroop(void) const -{ - return *MinElement(army.begin(), army.end(), SlowestTroop); -} - -/* draw MONS32 sprite in line, first valid = 0, count = 0 */ -void Army::army_t::DrawMons32Line(s16 cx, s16 cy, u16 width, u8 first, u8 count, bool hide) const -{ - if(!isValid()) return; - - if(0 == count) count = GetCount(); - else - if(Size() < count) count = Size(); - - const u16 chunk = width / count; - cx += chunk / 2; - - std::string str; - Text text; - text.Set(Font::SMALL); - - for(u8 ii = 0; ii < Size(); ++ii) - { - const Army::Troop & troop = army[ii]; - - if(troop.isValid()) - { - if(0 == first && count) - { - const Sprite & monster = AGG::GetICN(ICN::MONS32, Monster::GetSpriteIndex(troop())); - - Display::Get().Blit(monster, cx - monster.w() / 2, cy + 30 - monster.h()); - - if(hide) - { - text.Set(Army::String(troop.GetCount())); - } - else - { - str.clear(); - String::AddInt(str, troop.GetCount()); - text.Set(str); - } - text.Blit(cx - text.w() / 2, cy + 28); - - cx += chunk; - --count; - } - else - --first; - } - } -} - -void Army::army_t::ArrangeForBattle(void) -{ - if(GetControl() != Game::AI) return; - - std::vector priority; - priority.reserve(ARMYMAXTROOPS); - - std::vector::iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - - for(; it1 != it2; ++it1) - { - Troop & troop = *it1; - if(!troop.isValid()) continue; - - std::vector::iterator it = std::find_if(priority.begin(), priority.end(), std::bind2nd(std::mem_fun_ref(&Troop::HasMonster), troop())); - - if(it == priority.end()) - priority.push_back(troop); - else - (*it).SetCount((*it).GetCount() + troop.GetCount()); - - troop.Reset(); - } - - switch(priority.size()) - { - case 1: - { - const Monster & m = priority.back(); - const u32 count = priority.back().GetCount(); - if(49 < count) - { - const u32 c = count / 5; - army[0].Set(m, c); - army[1].Set(m, c); - army[2].Set(m, c + count - (c * 5)); - army[3].Set(m, c); - army[4].Set(m, c); - } - else - if(20 < count) - { - const u32 c = count / 3; - army[1].Set(m, c); - army[2].Set(m, c + count - (c * 3)); - army[3].Set(m, c); - } - else - army[2].Set(m, count); - break; - } - case 2: - { - // TODO: need modify army for 2 troops - Import(priority); - break; - } - case 3: - { - // TODO: need modify army for 3 troops - Import(priority); - break; - } - case 4: - { - // TODO: need modify army for 4 troops - Import(priority); - break; - } - case 5: - { // possible change orders monster - // store - Import(priority); - break; - } - default: break; - } -} - -u32 Army::army_t::CalculateExperience(void) const -{ - u32 res = 0; - - for(u8 ii = 0; ii < Size(); ++ii) - res += army[ii].GetHitPoints(); - - if(commander) res += 500; - - return res; - -} - -void Army::army_t::BattleInit(void) -{ - // reserve ARMYMAXTROOPS for summons and mirrors spell - if(commander) - { - army.reserve(ARMYMAXTROOPS * 2); - commander->PreBattleAction(); - } -} - -void Army::army_t::BattleQuit(void) -{ - std::for_each(army.begin(), army.end(), std::mem_fun_ref(&Troop::BattleQuit)); - if(army.size() > ARMYMAXTROOPS) army.resize(ARMYMAXTROOPS); -} - -void Army::army_t::BattleNewTurn(void) -{ - std::for_each(army.begin(), army.end(), std::mem_fun_ref(&Troop::BattleNewTurn)); - if(commander) commander->ResetModes(Heroes::SPELLCASTED); -} - -void Army::army_t::BattleSetModes(u32 f) -{ - //std::for_each(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::BattleSetModes), f)); // Cannot call non-const function here - for( std::vector ::iterator it = army.begin(); it != army.end(); it++ ) - it->BattleSetModes(f); -} - -void Army::army_t::BattleResetModes(u32 f) -{ - //std::for_each(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::BattleResetModes), f)); // Cannot call non-const function here - for( std::vector ::iterator it = army.begin(); it != army.end(); it++ ) - it->BattleResetModes(f); -} - -Army::Troop* Army::army_t::BattleFindModes(u32 f) -{ - std::vector::iterator it = std::find_if(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::BattleFindModes), f)); - return it != army.end() ? &(*it) : NULL; -} - -const Army::Troop* Army::army_t::BattleFindModes(u32 f) const -{ - std::vector::const_iterator it = std::find_if(army.begin(), army.end(), std::bind2nd(std::mem_fun_ref(&Troop::BattleFindModes), f)); - return it != army.end() ? &(*it) : NULL; -} - -Army::Troop & Army::army_t::BattleNewTroop(Monster::monster_t id, u32 count) -{ - // find free invalid - std::vector::iterator it = army.begin(); - while(it != army.end() && NULL != (*it).GetBattleStats()) ++it; - - if(army.end() == it) - { - army.resize(army.size() + 1); - it = army.end() - 1; - } - - (*it).id = id; - (*it).count = count; - (*it).army = this; - - (*it).BattleInit(); - - return *it; -} - -u32 Army::army_t::BattleKilled(void) const -{ - u32 res = 0; - std::vector::const_iterator it = army.begin(); - for(; it != army.end(); ++it) res += (*it).BattleKilled(); - - return res; -} - -u8 Army::army_t::BattleUndeadTroopCount(void) const -{ - return std::count_if(army.begin(), army.end(), std::mem_fun_ref(&Troop::isUndead)); -} - -u8 Army::army_t::BattleLifeTroopCount(void) const -{ - return GetCount() - std::count_if(army.begin(), army.end(), std::mem_fun_ref(&Troop::isUndead)) - - std::count_if(army.begin(), army.end(), std::mem_fun_ref(&Troop::isElemental)); -} - -const Battle2::Stats* Army::army_t::BattleRandomTroop(void) const -{ - std::vector v; - - std::vector::const_iterator it = army.begin(); - for(; it != army.end(); ++it) if((*it).isValid()) - v.push_back((*it).GetBattleStats()); - - return v.size() ? *Rand::Get(v) : NULL; -} - -bool Army::army_t::BattleArchersPresent(void) const -{ - return army.end() != std::find_if(army.begin(), army.end(), std::mem_fun_ref(&Troop::BattleIsArchers)); -} - -bool Army::army_t::BattleDragonsPresent(void) const -{ - return army.end() != std::find_if(army.begin(), army.end(), std::mem_fun_ref(&Troop::BattleIsDragons)); -} - -Battle2::Stats* Army::army_t::BattleFastestTroop(bool skipmove) -{ - std::vector::iterator it = army.begin(); - Battle2::Stats* cur = NULL; - - for(; it != army.end(); ++it) if((*it).isValid()) - { - Battle2::Stats* b = (*it).GetBattleStats(); - - if(b && !b->Modes(Battle2::TR_MOVED) && - ((skipmove && b->Modes(Battle2::TR_SKIPMOVE)) || (!skipmove && !b->Modes(Battle2::TR_SKIPMOVE))) && - Speed::STANDING < b->GetSpeed() && - (NULL == cur || b->GetSpeed() > cur->GetSpeed())) cur = b; - } - - return cur; -} - -Battle2::Stats* Army::army_t::BattleSlowestTroop(bool skipmove) -{ - std::vector::iterator it = army.begin(); - Battle2::Stats* cur = NULL; - - for(; it != army.end(); ++it) if((*it).isValid()) - { - Battle2::Stats* b = (*it).GetBattleStats(); - - if(b && !b->Modes(Battle2::TR_MOVED) && - ((skipmove && b->Modes(Battle2::TR_SKIPMOVE)) ||(!skipmove && !b->Modes(Battle2::TR_SKIPMOVE))) && - Speed::STANDING < b->GetSpeed() && - (NULL == cur || b->GetSpeed() < cur->GetSpeed())) cur = b; - } - - return cur; -} - -void Army::army_t::Clear(void) -{ - std::for_each(army.begin(), army.end(), std::mem_fun_ref(&Troop::Reset)); -} - -void Army::army_t::BattleExportKilled(army_t & a) const -{ - a.army.resize(Size()); - - for(u8 ii = 0; ii < Size(); ++ii) - { - a.army[ii].SetMonster(army[ii].GetID()); - a.army[ii].SetCount(army[ii].BattleKilled()); - } - - a.commander = commander; -} - -void Army::army_t::Reset(bool soft) -{ - Clear(); - - if(commander) - { - const Monster mons1(commander->GetRace(), DWELLING_MONSTER1); - - if(soft) - { - const Monster mons2(commander->GetRace(), DWELLING_MONSTER2); - - switch(Rand::Get(1, 3)) - { - case 1: - JoinTroop(mons1, 3 * mons1.GetGrown()); - break; - case 2: - JoinTroop(mons2, static_cast(1.5 * mons2.GetGrown())); - break; - default: - JoinTroop(mons1, 2 * mons1.GetGrown()); - JoinTroop(mons2, mons2.GetGrown()); - break; - } - } - else - { - JoinTroop(mons1, 1); - } - } -} - -void Army::army_t::JoinStrongestFromArmy(army_t & army2) -{ - std::vector priority; - priority.reserve(ARMYMAXTROOPS * 2); - - std::vector::iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - - for(; it1 != it2; ++it1) - { - Troop & troop = *it1; - if(!troop.isValid()) continue; - - std::vector::iterator it = std::find_if(priority.begin(), priority.end(), std::bind2nd(std::mem_fun_ref(&Troop::HasMonster), troop())); - - if(it == priority.end()) - priority.push_back(troop); - else - (*it).SetCount((*it).GetCount() + troop.GetCount()); - - troop.Reset(); - } - - it1 = army2.army.begin(); - it2 = army2.army.end(); - - for(; it1 != it2; ++it1) - { - Troop & troop = *it1; - if(!troop.isValid()) continue; - - std::vector::iterator it = std::find_if(priority.begin(), priority.end(), std::bind2nd(std::mem_fun_ref(&Troop::HasMonster), troop())); - - if(it == priority.end()) - priority.push_back(troop); - else - (*it).SetCount((*it).GetCount() + troop.GetCount()); - - troop.Reset(); - } - - // sort: strongest - std::sort(priority.begin(), priority.end(), StrongestTroop); - - // weakest to army2 - while(Size() < priority.size()) - { - army2.JoinTroop(priority.back()); - priority.pop_back(); - } - - // save half weak of strongest to army2 - if(Size() > army2.army.size()) - { - Troop & last = priority.back(); - - army2.JoinTroop(last, last.GetCount() - last.GetCount() / 2); - JoinTroop(last, last.GetCount() / 2); - priority.pop_back(); - } - - // strongest to army - while(priority.size()) - { - JoinTroop(priority.back()); - priority.pop_back(); - } -} - -void Army::army_t::KeepOnlyWeakestTroops(army_t & army2) -{ - std::vector priority; - priority.reserve(ARMYMAXTROOPS * 2); - - std::vector::iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - - for(; it1 != it2; ++it1) - { - Troop & troop = *it1; - if(!troop.isValid()) continue; - - std::vector::iterator it = std::find_if(priority.begin(), priority.end(), std::bind2nd(std::mem_fun_ref(&Troop::HasMonster), troop())); - - if(it == priority.end()) - priority.push_back(troop); - else - (*it).SetCount((*it).GetCount() + troop.GetCount()); - - troop.Reset(); - } - - it1 = army2.army.begin(); - it2 = army2.army.end(); - - for(; it1 != it2; ++it1) - { - Troop & troop = *it1; - if(!troop.isValid()) continue; - - std::vector::iterator it = std::find_if(priority.begin(), priority.end(), std::bind2nd(std::mem_fun_ref(&Troop::HasMonster), troop())); - - if(it == priority.end()) - priority.push_back(troop); - else - (*it).SetCount((*it).GetCount() + troop.GetCount()); - - troop.Reset(); - } - - // sort: weakest - std::sort(priority.begin(), priority.end(), WeakestTroop); - - // strongest to army2 - while(1 < priority.size() && Size() > army2.GetCount()) - { - army2.JoinTroop(priority.back()); - priority.pop_back(); - } - - // weakest to army - while(priority.size()) - { - JoinTroop(priority.back()); - priority.pop_back(); - } -} - -void Army::army_t::UpgradeTroops(const Castle & castle) -{ - std::vector::iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - - for(; it1 != it2; ++it1) if((*it1).isValid()) - { - Troop & troop = *it1; - PaymentConditions::UpgradeMonster payment(troop()); - payment *= troop.GetCount(); - - if(castle.GetRace() == troop.GetRace() && - castle.isBuild(Monster::GetDwelling(Monster::Upgrade(troop))) && - payment <= world.GetKingdom(castle.GetColor()).GetFundsResource()) - { - world.GetKingdom(castle.GetColor()).OddFundsResource(payment); - troop.Upgrade(); - } - } -} - -void Army::army_t::Dump(void) const -{ - std::cout << "Army::Dump: " << Color::String(commander ? commander->GetColor() : color) << ": "; - - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - - for(; it1 != it2; ++it1) if((*it1).isValid()) std::cout << (*it1).GetName() << "(" << std::dec << (*it1).GetCount() << "), "; - - std::cout << std::endl; -} - -u16 Army::army_t::GetAttack(void) const -{ - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - u16 res = 0; - u8 count = 0; - - for(; it1 != it2; ++it1) if((*it1).isValid()){ res += (*it1).GetAttack(); ++count; } - - return count ? res / count : 0; -} - -u16 Army::army_t::GetDefense(void) const -{ - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - u16 res = 0; - u8 count = 0; - - for(; it1 != it2; ++it1) if((*it1).isValid()){ res += (*it1).GetDefense(); ++count; } - - return count ? res / count : 0; -} - -u32 Army::army_t::GetHitPoints(void) const -{ - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - u32 res = 0; - - for(; it1 != it2; ++it1) if((*it1).isValid()) res += (*it1).GetHitPoints(); - - return res; -} - -u32 Army::army_t::GetDamageMin(void) const -{ - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - u32 res = 0; - u8 count = 0; - - for(; it1 != it2; ++it1) if((*it1).isValid()){ res += (*it1).GetDamageMin(); ++count; } - - return count ? res / count : 0; -} - -u32 Army::army_t::GetDamageMax(void) const -{ - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - u32 res = 0; - u8 count = 0; - - for(; it1 != it2; ++it1) if((*it1).isValid()){ res += (*it1).GetDamageMax(); ++count; } - - return count ? res / count : 0; -} - -double Army::army_t::GetStrength(void) const -{ - return (GetDamageMin() + GetDamageMax()) / static_cast(2 * GetHitPoints()); -} - -bool Army::army_t::StrongerEnemyArmy(const army_t & army2) const -{ - const u16 a1 = GetAttack(); - const u16 d1 = GetDefense(); - double r1 = 0; - - const u16 a2 = army2.GetAttack(); - const u16 d2 = army2.GetDefense(); - double r2 = 0; - - if(a1 > d2) - r1 = 1 + 0.1 * static_cast(std::min(a1 - d2, 20)); - else - r1 = 1 + 0.05 * static_cast(std::min(d2 - a1, 14)); - - if(a2 > d1) - r2 = 1 + 0.1 * static_cast(std::min(a2 - d1, 20)); - else - r2 = 1 + 0.05 * static_cast(std::min(d1 - a2, 14)); - - r1 *= GetStrength(); - r2 *= army2.GetStrength(); - - if(IS_DEBUG(DBG_GAME, DBG_INFO)) - { - Dump(); - army2.Dump(); - VERBOSE("Army::StrongerEnemyArmy: " << "army1: " << r1 << ", army2: " << r2); - } - - return 0 == r2 || 1 <= (r1 / r2); -} - -void Army::army_t::SetCommander(HeroBase* c) -{ - commander = c; -} - -HeroBase* Army::army_t::GetCommander(void) -{ - return (!commander || (Skill::Primary::CAPTAIN == commander->GetType() && !commander->isValid()) ? NULL : commander); -} - -const HeroBase* Army::army_t::GetCommander(void) const -{ - return (!commander || (Skill::Primary::CAPTAIN == commander->GetType() && !commander->isValid()) ? NULL : commander); -} - -u32 Army::army_t::ActionToSirens(void) -{ - std::vector::iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - u32 res = 0; - - for(; it1 != it2; ++it1) if((*it1).isValid()) - { - const u32 kill = (*it1).GetCount() * 30 / 100; - - if(kill) - { - (*it1).SetCount((*it1).GetCount() - kill); - res += kill * static_cast(*it1).GetHitPoints(); - } - } - - return res; -} - -u8 Army::army_t::GetControl(void) const -{ - return commander ? commander->GetControl() : (color == Color::GRAY ? Game::AI : world.GetKingdom(color).Control()); -} - -u32 Army::army_t::GetSurrenderCost(void) const -{ - std::vector::const_iterator it1 = army.begin(); - std::vector::const_iterator it2 = army.end(); - - u32 res = 0; - - for(; it1 != it2; ++it1) if((*it1).isValid()) - { - // FIXME: orig: 3 titan = 7500 - PaymentConditions::BuyMonster payment((*it1).GetID()); - res += (payment.gold * (*it1).GetCount()); - } - - if(commander) - { - switch(commander->GetLevelSkill(Skill::Secondary::DIPLOMACY)) - { - // 40% - case Skill::Level::BASIC: res = res * 40 / 100; break; - // 30% - case Skill::Level::ADVANCED: res = res * 30 / 100; break; - // 20% - case Skill::Level::EXPERT: res = res * 20 / 100; break; - // 50% - default: res = res * 50 / 100; break; - } - - if(commander->HasArtifact(Artifact::STATESMAN_QUILL)) - res /= 5; - } - - // limit - if(res < 100) res = 100; - - return res; -} - -u8 Army::GetJoinSolution(const Heroes & hero, const Maps::Tiles & tile, u32 & join, s32 & cost) -{ - const Army::Troop troop(tile); - - if(! troop.isValid()) return 0xFF; - - const float ratios = troop.isValid() ? hero.GetArmy().GetHitPoints() / troop.GetHitPoints() : 0; - const bool check_free_stack = (hero.GetArmy().GetCount() < hero.GetArmy().Size() || hero.GetArmy().HasMonster(troop())); - const bool check_extra_condition = (!hero.HasArtifact(Artifact::HIDEOUS_MASK) && Morale::NORMAL <= hero.GetMorale()); - - // force join for campain and others... - const bool force_join = (5 == tile.GetQuantity4()); - - if(tile.GetQuantity4() && check_free_stack && ((check_extra_condition && ratios >= 2) || force_join)) - { - if(2 == tile.GetQuantity4() || force_join) - { - join = troop.GetCount(); - return 1; - } - else - if(hero.HasSecondarySkill(Skill::Secondary::DIPLOMACY)) - { - const Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - Resource::funds_t payment = PaymentConditions::BuyMonster(troop()); - cost = payment.gold * troop.GetCount(); - payment.Reset(); - payment.gold = cost; - - // skill diplomacy - const u32 to_join = Monster::GetCountFromHitPoints(troop(), troop.GetHitPoints() * hero.GetSecondaryValues(Skill::Secondary::DIPLOMACY) / 100); - - if(to_join && kingdom.AllowPayment(payment)) - { - join = to_join; - return 2; - } - } - } - else - if(ratios >= 5) - { - // ... surely flee before us - - if(hero.GetControl() == Game::AI) return Rand::Get(0, 10) < 5 ? 0 : 3; - - return 3; - } - - return 0; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/army/army.h b/project/jni/application/fheroes2/src/fheroes2/army/army.h deleted file mode 100644 index ca9a74c09..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/army/army.h +++ /dev/null @@ -1,169 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2ARMY_H -#define H2ARMY_H - -#include -#include -#include "bitmodes.h" -#include "heroes_base.h" -#include "army_troop.h" - -class Castle; -class Heroes; -namespace Maps { class Tiles; } -namespace Battle2 { class Stats; } -namespace Resource { struct funds_t; } - -namespace Army -{ - class BattleTroop; - - enum format_t - { - FORMAT_GROUPED = 0, - FORMAT_SPREAD = 1 - }; - - enum armysize_t - { - FEW = 1, - SEVERAL = 5, - PACK = 10, - LOTS = 20, - HORDE = 50, - THRONG = 100, - SWARM = 250, - ZOUNDS = 500, - LEGION = 1000 - }; - - const char* String(u32); - armysize_t GetSize(u32); - - // 0: fight, 1: free join, 2: join with gold, 3: flee - u8 GetJoinSolution(const Heroes &, const Maps::Tiles &, u32 &, s32 &); - - class army_t - { - public: - army_t(HeroBase* s = NULL); - army_t(const army_t &); - army_t & operator= (const army_t &); - - void FromGuardian(const Maps::Tiles &); - void UpgradeMonsters(const Monster &); - void UpgradeMonsters(const Monster::monster_t); - void Clear(void); - void Reset(bool = false); // reset: soft or hard - - void BattleExportKilled(army_t &) const; - void BattleSetModes(u32); - void BattleResetModes(u32); - Troop* BattleFindModes(u32); - const Troop*BattleFindModes(u32) const; - void BattleInit(void); - void BattleQuit(void); - void BattleNewTurn(void); - Troop & BattleNewTroop(Monster::monster_t, u32); - bool BattleArchersPresent(void) const; - bool BattleDragonsPresent(void) const; - u32 BattleKilled(void) const; - u8 BattleUndeadTroopCount(void) const; - u8 BattleLifeTroopCount(void) const; - const Battle2::Stats* BattleRandomTroop(void) const; - Battle2::Stats* BattleSlowestTroop(bool skipmove); - Battle2::Stats* BattleFastestTroop(bool skipmove); - - void DrawMons32Line(s16, s16, u16, u8 = 0, u8 = 0, bool = false) const; - - Troop & FirstValid(void); - Troop & At(u8); - Troop & GetWeakestTroop(void); - - const Troop & At(u8) const; - const Troop & GetSlowestTroop(void) const; - - Race::race_t GetRace(void) const; - Color::color_t GetColor(void) const; - u8 GetControl(void) const; - - void SetColor(Color::color_t); - - u8 Size(void) const; - u8 GetCount(void) const; - u8 GetUniqCount(void) const; - u32 GetCountMonsters(const Monster &) const; - u32 GetCountMonsters(const Monster::monster_t) const; - s8 GetMorale(void) const; - s8 GetLuck(void) const; - s8 GetMoraleModificator(std::string *strs) const; - s8 GetLuckModificator(std::string *strs) const; - u32 CalculateExperience(void) const; - u32 ActionToSirens(void); - u32 GetSurrenderCost(void) const; - - u16 GetAttack(void) const; - u16 GetDefense(void) const; - u32 GetHitPoints(void) const; - u32 GetDamageMin(void) const; - u32 GetDamageMax(void) const; - double GetStrength(void) const; - - bool isValid(void) const; - bool HasMonster(const Monster &) const; - bool HasMonster(const Monster::monster_t) const; - bool JoinTroop(const Troop & troop); - bool JoinTroop(const Monster::monster_t mon, const u32 count); - bool JoinTroop(const Monster & mon, const u32 count); - bool StrongerEnemyArmy(const army_t &) const; - bool AllTroopsIsRace(u8) const; - - void JoinStrongestFromArmy(army_t &); - void KeepOnlyWeakestTroops(army_t &); - void UpgradeTroops(const Castle &); - void ArrangeForBattle(void); - - void Dump(void) const; - - const HeroBase* GetCommander(void) const; - HeroBase* GetCommander(void); - void SetCommander(HeroBase*); - - void SetCombatFormat(format_t); - u8 GetCombatFormat(void) const; - - protected: - friend class Troop; - void Import(army_t &); - void Import(const std::vector &); - s8 GetTroopIndex(const Troop &) const; - - std::vector army; - HeroBase* commander; - u8 combat_format; - Color::color_t color; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/army/army_troop.cpp b/project/jni/application/fheroes2/src/fheroes2/army/army_troop.cpp deleted file mode 100644 index 3a8695905..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/army/army_troop.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "speed.h" -#include "spell.h" -#include "settings.h" -#include "luck.h" -#include "morale.h" -#include "army.h" -#include "maps_tiles.h" -#include "army_troop.h" -#include "battle_stats.h" - -Army::Troop::Troop(monster_t m, u32 c) : Monster(m), count(c), army(NULL), battle(NULL) -{ -} - -Army::Troop::Troop(const Troop & t) : Monster(t.id), count(t.count), army(t.army), battle(NULL) -{ -} - -Army::Troop::Troop(const Maps::Tiles & t) : army(NULL), battle(NULL) -{ - id = Monster::FromInt(t.GetQuantity3()); - count = t.GetCountMonster(); -} - -Army::Troop::~Troop() -{ - if(battle) BattleQuit(); -} - -Army::Troop & Army::Troop::operator= (const Troop & t) -{ - id = t.id; - count = t.count; - if(!army && t.army) army = t.army; - if(battle) BattleQuit(); - - return *this; -} - -bool Army::Troop::HasMonster(monster_t m) const -{ - return id == m; -} - -void Army::Troop::Set(const Monster & m, u32 c) -{ - Monster::Set(m); - count = c; -} - -void Army::Troop::Set(monster_t m, u32 c) -{ - Monster::Set(m); - count = c; -} - -void Army::Troop::SetMonster(const Monster & m) -{ - Monster::Set(m); -} - -void Army::Troop::SetMonster(monster_t m) -{ - Monster::Set(m); -} - -void Army::Troop::SetCount(u32 c) -{ - count = c; -} - -void Army::Troop::Reset(void) -{ - Monster::Set(Monster::UNKNOWN); - count = 0; -} - -const Battle2::Stats* Army::Troop::GetBattleStats(void) const -{ - if(!battle) DEBUG(DBG_GAME, DBG_INFO, "Army::Troop::GetBattleStats: return NULL"); - return battle; -} - -Battle2::Stats* Army::Troop::GetBattleStats(void) -{ - return battle; -} - -bool Army::Troop::BattleInit(void) -{ - if(isValid()) - { - if(battle) delete battle; - battle = new Battle2::Stats(*this); - return battle; - } - DEBUG(DBG_BATTLE, DBG_WARN, "Army::Troop::BattleInit: invalid troop"); - return false; -} - -void Army::Troop::BattleQuit(void) -{ - if(battle) - { - if(battle->dead > count) - { - VERBOSE("Army::Troop::BattleQuit: " << GetName() << ", dead(" << battle->dead << ") > current(" << count << ") incorrect!! FIXME!"); - count = 0; - } - else - count -= battle->dead; - - delete battle; - battle = NULL; - } -} - -void Army::Troop::BattleNewTurn(void) -{ - if(isValid() && battle) battle->NewTurn(); -} - -u32 Army::Troop::BattleKilled(void) const -{ - return battle ? battle->dead : 0; -} - -void Army::Troop::BattleSetModes(u32 f) -{ - if(battle) battle->SetModes(f); -} - -bool Army::Troop::BattleFindModes(u32 f) const -{ - return battle && battle->isValid() && battle->Modes(f); -} - -void Army::Troop::BattleResetModes(u32 f) -{ - if(battle) battle->ResetModes(f); -} - -bool Army::Troop::BattleIsDragons(void) const -{ - return battle && battle->isValid() && isDragons(); -} - -bool Army::Troop::BattleIsArchers(void) const -{ - return battle && battle->isValid() && battle->isArchers(); -} - -const Skill::Primary* Army::Troop::MasterSkill(void) const -{ - return army ? army->commander : NULL; -} - -Army::army_t* Army::Troop::GetArmy(void) -{ - return army; -} - -const Army::army_t* Army::Troop::GetArmy(void) const -{ - return army; -} - -const char* Army::Troop::GetName(u32 amount /* = 0 */) const -{ - u32 cmp = count; - if(amount) - cmp = amount; - return 1 < cmp ? Monster::GetMultiName() : Monster::GetName(); -} - -u32 Army::Troop::GetCount(void) const -{ - return count; -} - -u8 Army::Troop::GetAttack(void) const -{ - return battle ? battle->GetAttack() : Monster::GetAttack() + - (army && army->commander ? army->commander->GetAttack() : 0); -} - -u8 Army::Troop::GetDefense(void) const -{ - return battle ? battle->GetDefense() : Monster::GetDefense() + - (army && army->commander ? army->commander->GetDefense() : 0); -} - -Color::color_t Army::Troop::GetColor(void) const -{ - return army ? army->GetColor() : Color::GRAY; -} - -u32 Army::Troop::GetHitPoints(void) const -{ - return battle ? battle->GetHitPoints() : Monster::GetHitPoints() * count; -} - -u32 Army::Troop::GetDamageMin(void) const -{ - return Monster::GetDamageMin() * count; -} - -u32 Army::Troop::GetDamageMax(void) const -{ - return Monster::GetDamageMax() * count; -} - -u8 Army::Troop::GetSpeed(void) const -{ - return battle ? battle->GetSpeed() : Monster::GetSpeed(); -} - -s8 Army::Troop::GetMorale(void) const -{ - return isAffectedByMorale() && army ? army->GetMorale() : Morale::NORMAL; -} - -s8 Army::Troop::GetLuck(void) const -{ - return army ? army->GetLuck() : Luck::NORMAL; -} - -bool Army::Troop::isValid(void) const -{ - return battle ? battle->isValid() : Monster::UNKNOWN < id && count; -} - -bool Army::Troop::isAffectedByMorale(void) const -{ - return !(isUndead() || isElemental()); -} - -s8 Army::Troop::GetArmyIndex(void) const -{ - return army ? army->GetTroopIndex(*this) : -1; -} - -bool Army::isValidTroop(const Troop & troop) -{ - return troop.isValid(); -} - -bool Army::WeakestTroop(const Troop & t1, const Troop & t2) -{ - return t1.GetDamageMax() < t2.GetDamageMax(); -} - -bool Army::StrongestTroop(const Troop & t1, const Troop & t2) -{ - return t1.GetDamageMin() > t2.GetDamageMin(); -} - -bool Army::SlowestTroop(const Troop & t1, const Troop & t2) -{ - return t1.GetSpeed() < t2.GetSpeed(); -} - -void Army::SwapTroops(Troop & t1, Troop & t2) -{ - std::swap(t1, t2); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/army/army_troop.h b/project/jni/application/fheroes2/src/fheroes2/army/army_troop.h deleted file mode 100644 index 6d0da28ef..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/army/army_troop.h +++ /dev/null @@ -1,115 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2ARMYTROOP_H -#define H2ARMYTROOP_H - -#include -#include "bitmodes.h" -#include "monster.h" - -namespace Battle2 -{ - class Arena; - class Stats; -} - -namespace Maps { class Tiles; } - -namespace Army -{ - class army_t; - class Troop; - - bool isValidTroop(const Troop & troop); - bool WeakestTroop(const Troop & t1, const Troop & t2); - bool StrongestTroop(const Troop & t1, const Troop & t2); - bool SlowestTroop(const Troop & t1, const Troop & t2); - void SwapTroops(Troop & t1, Troop & t2); - - class Troop : public Monster - { - public: - Troop(monster_t m = Monster::UNKNOWN, u32 c = 0); - Troop(const Troop &); - Troop(const Maps::Tiles &); - ~Troop(); - - Troop & operator= (const Troop &); - - void Set(const Monster &, u32); - void Set(monster_t, u32); - void SetMonster(const Monster &); - void SetMonster(monster_t); - void SetCount(u32); - void Reset(void); - - const Skill::Primary* MasterSkill(void) const; - army_t* GetArmy(void); - const army_t* GetArmy(void) const; - const char* GetName(u32 amount = 0) const; - - u32 Count(void) const { return GetCount(); } - u32 GetCount(void) const; - - u8 GetAttack(void) const; - u8 GetDefense(void) const; - u32 GetHitPoints(void) const; - - Color::color_t GetColor(void) const; - u8 GetSpeed(void) const; - - const Battle2::Stats* GetBattleStats(void) const; - Battle2::Stats* GetBattleStats(void); - u32 GetDamageMin(void) const; - u32 GetDamageMax(void) const; - - s8 GetMorale(void) const; - s8 GetLuck(void) const; - - bool isValid(void) const; - bool isAffectedByMorale(void) const; - bool HasMonster(monster_t) const; - - bool BattleInit(void); - void BattleQuit(void); - void BattleNewTurn(void); - void BattleSetModes(u32); - void BattleResetModes(u32); - bool BattleFindModes(u32) const; - bool BattleIsDragons(void) const; - bool BattleIsArchers(void) const; - u32 BattleKilled(void) const; - s8 GetArmyIndex(void) const; - - protected: - friend class army_t; - friend class Battle2::Stats; - friend class Battle2::Arena; - - u32 count; - army_t* army; - Battle2::Stats* battle; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle2.h b/project/jni/application/fheroes2/src/fheroes2/battle2/battle2.h deleted file mode 100644 index 38e13f206..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle2.h +++ /dev/null @@ -1,149 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BATTLE2_H -#define H2BATTLE2_H - -#include -#include -#include "network.h" -#include "icn.h" -#include "m82.h" -#include "gamedefs.h" - -#ifdef WITH_NET -#include "localclient.h" -#endif - -namespace Army { class army_t; } -namespace Battle2 -{ - struct Stats; - - enum { RESULT_LOSS = 0x01, RESULT_RETREAT = 0x02, RESULT_SURRENDER = 0x04, RESULT_WINS = 0x80 }; - - struct Result - { - Result() : army1(0), army2(0), exp1(0), exp2(0) {} - - bool AttackerWins(void) const; - bool DefenderWins(void) const; - u8 AttackerResult(void) const; - u8 DefenderResult(void) const; - u32 GetExperienceAttacker(void) const; - u32 GetExperienceDefender(void) const; - - u8 army1; - u8 army2; - u32 exp1; - u32 exp2; - }; - - Result Loader(Army::army_t &, Army::army_t &, s32); - void UpdateMonsterInfoAnimation(const std::string &); - void UpdateMonsterAttributes(const std::string &); - - enum direction_t - { - UNKNOWN = 0xFF, - TOP_LEFT = 0x01, - TOP_RIGHT = 0x02, - RIGHT = 0x04, - BOTTOM_RIGHT = 0x08, - BOTTOM_LEFT = 0x10, - LEFT = 0x20, - CENTER = 0x40 - }; - - inline direction_t & operator++ (direction_t & d){ return d = ( CENTER == d ? TOP_LEFT : direction_t(d << 1)); } - inline direction_t & operator-- (direction_t & d){ return d = ( TOP_LEFT == d ? CENTER : direction_t(d >> 1)); } - - enum tower_t { TWR_LEFT, TWR_CENTER, TWR_RIGHT }; - - enum catapult_t { CAT_WALL1 = 1, CAT_WALL2 = 2, CAT_WALL3 = 3, CAT_WALL4 = 4, CAT_TOWER1 = 5, CAT_TOWER2 = 6, CAT_BRIDGE = 7, CAT_TOWER3 = 8, CAT_MISS = 9 }; - - enum animstate_t - { - AS_NONE, - AS_IDLE, - AS_MOVE, - AS_FLY1, - AS_FLY2, - AS_FLY3, - AS_SHOT0, - AS_SHOT1, - AS_SHOT2, - AS_SHOT3, - AS_ATTK0, - AS_ATTK1, - AS_ATTK2, - AS_ATTK3, - AS_WNCE, - AS_KILL - }; - - struct animframe_t - { - u8 start; - u8 count; - }; - - struct MonsterInfo - { - ICN::icn_t icn_file; - animframe_t frm_idle; - animframe_t frm_move; - animframe_t frm_fly1; - animframe_t frm_fly2; - animframe_t frm_fly3; - animframe_t frm_shot0; - animframe_t frm_shot1; - animframe_t frm_shot2; - animframe_t frm_shot3; - animframe_t frm_attk0; - animframe_t frm_attk1; - animframe_t frm_attk2; - animframe_t frm_attk3; - animframe_t frm_wnce; - animframe_t frm_kill; - M82::m82_t m82_attk; - M82::m82_t m82_kill; - M82::m82_t m82_move; - M82::m82_t m82_wnce; - }; - - struct TargetInfo - { - TargetInfo() : defender(NULL), damage(0), killed(0), resist(false) {}; - - Stats* defender; - u32 damage; - u32 killed; - bool resist; - - bool isFinishAnimFrame(void) const; - }; - - typedef QueueMessage Action; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_action.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_action.cpp deleted file mode 100644 index f53e0b6ef..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_action.cpp +++ /dev/null @@ -1,1013 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "settings.h" -#include "world.h" -#include "kingdom.h" -#include "battle_cell.h" -#include "battle_stats.h" -#include "battle_arena.h" -#include "battle_tower.h" -#include "battle_bridge.h" -#include "battle_catapult.h" -#include "battle_interface.h" -#include "remoteclient.h" - -void Battle2::Actions::AddedSurrenderAction(void) -{ - Action action; - action.SetID(MSG_BATTLE_SURRENDER); - - push_back(action); -} - -void Battle2::Actions::AddedRetreatAction(void) -{ - Action action; - action.SetID(MSG_BATTLE_RETREAT); - - push_back(action); -} - -void Battle2::Actions::AddedCastAction(u8 spell, u16 dst) -{ - Action action; - action.SetID(MSG_BATTLE_CAST); - action.Push(spell); - action.Push(dst); - - push_back(action); -} - -void Battle2::Actions::AddedCastTeleportAction(u16 src, u16 dst) -{ - Action action; - action.SetID(MSG_BATTLE_CAST); - action.Push(static_cast(Spell::TELEPORT)); - action.Push(src); - action.Push(dst); - - push_back(action); -} - -void Battle2::Actions::AddedEndAction(const Stats & b) -{ - Action action; - action.SetID(MSG_BATTLE_END_TURN); - action.Push(b.id); - - push_back(action); -} - -void Battle2::Actions::AddedSkipAction(const Stats & b, bool hard) -{ - Action action; - action.SetID(MSG_BATTLE_SKIP); - action.Push(b.id); - action.Push(static_cast(hard)); - - push_back(action); -} - -void Battle2::Actions::AddedMoveAction(const Stats & b, u16 dst) -{ - Action action; - action.SetID(MSG_BATTLE_MOVE); - action.Push(b.id); - action.Push(dst); - action.Push(static_cast(0)); - - push_back(action); -} - -void Battle2::Actions::AddedMoveAction(const Stats & b, const std::vector & path) -{ - Action action; - action.SetID(MSG_BATTLE_MOVE); - action.Push(b.id); - action.Push(path.back()); - action.Push(static_cast(path.size())); - for(u16 ii = 0; ii < path.size(); ++ii) action.Push(path[ii]); - - push_back(action); -} - -void Battle2::Actions::AddedAttackAction(const Stats & a, const Stats & d) -{ - Action action; - action.SetID(MSG_BATTLE_ATTACK); - action.Push(a.id); - action.Push(d.id); - - push_back(action); -} - -void Battle2::Actions::AddedMoraleAction(const Stats & b, u8 state) -{ - Action action; - action.SetID(MSG_BATTLE_MORALE); - action.Push(b.id); - action.Push(state); - - push_back(action); -} - -void Battle2::Arena::BattleProcess(Stats & attacker, Stats & defender) -{ - std::vector targets; - - GetTargetsForDamage(attacker, defender, targets); - if(interface) interface->RedrawActionAttackPart1(attacker, defender, targets); - - TargetsApplyDamage(attacker, defender, targets); - if(interface) interface->RedrawActionAttackPart2(attacker, targets); - - const u8 spell = attacker.GetSpellMagic(); - - // magic attack - if(defender.isValid() && Spell::NONE != spell) - { - const std::string name(attacker.GetName()); - - GetTargetsForSpells(attacker.GetCommander(), spell, defender.GetPosition(), targets); - if(interface) interface->RedrawActionSpellCastPart1(spell, defender.GetPosition(), name, targets); - - // magic attack not depends from hero - TargetsApplySpell(NULL, spell, targets); - if(interface) interface->RedrawActionSpellCastPart2(spell, targets); - if(interface) interface->RedrawActionMonsterSpellCastStatus(attacker, targets.front()); - -#ifdef WITH_NET - if(Game::REMOTE == army1.GetControl()) FH2RemoteClient::SendBattleSpell(army1.GetColor(), spell, attacker.GetColor(), targets); - if(Game::REMOTE == army2.GetControl()) FH2RemoteClient::SendBattleSpell(army2.GetColor(), spell, attacker.GetColor(), targets); -#endif - } - - attacker.PostAttackAction(defender); -} - -void Battle2::Arena::ApplyAction(Action & action) -{ - switch(action.GetID()) - { - case MSG_BATTLE_CAST: ApplyActionSpellCast(action); break; - case MSG_BATTLE_ATTACK: ApplyActionAttack(action); break; - case MSG_BATTLE_MOVE: ApplyActionMove(action); break; - case MSG_BATTLE_SKIP: ApplyActionSkip(action); break; - case MSG_BATTLE_END_TURN: ApplyActionEnd(action); break; - case MSG_BATTLE_MORALE: ApplyActionMorale(action); break; - - case MSG_BATTLE_TOWER: ApplyActionTower(action); break; - case MSG_BATTLE_CATAPULT: ApplyActionCatapult(action); break; - - case MSG_BATTLE_RETREAT: ApplyActionRetreat(action); break; - case MSG_BATTLE_SURRENDER: ApplyActionSurrender(action); break; - - default: break; - } - -#ifdef WITH_NET - switch(action.GetID()) - { - case MSG_BATTLE_MOVE: - case MSG_BATTLE_SKIP: - case MSG_BATTLE_END_TURN: - case MSG_BATTLE_MORALE: - case MSG_BATTLE_TOWER: - case MSG_BATTLE_CATAPULT: - if(Network::isRemoteClient()) - { - if(Game::REMOTE == army1.GetControl()) FH2RemoteClient::SendBattleAction(army1.GetColor(), action); - if(Game::REMOTE == army2.GetControl()) FH2RemoteClient::SendBattleAction(army2.GetColor(), action); - } - break; - - default: break; - } -#endif -} - -void Battle2::Arena::ApplyActionSpellCast(Action & action) -{ - u8 byte8; - u16 dst; - - action.Pop(byte8); - action.Pop(dst); - - const Spell::spell_t spell = Spell::FromInt(byte8); - if(current_commander && !current_commander->Modes(Heroes::SPELLCASTED) && - current_commander->HaveSpell(spell) && - Spell::isCombat(spell) && current_commander->HaveSpellPoints(Spell::CostManaPoints(spell, current_commander))) - { - const u8 color = current_commander->GetColor(); - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionSpellCast: " << \ - current_commander->GetName() << ", color: " << Color::String(color) << ", spell: " << Spell::GetName(spell) << ", dst: " << dst); - - // uniq spells action - switch(spell) - { - case Spell::TELEPORT: - { - u16 src = dst; - action.Pop(dst); - SpellActionTeleport(src, dst); -#ifdef WITH_NET - if(Game::REMOTE == army1.GetControl()) FH2RemoteClient::SendBattleTeleportSpell(army1.GetColor(), src, dst); - if(Game::REMOTE == army2.GetControl()) FH2RemoteClient::SendBattleTeleportSpell(army2.GetColor(), src, dst); -#endif - break; - } - - case Spell::EARTHQUAKE: - SpellActionEarthQuake(); - break; - - default: - { - std::vector targets; - - GetTargetsForSpells(current_commander, spell, dst, targets); - if(interface) interface->RedrawActionSpellCastPart1(spell, dst, current_commander->GetName(), targets); - - TargetsApplySpell(current_commander, spell, targets); - if(interface) interface->RedrawActionSpellCastPart2(spell, targets); -#ifdef WITH_NET - if(Game::REMOTE == army1.GetControl()) FH2RemoteClient::SendBattleSpell(army1.GetColor(), spell, current_commander->GetColor(), targets); - if(Game::REMOTE == army2.GetControl()) FH2RemoteClient::SendBattleSpell(army2.GetColor(), spell, current_commander->GetColor(), targets); -#endif - } - break; - } - - current_commander->SetModes(Heroes::SPELLCASTED); - current_commander->TakeSpellPoints(Spell::CostManaPoints(spell, current_commander)); - } - else - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionSpellCast: " << "incorrect param: "); -} - -void Battle2::Arena::ApplyActionAttack(Action & action) -{ - u16 id1, id2; - - action.Pop(id1); - action.Pop(id2); - - Battle2::Stats* b1 = GetTroopID(id1); - Battle2::Stats* b2 = GetTroopID(id2); - - if(b1 && b1->isValid() && - b2 && b2->isValid() && - (b1->GetColor() != b2->GetColor() || b2->Modes(SP_HYPNOTIZE))) - { - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionAttack: " << \ - b1->GetName() << "(color: " << Color::String(b1->GetColor()) << ", pos: " << b1->position << ") to " << \ - b2->GetName() << "(color: " << Color::String(b2->GetColor()) << ", pos: " << b2->position << ")"); - - const bool handfighting = Stats::isHandFighting(*b1, *b2); - // check position - if(b1->isArchers() || handfighting) - { - b1->UpdateDirection(*b2); - b2->UpdateDirection(*b1); - - // attack - BattleProcess(*b1, *b2); - - if(b2->isValid()) - { - // defense answer - if(handfighting && !b1->isHideAttack() && b2->AllowResponse()) - { - BattleProcess(*b2, *b1); - b2->SetResponse(); - } - - if(b2->Modes(SP_BLIND)) b2->ResetBlind(); - - // twice attack - if(b1->isValid() && b1->isTwiceAttack() && !b1->Modes(IS_PARALYZE_MAGIC)) - BattleProcess(*b1, *b2); - } - } - else - { - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionAttack: " << "incorrect position: " << \ - b1->GetName() << "(color: " << Color::String(b1->GetColor()) << ", pos: " << b1->position << ") to " << \ - b2->GetName() << "(color: " << Color::String(b2->GetColor()) << ", pos: " << b2->position << ")"); - } - - if(!Settings::Get().ExtBattleTroopDirection()) - { - b1->UpdateDirection(); - b2->UpdateDirection(); - } - } - else - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionAttack: " << "incorrect param: " << "id1: " << id1 << ", id2: " << id2); -} - -void Battle2::Arena::ApplyActionMove(Action & action) -{ - u16 id, dst, size; - - action.Pop(id); - action.Pop(dst); - action.Pop(size); - - Battle2::Stats* b = GetTroopID(id); - Cell* cell = GetCell(dst); - - if(b && b->isValid() && - cell && cell->isPassable(*b, false)) - { - b->UpdateDirection(*cell); - - // change pos to tail - if(b->isWide() && !cell->isPassable(*b, true)) - { - dst = Board::GetIndexDirection(dst, b->isReflect() ? LEFT : RIGHT); - cell = GetCell(dst); - } - - // force check fly - if(b->troop.isFly()) - { - if(interface) interface->RedrawActionFly(*b, dst); - } - else - { - std::vector path; - - // check path - if(b->GetControl() != Game::AI || 0 == size) - { - GetPath(*b, dst, path); - } - else - { - path.resize(size, 0); - for(u16 ii = 0; ii < size; ++ii) action.Pop(path[ii]); - } - - if(path.empty()) - { - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionMove: " << "ERROR empty path, " << \ - b->GetName() << "(color: " << Color::String(b->GetColor()) << ", pos: " << b->GetPosition() << ") to " << "dst: " << dst); - return; - } - - if(interface) interface->RedrawActionMove(*b, path); - else - if(bridge) - { - if(!bridge->isDown() && bridge->NeedDown(*b, dst)) - bridge->SetDown(true); - else - if(bridge->isDown() && bridge->AllowUp()) - bridge->SetDown(false); - } - } - - b->position = dst; - b->UpdateDirection(); - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionMove: " << \ - b->GetName() << "(color: " << Color::String(b->GetColor()) << ", pos: " << b->GetPosition() << ") to " << "dst: " << dst); - } - else - { - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionMove: " << "incorrect param: " << "id: " << id << ", dst: " << dst); - } -} - -void Battle2::Arena::ApplyActionSkip(Action & action) -{ - u16 id; - u8 hard; - action.Pop(id); - action.Pop(hard); - - Battle2::Stats* battle = GetTroopID(id); - if(battle && battle->isValid() && !battle->Modes(TR_MOVED)) - { - if(hard) - { - battle->SetModes(TR_HARDSKIP); - battle->SetModes(TR_SKIPMOVE); - battle->SetModes(TR_MOVED); - } - else - battle->SetModes(battle->Modes(TR_SKIPMOVE) ? TR_MOVED : TR_SKIPMOVE); - - if(interface) interface->RedrawActionSkipStatus(*battle); - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionSkip: " << \ - battle->GetName() << "(color: " << Color::String(battle->GetColor()) << ", pos: " << battle->position << ")"); - } - else - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionSkip: " << "incorrect param: " << "id: " << id); -} - -void Battle2::Arena::ApplyActionEnd(Action & action) -{ - u16 id; - - action.Pop(id); - - Battle2::Stats* battle = GetTroopID(id); - - if(battle && !battle->Modes(TR_MOVED)) - { - battle->SetModes(TR_MOVED); - - if(battle->Modes(TR_SKIPMOVE) && interface) interface->RedrawActionSkipStatus(*battle); - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionEnd: " << \ - battle->GetName() << "(color: " << Color::String(battle->GetColor()) << ", pos: " << battle->position << ")"); - } - else - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionEnd: " << "incorrect param: " << "id: " << id); -} - -void Battle2::Arena::ApplyActionMorale(Action & action) -{ - u16 id; - u8 morale; - - action.Pop(id); - action.Pop(morale); - - Battle2::Stats* b = GetTroopID(id); - - if(b && b->isValid()) - { - // good morale - if(morale && b->Modes(TR_MOVED) && b->Modes(MORALE_GOOD)) - { - b->ResetModes(TR_MOVED); - b->ResetModes(MORALE_GOOD); - } - // bad morale - else - if(!morale && !b->Modes(TR_MOVED) && b->Modes(MORALE_BAD)) - { - b->SetModes(TR_MOVED); - b->ResetModes(MORALE_BAD); - } - - if(interface) interface->RedrawActionMorale(*b, morale); - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionMorale: " << (morale ? "good" : "bad")); - } - else - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionMorale: " << "incorrect param: " << "id: " << id); -} - -void Battle2::Arena::ApplyActionRetreat(Action & action) -{ - if(!result_game || !current_commander) return; - - const u8 color = current_commander->GetColor(); - - if(CanRetreatOpponent(color)) - { - if(army1.GetColor() == color && result_game) - { - result_game->army1 = RESULT_RETREAT; - } - else - if(army2.GetColor() == color && result_game) - { - result_game->army2 = RESULT_RETREAT; - } - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionRetreat: " << "color: " << Color::String(color)); - } - else - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionRetreat: " << "incorrect param: "); -} - -void Battle2::Arena::ApplyActionSurrender(Action & action) -{ - if(!result_game || !current_commander) return; - - const u8 color = current_commander->GetColor(); - - if(CanSurrenderOpponent(color)) - { - Resource::funds_t cost; - - if(army1.GetColor() == color) - cost.gold = army1.GetSurrenderCost(); - else - if(army2.GetColor() == color) - cost.gold = army2.GetSurrenderCost(); - - if(world.GetKingdom(color).AllowPayment(cost)) - { - if(army1.GetColor() == color) - { - result_game->army1 = RESULT_SURRENDER; - world.GetKingdom(color).OddFundsResource(cost); - world.GetKingdom(army2.GetColor()).AddFundsResource(cost); - } - else - if(army2.GetColor() == color) - { - result_game->army2 = RESULT_SURRENDER; - world.GetKingdom(color).OddFundsResource(cost); - world.GetKingdom(army1.GetColor()).AddFundsResource(cost); - } - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionSurrender: " << "color: " << Color::String(color)); - } - } - else - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionSurrender: " << "incorrect param: "); -} - -void Battle2::Arena::TargetsApplyDamage(Stats & attacker, Stats & defender, std::vector & targets) -{ - std::vector::iterator it = targets.begin(); - - for(; it != targets.end(); ++it) - { - TargetInfo & target = *it; - if(target.defender) target.killed = target.defender->ApplyDamage(attacker, target.damage); - } -} - -void Battle2::Arena::GetTargetsForDamage(Stats & attacker, Stats & defender, std::vector & targets) -{ - if(targets.size()) targets.clear(); - targets.reserve(8); - - Stats* enemy = NULL; - Cell* cell = NULL; - TargetInfo res; - - // first target - res.defender = &defender; - res.damage = attacker.GetDamage(defender); - targets.push_back(res); - - // long distance attack - if(attacker.isDoubleCellAttack()) - { - const direction_t dir = Board::GetDirection(attacker.position, defender.position); - if((!defender.isWide() || 0 == ((RIGHT | LEFT) & dir))) - { - if(NULL != (cell = GetCell(defender.position, dir)) && - NULL != (enemy = GetTroopBoard(cell->index)) && enemy != &defender) - { - res.defender = enemy; - res.damage = attacker.GetDamage(*enemy); - targets.push_back(res); - } - } - } - else - // around hydra - if(attacker.troop() == Monster::HYDRA) - { - std::vector v; - v.reserve(8); - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - if(NULL != (cell = GetCell(attacker.position, dir)) && - NULL != (enemy = GetTroopBoard(cell->index)) && enemy != &defender && enemy->GetColor() != attacker.GetColor()) - v.push_back(enemy); - - if(NULL != (cell = GetCell(attacker.GetTailIndex(), dir)) && - NULL != (enemy = GetTroopBoard(cell->index)) && enemy != &defender && enemy->GetColor() != attacker.GetColor()) - v.push_back(enemy); - } - std::unique(v.begin(), v.end()); - for(u8 ii = 0; ii < v.size(); ++ii) - { - enemy = v[ii]; - res.defender = enemy; - res.damage = attacker.GetDamage(*enemy); - targets.push_back(res); - } - } - else - // lich cloud damages - if((attacker.troop() == Monster::LICH || - attacker.troop() == Monster::POWER_LICH) && !attacker.isHandFighting()) - { - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - if(NULL != (cell = GetCell(defender.position, dir)) && - NULL != (enemy = GetTroopBoard(cell->index)) && enemy != &defender) - { - res.defender = enemy; - res.damage = attacker.GetDamage(*enemy); - targets.push_back(res); - } - } - } - -#ifdef WITH_NET - if(Game::REMOTE == army1.GetControl()) FH2RemoteClient::SendBattleAttack(army1.GetColor(), attacker.GetID(), targets); - if(Game::REMOTE == army2.GetControl()) FH2RemoteClient::SendBattleAttack(army2.GetColor(), attacker.GetID(), targets); -#endif -} - -void Battle2::Arena::TargetsApplySpell(const HeroBase* hero, const u8 spell, std::vector & targets) -{ - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::TargetsApplySpell: " << "targets: " << targets.size()); - - if(Spell::isSummon(spell)) - { - SpellActionSummonElemental(hero, spell); - } - else - { - std::vector::iterator it = targets.begin(); - - for(; it != targets.end(); ++it) - { - TargetInfo & target = *it; - if(target.defender) target.defender->ApplySpell(spell, hero, target); - } - } -} - -void Battle2::Arena::GetTargetsForSpells(const HeroBase* hero, const u8 spell, const u16 dst, std::vector & targets) -{ - if(targets.size()) targets.clear(); - targets.reserve(8); - - TargetInfo res; - Stats* target = GetTroopBoard(dst); - - // from spells - switch(spell) - { - case Spell::CHAINLIGHTNING: - case Spell::COLDRING: - // skip center - target = NULL; - break; - - default: break; - } - - // first target - if(target && target->AllowApplySpell(spell, hero)) - { - res.defender = target; - targets.push_back(res); - } - - // resurrect spell? get target from graveyard - if(NULL == target && isAllowResurrectFromGraveyard(spell, dst)) - { - target = GetTroopID(graveyard.GetLastTroopIDFromCell(dst)); - - if(target && target->AllowApplySpell(spell, hero)) - { - res.defender = target; - targets.push_back(res); - } - } - else - // check other spells - switch(spell) - { - case Spell::CHAINLIGHTNING: - { - std::vector trgts; - std::vector reslt; - std::vector::iterator it1, it2; - u16 index = dst; - trgts.push_back(index); - - // find targets - for(u8 ii = 0; ii < 3; ++ii) - { - GetNearestTroops(index, reslt, &trgts); - if(reslt.empty()) break; - index = reslt.size() > 1 ? *Rand::Get(reslt) : reslt.front(); - trgts.push_back(index); - reslt.clear(); - } - - // save targets - it1 = trgts.begin(); - it2 = trgts.end(); - for(; it1 != it2; ++it1) - { - Stats* target = GetTroopBoard(*it1); - if(target) - { - res.defender = target; - // store temp priority for calculate damage - res.damage = std::distance(trgts.begin(), it1); - targets.push_back(res); - } - } - } - break; - - // check abroads - case Spell::FIREBALL: - case Spell::METEORSHOWER: - case Spell::COLDRING: - case Spell::FIREBLAST: - { - std::vector positions; - u8 radius = (Spell::FIREBLAST == spell ? 2 : 1); - board.GetAbroadPositions(dst, radius, positions); - std::vector::const_iterator it1 = positions.begin(); - std::vector::const_iterator it2 = positions.end(); - for(; it1 != it2; ++it1) - { - Stats* target = GetTroopBoard(*it1); - if(target && target->AllowApplySpell(spell, hero)) - { - res.defender = target; - targets.push_back(res); - } - } - } - break; - - // check all troops - case Spell::DEATHRIPPLE: - case Spell::DEATHWAVE: - case Spell::ELEMENTALSTORM: - case Spell::HOLYWORD: - case Spell::HOLYSHOUT: - case Spell::ARMAGEDDON: - case Spell::MASSBLESS: - case Spell::MASSCURE: - case Spell::MASSCURSE: - case Spell::MASSDISPEL: - case Spell::MASSHASTE: - case Spell::MASSSHIELD: - case Spell::MASSSLOW: - { - Board::const_iterator it1 = board.begin(); - Board::const_iterator it2 = board.end(); - for(; it1 != it2; ++it1) - { - Stats* target = GetTroopBoard((*it1).index); - if(target && target->GetPosition() != dst && target->AllowApplySpell(spell, hero)) - { - res.defender = target; - targets.push_back(res); - } - } - } - break; - - default: break; - } - - // remove resistent magic troop - std::vector::iterator it = targets.begin(); - while(it != targets.end()) - { - const u8 resist = (*it).defender->GetMagicResist(spell, hero ? hero->GetPower() : 0); - - if(0 < resist && 100 > resist && resist >= Rand::Get(1, 100)) - { - if(interface) interface->RedrawActionResistSpell(*(*it).defender); - - // erase(it) - if(it + 1 != targets.end()) std::swap(*it, targets.back()); - targets.pop_back(); - } - else ++it; - } -} - -void Battle2::Arena::ApplyActionTower(Action & action) -{ - u8 type; - u16 id; - - action.Pop(type); - action.Pop(id); - - Battle2::Stats* b2 = GetTroopID(id); - Tower* tower = GetTower(type); - - if(b2 && b2->isValid() && tower) - { - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionTower: " << "tower: " << static_cast(type) << \ - ", attack pos: " << b2->position << ", troop: " << b2->GetName()); - - Stats* b1 = tower->GetBattleStats(); - TargetInfo target; - target.defender = b2; - target.damage = b1->GetDamage(*b2); - - if(interface) interface->RedrawActionTowerPart1(*tower, *b2); - target.killed = b2->ApplyDamage(*b1, target.damage); - if(interface) interface->RedrawActionTowerPart2(*tower, target); - } - else - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionTower: " << "incorrect param: " << "tower: " << static_cast(type) << ", id: " << id); -} - -void Battle2::Arena::ApplyActionCatapult(Action & action) -{ - if(catapult) - { - u8 shots, target, damage; - - action.Pop(shots); - - while(shots--) - { - action.Pop(target); - action.Pop(damage); - - if(target) - { - if(interface) interface->RedrawActionCatapult(target); - SetCastleTargetValue(target, GetCastleTargetValue(target) - damage); - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::ApplyActionCatapult: " << "target: " << static_cast(target)); - } - } - } - else - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::ApplyActionCatapult: " << "incorrect param: "); -} - -void Battle2::Arena::SpellActionSummonElemental(const HeroBase* hero, u8 type) -{ - const u16 pos = GetFreePositionNearHero(hero->GetColor()); - Army::army_t* army = GetArmy(hero->GetColor()); - - if(army && 0 != pos) - { - const Army::Troop* other = army->BattleFindModes(CAP_SUMMONELEM); - bool affect = true; - if(other) switch(type) - { - case Spell::SUMMONEELEMENT: if(other->GetID() != Monster::EARTH_ELEMENT) affect = false; break; - case Spell::SUMMONAELEMENT: if(other->GetID() != Monster::AIR_ELEMENT) affect = false; break; - case Spell::SUMMONFELEMENT: if(other->GetID() != Monster::FIRE_ELEMENT) affect = false; break; - case Spell::SUMMONWELEMENT: if(other->GetID() != Monster::WATER_ELEMENT) affect = false; break; - default: break; - } - - if(!affect) - { - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::SpellActionSummonElemental: " << "incorrect elemental"); - return; - } - - Monster::monster_t mons = Monster::UNKNOWN; - switch(type) - { - case Spell::SUMMONEELEMENT: mons = Monster::EARTH_ELEMENT; break; - case Spell::SUMMONAELEMENT: mons = Monster::AIR_ELEMENT; break; - case Spell::SUMMONFELEMENT: mons = Monster::FIRE_ELEMENT; break; - case Spell::SUMMONWELEMENT: mons = Monster::WATER_ELEMENT; break; - default: break; - } - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::SpellActionSummonElemental: " << Monster::GetName(mons) << ", position: " << pos); - u16 count = Spell::GetExtraValue(Spell::FromInt(type)) * hero->GetPower(); - if(hero->HasArtifact(Artifact::BOOK_ELEMENTS)) count *= 2; - - Stats* elem = army->BattleNewTroop(mons, count).GetBattleStats(); - elem->position = pos; - elem->arena = this; - elem->SetReflection(hero == army2.GetCommander()); - elem->SetModes(CAP_SUMMONELEM); - if(interface) - { - elem->InitContours(); - interface->RedrawActionSummonElementalSpell(*elem); - } - } - else - { - if(interface) interface->SetStatus(_("Summon Elemental spell failed!"), true); - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::SpellActionSummonElemental: " << "incorrect param"); - } -} - -void Battle2::Arena::SpellActionTeleport(u16 src, u16 dst) -{ - Stats* b = GetTroopBoard(src); - Cell* cell = GetCell(dst); - - if(b) - { - if(b->isWide() && !cell->isPassable(*b, true)) - { - dst = Board::GetIndexDirection(dst, b->isReflect() ? LEFT : RIGHT); - } - if(interface) interface->RedrawActionTeleportSpell(*b, dst); - b->position = dst; - b->UpdateDirection(); - } -} - -void Battle2::Arena::SpellActionEarthQuake(void) -{ - std::vector targets; - - // check walls - if(0 != board[8].object) targets.push_back(CAT_WALL1); - if(0 != board[29].object) targets.push_back(CAT_WALL2); - if(0 != board[73].object) targets.push_back(CAT_WALL3); - if(0 != board[96].object) targets.push_back(CAT_WALL4); - - // check right/left towers - if(towers[0] && towers[0]->isValid()) targets.push_back(CAT_TOWER1); - if(towers[2] && towers[2]->isValid()) targets.push_back(CAT_TOWER2); - - if(interface) interface->RedrawActionEarthQuakeSpell(targets); - - // FIXME: Arena::SpellActionEarthQuake: check hero spell power - - // apply random damage - if(0 != board[8].object) board[8].object = Rand::Get(board[8].object); - if(0 != board[29].object) board[29].object = Rand::Get(board[29].object); - if(0 != board[73].object) board[73].object = Rand::Get(board[73].object); - if(0 != board[96].object) board[96].object = Rand::Get(board[96].object); - - if(towers[0] && towers[0]->isValid() && Rand::Get(1)) towers[0]->SetDestroy(); - if(towers[2] && towers[2]->isValid() && Rand::Get(1)) towers[2]->SetDestroy(); - -#ifdef WITH_NET - if(Game::REMOTE == army1.GetControl()) FH2RemoteClient::SendBattleEarthQuakeSpell(army1.GetColor(), targets); - if(Game::REMOTE == army2.GetControl()) FH2RemoteClient::SendBattleEarthQuakeSpell(army2.GetColor(), targets); - - if(Game::REMOTE == army1.GetControl()) FH2RemoteClient::SendBattleBoard(army1.GetColor(), *this); - if(Game::REMOTE == army2.GetControl()) FH2RemoteClient::SendBattleBoard(army2.GetColor(), *this); -#endif -} - -void Battle2::Arena::SpellActionMirrorImage(Stats & b) -{ - std::vector v; - board.GetAbroadPositions(b.position, 4, v); - - std::vector::const_iterator it1 = v.begin(); - std::vector::const_iterator it2 = v.end(); - - for(; it1 != it2; ++it1) - { - const Cell* cell = GetCell(*it1); - if(cell && cell->isPassable(b, true)) - { - if(b.isWide() && (b.position + 1 == *it1)) - continue; - else - break; - } - } - - if(it1 != v.end()) - { - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::SpellCreateMirrorImage: " << "set position: " << *it1); - if(interface) interface->RedrawActionMirrorImageSpell(b, *it1); - - Stats* image = b.GetArmy()->BattleNewTroop(b.troop(), b.count).GetBattleStats(); - - b.mirror = image; - image->position = *it1; - image->arena = this; - image->mirror = &b; - image->SetReflection(b.reflect); - image->SetModes(CAP_MIRRORIMAGE); - if(interface) image->InitContours(); - b.SetModes(CAP_MIRROROWNER); - } - else - { - if(interface) interface->SetStatus(_("Mirror Image spell failed!"), true); - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::SpellCreateMirrorImage: " << "new position not found!"); - } -} - diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_ai.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_ai.cpp deleted file mode 100644 index f859274ff..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_ai.cpp +++ /dev/null @@ -1,276 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "settings.h" -#include "heroes.h" -#include "castle.h" -#include "battle_arena.h" -#include "battle_cell.h" -#include "battle_stats.h" -#include "battle_interface.h" - -namespace Battle2 -{ - bool isApplySpell(const Spell::spell_t, const Stats*, const HeroBase &, Actions &); -} - -void Battle2::Arena::AITurn(const Stats & b, Actions & a) -{ - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::AITurn: " << \ - b.GetName() << "(color: " << Color::String(b.GetColor()) << \ - ", id: " << b.id << ", pos: " << b.position << ")"); - - // reset quality param for board - ResetBoard(); - - // set quality for enemy troop - board.SetEnemyQuality(b); - - const Stats* enemy = NULL; - bool attack = false; - - if(b.isArchers() && !b.isHandFighting()) - { - enemy = GetEnemyMaxQuality(b.GetColor()); - AIMagicAction(b, a, enemy); - attack = true; - } - else - if(b.Modes(SP_BERSERKER)) - { - std::vector pos; - GetNearestTroops(b.GetPosition(), pos, NULL); - const u16* move = Rand::Get(pos); - - if(move) - { - a.AddedMoveAction(b, *move); - enemy = GetEnemyAbroadMaxQuality(*move, 0); - attack = true; - } - } - else - if(b.isHandFighting()) - { - enemy = GetEnemyAbroadMaxQuality(b.GetPosition(), b.GetColor()); - AIMagicAction(b, a, enemy); - attack = true; - } - else - { - // set quality position from enemy - board.SetPositionQuality(b); - - // get passable quality positions - std::vector positions; - positions.reserve(30); - GetPassableQualityPositions(b, positions); - attack = true; - - if(positions.size()) - { - const u16 move = b.AIGetAttackPosition(positions); - - if(b.isFly()) - { - enemy = GetEnemyAbroadMaxQuality(move, b.GetColor()); - AIMagicAction(b, a, enemy); - a.AddedMoveAction(b, move); - attack = true; - } - else - { - std::vector path; - GetPath(b, move, path); - if(path.size()) - { - enemy = GetEnemyAbroadMaxQuality(path.back(), b.GetColor()); - AIMagicAction(b, a, enemy); - a.AddedMoveAction(b, path); - - // archers move and short attack only - attack = b.isArchers() ? false : true; - } - } - } - else - enemy = GetEnemyAbroadMaxQuality(b); - } - - if(enemy) - { - if(attack) a.AddedAttackAction(b, *enemy); - } - else - if(IS_DEBUG(DBG_BATTLE, DBG_TRACE)) - { - VERBOSE("Battle2::Arena::AITurn: " << "enemy is NULL"); - DumpBoard(); - } - - // end action - a.AddedEndAction(b); -} - -void Battle2::Arena::AIMagicAction(const Stats & b, Actions & a, const Stats* enemy) -{ - const HeroBase* hero = b.GetCommander(); - - if(b.Modes(SP_BERSERKER) || !hero || hero->Modes(Heroes::SPELLCASTED) || !hero->HaveSpellBook()) return; - - const Army::army_t* my_army = b.GetArmy(); - const Army::army_t* enemy_army = GetArmy(GetOppositeColor(b.GetColor())); - - const Army::Troop* troop = NULL; - const Stats* stats = NULL; - - // troop bad spell - clean - if(b.Modes(IS_BAD_MAGIC)) - { - if(isApplySpell(Spell::DISPEL, &b, *hero, a)) return; - if(isApplySpell(Spell::CURE, &b, *hero, a)) return; - } - - if(enemy) - { - // curse - if(!enemy->Modes(SP_CURSE) && isApplySpell(Spell::CURSE, enemy, *hero, a)) return; - // enemy good spell - clean - if(enemy->Modes(IS_GOOD_MAGIC) && isApplySpell(Spell::DISPEL, enemy, *hero, a)) return; - - // up defense - if(!b.Modes(SP_STEELSKIN) && !b.Modes(SP_STONESKIN) && isApplySpell(Spell::STEELSKIN, &b, *hero, a)) return; - if(!b.Modes(SP_STONESKIN) && !b.Modes(SP_STEELSKIN) && isApplySpell(Spell::STONESKIN, &b, *hero, a)) return; - } - - // my army blessing - if(b.isArchers() || enemy) - { - if(enemy->troop.isDragons() && !b.Modes(SP_DRAGONSLAYER) && isApplySpell(Spell::DRAGONSLAYER, &b, *hero, a)) return; - if(!b.Modes(SP_BLESS) && isApplySpell(Spell::BLESS, &b, *hero, a)) return; - if(!b.Modes(SP_BLOODLUST) && isApplySpell(Spell::BLOODLUST, &b, *hero, a)) return; - if(!b.Modes(SP_HASTE) && isApplySpell(Spell::HASTE, &b, *hero, a)) return; - } - - // shield spell conditions - if(NULL != enemy_army) - { - // find archers - if(enemy_army->BattleArchersPresent() || - // or archers tower - (castle && castle->GetColor() != b.GetColor() && castle->isCastle())) - { - if(!b.Modes(SP_SHIELD) && isApplySpell(Spell::SHIELD, &b, *hero, a)) return; - } - } - - // my army scan - clean - if(NULL != my_army && NULL != (troop = my_army->BattleFindModes(IS_BAD_MAGIC))) - { - if(NULL != (stats = troop->GetBattleStats())) - { - if(isApplySpell(Spell::DISPEL, stats, *hero, a)) return; - if(isApplySpell(Spell::CURE, stats, *hero, a)) return; - } - } - - // enemy army spell - if(NULL != enemy_army) - { - // find mirror image or summon elem - if(NULL != (troop = enemy_army->BattleFindModes(CAP_MIRRORIMAGE | CAP_SUMMONELEM)) && NULL != (stats = troop->GetBattleStats())) - { - if(isApplySpell(Spell::ARROW, stats, *hero, a)) return; - if(isApplySpell(Spell::COLDRAY, stats, *hero, a)) return; - if(isApplySpell(Spell::FIREBALL, stats, *hero, a)) return; - if(isApplySpell(Spell::LIGHTNINGBOLT, stats, *hero, a)) return; - } - - // find good magic - if(NULL != (troop = enemy_army->BattleFindModes(IS_GOOD_MAGIC)) && NULL != (stats = troop->GetBattleStats())) - { - // slow - if(stats->Modes(SP_HASTE) && isApplySpell(Spell::SLOW, stats, *hero, a)) return; - // curse - if(!stats->Modes(SP_CURSE) && isApplySpell(Spell::CURSE, stats, *hero, a)) return; - // - if(isApplySpell(Spell::DISPEL, stats, *hero, a)) return; - } - - // check undead - if(my_army->BattleUndeadTroopCount() < enemy_army->BattleUndeadTroopCount()) - { - if(isApplySpell(Spell::HOLYSHOUT, NULL, *hero, a)) return; - if(isApplySpell(Spell::HOLYWORD, NULL, *hero, a)) return; - } - - // check alife - if(my_army->BattleLifeTroopCount() < enemy_army->BattleLifeTroopCount()) - { - if(isApplySpell(Spell::DEATHRIPPLE, NULL, *hero, a)) return; - if(isApplySpell(Spell::DEATHWAVE, NULL, *hero, a)) return; - } - - stats = enemy_army->BattleRandomTroop(); - - if(isApplySpell(Spell::LIGHTNINGBOLT, stats, *hero, a)) return; - if(isApplySpell(Spell::FIREBALL, stats, *hero, a)) return; - if(isApplySpell(Spell::COLDRAY, stats, *hero, a)) return; - if(isApplySpell(Spell::ARROW, stats, *hero, a)) return; - } - -/* FIX: Battle2::Arena: AIMagicAction:Damage Spell: - Spell::FIREBLAST - Spell::COLDRING - Spell::CHAINLIGHTNING - Spell::METEORSHOWER -*/ - - if(isApplySpell(Spell::ARMAGEDDON, NULL, *hero, a)) return; - if(isApplySpell(Spell::ELEMENTALSTORM, NULL, *hero, a)) return; -} - -bool Battle2::isApplySpell(const Spell::spell_t spell, const Stats* b, const HeroBase & hero, Actions & a) -{ - switch(spell) - { - case Spell::CURE: if(isApplySpell(Spell::MASSCURE, b, hero, a)) return true; break; - case Spell::HASTE: if(isApplySpell(Spell::MASSHASTE, b, hero, a)) return true; break; - case Spell::SLOW: if(isApplySpell(Spell::MASSSLOW, b, hero, a)) return true; break; - case Spell::BLESS: if(isApplySpell(Spell::MASSBLESS, b, hero, a)) return true; break; - case Spell::CURSE: if(isApplySpell(Spell::MASSCURSE, b, hero, a)) return true; break; - case Spell::DISPEL: if(isApplySpell(Spell::MASSDISPEL, b, hero, a)) return true; break; - case Spell::SHIELD: if(isApplySpell(Spell::MASSSHIELD, b, hero, a)) return true; break; - - default: break; - } - - if(hero.HaveSpell(spell) && hero.HaveSpellPoints(Spell::CostManaPoints(spell, &hero)) && (!b || b->AllowApplySpell(spell, &hero))) - { - a.AddedCastAction(spell, (b ? b->GetPosition() : MAXU16)); - return true; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_arena.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_arena.cpp deleted file mode 100644 index 82d055c2f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_arena.cpp +++ /dev/null @@ -1,1675 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "settings.h" -#include "tools.h" -#include "army.h" -#include "cursor.h" -#include "castle.h" -#include "world.h" -#include "agg.h" -#include "speed.h" -#include "army_troop.h" -#include "server.h" -#include "remoteclient.h" -#include "battle_arena.h" -#include "battle_cell.h" -#include "battle_stats.h" -#include "battle_tower.h" -#include "battle_catapult.h" -#include "battle_bridge.h" -#include "battle_interface.h" - -ICN::icn_t GetCovr(u16 ground) -{ - std::vector covrs; - - switch(ground) - { - case Maps::Ground::SNOW: - covrs.push_back(ICN::COVR0007); - covrs.push_back(ICN::COVR0008); - covrs.push_back(ICN::COVR0009); - covrs.push_back(ICN::COVR0010); - covrs.push_back(ICN::COVR0011); - covrs.push_back(ICN::COVR0012); - break; - - case Maps::Ground::WASTELAND: - covrs.push_back(ICN::COVR0019); - covrs.push_back(ICN::COVR0020); - covrs.push_back(ICN::COVR0021); - covrs.push_back(ICN::COVR0022); - covrs.push_back(ICN::COVR0023); - covrs.push_back(ICN::COVR0024); - break; - - case Maps::Ground::DIRT: - covrs.push_back(ICN::COVR0013); - covrs.push_back(ICN::COVR0014); - covrs.push_back(ICN::COVR0015); - covrs.push_back(ICN::COVR0016); - covrs.push_back(ICN::COVR0017); - covrs.push_back(ICN::COVR0018); - break; - - case Maps::Ground::GRASS: - covrs.push_back(ICN::COVR0001); - covrs.push_back(ICN::COVR0002); - covrs.push_back(ICN::COVR0003); - covrs.push_back(ICN::COVR0004); - covrs.push_back(ICN::COVR0005); - covrs.push_back(ICN::COVR0006); - break; - - default: break; - } - - return covrs.empty() ? ICN::UNKNOWN : *Rand::Get(covrs); -} - -u16 GetObstaclePosition(void) -{ - return Rand::Get(3, 6) + (11 * Rand::Get(1, 7)); -} - -Battle2::Board::Board() -{ -} - -Rect Battle2::Board::GetArea(void) const -{ - std::vector rects; - rects.reserve(size()); - std::vector::const_iterator it1 = begin(); - std::vector::const_iterator it2 = end(); - for(; it1 != it2; ++it1) rects.push_back((*it1).pos); - return Rect(rects); -} - -void Battle2::Board::SetPositionQuality(const Stats & b) -{ - iterator it1 = begin(); - iterator it2 = end(); - for(; it1 != it2; ++it1) (*it1).SetPositionQuality(b); -} - - -void Battle2::Board::SetEnemyQuality(const Stats & b) -{ - iterator it1 = begin(); - iterator it2 = end(); - for(; it1 != it2; ++it1) (*it1).SetEnemyQuality(b); -} - -u16 Battle2::Board::GetDistance(u16 index1, u16 index2) -{ - const s16 dx = (index1 % ARENAW) - (index2 % ARENAW); - const s16 dy = (index1 / ARENAW) - (index2 / ARENAW); - - return Sign(dx) == Sign(dy) ? std::max(std::abs(dx), std::abs(dy)) : std::abs(dx) + std::abs(dy); -} - -Battle2::direction_t Battle2::Board::GetDirection(u16 from, u16 to) -{ - if(from == to) return CENTER; - else - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - if(isValidDirection(from, dir) && to == GetIndexDirection(from, dir)) return dir; - } - - return UNKNOWN; -} - -Battle2::direction_t Battle2::Board::GetReflectDirection(u8 d) -{ - switch(d) - { - case TOP_LEFT: return BOTTOM_RIGHT; - case TOP_RIGHT: return BOTTOM_LEFT; - case LEFT: return RIGHT; - case RIGHT: return LEFT; - case BOTTOM_LEFT: return TOP_RIGHT; - case BOTTOM_RIGHT: return TOP_LEFT; - default: break; - } - - return UNKNOWN; -} - -bool Battle2::Board::isValidDirection(u16 i, u8 d) -{ - const u16 x = i % ARENAW; - const u16 y = i / ARENAW; - - switch(d) - { - case CENTER: break; - case TOP_LEFT: if(0 == y || (0 == x && (y % 2))) return false; break; - case TOP_RIGHT: if(0 == y || ((ARENAW - 1) == x && !(y % 2))) return false; break; - case LEFT: if(0 == x) return false; break; - case RIGHT: if((ARENAW - 1) == x) return false; break; - case BOTTOM_LEFT: if((ARENAH - 1) == y || (0 == x && (y % 2))) return false; break; - case BOTTOM_RIGHT: if((ARENAH - 1) == y || ((ARENAW - 1) == x && !(y % 2))) return false; break; - default: return false; - } - - return true; -} - -u16 Battle2::Board::GetIndexDirection(u16 i, u8 d) -{ - const u16 y = i / ARENAW; - - switch(d) - { - case TOP_LEFT: return i - (y % 2 ? ARENAW + 1 : ARENAW); - case TOP_RIGHT: return i - (y % 2 ? ARENAW : ARENAW - 1); - case LEFT: return i - 1; - case RIGHT: return i + 1; - case BOTTOM_LEFT: return i + (y % 2 ? ARENAW - 1 : ARENAW); - case BOTTOM_RIGHT: return i + (y % 2 ? ARENAW : ARENAW + 1); - default: break; - } - - return i; -} - -s16 Battle2::Board::GetIndexAbsPosition(const Point & pt) const -{ - const_iterator it1 = begin(); - const_iterator it2 = end(); - for(; it1 != it2; ++it1) if((*it1).isPositionIncludePoint(pt)) break; - return it1 != it2 ? (*it1).GetIndex() : -1; -} - -void Battle2::Board::GetIndexesFromAbsPoints(std::vector & indexes, const std::vector & points) const -{ - std::vector::const_iterator it = points.begin(); - for(; it != points.end(); ++it) - { - const s16 index = GetIndexAbsPosition(*it); - if(0 <= index) indexes.push_back(index); - } - - if(indexes.size()) - { - std::sort(indexes.begin(), indexes.end()); - - std::vector::iterator it1 = std::unique(indexes.begin(), indexes.end()); - indexes.resize(it1 - indexes.begin()); - } -} - -bool Battle2::Board::inCastle(u16 ii) -{ - return((8 < ii && ii <= 10) || - (19 < ii && ii <= 21) || - (29 < ii && ii <= 32) || - (40 < ii && ii <= 43) || - (50 < ii && ii <= 54) || - (62 < ii && ii <= 65) || - (73 < ii && ii <= 76) || - (85 < ii && ii <= 87) || - (96 < ii && ii <= 98)); -} - -bool Battle2::Board::isMoatIndex(u16 ii) -{ - switch(ii) - { - case 7: - case 18: - case 28: - case 39: - case 61: - case 72: - case 84: - case 95: - return true; - - default: break; - } - return false; -} - -void Battle2::Board::GetAbroadPositions(u16 center, u8 radius, std::vector & positions) const -{ - if(center < size()) - { - if(positions.size()) positions.clear(); - positions.reserve(radius * 9); - - std::vector v1, v2; - std::vector::iterator it; - - v1.reserve(ARENASIZE / 2); - v2.reserve(ARENASIZE / 2); - - v1.push_back(center); - - while(v1.size() && radius) - { - for(it = v1.begin(); it != v1.end(); ++it) - { - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) if(isValidDirection(*it, dir)) - { - const u16 index = GetIndexDirection(*it, dir); - if(v1.end() == std::find(v1.begin(), v1.end(), index) && - positions.end() == std::find(positions.begin(), positions.end(), index) && - center != index) - { - v2.push_back(index); - positions.push_back(index); - } - } - } - - v1 = v2; - v2.clear(); - - --radius; - } - } -} - -void Battle2::Board::SetCobjObjects(s32 center) -{ -// bool trees = Maps::ScanAroundObject(center, MP2::OBJ_TREES, false); - const Heroes* hero = world.GetHeroes(center); - bool grave = hero && MP2::OBJ_GRAVEYARD == hero->GetUnderObject(); - u16 ground = world.GetTiles(center).GetGround(); - std::vector objs; - - if(grave) - { - objs.push_back(ICN::COBJ0000); - objs.push_back(ICN::COBJ0001); - } - else - switch(ground) - { - case Maps::Ground::DESERT: - objs.push_back(ICN::COBJ0009); - objs.push_back(ICN::COBJ0012); - objs.push_back(ICN::COBJ0017); - objs.push_back(ICN::COBJ0024); - break; - - case Maps::Ground::SNOW: - objs.push_back(ICN::COBJ0022); - objs.push_back(ICN::COBJ0026); - break; - - case Maps::Ground::SWAMP: - objs.push_back(ICN::COBJ0006); - objs.push_back(ICN::COBJ0015); - objs.push_back(ICN::COBJ0016); - objs.push_back(ICN::COBJ0019); - objs.push_back(ICN::COBJ0025); - objs.push_back(ICN::COBJ0027); - break; - - case Maps::Ground::BEACH: - objs.push_back(ICN::COBJ0017); - break; - - case Maps::Ground::DIRT: - objs.push_back(ICN::COBJ0011); - case Maps::Ground::GRASS: - objs.push_back(ICN::COBJ0002); - objs.push_back(ICN::COBJ0004); - objs.push_back(ICN::COBJ0005); - objs.push_back(ICN::COBJ0008); - objs.push_back(ICN::COBJ0012); - objs.push_back(ICN::COBJ0028); - break; - - case Maps::Ground::WASTELAND: - objs.push_back(ICN::COBJ0013); - objs.push_back(ICN::COBJ0018); - objs.push_back(ICN::COBJ0020); - objs.push_back(ICN::COBJ0021); - break; - - case Maps::Ground::LAVA: - objs.push_back(ICN::COBJ0007); - objs.push_back(ICN::COBJ0029); - objs.push_back(ICN::COBJ0030); - objs.push_back(ICN::COBJ0031); - break; - - case Maps::Ground::WATER: - objs.push_back(ICN::COBJ0003); - objs.push_back(ICN::COBJ0010); - objs.push_back(ICN::COBJ0023); - break; - - default: break; - } - - if(objs.size() && 2 < Rand::Get(1, 10)) - { - // 80% 1 obj - u16 dst = GetObstaclePosition(); - SetCobjObject(*Rand::Get(objs), dst); - - // 50% 2 obj - while(at(dst).object) dst = GetObstaclePosition(); - if(objs.size() > 1 && 5 < Rand::Get(1, 10)) SetCobjObject(*Rand::Get(objs), dst); - - // 30% 3 obj - while(at(dst).object) dst = GetObstaclePosition(); - if(objs.size() > 1 && 7 < Rand::Get(1, 10)) SetCobjObject(*Rand::Get(objs), dst); - } -} - -void Battle2::Board::SetCobjObject(u16 icn, u16 dst) -{ - switch(icn) - { - case ICN::COBJ0000: at(dst).object = 0x80; break; - case ICN::COBJ0001: at(dst).object = 0x81; break; - case ICN::COBJ0002: at(dst).object = 0x82; break; - case ICN::COBJ0003: at(dst).object = 0x83; break; - case ICN::COBJ0004: at(dst).object = 0x84; break; - case ICN::COBJ0005: at(dst).object = 0x85; break; - case ICN::COBJ0006: at(dst).object = 0x86; break; - case ICN::COBJ0007: at(dst).object = 0x87; break; - case ICN::COBJ0008: at(dst).object = 0x88; break; - case ICN::COBJ0009: at(dst).object = 0x89; break; - case ICN::COBJ0010: at(dst).object = 0x8A; break; - case ICN::COBJ0011: at(dst).object = 0x8B; break; - case ICN::COBJ0012: at(dst).object = 0x8C; break; - case ICN::COBJ0013: at(dst).object = 0x8D; break; - case ICN::COBJ0014: at(dst).object = 0x8E; break; - case ICN::COBJ0015: at(dst).object = 0x8F; break; - case ICN::COBJ0016: at(dst).object = 0x90; break; - case ICN::COBJ0017: at(dst).object = 0x91; break; - case ICN::COBJ0018: at(dst).object = 0x92; break; - case ICN::COBJ0019: at(dst).object = 0x93; break; - case ICN::COBJ0020: at(dst).object = 0x94; break; - case ICN::COBJ0021: at(dst).object = 0x95; break; - case ICN::COBJ0022: at(dst).object = 0x96; break; - case ICN::COBJ0023: at(dst).object = 0x97; break; - case ICN::COBJ0024: at(dst).object = 0x98; break; - case ICN::COBJ0025: at(dst).object = 0x99; break; - case ICN::COBJ0026: at(dst).object = 0x9A; break; - case ICN::COBJ0027: at(dst).object = 0x9B; break; - case ICN::COBJ0028: at(dst).object = 0x9C; break; - case ICN::COBJ0029: at(dst).object = 0x9D; break; - case ICN::COBJ0030: at(dst).object = 0x9E; break; - case ICN::COBJ0031: at(dst).object = 0x9F; break; - - default: break; - } - - switch(icn) - { - case ICN::COBJ0004: - case ICN::COBJ0005: - case ICN::COBJ0007: - case ICN::COBJ0011: - case ICN::COBJ0014: - case ICN::COBJ0015: - case ICN::COBJ0017: - case ICN::COBJ0018: - case ICN::COBJ0019: - case ICN::COBJ0020: - case ICN::COBJ0022: - case ICN::COBJ0030: - case ICN::COBJ0031: - at(dst + 1).object = 0x40; - break; - - default: break; - } -} - -void Battle2::Board::SetCovrObjects(u16 icn) -{ - switch(icn) - { - case ICN::COVR0001: - case ICN::COVR0007: - case ICN::COVR0013: - case ICN::COVR0019: - at(15).object = 0x40; - at(16).object = 0x40; - at(17).object = 0x40; - at(25).object = 0x40; - at(26).object = 0x40; - at(27).object = 0x40; - at(28).object = 0x40; - at(40).object = 0x40; - at(51).object = 0x40; - break; - - case ICN::COVR0002: - case ICN::COVR0008: - case ICN::COVR0014: - case ICN::COVR0020: - at(47).object = 0x40; - at(48).object = 0x40; - at(49).object = 0x40; - at(50).object = 0x40; - at(51).object = 0x40; - break; - - case ICN::COVR0003: - case ICN::COVR0009: - case ICN::COVR0015: - case ICN::COVR0021: - at(35).object = 0x40; - at(41).object = 0x40; - at(46).object = 0x40; - at(47).object = 0x40; - at(48).object = 0x40; - at(49).object = 0x40; - at(50).object = 0x40; - at(51).object = 0x40; - break; - - case ICN::COVR0004: - case ICN::COVR0010: - case ICN::COVR0016: - case ICN::COVR0022: - at(41).object = 0x40; - at(51).object = 0x40; - at(58).object = 0x40; - at(59).object = 0x40; - at(60).object = 0x40; - at(61).object = 0x40; - at(62).object = 0x40; - break; - - case ICN::COVR0005: - case ICN::COVR0017: - at(24).object = 0x40; - at(25).object = 0x40; - at(26).object = 0x40; - at(27).object = 0x40; - at(28).object = 0x40; - at(29).object = 0x40; - at(30).object = 0x40; - at(58).object = 0x40; - at(59).object = 0x40; - at(60).object = 0x40; - at(61).object = 0x40; - at(62).object = 0x40; - at(63).object = 0x40; - at(68).object = 0x40; - at(74).object = 0x40; - break; - - case ICN::COVR0006: - case ICN::COVR0018: - at(14).object = 0x40; - at(15).object = 0x40; - at(16).object = 0x40; - at(17).object = 0x40; - at(18).object = 0x40; - at(24).object = 0x40; - at(68).object = 0x40; - at(80).object = 0x40; - at(81).object = 0x40; - at(82).object = 0x40; - at(83).object = 0x40; - at(84).object = 0x40; - break; - - case ICN::COVR0011: - case ICN::COVR0023: - at(15).object = 0x40; - at(25).object = 0x40; - at(36).object = 0x40; - at(51).object = 0x40; - at(62).object = 0x40; - at(71).object = 0x40; - at(72).object = 0x40; - break; - - case ICN::COVR0012: - case ICN::COVR0024: - at(18).object = 0x40; - at(29).object = 0x40; - at(41).object = 0x40; - at(59).object = 0x40; - at(70).object = 0x40; - at(82).object = 0x40; - at(83).object = 0x40; - break; - - default: break; - } -} - -Battle2::GraveyardTroop::GraveyardTroop(const Arena & a) : arena(a) -{ -} - -void Battle2::GraveyardTroop::GetClosedCells(std::vector & v) const -{ - v.clear(); - std::map >::const_iterator it1 = map.begin(); - std::map >::const_iterator it2 = map.end(); - for(; it1 != it2; ++it1) v.push_back((*it1).first); -} - -u16 Battle2::GraveyardTroop::GetLastTroopIDFromCell(u16 index) const -{ - std::map >::const_iterator it1 = map.begin(); - std::map >::const_iterator it2 = map.end(); - for(; it1 != it2; ++it1) if(index == (*it1).first) break; - - return it1 != it2 && (*it1).second.size() ? (*it1).second.back() : 0; -} - -void Battle2::GraveyardTroop::AddTroopID(u16 id) -{ - const Stats* b = arena.GetTroopID(id); - if(b) - { - std::vector & v = map[b->position]; - if(v.empty()) v.reserve(3); - v.push_back(id); - - if(b->isWide()) - { - std::vector & v2 = map[b->GetTailIndex()]; - if(v2.empty()) v2.reserve(3); - v2.push_back(id); - } - } -} - -void Battle2::GraveyardTroop::RemoveTroopID(u16 id) -{ - const Stats* b = arena.GetTroopID(id); - if(b) - { - std::vector & v = map[b->position]; - std::vector::iterator it = std::find(v.begin(), v.end(), id); - if(it != v.end()) v.erase(it); - - if(b->isWide()) - { - std::vector & v2 = map[b->GetTailIndex()]; - std::vector::iterator it = std::find(v2.begin(), v2.end(), id); - if(it != v2.end()) v2.erase(it); - } - } -} - -Battle2::Arena::Arena(Army::army_t & a1, Army::army_t & a2, s32 index, bool local) : - army1(a1), army2(a2), castle(NULL), current_commander(NULL), catapult(NULL), bridge(NULL), interface(NULL), result_game(NULL), graveyard(*this), - icn_covr(ICN::UNKNOWN) -{ - const Settings & conf = Settings::Get(); - usage_spells.reserve(10); - - interface = local ? new Interface(*this, index) : NULL; - - if(interface && conf.Sound()) - AGG::PlaySound(M82::PREBATTL); - - board.reserve(ARENASIZE); - for(u16 ii = 0; ii < ARENASIZE; ++ii) board.push_back(Cell(ii, (interface ? &interface->GetArea() : NULL), *this)); - - for(u8 ii = 0; ii < army1.Size(); ++ii) - { - // place army1 troops - const u8 index1 = Army::FORMAT_SPREAD == army1.GetCombatFormat() ? ii * 22 : 22 + ii * 11; - Army::Troop & troop1 = army1.At(ii); - if(troop1.isValid() && troop1.BattleInit()) - { - Stats* stats = troop1.GetBattleStats(); - stats->SetPosition(troop1.isWide() ? index1 + 1 : index1); - stats->SetArena(this); - stats->SetReflection(false); - if(interface) stats->InitContours(); - } - } - - for(u8 ii = 0; ii < army2.Size(); ++ii) - { - // place army2 troops - const u8 index2 = Army::FORMAT_SPREAD == army2.GetCombatFormat() ? 10 + ii * 22 : 32 + ii * 11; - Army::Troop & troop2 = army2.At(ii); - if(troop2.isValid() && troop2.BattleInit()) - { - Stats* stats = troop2.GetBattleStats(); - stats->SetPosition(index2); - stats->SetArena(this); - stats->SetReflection(true); - if(interface) stats->InitContours(); - } - } - - castle = world.GetCastle(index); - if(castle && (castle->GetIndex() != index || !castle->isCastle())) castle = NULL; - towers[0] = NULL; - towers[1] = NULL; - towers[2] = NULL; - - if(castle) - { - // init - towers[0] = castle->isBuild(BUILD_LEFTTURRET) ? new Tower(*castle, TWR_LEFT, *this) : NULL; - towers[1] = new Tower(*castle, TWR_CENTER, *this); - towers[2] = castle->isBuild(BUILD_RIGHTTURRET) ? new Tower(*castle, TWR_RIGHT, *this) : NULL; - bool fortification = (Race::KNGT == castle->GetRace()) && castle->isBuild(BUILD_SPEC); - catapult = army1.GetCommander() ? new Catapult(*army1.GetCommander(), fortification, *this) : NULL; - bridge = new Bridge(*this); - - // catapult cell - board[77].object = 1; - - // wall (3,2,1,0) - board[8].object = fortification ? 3 : 2; - board[29].object = fortification ? 3 : 2; - board[73].object = fortification ? 3 : 2; - board[96].object = fortification ? 3 : 2; - - // tower - board[40].object = 2; - board[62].object = 2; - - // archers tower - board[19].object = 2; - board[85].object = 2; - - // bridge - board[49].object = 1; - board[50].object = 1; - } - else - // set obstacles - { - icn_covr = Maps::ScanAroundObject(index, MP2::OBJ_CRATER) ? GetCovr(world.GetTiles(index).GetGround()) : ICN::UNKNOWN; - - if(icn_covr != ICN::UNKNOWN) - board.SetCovrObjects(icn_covr); - else - board.SetCobjObjects(index); - } - -#ifdef WITH_NET - if(Network::isRemoteClient()) - { - if(Game::REMOTE == army1.GetControl()) FH2RemoteClient::SendBattleBoard(army1.GetColor(), *this); - if(Game::REMOTE == army2.GetControl()) FH2RemoteClient::SendBattleBoard(army2.GetColor(), *this); - } -#endif - - // - if(interface) - { - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - - cursor.Hide(); - if(conf.ExtUseFade()) display.Fade(); - cursor.SetThemes(Cursor::WAR_NONE); - interface->Redraw(); - cursor.Show(); - display.Flip(); - - // pause for play M82::PREBATTL - if(conf.Sound()) - while(LocalEvent::Get().HandleEvents() && Mixer::isPlaying(-1)); - } -} - -Battle2::Arena::~Arena() -{ - if(towers[0]) delete towers[0]; - if(towers[1]) delete towers[1]; - if(towers[2]) delete towers[2]; - - if(catapult) delete catapult; - if(interface) delete interface; -} - -Battle2::Interface* Battle2::Arena::GetInterface(void) -{ - return interface; -} - -void Battle2::Arena::Turns(u16 turn, Result & result) -{ - DEBUG(DBG_BATTLE , DBG_TRACE, "Battle2::Arena::Turns: " << turn); - - result_game = &result; - - army1.BattleNewTurn(); - army2.BattleNewTurn(); - - Actions actions; - Stats* current_troop = NULL; - u8 equal_color = 0; - u8 current_color = 0; - bool tower_moved = false; - bool catapult_moved = false; - - // turn - while(1) - { - // check exit - if(!army1.isValid() || !army2.isValid() || result.army1 || result.army2) break; - - if(NULL == current_troop) - { - Battle2::Stats* btroop1 = army1.BattleFastestTroop(false); - Battle2::Stats* btroop2 = army2.BattleFastestTroop(false); - - if(btroop1 && btroop2) - { - if(btroop1->GetSpeed() > btroop2->GetSpeed()) - { - current_troop = btroop1; - current_color = army1.GetColor(); - equal_color = 0; - } - else - if(btroop1->GetSpeed() < btroop2->GetSpeed()) - { - current_troop = btroop2; - current_color = army2.GetColor(); - equal_color = 0; - } - else - // equal speed - { - // first attacker moved - if(0 == equal_color) - { - current_troop = btroop1; - current_color = army1.GetColor(); - equal_color = army1.GetColor(); - } - else - // changed - if(equal_color == army1.GetColor()) - { - current_troop = btroop2; - current_color = army2.GetColor(); - equal_color = army2.GetColor(); - } - else - { - current_troop = btroop1; - current_color = army1.GetColor(); - equal_color = army1.GetColor(); - } - } - } - else - if(btroop1) - { - current_troop = btroop1; - current_color = army1.GetColor(); - } - else - if(btroop2) - { - current_troop = btroop2; - current_color = army2.GetColor(); - } - else - { - btroop1 = army1.BattleSlowestTroop(true); - btroop2 = army2.BattleSlowestTroop(true); - - if(btroop1 && btroop2) - { - if(btroop1->GetSpeed() < btroop2->GetSpeed()) - { - current_troop = btroop1; - current_color = army1.GetColor(); - equal_color = 0; - } - else - if(btroop1->GetSpeed() > btroop2->GetSpeed()) - { - current_troop = btroop2; - current_color = army2.GetColor(); - equal_color = 0; - } - else - // equal speed - { - // first defender moved (attacker have priority) - if(0 == equal_color) - { - current_troop = btroop2; - current_color = army2.GetColor(); - equal_color = army2.GetColor(); - } - else - // changed - if(equal_color == army1.GetColor()) - { - current_troop = btroop2; - current_color = army2.GetColor(); - equal_color = army2.GetColor(); - } - else - { - current_troop = btroop1; - current_color = army1.GetColor(); - equal_color = army1.GetColor(); - } - } - } - else - if(btroop1) - { - current_troop = btroop1; - current_color = army1.GetColor(); - } - else - if(btroop2) - { - current_troop = btroop2; - current_color = army2.GetColor(); - } - } - - // end turns - if(!current_troop) break; - } - - DEBUG(DBG_BATTLE , DBG_TRACE, "Battle2::Arena::Turns: " << current_troop->GetName() << ", color: " << \ - Color::String(current_troop->GetColor()) << ", speed: " << Speed::String(current_troop->GetSpeed()) << "(" << static_cast(current_troop->GetSpeed()) << ")"); - - current_commander = current_troop->GetCommander(); - - // first turn: castle and catapult action - if(castle) - { - if(!catapult_moved && current_color == army1.GetColor()) - { - catapult->Action(); - catapult_moved = true; - } - - if(!tower_moved && current_color == army2.GetColor()) - { - if(towers[0] && towers[0]->isValid()) towers[0]->Action(); - if(towers[1] && towers[1]->isValid()) towers[1]->Action(); - if(towers[2] && towers[2]->isValid()) towers[2]->Action(); - tower_moved = true; - - // check dead last army from towers - if(!army1.isValid() || !army2.isValid() || result.army1 || result.army2) break; - } - } - - // set bridge passable - if(bridge && bridge->isValid() && !bridge->isDown()) bridge->SetPassable(*current_troop); - - // bad morale - if(current_troop->Modes(MORALE_BAD)) - { - actions.AddedMoraleAction(*current_troop, false); - } - else - // turn opponents - switch(current_troop->GetControl()) - { - case Game::REMOTE: RemoteTurn(*current_troop, actions); break; - case Game::LOCAL: HumanTurn(*current_troop, actions); break; - default: AITurn(*current_troop, actions); break; - } - - // apply task - while(actions.size()) - { - bool check_morale = (MSG_BATTLE_END_TURN == actions.front().GetID()); - - ApplyAction(actions.front()); - actions.pop_front(); - - // good morale - if(check_morale && !current_troop->Modes(TR_SKIPMOVE) && - current_troop->Modes(TR_MOVED) && current_troop->Modes(MORALE_GOOD) && army1.isValid() && army2.isValid() && - 0 == result.army1 && 0 == result.army2) - actions.AddedMoraleAction(*current_troop, true); - } - - ResetBoard(); - - // current troop moved! - if(current_troop->Modes(TR_SKIPMOVE | TR_MOVED)) current_troop = NULL; - - DELAY(10); - } - - // end turn: fix result - if(!army1.isValid() || (result.army1 & (RESULT_RETREAT | RESULT_SURRENDER))) - { - result.army1 |= RESULT_LOSS; - if(army2.isValid()) result.army2 = RESULT_WINS; - } - - if(!army2.isValid() || (result.army2 & (RESULT_RETREAT | RESULT_SURRENDER))) - { - result.army2 |= RESULT_LOSS; - if(army1.isValid()) result.army1 = RESULT_WINS; - } -} - -void Battle2::Arena::RemoteTurn(const Stats & b, Actions & a) -{ -#ifdef WITH_NET - if(current_commander) - { - FH2RemoteClient* remote = FH2Server::Get().GetRemoteClient(current_commander->GetColor()); - if(remote) - { - remote->RecvBattleHumanTurn(b, *this, a); - return; - } - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::RemoteTurn: " << "remote client is NULL"); - } - else - { - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::RemoteTurn: " << "current commander is NULL"); - } -#endif - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::RemoteTurn: " << "AI turn"); - AITurn(b, a); -} - -void Battle2::Arena::HumanTurn(const Stats & b, Actions & a) -{ - Settings & conf = Settings::Get(); - - conf.SetMyColor(Color::Get(b.GetColor())); - - if(conf.AutoBattle()) - AITurn(b, a); - else - if(interface) - interface->HumanTurn(b, a); -} - -const Battle2::Cell* Battle2::Arena::GetCell(u16 position, direction_t dir) const -{ - if(position < board.size()) - { - if(dir == CENTER || dir == UNKNOWN) - return &board[position]; - else - if(Board::isValidDirection(position, dir)) - return &board[Board::GetIndexDirection(position, dir)]; - } - return NULL; -} - -Battle2::Cell* Battle2::Arena::GetCell(u16 position, direction_t dir) -{ - if(position < board.size()) - { - if(dir == CENTER || dir == UNKNOWN) - return &board[position]; - else - if(Board::isValidDirection(position, dir)) - return &board[Board::GetIndexDirection(position, dir)]; - } - return NULL; -} - -void Battle2::Arena::ResetBoard(void) -{ - std::for_each(board.begin(), board.end(), std::mem_fun_ref(&Cell::Reset)); -} - -void Battle2::Arena::ScanPassabilityBoard(const Stats & b, bool skip_speed) -{ - u16 from = b.GetPosition(); - u8 max_turn = skip_speed ? 255 : b.GetSpeed(); - - if(b.isFly()) - { - std::vector::iterator it = board.begin(); - for(; it != board.end(); ++it) if((*it).isPassable(b, false)) (*it).direction = CENTER; - } - else - { - std::vector v1, v2; - std::vector::iterator it; - - v1.reserve(ARENASIZE / 2); - v2.reserve(ARENASIZE / 2); - - v1.push_back(from); - board[from].direction = CENTER; - - while(v1.size() && max_turn) - { - for(it = v1.begin(); it != v1.end(); ++it) board[*it].SetPassabilityAbroad(b, v2); - - v1.clear(); - for(it = v2.begin(); it != v2.end(); ++it) - { - if(!skip_speed && castle) - { - // skip moat positions - if((castle->isBuild(BUILD_MOAT) && Board::isMoatIndex(*it)) || - // skip bridge position - (Bridge::isIndex(*it) && !bridge->isPassable(b.GetColor()))) continue; - } - v1.push_back(*it); - } - v2.clear(); - - --max_turn; - } - } -} - -u16 Battle2::Arena::GetShortDistance(u16 from, const std::vector & dst) -{ - u16 len = MAXU16; - u16 res = MAXU16; - - for(std::vector::const_iterator it = dst.begin(); it != dst.end(); ++it) - { - const u16 length = Board::GetDistance(from, *it); - if(len > length) - { - len = length; - res = *it; - } - } - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Arena::GetShortDistance: " << res); - - return res; -} - -u16 Battle2::Arena::GetPath(const Stats & b, u16 to, std::vector & v) -{ - if(v.size()) v.clear(); - v.reserve(15); - - if(b.GetPosition() < board.size()) - { - ScanPassabilityBoard(b, true); - - u16 cur = to; - while(CENTER != board[cur].direction && UNKNOWN != board[cur].direction){ v.push_back(cur); cur = Board::GetIndexDirection(cur, board[cur].direction); } - } - - std::reverse(v.begin(), v.end()); - - // correct distance movement - if(v.size() > b.GetSpeed()) v.resize(b.GetSpeed()); - - // correct moat present - if(castle && castle->isBuild(BUILD_MOAT)) - { - std::vector::iterator it = std::find_if(v.begin(), v.end(), Board::isMoatIndex); - if(it != v.end()) v.resize(std::distance(v.begin(), it) + 1); - } - - if(IS_DEBUG(DBG_BATTLE, DBG_TRACE)) - { - std::cout << "Battle2::Arena::GetPath: from: " << b.GetPosition() << ", to: " << to << " :: "; - for(u16 ii = 0; ii < v.size(); ++ii) std::cout << v[ii] << ", "; - std::cout << std::endl; - } - - return v.size(); -} - -void Battle2::Arena::GetPassableQualityPositions(const Stats & b, std::vector & v) -{ - ScanPassabilityBoard(b, true); - - std::vector::iterator it; - v.clear(); - - for(it = board.begin(); it != board.end(); ++it) - if((*it).isPassable(b, false) && (*it).quality && UNKNOWN != (*it).direction) - v.push_back((*it).index); - - if(IS_DEBUG(DBG_BATTLE, DBG_TRACE)) - { - std::cout << "Battle2::Arena::GetPassableQualityPositions: "; - if(v.empty()) std::cout << "empty"; - for(u16 ii = 0; ii < v.size(); ++ii) std::cout << v[ii] << ", "; - std::cout << std::endl; - } -} - -Battle2::Stats* Battle2::Arena::GetTroopBoard(u16 index) -{ - for(u8 ii = 0; ii < army1.Size(); ++ii) - if(army1.At(ii).isValid() && - (army1.At(ii).GetBattleStats()->position == index || - (army1.At(ii).isWide() && army1.At(ii).GetBattleStats()->GetTailIndex() == index))) return army1.At(ii).GetBattleStats(); - - for(u8 ii = 0; ii < army2.Size(); ++ii) - if(army2.At(ii).isValid() && - (army2.At(ii).GetBattleStats()->position == index || - (army2.At(ii).isWide() && army2.At(ii).GetBattleStats()->GetTailIndex() == index))) return army2.At(ii).GetBattleStats(); - - return NULL; -} - -const Battle2::Stats* Battle2::Arena::GetTroopBoard(u16 index) const -{ - for(u8 ii = 0; ii < army1.Size(); ++ii) - if(army1.At(ii).isValid() && army1.At(ii).GetBattleStats()->position == index) return army1.At(ii).GetBattleStats(); - - for(u8 ii = 0; ii < army2.Size(); ++ii) - if(army2.At(ii).isValid() && army2.At(ii).GetBattleStats()->position == index) return army2.At(ii).GetBattleStats(); - - return NULL; -} - -const Army::army_t* Battle2::Arena::GetArmy(u8 color) const -{ - if(army1.GetColor() == color) return &army1; - else - if(army2.GetColor() == color) return &army2; - - return NULL; -} - -Army::army_t* Battle2::Arena::GetArmy(u8 color) -{ - if(army1.GetColor() == color) return &army1; - else - if(army2.GetColor() == color) return &army2; - - return NULL; -} - -void Battle2::Arena::GetArmyPositions(u8 color, std::vector & res) const -{ - if(res.size()) res.clear(); - - const Army::army_t* army = GetArmy(color); - if(army) - { - for(u8 ii = 0; ii < army->Size(); ++ii) - if(army->At(ii).isValid()) res.push_back(army->At(ii).GetBattleStats()->GetPosition()); - } -} - -Battle2::Stats* Battle2::Arena::GetTroopID(u16 id) -{ - Army::army_t* army = GetArmy(id >> 8); - return army && army->Size() > (0x000F & id) ? army->At(0x000F & id).GetBattleStats() : NULL; -} - -const Battle2::Stats* Battle2::Arena::GetTroopID(u16 id) const -{ - const Army::army_t* army = GetArmy(id >> 8); - return army && army->Size() > (0x000F & id) ? army->At(0x000F & id).GetBattleStats() : NULL; -} - -const Battle2::Stats* Battle2::Arena::GetEnemyAbroadMaxQuality(u16 position, u8 color) const -{ - const Stats* res = NULL; - const Stats* enemy = NULL; - const Cell* cell = NULL; - s32 quality = 0; - - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - cell = GetCell(position, dir); - if(cell && NULL != (enemy = GetTroopBoard(cell->index)) && - enemy->GetColor() != color && quality < cell->quality) - { - res = enemy; - quality = cell->quality; - } - } - - return res; -} - -u16 Battle2::Arena::GetMaxQualityPosition(const std::vector & positions) const -{ - std::vector::const_iterator it1 = positions.begin(); - std::vector::const_iterator it2 = positions.end(); - u16 res = MAXU16; - - for(; it1 != it2; ++it1) if(board.size() > *it1) - { - if(res == MAXU16 || - board[res].quality < board[*it1].quality) res = *it1; - } - - return res; -} - -const Battle2::Stats* Battle2::Arena::GetEnemyAbroadMaxQuality(const Stats & b) const -{ - const Stats* res1 = GetEnemyAbroadMaxQuality(b.GetPosition(), b.GetColor()); - - if(b.isWide()) - { - const Stats* res2 = GetEnemyAbroadMaxQuality(b.GetTailIndex(), b.GetColor()); - - if(!res1) return res2; - else - if(!res2) return res1; - else - return res1->GetCellQuality() > res2->GetCellQuality() ? res1 : res2; - } - - return res1; -} - -Battle2::Stats* Battle2::Arena::GetEnemyAbroadMaxQuality(u16 position, u8 color) -{ - Stats* res = NULL; - Stats* enemy = NULL; - Cell* cell = NULL; - s32 quality = 0; - - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - cell = GetCell(position, dir); - if(cell && NULL != (enemy = GetTroopBoard(cell->index)) && - enemy->GetColor() != color && quality < cell->quality) - { - res = enemy; - quality = cell->quality; - } - } - - return res; -} - -Battle2::Stats* Battle2::Arena::GetEnemyAbroadMaxQuality(const Stats & b) -{ - Stats* res1 = GetEnemyAbroadMaxQuality(b.GetPosition(), b.GetColor()); - - if(b.isWide()) - { - Stats* res2 = GetEnemyAbroadMaxQuality(b.GetTailIndex(), b.GetColor()); - - if(!res1) return res2; - else - if(!res2) return res1; - else - return res1->GetCellQuality() > res2->GetCellQuality() ? res1 : res2; - } - - return res1; -} - -const Battle2::Stats* Battle2::Arena::GetEnemyMaxQuality(u8 my_color) const -{ - const Stats* res = NULL; - s32 quality = 0; - Board::const_iterator it1 = board.begin(); - Board::const_iterator it2 = board.end(); - for(; it1 != it2; ++it1) - { - const Stats* enemy = GetTroopBoard((*it1).index); - if(enemy && enemy->isWide() && enemy->GetTailIndex() == (*it1).index) continue; - if(enemy && enemy->GetColor() != my_color && quality < (*it1).quality) - { - res = enemy; - quality = (*it1).quality; - } - } - return res; -} - -Battle2::Stats* Battle2::Arena::GetEnemyMaxQuality(u8 my_color) -{ - Stats* res = NULL; - s32 quality = 0; - Board::iterator it1 = board.begin(); - Board::iterator it2 = board.end(); - for(; it1 != it2; ++it1) - { - Stats* enemy = GetTroopBoard((*it1).index); - if(enemy && enemy->isWide() && enemy->GetTailIndex() == (*it1).index) continue; - if(enemy && enemy->GetColor() != my_color && quality < (*it1).quality) - { - res = enemy; - quality = (*it1).quality; - } - } - return res; -} - -u8 Battle2::Arena::GetOppositeColor(u8 color) const -{ - if(army1.GetColor() == color) return army2.GetColor(); - else - if(army2.GetColor() == color) return army1.GetColor(); - - return 0; -} - -void Battle2::Arena::FadeArena(void) const -{ - if(interface) interface->FadeArena(); -} - -const std::vector & Battle2::Arena::GetUsageSpells(void) const -{ - return usage_spells; -} - -void Battle2::Arena::AddSpell(u8 spell) -{ - if(usage_spells.end() == std::find(usage_spells.begin(), usage_spells.end(), spell)) usage_spells.push_back(spell); -} - -u16 Battle2::Arena::GetFreePositionNearHero(u8 color) const -{ - const u8 cells1[] = { 11, 22, 33 }; - const u8 cells2[] = { 21, 32, 43 }; - const u8* cells = NULL; - - if(army1.GetColor() == color) cells = cells1; - else - if(army2.GetColor() == color) cells = cells2; - - if(cells) for(u8 ii = 0; ii < 3; ++ii) if(board[cells[ii]].isPassable() && NULL == GetTroopBoard(cells[ii])) return cells[ii]; - - return 0; -} - -void Battle2::Arena::DumpBoard(void) const -{ - Board::const_iterator it1 = board.begin(); - Board::const_iterator it2 = board.end(); - for(; it1 != it2; ++it1) - { - const Battle2::Stats* b = GetTroopBoard((*it1).index); - if(b) b->Dump(); - } -} - -struct IndexDistanceEqualDistance : std::binary_function -{ - bool operator() (const IndexDistance & id, u16 dist) const { return id.second == dist; }; -}; - -u16 Battle2::Arena::GetNearestTroops(u16 pos, std::vector & res, const std::vector* black) const -{ - std::vector dists; - dists.reserve(15); - - Board::const_iterator it1 = board.begin(); - Board::const_iterator it2 = board.end(); - for(; it1 != it2; ++it1) - { - const Battle2::Stats* b = GetTroopBoard((*it1).index); - if(b) - { - // check black list - if(black && black->end() != std::find(black->begin(), black->end(), b->GetPosition())) continue; - // added - if(pos != b->GetPosition()) dists.push_back(IndexDistance(b->GetPosition(), Board::GetDistance(pos, b->GetPosition()))); - } - } - - if(1 < dists.size()) - { - std::sort(dists.begin(), dists.end(), IndexDistance::Shortest); - dists.resize(std::count_if(dists.begin(), dists.end(), std::bind2nd(IndexDistanceEqualDistance(), dists.front().second))); - } - - if(dists.size()) - { - if(res.capacity() < res.size() + dists.size()) res.reserve(res.size() + dists.size()); - std::vector::const_iterator it1 = dists.begin(); - std::vector::const_iterator it2 = dists.end(); - for(; it1 != it2; ++it1) res.push_back((*it1).first); - } - - return res.size(); -} - -bool Battle2::Arena::CanSurrenderOpponent(u8 color) const -{ - const Army::army_t* enemy = GetArmy(GetOppositeColor(color)); - const Army::army_t* army = GetArmy(color); - - return army && army->GetCommander() && army->GetCommander()->GetType() == Skill::Primary::HEROES && - enemy && enemy->GetCommander(); -} - -bool Battle2::Arena::CanRetreatOpponent(u8 color) const -{ - const Army::army_t* army = GetArmy(color); - - return army && army->GetCommander() && army->GetCommander()->GetType() == Skill::Primary::HEROES && - NULL == army->GetCommander()->inCastle(); -} - -bool Battle2::Arena::isDisableCastSpell(u8 spell, std::string* msg) const -{ - const HeroBase* hero1 = army1.GetCommander(); - const HeroBase* hero2 = army2.GetCommander(); - - // check sphere negation (only for heroes) - if((hero1 && hero1->HasArtifact(Artifact::SPHERE_NEGATION)) || - (hero2 && hero2->HasArtifact(Artifact::SPHERE_NEGATION))) - { - if(msg) *msg = _("The Sphere of Negation artifact is in effect for this battle, disabling all combat spells."); - return true; - } - - // check casted - if(current_commander) - { - if(current_commander->Modes(Heroes::SPELLCASTED)) - { - if(msg) *msg = _("You have already cast a spell this round."); - return true; - } - - if(spell == Spell::EARTHQUAKE && !castle) - { - *msg = _("That spell will affect no one!"); - return true; - } - else - if(Spell::isSummon(spell)) - { - const Army::Troop* elem = GetArmy(current_commander->GetColor())->BattleFindModes(CAP_SUMMONELEM); - bool affect = true; - if(elem) switch(spell) - { - case Spell::SUMMONEELEMENT: if(elem->GetID() != Monster::EARTH_ELEMENT) affect = false; break; - case Spell::SUMMONAELEMENT: if(elem->GetID() != Monster::AIR_ELEMENT) affect = false; break; - case Spell::SUMMONFELEMENT: if(elem->GetID() != Monster::FIRE_ELEMENT) affect = false; break; - case Spell::SUMMONWELEMENT: if(elem->GetID() != Monster::WATER_ELEMENT) affect = false; break; - default: break; - } - if(!affect) - { - *msg = _("You may only summon one type of elemental per combat."); - return true; - } - - if(0 == GetFreePositionNearHero(current_commander->GetColor())) - { - *msg = _("There is no open space adjacent to your hero to summon an Elemental to."); - return true; - } - } - else - if(spell != Spell::NONE) - { - // check army - Board::const_iterator it1 = board.begin(); - Board::const_iterator it2 = board.end(); - for(; it1 != it2; ++it1) - { - const Battle2::Stats* b = GetTroopBoard((*it1).index); - - if(b) - { - if(b->AllowApplySpell(spell, current_commander, NULL)) - return false; - } - else - // check graveyard - if(isAllowResurrectFromGraveyard(spell, (*it1).index)) - return false; - } - *msg = _("That spell will affect no one!"); - return true; - } - } - - // may be check other.. - /* - */ - - return false; -} - -bool Battle2::Arena::isAllowResurrectFromGraveyard(u8 spell, u16 cell) const -{ - if(Spell::isResurrect(spell)) - { - std::vector closed; - std::vector::const_iterator it_closed; - graveyard.GetClosedCells(closed); - - it_closed = std::find(closed.begin(), closed.end(), cell); - - if(current_commander && it_closed != closed.end()) - { - const u16 id_killed = graveyard.GetLastTroopIDFromCell(cell); - if(id_killed) - { - const Battle2::Stats* killed = GetTroopID(id_killed); - if(killed->AllowApplySpell(spell, current_commander, NULL)) return true; - } - } - } - return false; -} - -void Battle2::Arena::SetCastleTargetValue(u8 target, u8 value) -{ - switch(target) - { - case CAT_WALL1: board[8].object = value; break; - case CAT_WALL2: board[29].object = value; break; - case CAT_WALL3: board[73].object = value; break; - case CAT_WALL4: board[96].object = value; break; - - case CAT_TOWER1:if(towers[0] && towers[0]->isValid()) towers[0]->SetDestroy(); break; - case CAT_TOWER2:if(towers[2] && towers[2]->isValid()) towers[2]->SetDestroy(); break; - case CAT_TOWER3:if(towers[1] && towers[1]->isValid()) towers[1]->SetDestroy(); break; - - case CAT_BRIDGE: - if(bridge->isValid()) - { - if(interface) interface->RedrawBridgeAnimation(true); - bridge->SetDown(true); - bridge->SetDestroy(); - } - break; - - default: break; - } -} - -u8 Battle2::Arena::GetCastleTargetValue(u8 target) const -{ - switch(target) - { - case CAT_WALL1: return board[8].object; - case CAT_WALL2: return board[29].object; - case CAT_WALL3: return board[73].object; - case CAT_WALL4: return board[96].object; - - case CAT_TOWER1:return towers[0] && towers[0]->isValid(); - case CAT_TOWER2:return towers[2] && towers[2]->isValid(); - case CAT_TOWER3:return towers[1] && towers[1]->isValid(); - - case CAT_BRIDGE:return bridge->isValid(); - - default: break; - } - return 0; -} - -Battle2::Tower* Battle2::Arena::GetTower(u8 type) -{ - switch(type) - { - case TWR_LEFT: return towers[0]; - case TWR_CENTER:return towers[1]; - case TWR_RIGHT: return towers[2]; - default: break; - } - return NULL; -} - -void Battle2::Arena::PackBoard(Action & msg) const -{ - msg.Push(static_cast(board.size())); - - Board::const_iterator it = board.begin(); - while(it != board.end()) - { - msg.Push((*it).object); - msg.Push((*it).direction); - msg.Push(static_cast((*it).quality)); - ++it; - } -} - -void Battle2::Arena::UnpackBoard(Action & msg) -{ - u32 size; - msg.Pop(size); - - if(size == board.size()) - { - Board::iterator it = board.begin(); - while(it != board.end()) - { - u32 byte32; - msg.Pop((*it).object); - msg.Pop((*it).direction); - msg.Pop(byte32); - (*it).quality = byte32; - ++it; - } - } - else - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Arena::UnpackBoard: " << "incorrect param"); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_arena.h b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_arena.h deleted file mode 100644 index 4e54a4a8b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_arena.h +++ /dev/null @@ -1,237 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BATTLE2_ARENA_H -#define H2BATTLE2_ARENA_H - -#include -#include - -#include "battle2.h" -#include "gamedefs.h" - -#define ARENAW 11 -#define ARENAH 9 -#define ARENASIZE ARENAW * ARENAH - -namespace Army { class Troop; } -class Castle; -class HeroBase; - -namespace Battle2 -{ - class Arena; - class Cell; - class Stats; - class Tower; - class Catapult; - class Bridge; - class Interface; - - struct Actions : public std::list - { - void AddedRetreatAction(void); - void AddedSurrenderAction(void); - void AddedCastAction(u8, u16); - void AddedCastTeleportAction(u16, u16); - void AddedEndAction(const Stats &); - void AddedSkipAction(const Stats &, bool); - void AddedMoveAction(const Stats &, u16); - void AddedMoveAction(const Stats &, const std::vector &); - void AddedAttackAction(const Stats &, const Stats &); - void AddedMoraleAction(const Stats &, u8); - }; - - struct Board : public std::vector - { - Board(); - - s16 GetIndexAbsPosition(const Point &) const; - Rect GetArea(void) const; - void SetEnemyQuality(const Stats &); - void SetPositionQuality(const Stats &); - void SetCobjObjects(s32); - void SetCobjObject(u16, u16); - void SetCovrObjects(u16); - - void GetAbroadPositions(u16, u8, std::vector &) const; - void GetIndexesFromAbsPoints(std::vector &, const std::vector &) const; - - static bool inCastle(u16); - static bool isMoatIndex(u16); - static direction_t GetReflectDirection(u8); - static direction_t GetDirection(u16, u16); - static u16 GetDistance(u16, u16); - static bool isValidDirection(u16, u8); - static u16 GetIndexDirection(u16, u8); - }; - - class GraveyardTroop - { - public: - GraveyardTroop(const Arena &); - - void GetClosedCells(std::vector &) const; - u16 GetLastTroopIDFromCell(u16) const; - void AddTroopID(u16); - void RemoveTroopID(u16); - - private: - std::map > map; - - const Arena & arena; - }; - - class Arena - { - public: - Arena(Army::army_t &, Army::army_t &, s32, bool); - ~Arena(); - - void Turns(u16, Result &); - void RemoteTurn(const Stats &, Actions &); - void HumanTurn(const Stats &, Actions &); - - const Cell* GetCell(u16, direction_t = CENTER) const; - Cell* GetCell(u16, direction_t = CENTER); - - Stats* GetTroopBoard(u16); - const Stats* GetTroopBoard(u16) const; - - Stats* GetTroopID(u16); - const Stats* GetTroopID(u16) const; - - Stats* GetEnemyAbroadMaxQuality(u16, u8); - const Stats* GetEnemyAbroadMaxQuality(u16, u8) const; - - Stats* GetEnemyAbroadMaxQuality(const Stats &); - const Stats* GetEnemyAbroadMaxQuality(const Stats &) const; - - Stats* GetEnemyMaxQuality(u8); - const Stats* GetEnemyMaxQuality(u8) const; - - Army::army_t* GetArmy(u8); - const Army::army_t* GetArmy(u8) const; - - void GetArmyPositions(u8, std::vector &) const; - u16 GetMaxQualityPosition(const std::vector &) const; - u16 GetNearestTroops(u16, std::vector &, const std::vector* black = NULL) const; - - void DialogBattleSummary(const Result &) const; - u8 DialogBattleHero(const HeroBase &) const; - - void FadeArena(void) const; - - const std::vector & GetUsageSpells(void) const; - void AddSpell(u8); - - u16 GetPath(const Stats &, u16, std::vector &); - void DumpBoard(void) const; - - Interface* GetInterface(void); - Tower* GetTower(u8); - - void ApplyAction(Action &); - - void GetTargetsForDamage(Stats &, Stats &, std::vector &); - void TargetsApplyDamage(Stats &, Stats &, std::vector &); - - void GetTargetsForSpells(const HeroBase*, const u8, const u16, std::vector &); - void TargetsApplySpell(const HeroBase*, const u8, std::vector &); - - void UnpackBoard(Action &); - void PackBoard(Action &) const; - - u8 GetCastleTargetValue(u8) const; - void SetCastleTargetValue(u8, u8); - - bool isDisableCastSpell(u8 spell, std::string *msg) const; - bool isAllowResurrectFromGraveyard(u8, u16) const; - - u8 GetOppositeColor(u8) const; - - void TowerAction(void); - void CatapultAction(void); - - bool CanSurrenderOpponent(u8 color) const; - bool CanRetreatOpponent(u8 color) const; - - void ResetBoard(void); - void ScanPassabilityBoard(const Stats &, bool skip_speed = false); - static u16 GetShortDistance(u16, const std::vector &); - void GetPassableQualityPositions(const Stats &, std::vector &); - u16 GetFreePositionNearHero(u8) const; - - // uniq spells - void SpellActionSummonElemental(const HeroBase*, u8); - void SpellActionTeleport(u16, u16); - void SpellActionEarthQuake(void); - void SpellActionMirrorImage(Stats &); - - // battle_ai - void AITurn(const Stats &, Actions &); - void AIMagicAction(const Stats &, Actions &, const Stats*); - - // battle_action - void ApplyActionRetreat(Action &); - void ApplyActionSurrender(Action &); - void ApplyActionAttack(Action &); - void ApplyActionMove(Action &); - void ApplyActionEnd(Action &); - void ApplyActionSkip(Action &); - void ApplyActionMorale(Action &); - void ApplyActionLuck(Action &); - void ApplyActionSpellCast(Action &); - void ApplyActionTower(Action &); - void ApplyActionCatapult(Action &); - void BattleProcess(Stats &, Stats &); - - protected: - friend class Interface; - friend class Cell; - friend class Stats; - friend class Tower; - friend class Bridge; - friend class Catapult; - - Army::army_t & army1; - Army::army_t & army2; - - const Castle* castle; - HeroBase* current_commander; - - Tower* towers[3]; - Catapult* catapult; - Bridge* bridge; - - Interface* interface; - Result *result_game; - - GraveyardTroop graveyard; - std::vector usage_spells; - - Board board; - ICN::icn_t icn_covr; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_bridge.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_bridge.cpp deleted file mode 100644 index cf9257081..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_bridge.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "castle.h" -#include "battle_stats.h" -#include "battle_cell.h" -#include "battle_bridge.h" - -Battle2::Bridge::Bridge(Arena & a) : arena(a), destroy(false), down(false) -{ -} - -bool Battle2::Bridge::isIndex(u16 index) -{ - switch(index) - { - case 49: - case 50: return true; - default: break; - } - return false; -} - -bool Battle2::Bridge::isValid(void) const -{ - return !isDestroy(); -} - -bool Battle2::Bridge::isDestroy(void) const -{ - return destroy; -} - -bool Battle2::Bridge::isDown(void) const -{ - return down || isDestroy(); -} - -void Battle2::Bridge::SetDown(bool f) -{ - down = f; -} - -bool Battle2::Bridge::AllowUp(void) -{ - return NULL == arena.GetTroopBoard(49) && NULL == arena.GetTroopBoard(50); -} - -bool Battle2::Bridge::NeedDown(const Stats & b, u16 pos2) -{ - const u16 pos1 = b.GetPosition(); - - if(pos2 == 50) - { - if(pos1 == 51) return true; - if((pos1 == 61 || pos1 == 39) && b.GetColor() == arena.castle->GetColor()) return true; - } - else - if(pos2 == 49) - { - if(pos1 != 50 && b.GetColor() == arena.castle->GetColor()) return true; - } - - return false; -} - -bool Battle2::Bridge::isPassable(u8 color) const -{ - return color == arena.castle->GetColor() || isDown(); -} - -void Battle2::Bridge::SetDestroy(void) -{ - destroy = true; - arena.board[49].object = 0; - arena.board[50].object = 0; -} - -void Battle2::Bridge::SetPassable(const Stats & b) -{ - if(Board::inCastle(b.GetPosition()) || b.GetColor() == arena.castle->GetColor()) - { - arena.board[49].object = 0; - arena.board[50].object = 0; - } - else - { - arena.board[49].object = 1; - arena.board[50].object = 1; - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_bridge.h b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_bridge.h deleted file mode 100644 index 203e2dc16..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_bridge.h +++ /dev/null @@ -1,58 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BATTLE2_BRIDGE_H -#define H2BATTLE2_BRIDGE_H - -#include "gamedefs.h" -#include "battle_arena.h" - -namespace Battle2 -{ - class Stats; - - class Bridge - { - public: - Bridge(Arena & a); - - void SetDestroy(void); - void SetDown(bool); - void SetPassable(const Stats &); - - bool AllowUp(void); - bool NeedDown(const Stats &, u16); - bool isPassable(u8) const; - bool isValid(void) const; - bool isDestroy(void) const; - bool isDown(void) const; - - static bool isIndex(u16); - - private: - Arena & arena; - bool destroy; - bool down; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_catapult.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_catapult.cpp deleted file mode 100644 index e7b6d52d3..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_catapult.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "castle.h" -#include "artifact.h" -#include "skill.h" -#include "settings.h" -#include "heroes_base.h" -#include "battle_arena.h" -#include "battle_cell.h" -#include "battle_tower.h" -#include "battle_bridge.h" -#include "battle_catapult.h" - -Battle2::Catapult::Catapult(const HeroBase & hero, bool fortification, Arena & a) : arena(a), cat_shots(1), cat_first(20), cat_miss(true), cat_fort(fortification) -{ - switch(hero.GetLevelSkill(Skill::Secondary::BALLISTICS)) - { - case Skill::Level::BASIC: - cat_first = 40; - cat_miss = false; - break; - - case Skill::Level::ADVANCED: - cat_first = 80; - cat_shots += 1; - cat_miss = false; - break; - - case Skill::Level::EXPERT: - cat_first = 100; - cat_shots += 1; - cat_miss = false; - break; - - default: break; - } - - if(hero.HasArtifact(Artifact::BALLISTA)) cat_shots += 1; -} - -u8 Battle2::Catapult::GetShots(void) const -{ - return cat_shots; -} - -u8 Battle2::Catapult::GetDamage(u8 target) -{ - u8 value = arena.GetCastleTargetValue(target); - - switch(target) - { - case CAT_WALL1: - case CAT_WALL2: - case CAT_WALL3: - case CAT_WALL4: - if(value) - { - if(cat_first == 100 || cat_first >= Rand::Get(1, 100)) - { - // value = value; - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Catapult::GetDamage: " << "from one blow capability"); - } - else - value = 1; - } - break; - - case CAT_MISS: DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Catapult::GetDamage: " << " miss!"); break; - - default: break; - } - - return value; -} - -Point Battle2::Catapult::GetTargetPosition(u8 target) const -{ - Point res; - - switch(target) - { - case CAT_WALL1: res = Point(475, 45); break; - case CAT_WALL2: res = Point(420, 115); break; - case CAT_WALL3: res = Point(415, 280); break; - case CAT_WALL4: res = Point(490, 390); break; - case CAT_TOWER1:res = Point(430, 40); break; - case CAT_TOWER2:res = Point(430, 300); break; - case CAT_TOWER3:res = Point(580, 160); break; - case CAT_BRIDGE:res = Point(400, 195); break; - case CAT_MISS: res = Point(610, 320); break; - - default: break; - } - - return res; -} - -u8 Battle2::Catapult::GetTarget(const std::vector & values) const -{ - std::vector targets; - targets.reserve(4); - - // check walls - if(0 != values[CAT_WALL1]) targets.push_back(CAT_WALL1); - if(0 != values[CAT_WALL2]) targets.push_back(CAT_WALL2); - if(0 != values[CAT_WALL3]) targets.push_back(CAT_WALL3); - if(0 != values[CAT_WALL4]) targets.push_back(CAT_WALL4); - - // check right/left towers - if(targets.empty()) - { - if(values[CAT_TOWER1]) targets.push_back(CAT_TOWER1); - if(values[CAT_TOWER2]) targets.push_back(CAT_TOWER2); - } - - // check bridge - if(targets.empty()) - { - if(values[CAT_BRIDGE]) targets.push_back(CAT_BRIDGE); - } - - // check general tower - if(targets.empty()) - { - if(values[CAT_TOWER3]) targets.push_back(CAT_TOWER3); - } - - if(targets.size()) - { - // miss for 30% - return cat_miss && 7 > Rand::Get(1, 20) ? CAT_MISS : (1 < targets.size() ? *Rand::Get(targets) : targets.front()); - } - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Catapult::ApplyDamage: " << "target not found.."); - - return 0; -} - -void Battle2::Catapult::Action(void) -{ - Battle2::Action action; - action.SetID(MSG_BATTLE_CATAPULT); - - u8 shots = GetShots(); - std::vector values; - values.resize(CAT_MISS, 0); - - values[CAT_WALL1] = arena.GetCastleTargetValue(CAT_WALL1); - values[CAT_WALL2] = arena.GetCastleTargetValue(CAT_WALL2); - values[CAT_WALL3] = arena.GetCastleTargetValue(CAT_WALL3); - values[CAT_WALL4] = arena.GetCastleTargetValue(CAT_WALL4); - values[CAT_TOWER1] = arena.GetCastleTargetValue(CAT_TOWER1); - values[CAT_TOWER2] = arena.GetCastleTargetValue(CAT_TOWER2); - values[CAT_TOWER3] = arena.GetCastleTargetValue(CAT_TOWER3); - values[CAT_BRIDGE] = arena.GetCastleTargetValue(CAT_BRIDGE); - - action.Push(shots); - while(shots--) - { - const u8 target = GetTarget(values); - const u8 damage = GetDamage(target); - action.Push(target); - action.Push(damage); - values[target] -= damage; - } - - arena.ApplyAction(action); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_catapult.h b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_catapult.h deleted file mode 100644 index 2b6090544..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_catapult.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BATTLE2_CATAPULT_H -#define H2BATTLE2_CATAPULT_H - -#include "gamedefs.h" - -class HeroBase; - -namespace Battle2 -{ - class Catapult - { - public: - Catapult(const HeroBase &, bool, Arena &); - - Point GetTargetPosition(u8) const; - u8 GetShots(void) const; - u8 GetTarget(const std::vector &) const; - u8 GetDamage(u8); - void Action(void); - - private: - Arena & arena; - u8 cat_shots; - u8 cat_first; - bool cat_miss; - bool cat_fort; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_cell.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_cell.cpp deleted file mode 100644 index 686c24550..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_cell.cpp +++ /dev/null @@ -1,251 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "army_troop.h" -#include "battle_arena.h" -#include "settings.h" -#include "battle_stats.h" -#include "battle_cell.h" - -#define CELLW 45 -#define CELLH 52 -#define CELLW2 23 -#define CELLH2 26 - -Battle2::Cell::Cell(u16 i, const Rect* area, Arena & a) : index(i), arena(&a) -{ - object = 0; - direction = UNKNOWN; - quality = 0; - - if(Settings::Get().QVGA()) - { - pos.x = (area ? area->x : 0) + 45 - ((i / ARENAW) % 2 ? CELLW2 / 2 : 0) + (CELLW2 - 1) * (i % ARENAW); - pos.y = (area ? area->y + area->h - 188 : 0) + ((CELLH2 / 4) * 3) * (i / ARENAW); - pos.w = CELLW2; - pos.h = CELLH2; - } - else - { - pos.x = (area ? area->x : 0) + 88 - ((i / ARENAW) % 2 ? CELLW / 2 : 0) + (CELLW - 1) * (i % ARENAW); - pos.y = (area ? area->y : 0) + 85 + ((CELLH / 4) * 3 - 1) * (i / ARENAW); - pos.w = CELLW; - pos.h = CELLH; - } -} - -bool Battle2::Cell::isPositionIncludePoint(const Point & pt) const -{ - return pos & pt; -} - -u16 Battle2::Cell::GetIndex(void) const -{ - return index; -} - -u8 Battle2::Cell::GetDirection(void) const -{ - return direction; -} - -const Rect & Battle2::Cell::GetPos(void) const -{ - return pos; -} - -bool GetReflectFromDirection(Battle2::direction_t dir) -{ - switch(dir) - { - case Battle2::TOP_LEFT: - case Battle2::BOTTOM_LEFT: - case Battle2::LEFT: - return true; - - default: break; - } - return false; -} - -bool Battle2::Cell::isPassable(const Stats & b, const Cell & from) const -{ - if(b.isWide()) - { - switch(Board::GetDirection(from.index, index)) - { - case BOTTOM_RIGHT: - case TOP_RIGHT: - { - if(CENTER == from.direction && b.isReflect()) return false; - else - if(GetReflectFromDirection(Board::GetReflectDirection(from.direction))) return false; - const Cell* cell2 = arena->GetCell(index, LEFT); - return cell2 && cell2->isPassable() && isPassable(); - } - - case BOTTOM_LEFT: - case TOP_LEFT: - { - if(CENTER == from.direction && !b.isReflect()) return false; - else - if(!GetReflectFromDirection(Board::GetReflectDirection(from.direction))) return false; - const Cell* cell2 = arena->GetCell(index, RIGHT); - return cell2 && cell2->isPassable() && isPassable(); - } - - case LEFT: - case RIGHT: - return isPassable() || index == b.GetTailIndex() || index == b.GetPosition(); - - default: break; - } - } - return isPassable(); -} - -bool Battle2::Cell::isPassable(const Stats & b, bool check_reflect) const -{ - if(b.isWide()) - { - if(index == b.GetTailIndex() || index == b.GetPosition()) return true; - - if(check_reflect) - { - const Cell* cell = arena->GetCell(index, b.isReflect() ? RIGHT : LEFT); - return cell && - (cell->isPassable() || cell->index == b.GetTailIndex() || cell->index == b.GetPosition()) && - isPassable(); - } - else - { - Cell* left = arena->GetCell(index, LEFT); - Cell* right = arena->GetCell(index, RIGHT); - return ((left && (left->isPassable() || left->index == b.GetTailIndex() || left->index == b.GetPosition())) || - (right && (right->isPassable() || right->index == b.GetTailIndex() || right->index == b.GetPosition()))) && - isPassable(); - } - } - - return isPassable(); -} - -bool Battle2::Cell::isPassable(void) const -{ - return NULL == arena->GetTroopBoard(index) && 0 == object; -} - -void Battle2::Cell::Reset(void) -{ - direction = UNKNOWN; - quality = 0; -} - -void Battle2::Cell::ResetDirection(void) -{ - direction = UNKNOWN; -} - -void Battle2::Cell::SetEnemyQuality(const Stats & my) -{ - const Stats* b = arena->GetTroopBoard(index); - if(b && b->GetColor() != my.GetColor() && my.isValid()) - { - // strength monster quality - quality = b->GetScoreQuality(my) * b->HowMuchWillKilled(my.GetDamage(*b)); - quality += b->GetExtraQuality(quality); - - if(quality < 1) quality = 1; - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Cell::SetEnemyQuality: " << quality << " for " << b->GetName()); - } -} - -void Battle2::Cell::SetPositionQuality(const Stats & a) -{ - const Stats* b = arena->GetTroopBoard(index); - if(b && b->isWide() && b->GetTailIndex() == index) return; - if(b && b->GetColor() != a.GetColor()) - { - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - Cell* cell = arena->GetCell(index, dir); - if(cell && cell->isPassable()) cell->quality += quality; - } - - // update for wide - if(b->isWide()) - { - Cell* cell = NULL; - if(b->isReflect()) - { - cell = arena->GetCell(b->GetTailIndex(), TOP_RIGHT); - if(cell && cell->isPassable()) cell->quality += quality; - - cell = arena->GetCell(b->GetTailIndex(), RIGHT); - if(cell && cell->isPassable()) cell->quality += quality; - - cell = arena->GetCell(b->GetTailIndex(), BOTTOM_RIGHT); - if(cell && cell->isPassable()) cell->quality += quality; - } - else - { - cell = arena->GetCell(b->GetTailIndex(), TOP_LEFT); - if(cell && cell->isPassable()) cell->quality += quality; - - cell = arena->GetCell(b->GetTailIndex(), LEFT); - if(cell && cell->isPassable()) cell->quality += quality; - - cell = arena->GetCell(b->GetTailIndex(), BOTTOM_LEFT); - if(cell && cell->isPassable()) cell->quality += quality; - } - } - } -} - -void Battle2::Cell::SetPassabilityAbroad(const Stats & b, std::vector & opens) -{ - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - Cell* cell = arena->GetCell(index, dir); - if(cell && UNKNOWN == cell->direction && cell->isPassable(b, *this)) - { - cell->direction = Board::GetReflectDirection(dir); - opens.push_back(cell->index); - } - } - - if(b.isWide()) - { - Cell* tail = arena->GetCell(b.GetTailIndex()); - - if(tail) - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - Cell* cell = arena->GetCell(tail->index, dir); - if(cell && UNKNOWN == cell->direction && cell->isPassable(b, *tail)) - { - cell->direction = Board::GetReflectDirection(dir); - opens.push_back(cell->index); - } - } - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_cell.h b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_cell.h deleted file mode 100644 index 8df76ceab..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_cell.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BATTLE2_CELL_H -#define H2BATTLE2_CELL_H - -#include "gamedefs.h" -#include "battle_arena.h" - -namespace Army { class Troop; } - -namespace Battle2 -{ - class Cell - { - public: - Cell(u16, const Rect*, Arena &); - void Reset(void); - void ResetDirection(void); - void SetEnemyQuality(const Stats &); - void SetPositionQuality(const Stats &); - bool isPassable(const Stats &, const Cell &) const; - bool isPassable(const Stats &, bool check_reflect) const; - bool isPassable(void) const; - bool isPositionIncludePoint(const Point &) const; - u16 GetIndex(void) const; - u8 GetDirection(void) const; - const Rect & GetPos(void) const; - - void SetPassabilityAbroad(const Stats & b, std::vector &); - - u16 index; - Rect pos; - u8 object; - u8 direction; - s32 quality; - Arena* arena; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_dialogs.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_dialogs.cpp deleted file mode 100644 index 9134d7fbe..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_dialogs.cpp +++ /dev/null @@ -1,545 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "engine.h" -#include "cursor.h" -#include "settings.h" -#include "agg.h" -#include "button.h" -#include "army.h" -#include "text.h" -#include "portrait.h" -#include "morale.h" -#include "luck.h" -#include "heroes.h" -#include "battle_interface.h" -#include "battle_arena.h" -#include "battle2.h" - -void Battle2::DialogBattleSettings(void) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - Settings & conf = Settings::Get(); - - cursor.Hide(); - - const Sprite & dialog = AGG::GetICN((conf.EvilInterface() ? ICN::CSPANBKE : ICN::CSPANBKG), 0); - - Rect pos_rt; - pos_rt.x = (display.w() - dialog.w()) / 2; - pos_rt.y = (display.h() - dialog.h()) / 2; - pos_rt.w = dialog.w(); - pos_rt.h = dialog.h(); - - Background back(pos_rt); - back.Save(); - - display.FillRect(0x00, 0x00, 0x00, back.GetRect()); - display.Blit(dialog, pos_rt.x, pos_rt.y); - - Button btn_ok(pos_rt.x + 113, pos_rt.y + 252, (conf.EvilInterface() ? ICN::CSPANBTE : ICN::CSPANBTN), 0, 1); - - Button opt_grid(pos_rt.x + 36, pos_rt.y + 157, ICN::CSPANEL, 8, 9); - Button opt_shadow_movement(pos_rt.x + 128, pos_rt.y + 157, ICN::CSPANEL, 10, 11); - Button opt_shadow_cursor(pos_rt.x + 220, pos_rt.y + 157, ICN::CSPANEL, 12, 13); - - btn_ok.Draw(); - - if(conf.ExtBattleShowGrid()) opt_grid.Press(); - if(conf.ExtBattleShowMoveShadow()) opt_shadow_movement.Press(); - if(conf.ExtBattleShowMouseShadow()) opt_shadow_cursor.Press(); - - opt_grid.Draw(); - opt_shadow_movement.Draw(); - opt_shadow_cursor.Draw(); - - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - le.MousePressLeft(btn_ok) ? btn_ok.PressDraw() : btn_ok.ReleaseDraw(); - - if(le.MouseClickLeft(opt_grid)) - { - conf.SetBattleGrid(!conf.ExtBattleShowGrid()); - cursor.Hide(); - opt_grid.isPressed() ? opt_grid.Release() : opt_grid.Press(); - opt_grid.Draw(); - cursor.Show(); - display.Flip(); - } - - if(le.MouseClickLeft(opt_shadow_movement)) - { - conf.SetBattleMovementShaded(!conf.ExtBattleShowMoveShadow()); - cursor.Hide(); - opt_shadow_movement.isPressed() ? opt_shadow_movement.Release() : opt_shadow_movement.Press(); - opt_shadow_movement.Draw(); - cursor.Show(); - display.Flip(); - } - - if(le.MouseClickLeft(opt_shadow_cursor)) - { - conf.SetBattleMouseShaded(!conf.ExtBattleShowMouseShadow()); - cursor.Hide(); - opt_shadow_cursor.isPressed() ? opt_shadow_cursor.Release() : opt_shadow_cursor.Press(); - opt_shadow_cursor.Draw(); - cursor.Show(); - display.Flip(); - } - - // exit - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(btn_ok)) break; - } - - // restore background - cursor.Hide(); - back.Restore(); - cursor.Show(); - display.Flip(); -} - -void GetSummaryParams(u8 res1, u8 res2, const std::string & name, u32 exp, ICN::icn_t & icn_anim, std::string & msg) -{ - if(res1 & Battle2::RESULT_WINS) - { - icn_anim = ICN::WINCMBT; - if(res2 & Battle2::RESULT_SURRENDER) - msg.append(_("The enemy has surrendered!")); - else - if(res2 & Battle2::RESULT_RETREAT) - msg.append(_("The enemy has fled!")); - else - msg.append(_("A glorious victory!")); - msg.append("\n"); - msg.append(_("For valor in combat, %{name} receives %{exp} experience")); - String::Replace(msg, "%{name}", name); - String::Replace(msg, "%{exp}", exp); - } - else - if(res1 & Battle2::RESULT_RETREAT) - { - icn_anim = ICN::CMBTFLE3; - msg.append(_("The cowardly %{name} flees from battle.")); - String::Replace(msg, "%{name}", name); - } - else - if(res1 & Battle2::RESULT_SURRENDER) - { - icn_anim = ICN::CMBTSURR; - msg.append(_("%{name} surrenders to the enemy, and departs in shame.")); - String::Replace(msg, "%{name}", name); - } - else - { - icn_anim = ICN::CMBTLOS3; - msg.append(_("Your force suffer a bitter defeat, and %{name} abandons your cause.")); - String::Replace(msg, "%{name}", name); - } -} - -void Battle2::Arena::DialogBattleSummary(const Result & res) const -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - Settings & conf = Settings::Get(); - - Army::army_t killed1; - army1.BattleExportKilled(killed1); - Army::army_t killed2; - army2.BattleExportKilled(killed2); - - - cursor.Hide(); - cursor.SetThemes(Cursor::POINTER); - - std::string msg; - ICN::icn_t icn_anim = ICN::UNKNOWN; - - if((res.army1 & RESULT_WINS) && army1.GetCommander() && Game::AI != army1.GetCommander()->GetControl()) - { - GetSummaryParams(res.army1, res.army2, army1.GetCommander()->GetName(), res.exp1, icn_anim, msg); - if(conf.Music()) AGG::PlayMusic(MUS::BATTLEWIN, false); - } - else - if((res.army2 & RESULT_WINS) && army2.GetCommander() && Game::AI != army2.GetCommander()->GetControl()) - { - GetSummaryParams(res.army2, res.army1, army2.GetCommander()->GetName(), res.exp2, icn_anim, msg); - if(conf.Music()) AGG::PlayMusic(MUS::BATTLEWIN, false); - } - else - if(army1.GetCommander() && Game::AI != army1.GetCommander()->GetControl()) - { - GetSummaryParams(res.army1, res.army2, army1.GetCommander()->GetName(), res.exp1, icn_anim, msg); - if(conf.Music()) AGG::PlayMusic(MUS::BATTLELOSE, false); - } - else - if(army2.GetCommander() && Game::AI != army2.GetCommander()->GetControl()) - { - GetSummaryParams(res.army2, res.army1, army2.GetCommander()->GetName(), res.exp2, icn_anim, msg); - if(conf.Music()) AGG::PlayMusic(MUS::BATTLELOSE, false); - } - else - // AI move - if(army1.GetCommander() && Game::AI == army1.GetCommander()->GetControl()) - { - // AI wins - if(res.army1 & RESULT_WINS) - { - icn_anim = ICN::CMBTLOS3; - msg.append(_("Your force suffer a bitter defeat.")); - } - else - // Human wins - if(res.army2 & RESULT_WINS) - { - icn_anim = ICN::WINCMBT; - msg.append(_("A glorious victory!")); - } - } - - const Sprite & dialog = AGG::GetICN((conf.EvilInterface() ? ICN::WINLOSEE : ICN::WINLOSE), 0); - - Rect pos_rt; - pos_rt.x = (display.w() - dialog.w()) / 2; - pos_rt.y = (display.h() - (conf.QVGA() ? 224 : dialog.h())) / 2; - pos_rt.w = dialog.w(); - pos_rt.h = conf.QVGA() ? 224 : dialog.h(); - - Background back(pos_rt); - back.Save(); - - if(conf.QVGA()) - { - display.Blit(dialog, Rect(0, 232, pos_rt.w, 224), pos_rt.x, pos_rt.y); - display.Blit(dialog, Rect(0, 0, pos_rt.w, 30), pos_rt.x, pos_rt.y); - } - else - display.Blit(dialog, pos_rt.x, pos_rt.y); - - const u8 anime_ox = 47; - const u8 anime_oy = 36; - - if(!conf.QVGA()) - { - const Sprite & sprite1 = AGG::GetICN(icn_anim, 0); - const Sprite & sprite2 = AGG::GetICN(icn_anim, 1); - - display.Blit(sprite1, pos_rt.x + anime_ox + sprite1.x(), pos_rt.y + anime_oy + sprite1.y()); - display.Blit(sprite2, pos_rt.x + anime_ox + sprite2.x(), pos_rt.y + anime_oy + sprite2.y()); - } - - Button btn_ok(pos_rt.x + 121, pos_rt.y + (conf.QVGA() ? 176 : 410), (conf.EvilInterface() ? ICN::WINCMBBE : ICN::WINCMBTB), 0, 1); - - TextBox box(msg, Font::BIG, 270); - box.Blit(pos_rt.x + 25, pos_rt.y + (conf.QVGA() ? 20 : 175)); - - // battlefield casualties - Text text(_("Battlefield Casualties"), Font::SMALL); - text.Blit(pos_rt.x + (pos_rt.w - text.w()) / 2, pos_rt.y + (conf.QVGA() ? 58 : 270)); - - // attacker - text.Set(_("Attacker"), Font::SMALL); - text.Blit(pos_rt.x + (pos_rt.w - text.w()) / 2, pos_rt.y + (conf.QVGA() ? 70 : 285)); - - if(killed1.isValid()) - killed1.DrawMons32Line(pos_rt.x + 25, pos_rt.y + (conf.QVGA() ? 83 : 303), 270); - else - { - text.Set("None", Font::SMALL); - text.Blit(pos_rt.x + (pos_rt.w - text.w()) / 2, pos_rt.y + (conf.QVGA() ? 80 : 300)); - } - - // defender - text.Set(_("Defender"), Font::SMALL); - text.Blit(pos_rt.x + (pos_rt.w - text.w()) / 2, pos_rt.y + (conf.QVGA() ? 120 : 345)); - - if(killed2.isValid()) - killed2.DrawMons32Line(pos_rt.x + 25, pos_rt.y + (conf.QVGA() ? 138 : 363), 270); - else - { - text.Set("None", Font::SMALL); - text.Blit(pos_rt.x + (pos_rt.w - text.w()) / 2, pos_rt.y + (conf.QVGA() ? 135 : 360)); - } - - btn_ok.Draw(); - - cursor.Show(); - display.Flip(); - - u32 frame = 0; - - while(le.HandleEvents()) - { - le.MousePressLeft(btn_ok) ? btn_ok.PressDraw() : btn_ok.ReleaseDraw(); - - // exit - if(HotKeyCloseWindow || le.MouseClickLeft(btn_ok)) break; - - // animation - if(!conf.QVGA() && Game::AnimateInfrequent(Game::BATTLE_DIALOG_DELAY)) - { - const Sprite & sprite1 = AGG::GetICN(icn_anim, 0); - const Sprite & sprite2 = AGG::GetICN(icn_anim, ICN::AnimationFrame(icn_anim, 1, frame)); - - cursor.Hide(); - display.Blit(sprite1, pos_rt.x + anime_ox + sprite1.x(), pos_rt.y + anime_oy + sprite1.y()); - display.Blit(sprite2, pos_rt.x + anime_ox + sprite2.x(), pos_rt.y + anime_oy + sprite2.y()); - cursor.Show(); - display.Flip(); - ++frame; - } - } - - // restore background - cursor.Hide(); - back.Restore(); - cursor.Show(); - display.Flip(); -} - -u8 Battle2::Arena::DialogBattleHero(const HeroBase & hero) const -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - Settings & conf = Settings::Get(); - - cursor.Hide(); - cursor.SetThemes(Cursor::POINTER); - - const bool readonly = conf.MyColor() != hero.GetColor(); - const Sprite & dialog = AGG::GetICN((conf.EvilInterface() ? ICN::VGENBKGE : ICN::VGENBKG), 0); - - Rect pos_rt; - pos_rt.x = (display.w() - dialog.w()) / 2; - pos_rt.y = (display.h() - dialog.h()) / 2; - pos_rt.w = dialog.w(); - pos_rt.h = dialog.h(); - - Background back(pos_rt); - back.Save(); - - display.Blit(dialog, pos_rt.x, pos_rt.y); - display.Blit(Portrait::Get(hero, Portrait::BIG), pos_rt.x + 27, pos_rt.y + 42); - - u8 col = (Color::GRAY == hero.GetColor() ? 1 : Color::GetIndex(hero.GetColor()) + 1); - display.Blit(AGG::GetICN(ICN::VIEWGEN, col), pos_rt.x + 148, pos_rt.y + 36); - - Point tp(pos_rt); - - std::string str; - Text text; - text.Set(Font::SMALL); - str = _("%{name} the %{race}"); - String::Replace(str, "%{name}", hero.GetName()); - String::Replace(str, "%{race}", Race::String(hero.GetRace())); - text.Set(str); - tp.x = pos_rt.x + (pos_rt.w - text.w()) / 2; - tp.y += 10; - text.Blit(tp); - str = _("Attack") + std::string(": "); - String::AddInt(str, hero.GetAttack()); - text.Set(str); - tp.x = pos_rt.x + 205 - text.w() / 2; - tp.y = pos_rt.y + 40; - text.Blit(tp); - str = _("Defense") + std::string(": "); - String::AddInt(str, hero.GetDefense()); - text.Set(str); - tp.x = pos_rt.x + 205 - text.w() / 2; - tp.y = pos_rt.y + 51; - text.Blit(tp); - str = _("Spell Power") + std::string(": "); - String::AddInt(str, hero.GetPower()); - text.Set(str); - tp.x = pos_rt.x + 205 - text.w() / 2; - tp.y = pos_rt.y + 62; - text.Blit(tp); - str = _("Knowledge") + std::string(": "); - String::AddInt(str, hero.GetKnowledge()); - text.Set(str); - tp.x = pos_rt.x + 205 - text.w() / 2; - tp.y = pos_rt.y + 73; - text.Blit(tp); - str = _("Morale") + std::string(": ") + Morale::String(hero.GetMorale()); - text.Set(str); - tp.x = pos_rt.x + 205 - text.w() / 2; - tp.y = pos_rt.y + 84; - text.Blit(tp); - str = _("Luck") + std::string(": ") + Luck::String(hero.GetLuck()); - text.Set(str); - tp.x = pos_rt.x + 205 - text.w() / 2; - tp.y = pos_rt.y + 95; - text.Blit(tp); - str = _("Spell Points") + std::string(": "); - String::AddInt(str, hero.GetSpellPoints()); - str += "/"; - String::AddInt(str, hero.GetMaxSpellPoints()); - text.Set(str); - tp.x = pos_rt.x + 205 - text.w() / 2; - tp.y = pos_rt.y + 117; - text.Blit(tp); - - Button btnCast(pos_rt.x + 30, pos_rt.y + 148, ICN::VIEWGEN, 9, 10); - Button btnRetreat(pos_rt.x + 89, pos_rt.y + 148, ICN::VIEWGEN, 11, 12); - Button btnSurrender(pos_rt.x + 148, pos_rt.y + 148, ICN::VIEWGEN, 13, 14); - Button btnClose(pos_rt.x + 207, pos_rt.y + 148, ICN::VIEWGEN, 15, 16); - - btnCast.SetDisable(readonly || !hero.HaveSpellBook() || hero.Modes(Heroes::SPELLCASTED)); - btnRetreat.SetDisable(readonly || !CanRetreatOpponent(hero.GetColor())); - btnSurrender.SetDisable(readonly || !CanSurrenderOpponent(hero.GetColor())); - - btnCast.Draw(); - btnRetreat.Draw(); - btnSurrender.Draw(); - btnClose.Draw(); - - if(!conf.QVGA()) - { - Surface shadow(btnCast.w, btnCast.h); - shadow.Fill(0, 0, 0); - shadow.SetAlpha(80); - if(btnCast.isDisable()) display.Blit(shadow, btnCast); - if(btnRetreat.isDisable()) display.Blit(shadow, btnRetreat); - if(btnSurrender.isDisable()) display.Blit(shadow, btnSurrender); - } - - u8 result = 0; - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents() && !result) - { - btnCast.isEnable() && le.MousePressLeft(btnCast) ? btnCast.PressDraw() : btnCast.ReleaseDraw(); - btnRetreat.isEnable() && le.MousePressLeft(btnRetreat) ? btnRetreat.PressDraw() : btnRetreat.ReleaseDraw(); - btnSurrender.isEnable() && le.MousePressLeft(btnSurrender) ? btnSurrender.PressDraw() : btnSurrender.ReleaseDraw(); - le.MousePressLeft(btnClose) ? btnClose.PressDraw() : btnClose.ReleaseDraw(); - - if(Game::HotKeyPress(Game::EVENT_BATTLE_CASTSPELL) || - (btnCast.isEnable() && le.MouseClickLeft(btnCast))) result = 1; - - if(Game::HotKeyPress(Game::EVENT_BATTLE_RETREAT) || - (btnRetreat.isEnable() && le.MouseClickLeft(btnRetreat))) result = 2; - - if(Game::HotKeyPress(Game::EVENT_BATTLE_SURRENDER) || - (btnSurrender.isEnable() && le.MouseClickLeft(btnSurrender))) result = 3; - - if(le.MousePressRight(btnCast)) - Dialog::Message(_("Cast Spell"), _("Cast a magical spell. You may only cast one spell per combat round. The round is reset when every creature has had a turn"), Font::BIG); - else - if(le.MousePressRight(btnRetreat)) - Dialog::Message(_("Retreat"), _("Retreat your hero, abandoning your creatures. Your hero will be available for you to recruit again, however, the hero will have only a novice hero's forces."), Font::BIG); - else - if(le.MousePressRight(btnSurrender)) - Dialog::Message(_("Surrender"), _("Surrendering costs gold. However if you pay the ransom, the hero and all of his or her surviving creatures will be available to recruit again."), Font::BIG); - else - if(le.MousePressRight(btnClose)) - Dialog::Message(_("Cancel"), _("Return to the battle."), Font::BIG); - - // exit - if(HotKeyCloseWindow || le.MouseClickLeft(btnClose)) break; - } - - cursor.Hide(); - back.Restore(); - cursor.Show(); - display.Flip(); - - return result; -} - -bool Battle2::DialogBattleSurrender(const HeroBase & hero, u32 cost) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - Settings & conf = Settings::Get(); - - cursor.Hide(); - cursor.SetThemes(Cursor::POINTER); - - const Sprite & dialog = AGG::GetICN(conf.EvilInterface() ? ICN::SURDRBKE : ICN::SURDRBKG, 0); - - Rect pos_rt; - pos_rt.x = (display.w() - dialog.w() + 16) / 2; - pos_rt.y = (display.h() - dialog.h() + 16) / 2; - pos_rt.w = dialog.w(); - pos_rt.h = dialog.h(); - - Background back(pos_rt); - back.Save(); - - display.Blit(dialog, pos_rt.x, pos_rt.y); - - const ICN::icn_t icn = conf.EvilInterface() ? ICN::SURRENDE : ICN::SURRENDR; - - Button btnAccept(pos_rt.x + 90, pos_rt.y + 150, icn, 0, 1); - Button btnDecline(pos_rt.x + 295, pos_rt.y + 150, icn, 2, 3); - - btnAccept.Draw(); - btnDecline.Draw(); - - const Sprite & window = AGG::GetICN(icn, 4); - display.Blit(window, pos_rt.x + 54, pos_rt.y + 30); - display.Blit(Portrait::Get(hero, Portrait::BIG), pos_rt.x + 58, pos_rt.y + 38); - - std::string str = _("%{name} states:"); - String::Replace(str, "%{name}", hero.GetName()); - Text text(str, Font::BIG); - text.Blit(pos_rt.x + 320 - text.w() / 2, pos_rt.y + 30); - - str = _("I will accept your surrender and grant you and your toops safe passage for the price of %{price} gold."); - String::Replace(str, "%{price}", cost); - - TextBox box(str, Font::BIG, 275); - box.Blit(pos_rt.x + 175, pos_rt.y + 65); - u8 result = 0; - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents() && !result) - { - le.MousePressLeft(btnAccept) ? btnAccept.PressDraw() : btnAccept.ReleaseDraw(); - le.MousePressLeft(btnDecline) ? btnDecline.PressDraw() : btnDecline.ReleaseDraw(); - - if(le.MouseClickLeft(btnAccept)) result = 1; - - // exit - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(btnDecline)) break; - } - - cursor.Hide(); - back.Restore(); - cursor.Show(); - display.Flip(); - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_interface.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_interface.cpp deleted file mode 100644 index d16952f57..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_interface.cpp +++ /dev/null @@ -1,3856 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "engine.h" -#include "cursor.h" -#include "agg.h" -#include "settings.h" -#include "kingdom.h" -#include "world.h" -#include "castle.h" -#include "settings.h" -#include "pocketpc.h" -#include "battle_arena.h" -#include "battle_cell.h" -#include "battle_stats.h" -#include "battle_tower.h" -#include "battle_bridge.h" -#include "battle_catapult.h" -#include "battle_interface.h" - -namespace Battle2 -{ - u8 GetIndexIndicator(const Stats &); - direction_t GetCellDirection(const Rect &, const Point &); - u16 GetSwordCursorDirection(direction_t); - direction_t GetDirectionFromCursorSword(u16); - u16 GetCursorFromSpell(u8); - - bool ArmyNextIdleAnimation(Army::army_t &); - bool ArmySetIdleAnimation(Army::army_t &); - - struct CursorPosition - { - CursorPosition() : index(-1) {}; - - Point coord; - s16 index; - }; -} - -void DrawHexagon(Surface & sf, u8 index_color) -{ - u8 r, l, w, h; - - if(Settings::Get().QVGA()) - { - r = 11; - l = 7; - w = 23; - h = 26; - - sf.Set(w, h); - sf.SetColorKey(); - - u32 color = sf.GetColor(index_color); - - sf.DrawLine(r, 0, 0, l, color); - sf.DrawLine(r, 0, w - 1, l, color); - - sf.DrawLine(0, l + 1, 0, h - l - 1, color); - sf.DrawLine(w - 1, l + 1, w - 1, h - l - 1, color); - - sf.DrawLine(r, h - 1, 0, h - l - 1, color); - sf.DrawLine(r, h - 1, w - 1, h - l - 1, color); - } - else - { - r = 22; - l = 13; - w = 45; - h = 52; - - sf.Set(w, h); - sf.SetColorKey(); - - u32 color = sf.GetColor(index_color); - - sf.DrawLine(r, 0, 0, l, color); - sf.DrawLine(r, 0, w - 1, l, color); - - sf.DrawLine(0, l + 1, 0, h - l - 1, color); - sf.DrawLine(w - 1, l + 1, w - 1, h - l - 1, color); - - sf.DrawLine(r, h - 1, 0, h - l - 1, color); - sf.DrawLine(r, h - 1, w - 1, h - l - 1, color); - } - -} - -void DrawHexagonShadow(Surface & sf) -{ - u8 l, w, h; - - if(Settings::Get().QVGA()) - { - //r = 11; - l = 7; - w = 23; - h = 26; - } - else - { - //r = 22; - l = 13; - w = 45; - h = 52; - } - - sf.Set(w, h); - sf.SetColorKey(); - - Rect rt(0, l, w, 2 * l); - sf.FillRect(0x00, 0x00, 0x00, rt); - for(u8 i = 1; i < w / 2; i += 2) - { - --rt.y; - rt.h += 2; - rt.x += 2; - rt.w -= 4; - sf.FillRect(0x00, 0x00, 0x00, rt); - } - sf.SetAlpha(0x30); -} - -void GetLinePoints(const Point & pt1, const Point & pt2, u16 step, std::vector & res) -{ - const u16 dx = std::abs(pt2.x - pt1.x); - const u16 dy = std::abs(pt2.y - pt1.y); - - s16 ns = std::div((dx > dy ? dx : dy), 2).quot; - Point pt(pt1); - - for(u16 i = 0; i <= (dx > dy ? dx : dy); ++i) - { - if(dx > dy) - { - pt.x < pt2.x ? ++pt.x : --pt.x; - ns -= dy; - } - else - { - pt.y < pt2.y ? ++pt.y : --pt.y; - ns -= dx; - } - - if(ns < 0) - { - if(dx > dy) - { - pt.y < pt2.y ? ++pt.y : --pt.y; - ns += dx; - } - else - { - pt.x < pt2.x ? ++pt.x : --pt.x; - ns += dy; - } - } - - if(0 == (i % step)) res.push_back(pt); - } -} - -void GetArcPoints(const Point & from, const Point & to, const Point & max, u16 step, std::vector & res) -{ - Point pt1, pt2; - - pt1 = from; - pt2 = Point(from.x + std::abs(max.x - from.x) / 2, from.y - std::abs(max.y - from.y) * 3 / 4); - GetLinePoints(pt1, pt2, step, res); - - pt1 = pt2; - pt2 = max; - GetLinePoints(pt1, pt2, step, res); - - pt1 = max; - pt2 = Point(max.x + std::abs(to.x - max.x) / 2, to.y - std::abs(to.y - max.y) * 3 / 4); - GetLinePoints(pt1, pt2, step, res); - - pt1 = pt2; - pt2 = to; - GetLinePoints(pt1, pt2, step, res); -} - -bool Battle2::TargetInfo::isFinishAnimFrame(void) const -{ - return defender && defender->isFinishAnimFrame(); -} - -u16 Battle2::GetCursorFromSpell(u8 spell) -{ - switch(spell) - { - case Spell::SLOW: return Cursor::SP_SLOW; - case Spell::CURSE: return Cursor::SP_CURSE; - case Spell::CURE: return Cursor::SP_CURE; - case Spell::BLESS: return Cursor::SP_BLESS; - case Spell::FIREBALL: return Cursor::SP_FIREBALL; - case Spell::FIREBLAST: return Cursor::SP_FIREBLAST; - case Spell::TELEPORT: return Cursor::SP_TELEPORT; - case Spell::RESURRECT: return Cursor::SP_RESURRECT; - case Spell::HASTE: return Cursor::SP_HASTE; - case Spell::SHIELD: return Cursor::SP_SHIELD; - case Spell::ARMAGEDDON: return Cursor::SP_ARMAGEDDON; - case Spell::ANTIMAGIC: return Cursor::SP_ANTIMAGIC; - case Spell::BERSERKER: return Cursor::SP_BERSERKER; - case Spell::PARALYZE: return Cursor::SP_PARALYZE; - case Spell::BLIND: return Cursor::SP_BLIND; - - case Spell::LIGHTNINGBOLT: return Cursor::SP_LIGHTNINGBOLT; - case Spell::CHAINLIGHTNING: return Cursor::SP_CHAINLIGHTNING; - case Spell::ELEMENTALSTORM: return Cursor::SP_ELEMENTALSTORM; - case Spell::RESURRECTTRUE: return Cursor::SP_RESURRECTTRUE; - case Spell::DISPEL: return Cursor::SP_DISPEL; - case Spell::HOLYWORD: return Cursor::SP_HOLYWORD; - case Spell::HOLYSHOUT: return Cursor::SP_HOLYSHOUT; - case Spell::METEORSHOWER: return Cursor::SP_METEORSHOWER; - - case Spell::ANIMATEDEAD: return Cursor::SP_ANIMATEDEAD; - case Spell::MIRRORIMAGE: return Cursor::SP_MIRRORIMAGE; - case Spell::BLOODLUST: return Cursor::SP_BLOODLUST; - case Spell::DEATHRIPPLE: return Cursor::SP_DEATHRIPPLE; - case Spell::DEATHWAVE: return Cursor::SP_DEATHWAVE; - case Spell::STEELSKIN: return Cursor::SP_STEELSKIN; - case Spell::STONESKIN: return Cursor::SP_STONESKIN; - case Spell::DRAGONSLAYER: return Cursor::SP_DRAGONSLAYER; - case Spell::EARTHQUAKE: return Cursor::SP_EARTHQUAKE; - case Spell::DISRUPTINGRAY: return Cursor::SP_DISRUPTINGRAY; - case Spell::COLDRING: return Cursor::SP_COLDRING; - case Spell::COLDRAY: return Cursor::SP_COLDRAY; - case Spell::HYPNOTIZE: return Cursor::SP_HYPNOTIZE; - case Spell::ARROW: return Cursor::SP_ARROW; - - default: break; - } - return Cursor::WAR_NONE; -} - -u16 Battle2::GetSwordCursorDirection(direction_t dir) -{ - switch(dir) - { - case BOTTOM_RIGHT: return Cursor::SWORD_TOPLEFT; - case BOTTOM_LEFT: return Cursor::SWORD_TOPRIGHT; - case RIGHT: return Cursor::SWORD_LEFT; - case TOP_RIGHT: return Cursor::SWORD_BOTTOMLEFT; - case TOP_LEFT: return Cursor::SWORD_BOTTOMRIGHT; - case LEFT: return Cursor::SWORD_RIGHT; - default: break; - } - return 0; -} - -Battle2::direction_t Battle2::GetDirectionFromCursorSword(u16 sword) -{ - switch(sword) - { - case Cursor::SWORD_TOPLEFT: return BOTTOM_RIGHT; - case Cursor::SWORD_TOPRIGHT: return BOTTOM_LEFT; - case Cursor::SWORD_LEFT: return RIGHT; - case Cursor::SWORD_BOTTOMLEFT: return TOP_RIGHT; - case Cursor::SWORD_BOTTOMRIGHT: return TOP_LEFT; - case Cursor::SWORD_RIGHT: return LEFT; - default: break; - } - - return UNKNOWN; -} - -Battle2::direction_t Battle2::GetCellDirection(const Rect & rt, const Point & pt) -{ - const u16 cw = rt.w / 2; - const u16 ch = (rt.h + (Settings::Get().QVGA() ? 3 : 6)) / 3; - - if(Rect(rt.x, rt.y, cw, ch) & pt) - return TOP_LEFT; - else - if(Rect(rt.x, rt.y + ch, cw, ch) & pt) - return LEFT; - else - if(Rect(rt.x, rt.y + 2 * ch, cw, ch) & pt) - return BOTTOM_LEFT; - else - if(Rect(rt.x + cw, rt.y, cw, ch) & pt) - return TOP_RIGHT; - else - if(Rect(rt.x + cw, rt.y + ch, cw, ch) & pt) - return RIGHT; - else - if(Rect(rt.x + cw, rt.y + 2 * ch, cw, ch) & pt) - return BOTTOM_RIGHT; - - return UNKNOWN; -} - -Battle2::OpponentSprite::OpponentSprite(const Rect & area, const HeroBase *b, bool r) : base(b), - icn(ICN::UNKNOWN), animframe(0), animframe_start(0), animframe_count(0), reflect(r) -{ - ResetAnimFrame(OP_IDLE); - - if(Settings::Get().QVGA()) - { - if(reflect) - { - pos.x = area.x + area.w - 40; - pos.y = area.y + 50; - } - else - { - pos.x = area.x + 5; - pos.y = area.y + 50; - } - - const Sprite & sprite = AGG::GetICN(icn, animframe, reflect); - - pos.w = sprite.w(); - pos.h = sprite.h(); - } - else - { - - if(reflect) - { - pos.x = area.x + area.w - 60; - pos.y = area.y + 50; - } - else - { - pos.x = area.x + 5; - pos.y = area.y + 50; - } - - const Sprite & sprite = AGG::GetICN(icn, animframe, reflect); - - pos.w = sprite.w(); - pos.h = sprite.h(); - } -} - -u8 Battle2::OpponentSprite::GetColor(void) const -{ - return base ? base->GetColor() : 0; -} - -const HeroBase* Battle2::OpponentSprite::GetHero(void) const -{ - return base; -} - -void Battle2::OpponentSprite::IncreaseAnimFrame(bool loop) -{ - if(animframe < animframe_start + animframe_count - 1) - ++animframe; - else - if(loop) - animframe = animframe_start; -} - -void Battle2::OpponentSprite::ResetAnimFrame(u8 rule) -{ - if(Settings::Get().QVGA()) - { - switch(base->GetColor()) - { - case Color::BLUE: animframe = 0; break; - case Color::GREEN: animframe = 7; break; - case Color::RED: animframe = 14; break; - case Color::YELLOW: animframe = 21; break; - case Color::ORANGE: animframe = 28; break; - case Color::PURPLE: animframe = 35; break; - default: break; - } - - switch(base->GetRace()) - { - case Race::KNGT: animframe += 0; break; - case Race::BARB: animframe += 1; break; - case Race::SORC: animframe += 2; break; - case Race::WRLK: animframe += 3; break; - case Race::WZRD: animframe += 4; break; - case Race::NECR: animframe += 5; break; - default: break; - } - - icn = ICN::MINIHERO; - } - else - { - if(Skill::Primary::HEROES == base->GetType()) - { - switch(base->GetRace()) - { - case Race::BARB: - icn = ICN::CMBTHROB; - switch(rule) - { - case OP_IDLE: animframe_start = 12; animframe_count = 7; break; - case OP_SRRW: animframe_start = 1; animframe_count = 5; break; - case OP_CAST: animframe_start = 7; animframe_count = 5; break; - default: break; - } - break; - case Race::KNGT: - icn = ICN::CMBTHROK; - switch(rule) - { - case OP_IDLE: animframe_start = 12; animframe_count = 8; break; - case OP_SRRW: animframe_start = 1; animframe_count = 5; break; - case OP_CAST: animframe_start = 7; animframe_count = 5; break; - default: break; - } - break; - case Race::NECR: - icn = ICN::CMBTHRON; - switch(rule) - { - case OP_IDLE: animframe_start = 16; animframe_count = 4; break; - case OP_SRRW: animframe_start = 1; animframe_count = 5; break; - case OP_CAST: animframe_start = 8; animframe_count = 6; break; - default: break; - } - break; - case Race::SORC: - icn = ICN::CMBTHROS; - switch(rule) - { - case OP_IDLE: animframe_start = 10; animframe_count = 6; break; - case OP_SRRW: animframe_start = 1; animframe_count = 5; break; - case OP_CAST: animframe_start = 7; animframe_count = 3; break; - default: break; - } - break; - case Race::WRLK: - icn = ICN::CMBTHROW; - switch(rule) - { - case OP_IDLE: animframe_start = 13; animframe_count = 4; break; - case OP_SRRW: animframe_start = 1; animframe_count = 5; break; - case OP_CAST: animframe_start = 7; animframe_count = 6; break; - default: break; - } - break; - case Race::WZRD: - icn = ICN::CMBTHROZ; - switch(rule) - { - case OP_IDLE: animframe_start = 16; animframe_count = 3; break; - case OP_SRRW: animframe_start = 1; animframe_count = 5; break; - case OP_CAST: animframe_start = 7; animframe_count = 9; break; - default: break; - } - break; - default: break; - } - animframe = animframe_start; - } - else - if(Skill::Primary::CAPTAIN == base->GetType()) - { - icn = ICN::CMBTCAPB; - switch(base->GetRace()) - { - case Race::BARB: icn = ICN::CMBTCAPB; break; - case Race::KNGT: icn = ICN::CMBTCAPK; break; - case Race::NECR: icn = ICN::CMBTCAPN; break; - case Race::SORC: icn = ICN::CMBTCAPS; break; - case Race::WRLK: icn = ICN::CMBTCAPW; break; - case Race::WZRD: icn = ICN::CMBTCAPZ; break; - default: break; - } - - switch(rule) - { - case OP_IDLE: animframe_start = 1; animframe_count = 1; break; - case OP_SRRW: animframe_start = 1; animframe_count = 1; break; - case OP_CAST: animframe_start = 3; animframe_count = 5; break; - default: break; - } - animframe = animframe_start; - } - } -} - -bool Battle2::OpponentSprite::isFinishFrame(void) const -{ - return !animframe_count || animframe >= animframe_start + animframe_count - 1; -} - -bool Battle2::OpponentSprite::isStartFrame(void) const -{ - return animframe_count && animframe == animframe_start; -} - -const Rect & Battle2::OpponentSprite::GetArea(void) const -{ - return pos; -} - -void Battle2::OpponentSprite::Redraw(void) const -{ - Display::Get().Blit(AGG::GetICN(icn, animframe, reflect), pos.x, pos.y); -} - -Battle2::Status::Status() : back1(AGG::GetICN(ICN::TEXTBAR, 8)), back2(AGG::GetICN(ICN::TEXTBAR, 9)) -{ - bar1.Set(Settings::Get().QVGA() ? Font::SMALL : Font::BIG); - bar2.Set(Settings::Get().QVGA() ? Font::SMALL : Font::BIG); -} - -void Battle2::Status::SetPosition(s16 cx, s16 cy) -{ - pos.x = cx; - pos.y = cy; -} - -void Battle2::Status::SetMessage(const std::string & str, bool top) -{ - - if(top) - bar1.Set(str); - else - if(str != message) - { - bar2.Set(str); - message = str; - } -} - -void Battle2::Status::Redraw(void) -{ - Display & display = Display::Get(); - - display.Blit(back1, pos.x, pos.y); - display.Blit(back2, pos.x, pos.y + back1.h()); - - if(bar1.Size()) bar1.Blit(pos.x + (back1.w() - bar1.w()) / 2, pos.y + (Settings::Get().QVGA() ? -1 : 3)); - if(bar2.Size()) bar2.Blit(pos.x + (back2.w() - bar2.w()) / 2, pos.y + back1.h() + (Settings::Get().QVGA() ? -3 : 0)); -} - -const std::string & Battle2::Status::GetMessage(void) const -{ - return message; -} - -Battle2::Interface::Interface(Arena & a, s32 center) : arena(a), icn_cbkg(ICN::UNKNOWN), icn_frng(ICN::UNKNOWN), humanturn_spell(Spell::NONE), - humanturn_exit(true), humanturn_redraw(true), animation_frame(0), catapult_frame(0), - b_current(NULL), b_move(NULL), b_fly(NULL), b_current_sprite(NULL), teleport_src(MAXU16) -{ - const Settings & conf = Settings::Get(); - bool pda = conf.QVGA(); - - // border - Display & display = Display::Get(); - const u16 arenaw = pda ? 320 : 640; - const u16 arenah = pda ? (display.h() < 240 ? display.h() : 240) : 480; - border.SetPosition((display.w() - arenaw) / 2 - BORDERWIDTH, (display.h() - arenah) / 2 - BORDERWIDTH, arenaw, arenah); - - // cover - bool trees = Maps::ScanAroundObject(center, MP2::OBJ_TREES); - const Heroes *hero = world.GetHeroes(center); - bool grave = hero && MP2::OBJ_GRAVEYARD == hero->GetUnderObject(); - bool light = true; - - switch(world.GetTiles(center).GetGround()) - { - case Maps::Ground::DESERT: icn_cbkg = ICN::CBKGDSRT; light = false; icn_frng = ICN::FRNG0004; break; - case Maps::Ground::SNOW: icn_cbkg = trees ? ICN::CBKGSNTR : ICN::CBKGSNMT; light = false; icn_frng = trees ? ICN::FRNG0006 : ICN::FRNG0007; break; - case Maps::Ground::SWAMP: icn_cbkg = ICN::CBKGSWMP; icn_frng = ICN::FRNG0008; break; - case Maps::Ground::WASTELAND: icn_cbkg = ICN::CBKGCRCK; light = false; icn_frng = ICN::FRNG0003; break; - case Maps::Ground::BEACH: icn_cbkg = ICN::CBKGBEAC; light = false; icn_frng = ICN::FRNG0002; break; - case Maps::Ground::LAVA: icn_cbkg = ICN::CBKGLAVA; icn_frng = ICN::FRNG0005; break; - case Maps::Ground::DIRT: icn_cbkg = trees ? ICN::CBKGDITR : ICN::CBKGDIMT; icn_frng = trees ? ICN::FRNG0010 : ICN::FRNG0009; break; - case Maps::Ground::GRASS: icn_cbkg = trees ? ICN::CBKGGRTR : ICN::CBKGGRMT; icn_frng = trees ? ICN::FRNG0011 : ICN::FRNG0012; break; - case Maps::Ground::WATER: icn_cbkg = ICN::CBKGWATR; icn_frng = ICN::FRNG0013; break; - default: break; - } - - if(grave){ icn_cbkg = ICN::CBKGGRAV; light = true; icn_frng = ICN::FRNG0001; } - if(conf.QVGA() || conf.ExtLowMemory()) icn_frng = ICN::UNKNOWN; - - // hexagon - DrawHexagon(sf_hexagon, (light ? 0xE0 : 0xE5)); - DrawHexagon(sf_cursor, 0xD8); - DrawHexagonShadow(sf_shadow); - - // buttons - const Rect & area = border.GetArea(); - - btn_auto.SetSprite(ICN::TEXTBAR, 4, 5); - btn_settings.SetSprite(ICN::TEXTBAR, 6, 7); - btn_skip.SetSprite(ICN::TEXTBAR, 0, 1); - - btn_auto.SetPos(area.x, area.y + area.h - btn_settings.h - btn_auto.h); - btn_settings.SetPos(area.x, area.y + area.h - btn_settings.h); - btn_skip.SetPos(area.x + area.w - btn_skip.w, area.y + area.h - btn_skip.h); - - status.SetPosition(area.x + btn_auto.w, btn_auto.y); - - // opponents - opponent1 = arena.army1.GetCommander() ? new OpponentSprite(area, arena.army1.GetCommander(), false) : NULL; - opponent2 = arena.army2.GetCommander() ? new OpponentSprite(area, arena.army2.GetCommander(), true) : NULL; -} - -Battle2::Interface::~Interface() -{ - if(opponent1) delete opponent1; - if(opponent2) delete opponent2; - if(Settings::Get().AutoBattle()) Settings::Get().SetAutoBattle(false); -} - -const Rect & Battle2::Interface::GetArea(void) const -{ - return border.GetArea(); -} - -void Battle2::Interface::SetStatus(const std::string & msg, bool top) -{ - if(top) - { - status.SetMessage(msg, true); - status.SetMessage("", false); - } - else - { - status.SetMessage(msg); - } - humanturn_redraw = true; -} - -void Battle2::Interface::Redraw(void) -{ - RedrawCover(); - RedrawOpponents(); - if(arena.castle) RedrawCastle3(); - RedrawArmies(); - RedrawInterface(); - RedrawBorder(); - if(Settings::Get().QVGA()) RedrawPocketControls(); -} - -void Battle2::Interface::RedrawInterface(void) -{ - status.Redraw(); - - btn_auto.Draw(); - btn_settings.Draw(); - btn_skip.Draw(); -} - -void Battle2::Interface::RedrawArmies(void) const -{ - for(u16 ii = 0; ii < arena.board.size(); ++ii) - { - if(arena.castle) RedrawCastle2(ii); - RedrawObjects(ii); - - const Stats* b = arena.GetTroopBoard(ii); - if(!b || (b->isWide() && ii == b->GetTailIndex())) continue; - - const Cell & cell = arena.board[ii]; - - if(b_fly != b) - { - RedrawTroopSprite(*b, cell.pos); - - if(b_move != b) - RedrawTroopCount(*b, cell.pos); - } - } - - if(b_fly) - { - RedrawTroopSprite(*b_fly, b_fly->GetCellPosition()); - } -} - -void Battle2::Interface::RedrawOpponents(void) const -{ - if(opponent1) opponent1->Redraw(); - if(opponent2) opponent2->Redraw(); - - RedrawOpponentsFlags(); -} - -void Battle2::Interface::RedrawOpponentsFlags(void) const -{ - if(!Settings::Get().QVGA() && opponent1) - { - ICN::icn_t icn = ICN::UNKNOWN; - - switch(arena.army1.GetColor()) - { - case Color::BLUE: icn = ICN::HEROFL00; break; - case Color::GREEN: icn = ICN::HEROFL01; break; - case Color::RED: icn = ICN::HEROFL02; break; - case Color::YELLOW: icn = ICN::HEROFL03; break; - case Color::ORANGE: icn = ICN::HEROFL04; break; - case Color::PURPLE: icn = ICN::HEROFL05; break; - default: icn = ICN::HEROFL06; break; - } - - const Sprite & flag = AGG::GetICN(icn, ICN::AnimationFrame(icn, 0, animation_frame), false); - Display::Get().Blit(flag, opponent1->GetArea().x + 38 - flag.w(), opponent1->GetArea().y + 5); - } - - if(!Settings::Get().QVGA() && opponent2) - { - ICN::icn_t icn = ICN::UNKNOWN; - - switch(arena.army2.GetColor()) - { - case Color::BLUE: icn = ICN::HEROFL00; break; - case Color::GREEN: icn = ICN::HEROFL01; break; - case Color::RED: icn = ICN::HEROFL02; break; - case Color::YELLOW: icn = ICN::HEROFL03; break; - case Color::ORANGE: icn = ICN::HEROFL04; break; - case Color::PURPLE: icn = ICN::HEROFL05; break; - default: icn = ICN::HEROFL06; break; - } - - const Sprite & flag = AGG::GetICN(icn, ICN::AnimationFrame(icn, 0, animation_frame), true); - const u8 ox = Skill::Primary::HEROES == opponent2->GetHero()->GetType() ? 38 : 26; - Display::Get().Blit(flag, opponent2->GetArea().x + ox - flag.w(), opponent2->GetArea().y + 5); - } -} - -void Battle2::Interface::RedrawTroopSprite(const Stats & b, const Rect & rt) const -{ - Display & display = Display::Get(); - const MonsterInfo & msi = b.GetMonsterInfo(); - const Sprite* spmon1 = NULL; - const Sprite* spmon2 = NULL; - - // redraw current - if(b_current == &b) - { - spmon1 = &AGG::GetICN(msi.icn_file, msi.frm_idle.start, b.reflect); - spmon2 = (b.reflect ? b.contours[1] : b.contours[0]); - - if(b_current_sprite) - { - spmon1 = b_current_sprite; - spmon2 = NULL; - } - } - else - if(b.Modes(SP_STONE)) - { - // black wite sprite - spmon1 = (b.reflect ? b.contours[3] : b.contours[2]); - } - else - { - spmon1 = &AGG::GetICN(msi.icn_file, b.animframe, b.reflect); - } - - if(spmon1) - { - // offset - s16 sx = b.isReflect() ? - rt.x + (b.isWide() ? rt.w + rt.w / 2 : rt.w / 2) - spmon1->w() - spmon1->x() : - rt.x + (b.isWide() ? -rt.w / 2 : rt.w / 2) + spmon1->x(); - s16 sy = rt.y + rt.h + spmon1->y() - 10; - - // move offset - if(b_move == &b) - { - const animframe_t & frm = b_move->GetFrameState(); - const Sprite* spmon0 = &AGG::GetICN(msi.icn_file, frm.start, b.reflect); - const s16 ox = spmon0 ? spmon1->x() - spmon0->x() : 0; - const Rect & pos = b_move->GetCellPosition(); - - if(frm.count) - { - const s16 cx = p_move.x - pos.x; - const s16 cy = p_move.y - pos.y; - - sy += ((b_move->animframe - frm.start) * cy) / frm.count; - if(0 != Sign(cy)) sx -= Sign(cx) * ox / 2; - } - } - else - // fly offset - if(b_fly == &b) - { - const Point & pos = b_fly->GetCellPosition(); - - if(b_fly->GetFrameCount()) - { - const s16 cx = p_fly.x - pos.x; - const s16 cy = p_fly.y - pos.y; - - sx += cx + Sign(cx) * b_fly->GetFrameOffset() * std::abs((p_fly.x - p_move.x) / b_fly->GetFrameCount()); - sy += cy + Sign(cy) * b_fly->GetFrameOffset() * std::abs((p_fly.y - p_move.y) / b_fly->GetFrameCount()); - } - } - - // sprite monster - display.Blit(*spmon1, sx, sy); - // contour - if(spmon2) display.Blit(*spmon2, sx - 1, sy - 1); - } -} - -void Battle2::Interface::RedrawTroopCount(const Stats & b, const Rect & rt) const -{ - Display & display = Display::Get(); - const Sprite & bar = AGG::GetICN(ICN::TEXTBAR, GetIndexIndicator(b)); - - s16 sx = 0; - s16 sy = 0; - - if(Settings::Get().QVGA()) - { - sy = rt.y + rt.h - bar.h(); - - if(b.isWide()) - sx = rt.x - (b.reflect ? 0 : rt.w) + (2 * rt.w - bar.w()) / 2; - else - sx = rt.x + (rt.w - bar.w()) / 2; - } - else - { - sy = rt.y + rt.h - bar.h() - 5; - - if(b.reflect) - sx = rt.x + 3; - else - sx = rt.x + rt.w - bar.w() - 3; - } - - std::string str; - - display.Blit(bar, sx, sy); - - if(b.count < 1000) - String::AddInt(str, b.count); - else - if(b.count < 1000000) - { - String::AddInt(str, b.count / 1000); - str += "K"; - } - else - { - String::AddInt(str, b.count / 1000000); - str += "M"; - } - - Text text(str, Font::SMALL); - text.Blit(sx + (bar.w() - text.w()) / 2, sy); -} - -void Battle2::Interface::RedrawCover(void) -{ - const Settings & conf = Settings::Get(); - Display & display = Display::Get(); - const Point & topleft = border.GetArea(); - const s16 cursor = arena.board.GetIndexAbsPosition(LocalEvent::Get().GetMouseCursor()); - - if(icn_cbkg != ICN::UNKNOWN) - { - const Sprite & cbkg = AGG::GetICN(icn_cbkg, 0); - display.Blit(cbkg, topleft); - } - - if(icn_frng != ICN::UNKNOWN) - { - const Sprite & frng = AGG::GetICN(icn_frng, 0); - display.Blit(frng, topleft.x + frng.x(), topleft.x + frng.y()); - } - - if(arena.icn_covr != ICN::UNKNOWN) - { - const Sprite & cover = AGG::GetICN(arena.icn_covr, 0); - display.Blit(cover, topleft.x + cover.x(), topleft.y + cover.y()); - } - - if(arena.castle) RedrawCastle1(); - - // shadow - if(!b_move && conf.ExtBattleShowMoveShadow()) - { - Board::const_iterator it1 = arena.board.begin(); - Board::const_iterator it2 = arena.board.end(); - - for(; it1 != it2; ++it1) if((*it1).isPassable() && UNKNOWN != (*it1).GetDirection()) - display.Blit(sf_shadow, (*it1).GetPos().x, (*it1).GetPos().y); - } - - // grid - if(conf.ExtBattleShowGrid()) - { - Board::const_iterator it1 = arena.board.begin(); - Board::const_iterator it2 = arena.board.end(); - - for(; it1 != it2; ++it1) - if((*it1).object == 0) display.Blit(sf_hexagon, (*it1).GetPos()); - } - - // cursor - if(conf.ExtBattleShowMouseShadow() && 0 <= cursor && b_current && Cursor::Get().Themes() != Cursor::WAR_NONE) - display.Blit(sf_cursor, arena.board[cursor].GetPos()); - - RedrawKilled(); -} - -void Battle2::Interface::RedrawCastle1(void) const -{ - Display & display = Display::Get(); - const Point & topleft = border.GetArea(); - const bool fortification = arena.castle && (Race::KNGT == arena.castle->GetRace()) && arena.castle->isBuild(BUILD_SPEC); - - ICN::icn_t icn_castbkg = ICN::UNKNOWN; - ICN::icn_t icn_castle = ICN::UNKNOWN; - - switch(arena.castle->GetRace()) - { - default: - case Race::BARB: icn_castbkg = ICN::CASTBKGB; break; - case Race::KNGT: icn_castbkg = ICN::CASTBKGK; break; - case Race::NECR: icn_castbkg = ICN::CASTBKGN; break; - case Race::SORC: icn_castbkg = ICN::CASTBKGS; break; - case Race::WRLK: icn_castbkg = ICN::CASTBKGW; break; - case Race::WZRD: icn_castbkg = ICN::CASTBKGZ; break; - } - - switch(arena.castle->GetRace()) - { - default: - case Race::BARB: icn_castle = ICN::CASTLEB; break; - case Race::KNGT: icn_castle = ICN::CASTLEK; break; - case Race::NECR: icn_castle = ICN::CASTLEN; break; - case Race::SORC: icn_castle = ICN::CASTLES; break; - case Race::WRLK: icn_castle = ICN::CASTLEW; break; - case Race::WZRD: icn_castle = ICN::CASTLEZ; break; - } - - // castle cover - const Sprite & sprite1 = AGG::GetICN(icn_castbkg, 1); - display.Blit(sprite1, sprite1.x() + topleft.x, sprite1.y() + topleft.y); - - // moat - if(arena.castle->isBuild(BUILD_MOAT)) - { - const Sprite & sprite = AGG::GetICN(ICN::MOATWHOL, 0); - display.Blit(sprite, sprite.x() + topleft.x, sprite.y() + topleft.y); - } - - // top wall - const Sprite & sprite2 = AGG::GetICN(icn_castbkg, fortification ? 4 : 3); - display.Blit(sprite2, sprite2.x() + topleft.x, sprite2.y() + topleft.y); - - // bridge - if(arena.bridge->isDown()) - { - const Sprite & sprite3 = AGG::GetICN(icn_castle, arena.bridge->isDestroy() ? 24 : 21); - display.Blit(sprite3, sprite3.x() + topleft.x, sprite3.y() + topleft.y); - } -} - -void Battle2::Interface::RedrawCastle2(const u16 cell_index) const -{ - const Settings & conf = Settings::Get(); - Display & display = Display::Get(); - const Point & topleft = border.GetArea(); - ICN::icn_t icn_castle = ICN::UNKNOWN; - - switch(arena.castle->GetRace()) - { - default: - case Race::BARB: icn_castle = ICN::CASTLEB; break; - case Race::KNGT: icn_castle = ICN::CASTLEK; break; - case Race::NECR: icn_castle = ICN::CASTLEN; break; - case Race::SORC: icn_castle = ICN::CASTLES; break; - case Race::WRLK: icn_castle = ICN::CASTLEW; break; - case Race::WZRD: icn_castle = ICN::CASTLEZ; break; - } - - // catapult - if(77 == cell_index) - { - const Sprite & sprite = AGG::GetICN(ICN::CATAPULT, catapult_frame); - const Rect & pos = arena.board[cell_index].pos; - display.Blit(sprite, sprite.x() + pos.x - pos.w, sprite.y() + pos.y + pos.h - 10); - } - else - // castle gate - if(50 == cell_index) - { - const Sprite & sprite = AGG::GetICN(icn_castle, 4); - display.Blit(sprite, sprite.x() + topleft.x, sprite.y() + topleft.y); - } - else - // castle wall - if(8 == cell_index || 29 == cell_index || 73 == cell_index || 96 == cell_index) - { - u8 index = 0; - const bool fortification = arena.castle && (Race::KNGT == arena.castle->GetRace()) && arena.castle->isBuild(BUILD_SPEC); - - switch(cell_index) - { - case 8: index = 5; break; - case 29: index = 6; break; - case 73: index = 7; break; - case 96: index = 8; break; - default: break; - } - - if(fortification) - { - switch(arena.board[cell_index].object) - { - case 0: index += 31; break; - case 1: index += 35; break; - case 2: index += 27; break; - case 3: index += 23; break; - break; - } - } - else - { - switch(arena.board[cell_index].object) - { - case 0: index += 8; break; - case 1: index += 4; break; - case 2: index += 0; break; - break; - } - } - - const Sprite & sprite = AGG::GetICN(icn_castle, index); - display.Blit(sprite, sprite.x() + topleft.x, sprite.y() + topleft.y); - } - else - // castle archer towers - if(19 == cell_index) - { - u8 index = 17; - - if(arena.castle->isBuild(BUILD_LEFTTURRET)) - { - index = (arena.towers[0] && arena.towers[0]->isValid() ? 18 : 19); - } - - display.Blit(AGG::GetICN(icn_castle, index), topleft.x + (conf.QVGA() ? 207 : 415), topleft.y + (conf.QVGA() ? 20 : 40)); - } - else - if(85 == cell_index) - { - u8 index = 17; - - if(arena.castle->isBuild(BUILD_RIGHTTURRET)) - { - index = ( arena.towers[2] && arena.towers[2]->isValid() ? 18 : 19); - } - - display.Blit(AGG::GetICN(icn_castle, index), topleft.x + (conf.QVGA() ? 207 : 415), topleft.y + (conf.QVGA() ? 145 : 290)); - } - else - // castle towers - if(40 == cell_index) - display.Blit(AGG::GetICN(icn_castle, 17), topleft.x + (conf.QVGA() ? 187 : 375), topleft.y + (conf.QVGA() ? 60 : 120)); - else - // castle towers - if(62 == cell_index) - display.Blit(AGG::GetICN(icn_castle, 17), topleft.x + (conf.QVGA() ? 187 : 375), topleft.y + (conf.QVGA() ? 102 : 205)); -} - -void Battle2::Interface::RedrawCastle3(void) const -{ - //const Settings & conf = Settings::Get(); - Display & display = Display::Get(); - const Point & topleft = border.GetArea(); - ICN::icn_t icn_castle = ICN::UNKNOWN; - - switch(arena.castle->GetRace()) - { - default: - case Race::BARB: icn_castle = ICN::CASTLEB; break; - case Race::KNGT: icn_castle = ICN::CASTLEK; break; - case Race::NECR: icn_castle = ICN::CASTLEN; break; - case Race::SORC: icn_castle = ICN::CASTLES; break; - case Race::WRLK: icn_castle = ICN::CASTLEW; break; - case Race::WZRD: icn_castle = ICN::CASTLEZ; break; - } - - const Sprite & sprite = AGG::GetICN(icn_castle, (arena.towers[1]->isValid() ? 20 : 26)); - - display.Blit(sprite, topleft.x + sprite.x() ,topleft.y + sprite.y()); -} - -void Battle2::Interface::RedrawObjects(const u16 cell_index) const -{ - const Sprite* sprite = NULL; - switch(arena.board[cell_index].object) - { - case 0x80: sprite = &AGG::GetICN(ICN::COBJ0000, 0); break; - case 0x81: sprite = &AGG::GetICN(ICN::COBJ0001, 0); break; - case 0x82: sprite = &AGG::GetICN(ICN::COBJ0002, 0); break; - case 0x83: sprite = &AGG::GetICN(ICN::COBJ0003, 0); break; - case 0x84: sprite = &AGG::GetICN(ICN::COBJ0004, 0); break; - case 0x85: sprite = &AGG::GetICN(ICN::COBJ0005, 0); break; - case 0x86: sprite = &AGG::GetICN(ICN::COBJ0006, 0); break; - case 0x87: sprite = &AGG::GetICN(ICN::COBJ0007, 0); break; - case 0x88: sprite = &AGG::GetICN(ICN::COBJ0008, 0); break; - case 0x89: sprite = &AGG::GetICN(ICN::COBJ0009, 0); break; - case 0x8A: sprite = &AGG::GetICN(ICN::COBJ0010, 0); break; - case 0x8B: sprite = &AGG::GetICN(ICN::COBJ0011, 0); break; - case 0x8C: sprite = &AGG::GetICN(ICN::COBJ0012, 0); break; - case 0x8D: sprite = &AGG::GetICN(ICN::COBJ0013, 0); break; - case 0x8E: sprite = &AGG::GetICN(ICN::COBJ0014, 0); break; - case 0x8F: sprite = &AGG::GetICN(ICN::COBJ0015, 0); break; - case 0x90: sprite = &AGG::GetICN(ICN::COBJ0016, 0); break; - case 0x91: sprite = &AGG::GetICN(ICN::COBJ0017, 0); break; - case 0x92: sprite = &AGG::GetICN(ICN::COBJ0018, 0); break; - case 0x93: sprite = &AGG::GetICN(ICN::COBJ0019, 0); break; - case 0x94: sprite = &AGG::GetICN(ICN::COBJ0020, 0); break; - case 0x95: sprite = &AGG::GetICN(ICN::COBJ0021, 0); break; - case 0x96: sprite = &AGG::GetICN(ICN::COBJ0022, 0); break; - case 0x97: sprite = &AGG::GetICN(ICN::COBJ0023, 0); break; - case 0x98: sprite = &AGG::GetICN(ICN::COBJ0024, 0); break; - case 0x99: sprite = &AGG::GetICN(ICN::COBJ0025, 0); break; - case 0x9A: sprite = &AGG::GetICN(ICN::COBJ0026, 0); break; - case 0x9B: sprite = &AGG::GetICN(ICN::COBJ0027, 0); break; - case 0x9C: sprite = &AGG::GetICN(ICN::COBJ0028, 0); break; - case 0x9D: sprite = &AGG::GetICN(ICN::COBJ0029, 0); break; - case 0x9E: sprite = &AGG::GetICN(ICN::COBJ0030, 0); break; - case 0x9F: sprite = &AGG::GetICN(ICN::COBJ0031, 0); break; - default: break; - } - - if(sprite) - { - Display & display = Display::Get(); - //const Point & topleft = border.GetArea(); - const Rect & pt = arena.board[cell_index].pos; - display.Blit(*sprite, pt.x + pt.w / 2 + sprite->x(), pt.y + pt.h + sprite->y() - (Settings::Get().QVGA() ? 5 : 10)); - } -} - -void Battle2::Interface::RedrawKilled(void) -{ - // redraw killed troop - std::vector cells; - arena.graveyard.GetClosedCells(cells); - if(cells.size()) - { - std::vector::const_iterator it; - - for(it = cells.begin(); it != cells.end(); ++it) - { - const u16 id_killed = arena.graveyard.GetLastTroopIDFromCell(*it); - - if(id_killed) - { - const Stats* b = arena.GetTroopID(id_killed); - if(b) - { - if(b->isWide() && *it == b->GetTailIndex()) continue; - RedrawTroopSprite(*b, arena.board[*it].pos); - } - } - } - } -} - -void Battle2::Interface::RedrawBorder(void) -{ - border.Redraw(); -} - -void Battle2::Interface::RedrawPocketControls(void) const -{ - const HeroBase* hero = b_current ? b_current->GetCommander() : NULL; - if(hero && hero->HaveSpellBook() && !hero->Modes(Heroes::SPELLCASTED)) - { - Display::Get().Blit(AGG::GetICN(ICN::ARTFX, 81), pocket_book); - } -} - -u16 Battle2::Interface::GetBattleCursor(const Point & mouse, std::string & status) -{ - status.clear(); - - const s16 index = arena.board.GetIndexAbsPosition(mouse); - - if(0 <= index && b_current) - { - const Cell & cell = arena.board[index]; - const Stats* b_enemy = arena.GetTroopBoard(index); - if(b_enemy) - { - if(b_current->GetColor() == b_enemy->GetColor() && !b_enemy->Modes(SP_HYPNOTIZE)) - { - status = _("View %{monster} info."); - String::Replace(status, "%{monster}", b_enemy->GetName()); - return Cursor::WAR_INFO; - } - else - { - if(b_current->isArchers() && !b_current->isHandFighting()) - { - status = _("Shot %{monster} (%{count} shot(s) left)"); - String::Replace(status, "%{monster}", b_enemy->GetName()); - String::Replace(status, "%{count}", b_current->GetShots()); - return b_enemy->GetObstaclesPenalty(*b_current) ? Cursor::WAR_BROKENARROW : Cursor::WAR_ARROW; - } - else - { - const direction_t dir = GetCellDirection(cell.GetPos(), mouse); - const u16 cursor = GetSwordCursorDirection(dir); - if(cursor && Board::isValidDirection(index, dir)) - { - const u16 from = Board::GetIndexDirection(index, dir); - - // if free cell or it is b_current - if(UNKNOWN != arena.board[from].GetDirection() || - from == b_current->GetPosition() || - (b_current->isWide() && from == b_current->GetTailIndex())) - { - status = _("Attack %{monster}"); - String::Replace(status, "%{monster}", b_enemy->GetName()); - return cursor; - } - } - } - } - } - else - if(cell.isPassable(*b_current, false) && UNKNOWN != cell.direction) - { - status = b_current->isFly() ? _("Fly %{monster} here.") : _("Move %{monster} here."); - String::Replace(status, "%{monster}", b_current->GetName()); - return b_current->isFly() ? Cursor::WAR_FLY : Cursor::WAR_MOVE; - } - } - - return Cursor::WAR_NONE; -} - -u16 Battle2::Interface::GetBattleSpellCursor(const Point & mouse, std::string & status) -{ - status.clear(); - - const s16 index = arena.board.GetIndexAbsPosition(mouse); - const Spell::spell_t spell = Spell::FromInt(humanturn_spell); - - if(0 <= index && b_current && Spell::NONE != spell) - { - const Stats* b_stats = arena.GetTroopBoard(index); - const Cell* cell = arena.GetCell(index); - - // over graveyard - if(!b_stats && arena.isAllowResurrectFromGraveyard(spell, index)) - { - const u16 id_killed = arena.graveyard.GetLastTroopIDFromCell(index); - if(id_killed) b_stats = arena.GetTroopID(id_killed); - } - - // teleport check first - if(MAXU16 != teleport_src) - { - if(!b_stats && cell && cell->isPassable(*b_current, false)) - { - status = _("Teleport Here"); - return Cursor::SP_TELEPORT; - } - - status = _("Invalid Teleport Destination"); - return Cursor::WAR_NONE; - } - else - if(b_stats && b_stats->AllowApplySpell(spell, b_current->GetCommander())) - { - status = _("Cast %{spell} on %{monster}"); - String::Replace(status, "%{spell}", Spell::GetName(spell)); - String::Replace(status, "%{monster}", b_stats->GetName()); - return GetCursorFromSpell(spell); - } - else - if(!Spell::isApplyToFriends(spell) && - !Spell::isApplyToEnemies(spell) && - !Spell::isApplyToAnyTroops(spell)) - { - status = _("Cast %{spell}"); - String::Replace(status, "%{spell}", Spell::GetName(spell)); - return GetCursorFromSpell(spell); - } - } - - status = _("Select Spell Target"); - - return Cursor::WAR_NONE; -} - -void Battle2::Interface::HumanTurn(const Stats & b, Actions & a) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - Settings & conf = Settings::Get(); - - cursor.SetThemes(Cursor::WAR_NONE); - b_current = &b; - humanturn_redraw = false; - humanturn_exit = false; - catapult_frame = 0; - - arena.ResetBoard(); - arena.ScanPassabilityBoard(b); - - rectBoard = arena.board.GetArea(); - - if(conf.Music() && !Music::isPlaying()) AGG::PlayMusic(MUS::GetBattleRandom(), false); - - if(conf.QVGA() && arena.current_commander && arena.current_commander->HaveSpellBook()) - { - const Rect & area = border.GetArea(); - const Sprite & book = AGG::GetICN(ICN::ARTFX, 81); - const u16 ox = (arena.army1.GetColor() == arena.current_commander->GetColor() ? 0 : 320 - book.w()); - pocket_book = Rect(area.x + ox, area.y + area.h - 19 - book.h(), book.w(), book.h()); - } - - // safe position coord - CursorPosition cursorPosition; - - cursor.Hide(); - Redraw(); - cursor.Show(); - display.Flip(); - - std::string msg; - animation_frame = 0; - - while(!humanturn_exit && le.HandleEvents()) - { - if(humanturn_spell != Spell::NONE) - HumanCastSpellTurn(b, a, msg); - else - HumanBattleTurn(b, a, msg); - - // update status - if(msg != status.GetMessage()) - { - status.SetMessage(msg); - humanturn_redraw = true; - } - - // animation troops - if(IdleTroopsAnimation()) humanturn_redraw = true; - - CheckGlobalEvents(le); - - // redraw arena - if(humanturn_redraw) - { - cursor.Hide(); - Redraw(); - cursor.Show(); - display.Flip(); - humanturn_redraw = false; - } - else - if(!cursor.isVisible()) - { - cursor.Show(); - display.Flip(); - } - } - - b_current = NULL; -} - -void Battle2::Interface::HumanBattleTurn(const Stats & b, Actions & a, std::string & msg) -{ - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - Settings & conf = Settings::Get(); - - if(le.KeyPress()) - { - // skip - if(Game::HotKeyPress(Game::EVENT_BATTLE_HARDSKIP)) - { - a.AddedSkipAction(b, true); - humanturn_exit = true; - } - else - // soft skip - if(Game::HotKeyPress(Game::EVENT_BATTLE_SOFTSKIP)) - { - a.AddedSkipAction(b, !conf.ExtBattleSoftWait()); - humanturn_exit = true; - } - else - // options - if(Game::HotKeyPress(Game::EVENT_BATTLE_OPTIONS)) - EventShowOptions(); - else - // auto switch - if(Game::HotKeyPress(Game::EVENT_BATTLE_AUTOSWITCH)) - EventAutoSwitch(b, a); - else - // cast - if(Game::HotKeyPress(Game::EVENT_BATTLE_CASTSPELL)) - ProcessingHeroDialogResult(1, a); - else - // retreat - if(Game::HotKeyPress(Game::EVENT_BATTLE_RETREAT)) - ProcessingHeroDialogResult(2, a); - else - // surrender - if(Game::HotKeyPress(Game::EVENT_BATTLE_SURRENDER)) - ProcessingHeroDialogResult(3, a); - - // debug only - if(IS_DEVEL()) switch(le.KeyValue()) - { - case KEY_w: - if(arena.result_game) - { - // fast wins game - arena.result_game->army1 = RESULT_WINS; - humanturn_exit = true; - } - break; - - case KEY_l: - if(arena.result_game) - { - // fast loss game - arena.result_game->army1 = RESULT_LOSS; - humanturn_exit = true; - } - break; - - default: break; - } - } - - if(pocket_book.w && le.MouseCursor(pocket_book)) - { - cursor.SetThemes(Cursor::WAR_POINTER); - msg = _("Spell cast"); - - if(le.MouseClickLeft(pocket_book)) - { - ProcessingHeroDialogResult(1, a); - humanturn_redraw = true; - } - } - else - if(le.MouseCursor(btn_auto)) - { - cursor.SetThemes(Cursor::WAR_POINTER); - msg = _("Auto combat"); - ButtonAutoAction(b, a); - } - else - if(le.MouseCursor(btn_settings)) - { - cursor.SetThemes(Cursor::WAR_POINTER); - msg = _("Customize system options."); - ButtonSettingsAction(); - } - else - if(le.MouseCursor(btn_skip)) - { - cursor.SetThemes(Cursor::WAR_POINTER); - msg = _("Skip this unit"); - ButtonSkipAction(a); - } - else - if(opponent1 && le.MouseCursor(opponent1->GetArea())) - { - if(conf.MyColor() == arena.army1.GetColor()) - { - msg = _("Hero's Options"); - cursor.SetThemes(Cursor::WAR_HERO); - - if(le.MouseClickLeft(opponent1->GetArea())) - { - ProcessingHeroDialogResult(arena.DialogBattleHero(*opponent1->GetHero()), a); - humanturn_redraw = true; - } - } - else - { - msg = _("View Opposing Hero"); - cursor.SetThemes(Cursor::WAR_INFO); - - if(le.MouseClickLeft(opponent1->GetArea())) - { - arena.DialogBattleHero(*opponent1->GetHero()); - humanturn_redraw = true; - } - } - } - else - if(opponent2 && le.MouseCursor(opponent2->GetArea())) - { - if(conf.MyColor() == arena.army2.GetColor()) - { - msg = _("Hero's Options"); - cursor.SetThemes(Cursor::WAR_HERO); - - if(le.MouseClickLeft(opponent2->GetArea())) - { - ProcessingHeroDialogResult(arena.DialogBattleHero(*opponent2->GetHero()), a); - humanturn_redraw = true; - } - } - else - { - msg = _("View Opposing Hero"); - cursor.SetThemes(Cursor::WAR_INFO); - - if(le.MouseClickLeft(opponent2->GetArea())) - { - arena.DialogBattleHero(*opponent2->GetHero()); - humanturn_redraw = true; - } - } - } - else - if(le.MouseCursor(rectBoard)) - { - const u16 themes = GetBattleCursor(le.GetMouseCursor(), msg); - - if(cursor.Themes() != themes) - cursor.SetThemes(themes); - - if(le.MouseClickLeft()) - MouseLeftClickBoardAction(themes, arena.board.GetIndexAbsPosition(le.GetMouseCursor()), a); - else - if(le.MousePressRight()) - MousePressRightBoardAction(themes, arena.board.GetIndexAbsPosition(le.GetMouseCursor()), a); - } - else - { - cursor.SetThemes(Cursor::WAR_NONE); - } -} - -void Battle2::Interface::HumanCastSpellTurn(const Stats & b, Actions & a, std::string & msg) -{ - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - // reset cast - if(le.MousePressRight()) - humanturn_spell = Spell::NONE; - else - if(le.MouseCursor(rectBoard) && humanturn_spell != Spell::NONE) - { - const u16 themes = GetBattleSpellCursor(le.GetMouseCursor(), msg); - - if(cursor.Themes() != themes) - cursor.SetThemes(themes); - - if(le.MouseClickLeft() && Cursor::WAR_NONE != cursor.Themes()) - { - const s16 index = arena.board.GetIndexAbsPosition(le.GetMouseCursor()); - - if(index < 0) - { - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Interface::HumanCastSpellTurn: " << " dst out of range"); - return; - } - - if(Cursor::SP_TELEPORT == cursor.Themes()) - { - if(MAXU16 == teleport_src) - teleport_src = index; - else - { - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Interface::HumanCastSpellTurn: " << Spell::GetName(Spell::FromInt(humanturn_spell)) << ", dst: " << index); - a.AddedCastTeleportAction(teleport_src, index); - humanturn_spell = Spell::NONE; - humanturn_exit = true; - teleport_src = MAXU16; - } - } - else - { - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Interface::HumanCastSpellTurn: " << Spell::GetName(Spell::FromInt(humanturn_spell)) << ", dst: " << index); - a.AddedCastAction(humanturn_spell, index); - humanturn_spell = Spell::NONE; - humanturn_exit = true; - } - } - } - else - { - cursor.SetThemes(Cursor::WAR_NONE); - } -} - -void Battle2::Interface::FadeArena(void) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - Settings & conf = Settings::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.WAR_POINTER); - Redraw(); - cursor.Show(); - display.Flip(); - if(!conf.QVGA()) - { - display.Fade(100); - display.Flip(); - } -} - -u8 Battle2::GetIndexIndicator(const Stats & b) -{ - // yellow - if(b.Modes(IS_GREEN_STATUS) && b.Modes(IS_RED_STATUS)) return 13; - else - // green - if(b.Modes(IS_GREEN_STATUS)) return 12; - else - // red - if(b.Modes(IS_RED_STATUS)) return 14; - - return 10; -} - -void Battle2::Interface::SetAutoBattle(const Stats & b, Actions & a) -{ - Settings::Get().SetAutoBattle(true); - Cursor::Get().SetThemes(Cursor::WAR_NONE); - status.SetMessage(_("Set auto battle on"), true); - arena.AITurn(b, a); - humanturn_redraw = true; - humanturn_exit = true; -} - -void Battle2::Interface::ResetAutoBattle(void) -{ - Settings::Get().SetAutoBattle(false); - status.SetMessage(_("Set auto battle off"), true); - humanturn_redraw = true; -} - -void Battle2::Interface::EventShowOptions(void) -{ - btn_settings.PressDraw(); - DialogBattleSettings(); - btn_settings.ReleaseDraw(); - humanturn_redraw = true; -} - -void Battle2::Interface::EventAutoSwitch(const Stats & b, Actions & a) -{ - btn_auto.PressDraw(); - if(Settings::Get().AutoBattle()) - ResetAutoBattle(); - else - SetAutoBattle(b, a); - btn_auto.ReleaseDraw(); -} - -void Battle2::Interface::ButtonAutoAction(const Stats & b, Actions & a) -{ - LocalEvent & le = LocalEvent::Get(); - - le.MousePressLeft(btn_auto) ? btn_auto.PressDraw() : btn_auto.ReleaseDraw(); - - if(le.MouseClickLeft(btn_auto)) - { - if(Settings::Get().AutoBattle()) - ResetAutoBattle(); - else - SetAutoBattle(b, a); - } -} - -void Battle2::Interface::ButtonSettingsAction(void) -{ - LocalEvent & le = LocalEvent::Get(); - - le.MousePressLeft(btn_settings) ? btn_settings.PressDraw() : btn_settings.ReleaseDraw(); - - if(le.MouseClickLeft(btn_settings)) - { - DialogBattleSettings(); - humanturn_redraw = true; - } -} - -void Battle2::Interface::ButtonSkipAction(Actions & a) - -{ - LocalEvent & le = LocalEvent::Get(); - - le.MousePressLeft(btn_skip) ? btn_skip.PressDraw() : btn_skip.ReleaseDraw(); - - if(le.MouseClickLeft(btn_skip) && b_current) - { - a.AddedSkipAction(*b_current, true); - humanturn_exit = true; - } -} - -u8 Battle2::Interface::GetAllowSwordDirection(u16 index) -{ - u8 res = 0; - - if(b_current) - { - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - if(Board::isValidDirection(index, dir)) - { - const u16 from = Board::GetIndexDirection(index, dir); - - if(UNKNOWN != arena.board[from].GetDirection() || - from == b_current->GetPosition() || - (b_current->isWide() && from == b_current->GetTailIndex())) - { - res |= dir; - } - } - } - } - - return res; -} - -void Battle2::Interface::MousePressRightBoardAction(u16 themes, s16 index, Actions & a) -{ - if(index >= 0) - { - const Stats* b = arena.GetTroopBoard(index); - if(b) - { - const Settings & conf = Settings::Get(); - const u8 allow = GetAllowSwordDirection(index); - - if(conf.MyColor() == b->GetColor() || !conf.ExtTapMode() || !allow) - Dialog::ArmyInfo(b->troop, Dialog::READONLY); - else - switch(PocketPC::GetCursorAttackDialog(b->GetCellPosition(), allow)) - { - case Cursor::SWORD_TOPLEFT: MouseLeftClickBoardAction(Cursor::SWORD_TOPLEFT, index, a); break; - case Cursor::SWORD_TOPRIGHT: MouseLeftClickBoardAction(Cursor::SWORD_TOPRIGHT, index, a); break; - case Cursor::SWORD_RIGHT: MouseLeftClickBoardAction(Cursor::SWORD_RIGHT, index, a); break; - case Cursor::SWORD_BOTTOMRIGHT: MouseLeftClickBoardAction(Cursor::SWORD_BOTTOMRIGHT, index, a); break; - case Cursor::SWORD_BOTTOMLEFT: MouseLeftClickBoardAction(Cursor::SWORD_BOTTOMLEFT, index, a); break; - case Cursor::SWORD_LEFT: MouseLeftClickBoardAction(Cursor::SWORD_LEFT, index, a); break; - - default: Dialog::ArmyInfo(b->troop, Dialog::READONLY); break; - } - } - } -} - -void Battle2::Interface::MouseLeftClickBoardAction(u16 themes, s16 index, Actions & a) -{ - if(index >= 0 && b_current) - switch(themes) - { - case Cursor::WAR_FLY: - case Cursor::WAR_MOVE: - a.AddedMoveAction(*b_current, index); - a.AddedEndAction(*b_current); - humanturn_exit = true; - break; - - case Cursor::SWORD_TOPLEFT: - case Cursor::SWORD_TOPRIGHT: - case Cursor::SWORD_RIGHT: - case Cursor::SWORD_BOTTOMRIGHT: - case Cursor::SWORD_BOTTOMLEFT: - case Cursor::SWORD_LEFT: - { - const Stats* enemy = arena.GetTroopBoard(index); - const direction_t dir = GetDirectionFromCursorSword(themes); - - if(enemy && Board::isValidDirection(index, dir)) - { - const u16 move = Board::GetIndexDirection(index, dir); - if(b_current->GetPosition() != move) - a.AddedMoveAction(*b_current, move); - a.AddedAttackAction(*b_current, *enemy); - a.AddedEndAction(*b_current); - humanturn_exit = true; - } - break; - } - - case Cursor::WAR_BROKENARROW: - case Cursor::WAR_ARROW: - { - const Stats* enemy = arena.GetTroopBoard(index); - if(enemy) - { - a.AddedAttackAction(*b_current, *enemy); - a.AddedEndAction(*b_current); - humanturn_exit = true; - } - break; - } - - case Cursor::WAR_INFO: - { - const Stats* b = arena.GetTroopBoard(index); - if(b) - { - Dialog::ArmyInfo(b->troop, Dialog::BUTTONS | Dialog::READONLY); - humanturn_redraw = true; - } - break; - } - - default: break; - } -} - -void Battle2::Interface::RedrawTroopFrameAnimation(Stats & b) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - while(le.HandleEvents()) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_FRAME_DELAY)) - { - cursor.Hide(); - Redraw(); - cursor.Show(); - display.Flip(); - if(b.isFinishAnimFrame()) break; - b.IncreaseAnimFrame(); - } - } -} - -void Battle2::Interface::RedrawActionSkipStatus(const Stats & attacker) -{ - std::string msg; - if(attacker.Modes(TR_HARDSKIP)) - { - msg = _("%{name} skipping turn"); - if(Settings::Get().ExtBattleSkipIncreaseDefense()) msg.append(_(", and get +2 defense")); - } - else - msg = _("%{name} waiting turn"); - - String::Replace(msg, "%{name}", attacker.GetName()); - status.SetMessage(msg, true); -} - -void Battle2::Interface::RedrawActionAttackPart1(Stats & attacker, Stats & defender, const std::vector & targets) -{ - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - Cursor & cursor = Cursor::Get(); - - cursor.SetThemes(Cursor::WAR_NONE); - - b_current = NULL; - b_move = &attacker; - p_move = attacker.GetCellPosition(); - - u8 action0 = AS_ATTK0; - u8 action1 = 0; - - const Rect & pos1 = attacker.GetCellPosition(); - const Rect & pos2 = defender.GetCellPosition(); - - if(pos2.y < pos1.y) - action1 = AS_ATTK1; - else - if(pos2.y > pos1.y) - action1 = AS_ATTK3; - else - action1 = AS_ATTK2; - - // long distance attack animation - if(attacker.isDoubleCellAttack() && 2 == targets.size()) - { - action0 = AS_SHOT0; - if(action1 == AS_ATTK1) - action1 = AS_SHOT1; - else - if(action1 == AS_ATTK3) - action1 = AS_SHOT3; - else - action1 = AS_SHOT2; - } - - // check archers - const bool archer = attacker.isArchers() && !attacker.isHandFighting(); - - if(archer) - { - const float dx = pos1.x - pos2.x; - const float dy = pos1.y - pos2.y; - const float tan = std::fabs(dy / dx); - - action0 = AS_SHOT0; - action1 = (0.6 >= tan ? AS_SHOT2 : (dy > 0 ? AS_SHOT1 : AS_SHOT3)); - } - - // redraw luck animation - if(attacker.Modes(LUCK_GOOD)) - { - std::string msg = _("Good luck shines on the %{attacker}"); - String::Replace(msg, "%{attacker}", attacker.GetName()); - status.SetMessage(msg, true); - status.SetMessage("", false); - - RedrawTroopWithFrameAnimation(attacker, ICN::BLESS, M82::FromSpell(Spell::BLESS), false); - } - else - if(attacker.Modes(LUCK_BAD)) - { - std::string msg = _("Bad luck descends on the %{attacker}"); - String::Replace(msg, "%{attacker}", attacker.GetName()); - status.SetMessage(msg, true); - status.SetMessage("", false); - } - - AGG::PlaySound(attacker.M82Attk()); - - // redraw attack animation - attacker.ResetAnimFrame(action0); - RedrawTroopFrameAnimation(attacker); - - if(attacker.GetFrameState(action1).count) - { - attacker.ResetAnimFrame(action1); - RedrawTroopFrameAnimation(attacker); - } - DELAY(200); - - // draw missile animation - if(archer) - { - const Sprite & missile = AGG::GetICN(attacker.ICNMiss(), ICN::GetMissIndex(attacker.ICNMiss(), pos1.x - pos2.x, pos1.y - pos2.y), pos1.x > pos2.x); - std::vector points; - std::vector::const_iterator pnt; - - if(Settings::Get().QVGA()) - { - const Point line_from(pos1.x + (attacker.isReflect() ? -5 : pos1.w), pos1.y + attacker.GetStartMissileOffset(action1) / 2); - const Point line_to(pos2.x + (attacker.isReflect() ? pos1.w : 0), pos2.y); - GetLinePoints(line_from, line_to, (missile.w() < 8 ? 8 : missile.w()), points); - } - else - { - const Point line_from(pos1.x + (attacker.isReflect() ? -10 : pos1.w), pos1.y + attacker.GetStartMissileOffset(action1)); - const Point line_to(pos2.x + (attacker.isReflect() ? pos1.w : 0), pos2.y); - GetLinePoints(line_from, line_to, (missile.w() < 8 ? 8 : missile.w()), points); - } - - pnt = points.begin(); - while(le.HandleEvents(false) && pnt != points.end()) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_MISSILE_DELAY)) - { - cursor.Hide(); - Redraw(); - display.Blit(missile, *pnt); - cursor.Show(); - display.Flip(); - ++pnt; - } - } - } - - // post attack action - switch(attacker.troop.GetID()) - { - case Monster::VAMPIRE_LORD: - // possible: vampire ressurect animation - //RedrawTroopWithFrameAnimation(attacker, , ); - break; - - case Monster::LICH: - case Monster::POWER_LICH: - // lich clod animation - RedrawTroopWithFrameAnimation(defender, ICN::LICHCLOD, attacker.M82Expl(), true); - break; - - default: break; - } -} - -void Battle2::Interface::RedrawActionAttackPart2(Stats & attacker, std::vector & targets) -{ - // targets damage animation - RedrawActionWinces(targets); - - // draw status for first defender - if(targets.size()) - { - std::string msg = _("%{attacker} do %{damage} damage."); - String::Replace(msg, "%{attacker}", attacker.GetName()); - - if(1 < targets.size()) - { - u32 killed = 0; - u32 damage = 0; - std::vector::const_iterator it1 = targets.begin(); - std::vector::const_iterator it2 = targets.end(); - for(; it1 != it2; ++it1){ killed += (*it1).killed; damage += (*it1).damage; } - - String::Replace(msg, "%{damage}", damage); - - if(killed) - { - msg.append(" "); - msg.append(_("%{count} creatures perished.")); - String::Replace(msg, "%{count}", killed); - } - } - else - { - TargetInfo & target = targets.front(); - String::Replace(msg, "%{damage}", target.damage); - - if(target.killed) - { - msg.append(" "); - msg.append(ngettext("one %{defender} perish.", "%{count} %{defender} perished.", target.killed)); - String::Replace(msg, "%{count}", target.killed); - String::Replace(msg, "%{defender}", target.defender->GetPluralName(target.killed)); - } - } - - status.SetMessage(msg, true); - status.SetMessage("", false); - } - - // targets killed animation - RedrawActionKills(targets); - - // restore - std::vector::iterator it = targets.begin(); - for(; it != targets.end(); ++it) if((*it).defender) - { - TargetInfo & target = *it; - if(!target.defender->isValid()) - { - const animframe_t & frm = target.defender->GetFrameState(AS_KILL); - target.defender->animframe = frm.start + frm.count - 1; - } - else - target.defender->ResetAnimFrame(AS_IDLE); - } - if(opponent1) opponent1->ResetAnimFrame(OP_IDLE); - if(opponent2) opponent2->ResetAnimFrame(OP_IDLE); - b_move = NULL; - attacker.ResetAnimFrame(AS_IDLE); -} - -void Battle2::Interface::RedrawActionWinces(std::vector & targets) -{ - const Settings & conf = Settings::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - Cursor & cursor = Cursor::Get(); - - // targets damage animation - std::vector::iterator it = targets.begin(); - std::string msg; - u16 py = (conf.QVGA() ? 20 : 50); - u8 finish = 0; - - for(; it != targets.end(); ++it) if((*it).defender) - { - if((*it).damage) - { - TargetInfo & target = *it; - // wnce animation - target.defender->ResetAnimFrame(AS_WNCE); - AGG::PlaySound(target.defender->M82Wnce()); - ++finish; - } - else - { - // defense - AGG::PlaySound(M82::RSBRYFZL); - } - } - - // targets damage animation loop - while(le.HandleEvents() && finish != std::count_if(targets.begin(), targets.end(), std::mem_fun_ref(&TargetInfo::isFinishAnimFrame))) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_FRAME_DELAY)) - { - it = targets.begin(); - for(; it != targets.end(); ++it) if((*it).defender) - { - TargetInfo & target = *it; - const Rect & pos = target.defender->GetCellPosition(); - - cursor.Hide(); - Redraw(); - - // extended damage info - if(conf.ExtBattleShowDamage() && target.killed) - { - msg = "-"; - String::AddInt(msg, target.killed); - Text txt(msg, Font::YELLOW_SMALL); - txt.Blit(pos.x + (target.defender->isWide() ? 0 : (pos.w - txt.w()) / 2), pos.y - py); - } - - cursor.Show(); - display.Flip(); - target.defender->IncreaseAnimFrame(); - } - py += (conf.QVGA() ? 5 : 10); - } - } - - DELAY(200); -} - -void Battle2::Interface::RedrawActionKills(std::vector & targets) -{ - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - Cursor & cursor = Cursor::Get(); - - // targets damage animation - std::vector::iterator it = targets.begin(); - std::string msg; - u8 finish = 0; - - // targets killed animation - it = targets.begin(); - finish = 0; - for(; it != targets.end(); ++it) if((*it).defender) - { - TargetInfo & target = *it; - - if(!target.defender->isValid()) - { - AGG::PlaySound(target.defender->M82Kill()); - target.defender->ResetAnimFrame(AS_KILL); - ++finish; - // set opponent OP_SRRW animation - OpponentSprite* commander = NULL; - if(target.defender->GetColor() != Color::GRAY) - { - commander = target.defender->GetColor() == arena.army1.GetColor() ? opponent1 : opponent2; - } - if(commander) commander->ResetAnimFrame(OP_SRRW); - } - else - target.defender->ResetAnimFrame(AS_IDLE); - } - - // targets killed animation loop - while(le.HandleEvents() && finish != std::count_if(targets.begin(), targets.end(), std::mem_fun_ref(&TargetInfo::isFinishAnimFrame))) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_FRAME_DELAY)) - { - it = targets.begin(); - for(; it != targets.end(); ++it) if((*it).defender) - { - TargetInfo & target = *it; - - cursor.Hide(); - Redraw(); - cursor.Show(); - display.Flip(); - - if(!target.defender->isValid()) target.defender->IncreaseAnimFrame(); - } - } - } -} - -void Battle2::Interface::RedrawActionMove(Stats & b, const std::vector & path) -{ - Cursor & cursor = Cursor::Get(); - std::vector::const_iterator dst = path.begin(); - - cursor.SetThemes(Cursor::WAR_NONE); - - b_current = NULL; - b_move = &b; - - while(dst != path.end() && *dst < arena.board.size()) - { - const Cell & cell = arena.board[*dst]; - p_move = cell.pos; - - if(arena.bridge) - { - if(!arena.bridge->isDown() && arena.bridge->NeedDown(b, *dst)) - { - RedrawBridgeAnimation(true); - arena.bridge->SetDown(true); - } - else - if(arena.bridge->isValid() && arena.bridge->isDown() && arena.bridge->AllowUp()) - { - RedrawBridgeAnimation(false); - arena.bridge->SetDown(false); - } - } - - if(b.isWide() && b.GetTailIndex() == *dst) - b.UpdateDirection(cell); - else - { - b.UpdateDirection(cell); - AGG::PlaySound(b.M82Move()); - b.ResetAnimFrame(AS_MOVE); - RedrawTroopFrameAnimation(b); - } - b.position = *dst; - ++dst; - } - - // restore - b_fly = NULL; - b_move = NULL; - b_current = NULL; - b.ResetAnimFrame(AS_IDLE); -} - -void Battle2::Interface::RedrawActionFly(Stats & b, u16 dst) -{ - Cursor & cursor = Cursor::Get(); - const Rect & pos1 = b.GetCellPosition(); - const Rect & pos2 = arena.board[dst].pos; - std::vector points; - std::vector::const_iterator pnt; - - Point pt1(pos1.x, pos1.y); - Point pt2(pos2.x, pos2.y); - - cursor.SetThemes(Cursor::WAR_NONE); - const u8 step = b.isWide() ? 80 : 40; - GetLinePoints(pt1, pt2, Settings::Get().QVGA() ? step / 2 : step, points); - - pnt = points.begin(); - - // jump up - b_current = NULL; - b_move = NULL; - p_move = pnt != points.end() ? *pnt : pt1; - b_fly = NULL; - b_move = &b; - p_fly = pt1; - - b.ResetAnimFrame(AS_FLY1); - RedrawTroopFrameAnimation(b); - - b_move = NULL; - b_fly = &b; - p_fly = p_move; - if(pnt != points.end()) ++pnt; - - while(pnt != points.end()) - { - p_move = *pnt; - - AGG::PlaySound(b.M82Move()); - b.ResetAnimFrame(AS_FLY2); - RedrawTroopFrameAnimation(b); - - p_fly = p_move; - ++pnt; - } - - b.position = dst; - - // jump down - b_fly = NULL; - b_move = &b; - p_move = pt2; - b.ResetAnimFrame(AS_FLY3); - RedrawTroopFrameAnimation(b); - - // restore - b_move = NULL; - b.ResetAnimFrame(AS_IDLE); -} - -void Battle2::Interface::RedrawActionResistSpell(const Stats & target) -{ - std::string str(_("The %{name} resist the spell!")); - String::Replace(str, "%{name}", target.GetName()); - status.SetMessage(str, true); - status.SetMessage("", false); -} - -void Battle2::Interface::RedrawActionSpellCastPart1(u8 spell2, u16 dst, const std::string & name, const std::vector & targets) -{ - Spell::spell_t spell = Spell::FromInt(spell2); - std::string msg; - Stats* target = targets.size() ? targets.front().defender : NULL; - - if(target && target->GetPosition() == dst) - { - msg = _("%{name} casts %{spell} on the %{troop}."); - String::Replace(msg, "%{troop}", target->GetName()); - } - else - if(Spell::isApplyWithoutFocusObject(spell)) - msg = _("%{name} casts %{spell}."); - - if(msg.size()) - { - String::Replace(msg, "%{name}", name); - String::Replace(msg, "%{spell}", Spell::GetName(Spell::FromInt(spell))); - status.SetMessage(msg, true); - status.SetMessage("", false); - } - - // without object - switch(spell) - { - case Spell::FIREBALL: RedrawTargetsWithFrameAnimation(dst, targets, ICN::FIREBALL, M82::FromSpell(spell)); break; - case Spell::FIREBLAST: RedrawTargetsWithFrameAnimation(dst, targets, ICN::FIREBAL2, M82::FromSpell(spell)); break; - case Spell::METEORSHOWER: RedrawTargetsWithFrameAnimation(dst, targets, ICN::METEOR, M82::FromSpell(spell)); break; - case Spell::COLDRING: RedrawActionColdRingSpell(dst, targets); break; - - case Spell::MASSSHIELD: RedrawTargetsWithFrameAnimation(targets, ICN::SHIELD, M82::FromSpell(spell), false); break; - case Spell::MASSCURE: RedrawTargetsWithFrameAnimation(targets, ICN::MAGIC01, M82::FromSpell(spell), false); break; - case Spell::MASSHASTE: RedrawTargetsWithFrameAnimation(targets, ICN::HASTE, M82::FromSpell(spell), false); break; - case Spell::MASSSLOW: RedrawTargetsWithFrameAnimation(targets, ICN::MAGIC02, M82::FromSpell(spell), false); break; - case Spell::MASSBLESS: RedrawTargetsWithFrameAnimation(targets, ICN::BLESS, M82::FromSpell(spell), false); break; - case Spell::MASSCURSE: RedrawTargetsWithFrameAnimation(targets, ICN::CURSE, M82::FromSpell(spell), false); break; - case Spell::MASSDISPEL: RedrawTargetsWithFrameAnimation(targets, ICN::MAGIC07, M82::FromSpell(spell), false); break; - - case Spell::DEATHRIPPLE: - case Spell::DEATHWAVE: RedrawTargetsWithFrameAnimation(targets, ICN::REDDEATH, M82::FromSpell(spell), true); break; - - case Spell::HOLYWORD: - case Spell::HOLYSHOUT: RedrawTargetsWithFrameAnimation(targets, ICN::BLUEFIRE, M82::FromSpell(spell), true); break; - - case Spell::ELEMENTALSTORM: RedrawActionElementalStormSpell(targets); break; - case Spell::ARMAGEDDON: RedrawActionArmageddonSpell(targets); break; - - default: break; - } - - // with object - if(target) - { - if(Spell::isResurrect(spell)) - RedrawActionResurrectSpell(*target, spell); - else - switch(spell) - { - // simple spell animation - case Spell::BLESS: RedrawTroopWithFrameAnimation(*target, ICN::BLESS, M82::FromSpell(spell), false); break; - case Spell::BLIND: RedrawTroopWithFrameAnimation(*target, ICN::BLIND, M82::FromSpell(spell), false); break; - case Spell::CURE: RedrawTroopWithFrameAnimation(*target, ICN::MAGIC01, M82::FromSpell(spell), false); break; - case Spell::SLOW: RedrawTroopWithFrameAnimation(*target, ICN::MAGIC02, M82::FromSpell(spell), false); break; - case Spell::SHIELD: RedrawTroopWithFrameAnimation(*target, ICN::SHIELD, M82::FromSpell(spell), false); break; - case Spell::HASTE: RedrawTroopWithFrameAnimation(*target, ICN::HASTE, M82::FromSpell(spell), false); break; - case Spell::CURSE: RedrawTroopWithFrameAnimation(*target, ICN::CURSE, M82::FromSpell(spell), false); break; - case Spell::ANTIMAGIC: RedrawTroopWithFrameAnimation(*target, ICN::MAGIC06, M82::FromSpell(spell), false); break; - case Spell::DISPEL: RedrawTroopWithFrameAnimation(*target, ICN::MAGIC07, M82::FromSpell(spell), false); break; - case Spell::STONESKIN: RedrawTroopWithFrameAnimation(*target, ICN::STONSKIN, M82::FromSpell(spell), false); break; - case Spell::STEELSKIN: RedrawTroopWithFrameAnimation(*target, ICN::STELSKIN, M82::FromSpell(spell), false); break; - case Spell::PARALYZE: RedrawTroopWithFrameAnimation(*target, ICN::PARALYZE, M82::FromSpell(spell), false); break; - case Spell::HYPNOTIZE: RedrawTroopWithFrameAnimation(*target, ICN::HYPNOTIZ, M82::FromSpell(spell), false); break; - case Spell::DRAGONSLAYER: RedrawTroopWithFrameAnimation(*target, ICN::DRAGSLAY, M82::FromSpell(spell), false); break; - case Spell::BERSERKER: RedrawTroopWithFrameAnimation(*target, ICN::BERZERK, M82::FromSpell(spell), false); break; - - // uniq spell animation - case Spell::LIGHTNINGBOLT: RedrawActionLightningBoltSpell(*target); break; - case Spell::CHAINLIGHTNING: RedrawActionChainLightningSpell(targets); break; - case Spell::ARROW: RedrawActionArrowSpell(*target); break; - case Spell::COLDRAY: RedrawActionColdRaySpell(*target); break; - case Spell::DISRUPTINGRAY: RedrawActionDisruptingRaySpell(*target); break; - case Spell::BLOODLUST: RedrawActionBloodLustSpell(*target); break; - default: break; - } - } -} - -void Battle2::Interface::RedrawActionSpellCastPart2(u8 spell, std::vector & targets) -{ - if(Spell::isDamage(spell)) - { - // targets damage animation - RedrawActionWinces(targets); - - u32 killed = 0; - u32 damage = 0; - std::vector::const_iterator it1 = targets.begin(); - std::vector::const_iterator it2 = targets.end(); - for(; it1 != it2; ++it1){ killed += (*it1).killed; damage += (*it1).damage; } - - if(damage) - { - std::string msg; - if(Spell::isUndeadOnly(spell)) - msg = _("The %{spell} spell does %{damage} damage to all undead creatures."); - else - if(Spell::isALiveOnly(spell)) - msg = _("The %{spell} spell does %{damage} damage to all living creatures."); - else - msg = _("The %{spell} does %{damage} damage."); - String::Replace(msg, "%{spell}", Spell::GetName(Spell::FromInt(spell))); - String::Replace(msg, "%{damage}", damage); - - if(killed) - { - msg.append(" "); - msg.append(ngettext("one creature perish.", "%{count} creatures perished.", killed)); - String::Replace(msg, "%{count}", killed); - } - - status.SetMessage(msg, true); - } - - // target killed animation - RedrawActionKills(targets); - } - - status.SetMessage(" ", false); - - // restore - std::vector::iterator it = targets.begin(); - for(; it != targets.end(); ++it) if((*it).defender) - { - TargetInfo & target = *it; - if(!target.defender->isValid()) - { - const animframe_t & frm = target.defender->GetFrameState(AS_KILL); - target.defender->animframe = frm.start + frm.count - 1; - } - else - target.defender->ResetAnimFrame(AS_IDLE); - } - if(opponent1) opponent1->ResetAnimFrame(OP_IDLE); - if(opponent2) opponent2->ResetAnimFrame(OP_IDLE); - b_move = NULL; -} - -void Battle2::Interface::RedrawActionMonsterSpellCastStatus(const Stats & attacker, const TargetInfo & target) -{ - const char* msg = NULL; - - switch(attacker.troop()) - { - case Monster::UNICORN: msg = _("The Unicorns attack blinds the %{name}!"); break; - case Monster::MEDUSA: msg = _("The Medusas gaze turns the %{name} to stone!"); break; - case Monster::ROYAL_MUMMY: - case Monster::MUMMY: msg = _("The Mummies' curse falls upon the %{name}!"); break; - case Monster::CYCLOPS: msg = _("The %{name} are paralyzed by the Cyclopes!"); break; - case Monster::ARCHMAGE: msg = _("The Archmagi dispel all good spells on your %{name}!"); break; - default: break; - } - - if(msg) - { - std::string str(msg); - String::Replace(str, "%{name}", target.defender->GetName()); - - status.SetMessage(str, true); - status.SetMessage("", false); - } -} - -void Battle2::Interface::RedrawActionMorale(Stats & b, bool good) -{ - std::string msg; - - if(good) - { - msg = _("High morale enables the %{monster} to attack again."); - String::Replace(msg, "%{monster}", b.GetName()); - status.SetMessage(msg, true); - RedrawTroopWithFrameAnimation(b, ICN::MORALEG, M82::GOODMRLE, false); - } - else - { - msg = _("Low morale causes the %{monster} to freeze in panic."); - String::Replace(msg, "%{monster}", b.GetName()); - status.SetMessage(msg, true); - RedrawTroopWithFrameAnimation(b, ICN::MORALEB, M82::BADMRLE, true); - } -} - -void Battle2::Interface::RedrawActionTowerPart1(Tower & tower, Stats & defender) -{ - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - Cursor & cursor = Cursor::Get(); - - cursor.SetThemes(Cursor::WAR_NONE); - b_current = NULL; - - const Point pos1 = tower.GetPortPosition(); - const Rect & pos2 = defender.GetCellPosition(); - - AGG::PlaySound(M82::KEEPSHOT); - - // draw missile animation - const Sprite & missile = AGG::GetICN(ICN::KEEP, ICN::GetMissIndex(ICN::KEEP, pos1.x - pos2.x, pos1.y - pos2.y), pos1.x > pos2.x); - std::vector points; - std::vector::const_iterator pnt; - - GetLinePoints(pos1, Point(pos2.x + pos2.w, pos2.y), missile.w(), points); - - pnt = points.begin(); - while(le.HandleEvents(false) && pnt != points.end()) - { - CheckGlobalEvents(le); - - // fast draw - if(Game::AnimateInfrequent(Game::BATTLE_MISSILE_DELAY)) - { - cursor.Hide(); - Redraw(); - display.Blit(missile, *pnt); - cursor.Show(); - display.Flip(); - ++pnt; - } - } -} - -void Battle2::Interface::RedrawActionTowerPart2(Tower & tower, TargetInfo & target) -{ - std::vector targets; - targets.push_back(target); - - // targets damage animation - RedrawActionWinces(targets); - - // draw status for first defender - std::string msg = _("Tower do %{damage} damage."); - String::Replace(msg, "%{damage}", target.damage); - if(target.killed) - { - msg.append(" "); - msg.append(ngettext("one %{defender} perish.", "%{count} %{defender} perished.", target.killed)); - String::Replace(msg, "%{count}", target.killed); - String::Replace(msg, "%{defender}", target.defender->GetName()); - } - status.SetMessage(msg, true); - status.SetMessage("", false); - - // targets killed animation - RedrawActionKills(targets); - - // restore - if(!target.defender->isValid()) - { - const animframe_t & frm = target.defender->GetFrameState(AS_KILL); - target.defender->animframe = frm.start + frm.count - 1; - } - else - target.defender->ResetAnimFrame(AS_IDLE); - - if(opponent1) opponent1->ResetAnimFrame(OP_IDLE); - if(opponent2) opponent2->ResetAnimFrame(OP_IDLE); - b_move = NULL; -} - -void Battle2::Interface::RedrawActionCatapult(u8 target) -{ - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - Cursor & cursor = Cursor::Get(); - - const Sprite & missile = AGG::GetICN(ICN::BOULDER, 0); - const Rect & area = border.GetArea(); - - std::vector points; - std::vector::const_iterator pnt; - AGG::PlaySound(M82::CATSND00); - - // catapult animation - while(le.HandleEvents(false) && catapult_frame < 6) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_CATAPULT_DELAY)) - { - cursor.Hide(); - Redraw(); - cursor.Show(); - display.Flip(); - ++catapult_frame; - } - } - - // boulder animation - Point pt1(90, 220); - Point pt2 = arena.catapult->GetTargetPosition(target); - Point max(300, 20); - - if(Settings::Get().QVGA()) - { - pt1.x /= 2; - pt1.y /= 2; - pt2.x /= 2; - pt2.y /= 2; - max.x /= 2; - max.y /= 2; - } - - pt1.x += area.x; - pt2.x += area.x; - max.x += area.x; - pt1.y += area.y; - pt2.y += area.y; - max.y += area.y; - - GetArcPoints(pt1, pt2, max, missile.w(), points); - - pnt = points.begin(); - while(le.HandleEvents(false) && pnt != points.end()) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_CATAPULT2_DELAY)) - { - if(catapult_frame < 9) ++catapult_frame; - - cursor.Hide(); - Redraw(); - display.Blit(missile, *pnt); - cursor.Show(); - display.Flip(); - ++pnt; - } - } - - // clod - u8 frame = 0; - ICN::icn_t icn = target == CAT_MISS ? ICN::SMALCLOD : ICN::LICHCLOD; - AGG::PlaySound(M82::CATSND02); - - while(le.HandleEvents() && frame < AGG::GetICNCount(icn)) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_CATAPULT3_DELAY)) - { - if(catapult_frame < 9) ++catapult_frame; - - cursor.Hide(); - Redraw(); - const Sprite & sprite = AGG::GetICN(icn, frame); - display.Blit(sprite, pt2.x + sprite.x(), pt2.y + sprite.y()); - cursor.Show(); - display.Flip(); - - ++frame; - } - } - - catapult_frame = 0; -} - -void Battle2::Interface::RedrawActionArrowSpell(const Stats & target) -{ - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - Cursor & cursor = Cursor::Get(); - - if(arena.current_commander) - { - Point pt_from, pt_to; - - if(arena.current_commander == opponent1->GetHero()) - { - const Rect & pos1 = opponent1->GetArea(); - pt_from = Point(pos1.x + pos1.w, pos1.y + pos1.h / 2); - - const Rect & pos2 = target.GetCellPosition(); - pt_to = Point(pos2.x, pos2.y); - } - else - { - const Rect & pos = opponent2->GetArea(); - pt_from = Point(pos.x, pos.y + pos.h / 2); - - const Rect & pos2 = target.GetCellPosition(); - pt_to = Point(pos2.x + pos2.w, pos2.y); - } - - const Sprite & missile = AGG::GetICN(ICN::ARCH_MSL, ICN::GetMissIndex(ICN::ARCH_MSL, pt_from.x - pt_to.x, pt_from.y - pt_to.y), pt_from.x > pt_to.x); - std::vector points; - std::vector::const_iterator pnt; - - GetLinePoints(pt_from, pt_to, missile.w(), points); - - cursor.SetThemes(Cursor::WAR_NONE); - AGG::PlaySound(M82::MAGCAROW); - - pnt = points.begin(); - while(le.HandleEvents(false) && pnt != points.end()) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_MISSILE_DELAY)) - { - cursor.Hide(); - Redraw(); - display.Blit(missile, *pnt); - cursor.Show(); - display.Flip(); - ++pnt; - } - } - } -} - -void Battle2::Interface::RedrawActionTeleportSpell(Stats & target, const u16 dst) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - u8 alpha = 250; - - const MonsterInfo & msi = target.GetMonsterInfo(); - const Sprite & sprite1 = AGG::GetICN(msi.icn_file, msi.frm_idle.start, target.reflect); - Sprite sprite2; - sprite2.Set(sprite1.w(), sprite1.h()); - sprite2.SetColorKey(); - sprite2.Blit(sprite1); - sprite2.SetOffset(sprite1.x(), sprite1.y()); - - - cursor.SetThemes(Cursor::WAR_NONE); - cursor.Hide(); - - b_current = ⌖ - b_current_sprite = &sprite2; - - AGG::PlaySound(M82::TELPTOUT); - - while(le.HandleEvents() && alpha > 30) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - sprite2.SetAlpha(alpha); - Redraw(); - cursor.Show(); - display.Flip(); - - alpha -= 20; - } - } - - sprite2.SetAlpha(0); - cursor.Hide(); - Redraw(); - while(Mixer::isValid() && Mixer::isPlaying(-1)) DELAY(10); - - target.SetPosition(dst); - AGG::PlaySound(M82::TELPTIN); - - while(le.HandleEvents() && alpha < 220) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - sprite2.SetAlpha(alpha); - Redraw(); - cursor.Show(); - display.Flip(); - - alpha += 20; - } - } - - b_current = NULL; - b_current_sprite = NULL; -} - -void Battle2::Interface::RedrawActionSummonElementalSpell(const Stats & target) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - u8 alpha = 0; - - const MonsterInfo & msi = target.GetMonsterInfo(); - const Sprite & sprite1 = AGG::GetICN(msi.icn_file, msi.frm_idle.start, target.reflect); - Sprite sprite2; - sprite2.Set(sprite1.w(), sprite1.h()); - sprite2.SetColorKey(); - sprite2.Blit(sprite1); - sprite2.SetOffset(sprite1.x(), sprite1.y()); - - cursor.SetThemes(Cursor::WAR_NONE); - cursor.Hide(); - - b_current = ⌖ - b_current_sprite = &sprite2; - - AGG::PlaySound(M82::SUMNELM); - - while(le.HandleEvents() && alpha < 220) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - sprite2.SetAlpha(alpha); - Redraw(); - cursor.Show(); - display.Flip(); - - alpha += 20; - } - } - - b_current = NULL; - b_current_sprite = NULL; -} - -void Battle2::Interface::RedrawActionMirrorImageSpell(const Stats & target, u16 dst) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - const MonsterInfo & msi = target.GetMonsterInfo(); - const Sprite & sprite = AGG::GetICN(msi.icn_file, msi.frm_idle.start, target.reflect); - std::vector points; - std::vector::const_iterator pnt; - const Rect & rt1 = target.GetCellPosition(); - const Point & pt2 = arena.board[dst].GetPos(); - - GetLinePoints(rt1, pt2, 5, points); - - cursor.SetThemes(Cursor::WAR_NONE); - cursor.Hide(); - - AGG::PlaySound(M82::MIRRORIM); - - pnt = points.begin(); - while(le.HandleEvents() && pnt != points.end()) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - - const s16 sx = target.isReflect() ? - (*pnt).x + (target.isWide() ? rt1.w + rt1.w / 2 : rt1.w / 2) - sprite.w() - sprite.x() : - (*pnt).x + (target.isWide() ? -rt1.w / 2 : rt1.w / 2) + sprite.x(); - const s16 sy = (*pnt).y + rt1.h + sprite.y() - 10; - - Redraw(); - display.Blit(sprite, sx, sy); - cursor.Show(); - display.Flip(); - - ++pnt; - } - } -} - -void Battle2::Interface::RedrawActionLightningBoltSpell(Stats & target) -{ - // FIX: LightningBolt draw - RedrawTroopWithFrameAnimation(target, ICN::SPARKS, M82::FromSpell(Spell::LIGHTNINGBOLT), true); -} - -void Battle2::Interface::RedrawActionChainLightningSpell(const std::vector & targets) -{ - std::vector::const_iterator it1 = targets.begin(); - std::vector::const_iterator it2 = targets.end(); - - // FIX: ChainLightning draw - //AGG::PlaySound(targets.size() > 1 ? M82::CHAINLTE : M82::LIGHTBLT); - - for(; it1 != it2; ++it1) - RedrawTroopWithFrameAnimation(*(it1->defender), ICN::SPARKS, M82::FromSpell(Spell::LIGHTNINGBOLT), true); -} - -void Battle2::Interface::RedrawActionBloodLustSpell(Stats & target) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - u8 alpha = 10; - - const MonsterInfo & msi = target.GetMonsterInfo(); - const Sprite & sprite1 = AGG::GetICN(msi.icn_file, msi.frm_idle.start, target.reflect); - Sprite sprite2; - sprite2.SetOffset(sprite1.x(), sprite1.y()); - sprite2.Set(sprite1.w(), sprite1.h()); - sprite2.SetColorKey(); - sprite2.Blit(sprite1); - Surface sprite3; - Surface::MakeStencil(sprite3, sprite1, sprite1.GetColor(0xD8)); - - cursor.SetThemes(Cursor::WAR_NONE); - cursor.Hide(); - - b_current = ⌖ - b_current_sprite = &sprite2; - AGG::PlaySound(M82::BLOODLUS); - - while(le.HandleEvents() && alpha < 120) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - sprite3.SetAlpha(alpha); - sprite2.Blit(sprite1); - sprite2.Blit(sprite3); - Redraw(); - cursor.Show(); - display.Flip(); - - alpha += 10; - } - } - - while(Mixer::isValid() && Mixer::isPlaying(-1)) DELAY(10); - - b_current = NULL; - b_current_sprite = NULL; -} - -void Battle2::Interface::RedrawActionColdRaySpell(Stats & target) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - const ICN::icn_t icn = ICN::COLDRAY; - u8 frame = 0; - - std::vector points; - std::vector::const_iterator pnt; - Point pt_from, pt_to; - - if(arena.current_commander == opponent1->GetHero()) - { - const Rect & pos1 = opponent1->GetArea(); - pt_from = Point(pos1.x + pos1.w, pos1.y + pos1.h / 2); - - const Rect & pos2 = target.GetCellPosition(); - pt_to = Point(pos2.x, pos2.y); - } - else - { - const Rect & pos = opponent2->GetArea(); - pt_from = Point(pos.x, pos.y + pos.h / 2); - - const Rect & pos2 = target.GetCellPosition(); - pt_to = Point(pos2.x + pos2.w, pos2.y); - } - - const u16 dx = std::abs(pt_from.x - pt_to.x); - const u16 dy = std::abs(pt_from.y - pt_to.y); - const u16 step = (dx > dy ? dx / AGG::GetICNCount(icn) : dy / AGG::GetICNCount(icn)); - GetLinePoints(pt_from, pt_to, step, points); - - cursor.SetThemes(Cursor::WAR_NONE); - AGG::PlaySound(M82::COLDRAY); - - pnt = points.begin(); - while(le.HandleEvents() && frame < AGG::GetICNCount(icn) && pnt != points.end()) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - const Sprite & sprite = AGG::GetICN(icn, frame); - display.Blit(sprite, (*pnt).x - sprite.w() / 2, (*pnt).y - sprite.h() / 2); - cursor.Show(); - display.Flip(); - - ++frame; - ++pnt; - } - } - - RedrawTroopWithFrameAnimation(target, ICN::ICECLOUD, M82::UNKNOWN, true); -} - -void Battle2::Interface::RedrawActionResurrectSpell(Stats & target, u8 spell) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - M82::m82_t wav = M82::UNKNOWN; - - switch(spell) - { - case Spell::ANIMATEDEAD: wav = M82::MNRDEATH; break; - case Spell::RESURRECT: wav = M82::RESURECT; break; - case Spell::RESURRECTTRUE: wav = M82::RESURTRU; break; - default: break; - } - - AGG::PlaySound(wav); - - if(!target.isValid()) - { - target.animstep = -1; - - while(le.HandleEvents() && !target.isFinishAnimFrame()) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - Redraw(); - cursor.Show(); - display.Flip(); - target.IncreaseAnimFrame(); - } - } - - target.animstep = 1; - } - - RedrawTroopWithFrameAnimation(target, ICN::YINYANG, M82::UNKNOWN, false); -} - -void Battle2::Interface::RedrawActionDisruptingRaySpell(Stats & target) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - const MonsterInfo & msi = target.GetMonsterInfo(); - const Sprite & sprite1 = AGG::GetICN(msi.icn_file, msi.frm_idle.start, target.reflect); - Sprite sprite2(*target.contours[target.isReflect() ? 3 : 2]); - sprite2.SetOffset(sprite1.x(), sprite1.y()); - - const ICN::icn_t icn = ICN::DISRRAY; - u8 frame = 0; - std::vector points; - std::vector::const_iterator pnt; - Point pt_from, pt_to; - - if(arena.current_commander == opponent1->GetHero()) - { - const Rect & pos1 = opponent1->GetArea(); - pt_from = Point(pos1.x + pos1.w, pos1.y + pos1.h / 2); - - const Rect & pos2 = target.GetCellPosition(); - pt_to = Point(pos2.x, pos2.y); - } - else - { - const Rect & pos = opponent2->GetArea(); - pt_from = Point(pos.x, pos.y + pos.h / 2); - - const Rect & pos2 = target.GetCellPosition(); - pt_to = Point(pos2.x + pos2.w, pos2.y); - } - - const u16 dx = std::abs(pt_from.x - pt_to.x); - const u16 dy = std::abs(pt_from.y - pt_to.y); - const u16 step = (dx > dy ? dx / AGG::GetICNCount(icn) : dy / AGG::GetICNCount(icn)); - GetLinePoints(pt_from, pt_to, step, points); - - cursor.SetThemes(Cursor::WAR_NONE); - AGG::PlaySound(M82::DISRUPTR); - - pnt = points.begin(); - while(le.HandleEvents() && frame < AGG::GetICNCount(icn) && pnt != points.end()) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - const Sprite & sprite = AGG::GetICN(icn, frame); - display.Blit(sprite, (*pnt).x - sprite.w() / 2, (*pnt).y - sprite.h() / 2); - cursor.Show(); - display.Flip(); - - ++frame; - ++pnt; - } - } - - // part 2 - frame = 0; - const Stats* old_current = b_current; - b_current = ⌖ - b_current_sprite = &sprite2; - p_move = Point(0, 0); - - while(le.HandleEvents() && frame < 20) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_DISRUPTING_DELAY)) - { - cursor.Hide(); - sprite2.SetOffset(sprite1.x() + (frame % 2 ? -1 : 1), sprite1.y()); - Redraw(); - cursor.Show(); - display.Flip(); - - ++frame; - } - } - - b_current = old_current; - b_current_sprite = NULL; -} - -void Battle2::Interface::RedrawActionColdRingSpell(const u16 dst, const std::vector & targets) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - const ICN::icn_t icn = ICN::COLDRING; - const M82::m82_t m82 = M82::FromSpell(Spell::COLDRING); - - u8 frame = 0; - std::vector::const_iterator it; - const Rect & center = arena.board[dst].GetPos(); - - cursor.SetThemes(Cursor::WAR_NONE); - - // set WNCE - b_current = NULL; - for(it = targets.begin(); it != targets.end(); ++it) - if((*it).defender && (*it).damage) (*it).defender->ResetAnimFrame(AS_WNCE); - - if(M82::UNKNOWN != m82) AGG::PlaySound(m82); - - while(le.HandleEvents() && frame < AGG::GetICNCount(icn)) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - Redraw(); - - const Sprite & sprite1 = AGG::GetICN(icn, frame); - display.Blit(sprite1, center.x + center.w / 2 + sprite1.x(), center.y + center.h / 2 + sprite1.y()); - const Sprite & sprite2 = AGG::GetICN(icn, frame, true); - display.Blit(sprite2, center.x + center.w / 2 - sprite2.w() - sprite2.x(), center.y + center.h / 2 + sprite2.y()); - cursor.Show(); - display.Flip(); - - for(it = targets.begin(); it != targets.end(); ++it) if((*it).defender && (*it).damage) - (*it).defender->IncreaseAnimFrame(false); - ++frame; - } - } - - - for(it = targets.begin(); it != targets.end(); ++it) if((*it).defender) - { - (*it).defender->ResetAnimFrame(AS_IDLE); - b_current = NULL; - } -} - -void Battle2::Interface::RedrawActionElementalStormSpell(const std::vector & targets) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - const ICN::icn_t icn = ICN::STORM; - const M82::m82_t m82 = M82::FromSpell(Spell::ELEMENTALSTORM); - const Rect & area = border.GetArea(); - - u8 frame = 0; - u8 repeat = 4; - std::vector::const_iterator it; - Point center; - - cursor.SetThemes(Cursor::WAR_NONE); - - b_current = NULL; - for(it = targets.begin(); it != targets.end(); ++it) - if((*it).defender && (*it).damage) (*it).defender->ResetAnimFrame(AS_WNCE); - - if(M82::UNKNOWN != m82) AGG::PlaySound(m82); - - while(le.HandleEvents() && frame < AGG::GetICNCount(icn)) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - Redraw(); - - const Sprite & sprite = AGG::GetICN(icn, frame); - for(center.y = area.y; center.y + sprite.h() < area.y + area.h - 20; center.y += sprite.h()) - for(center.x = area.x; center.x + sprite.w() < area.x + area.w; center.x += sprite.w()) - display.Blit(sprite, center); - - RedrawInterface(); - cursor.Show(); - display.Flip(); - - for(it = targets.begin(); it != targets.end(); ++it) if((*it).defender && (*it).damage) - (*it).defender->IncreaseAnimFrame(false); - ++frame; - - if(frame == AGG::GetICNCount(icn) && repeat) - { - --repeat; - frame = 0; - } - } - } - - - for(it = targets.begin(); it != targets.end(); ++it) if((*it).defender) - { - (*it).defender->ResetAnimFrame(AS_IDLE); - b_current = NULL; - } -} - -void Battle2::Interface::RedrawActionArmageddonSpell(const std::vector & targets) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - Rect area = border.GetArea(); - - u8 alpha = 10; - area.h -= Settings::Get().QVGA() ? 18 : 36; - - Surface sprite1; - Surface sprite2; - sprite1.Set(area.w, area.h); - sprite2.Set(area.w, area.h); - - cursor.SetThemes(Cursor::WAR_NONE); - cursor.Hide(); - - sprite1.Blit(display, area, 0, 0); - sprite2.Fill(sprite2.GetColor(0xD8)); - - b_current = NULL; - AGG::PlaySound(M82::ARMGEDN); - - while(le.HandleEvents() && alpha < 180) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - sprite2.SetAlpha(alpha); - Redraw(); - display.Blit(sprite1, area.x, area.y); - display.Blit(sprite2, area.x, area.y); - RedrawInterface(); - cursor.Show(); - display.Flip(); - - alpha += 10; - } - } - - cursor.Hide(); - - alpha = 0; - const u8 offset = Settings::Get().QVGA() ? 5 : 10; - bool restore = false; - - while(le.HandleEvents() && alpha < 20) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - if(restore) - { - display.Blit(sprite1, area.x, area.y); - restore = false; - } - else - { - switch(Rand::Get(1, 4)) - { - case 1: display.Blit(sprite1, area.x + offset, area.y + offset); break; - case 2: display.Blit(sprite1, area.x - offset, area.y - offset); break; - case 3: display.Blit(sprite1, area.x - offset, area.y + offset); break; - case 4: display.Blit(sprite1, area.x + offset, area.y - offset); break; - default: break; - } - restore = true; - } - - display.Blit(sprite2, area.x, area.y); - RedrawInterface(); - RedrawBorder(); - cursor.Show(); - display.Flip(); - ++alpha; - } - } - - while(Mixer::isValid() && Mixer::isPlaying(-1)) DELAY(10); -} - -void Battle2::Interface::RedrawActionEarthQuakeSpell(const std::vector & targets) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - Rect area = border.GetArea(); - - u8 frame = 0; - area.h -= Settings::Get().QVGA() ? 19 : 38; - - std::vector::const_iterator it; - - Surface sprite; - sprite.Set(area.w, area.h); - - cursor.SetThemes(Cursor::WAR_NONE); - cursor.Hide(); - - sprite.Blit(display, area, 0, 0); - - b_current = NULL; - AGG::PlaySound(M82::ERTHQUAK); - - const u8 offset = Settings::Get().QVGA() ? 5 : 10; - bool restore = false; - - while(le.HandleEvents() && frame < 18) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - if(restore) - { - display.Blit(sprite, area.x, area.y); - restore = false; - } - else - { - switch(Rand::Get(1, 4)) - { - case 1: display.Blit(sprite, area.x + offset, area.y + offset); break; - case 2: display.Blit(sprite, area.x - offset, area.y - offset); break; - case 3: display.Blit(sprite, area.x - offset, area.y + offset); break; - case 4: display.Blit(sprite, area.x + offset, area.y - offset); break; - default: break; - } - restore = true; - } - - RedrawInterface(); - RedrawBorder(); - cursor.Show(); - display.Flip(); - ++frame; - } - } - - // clod - frame = 0; - ICN::icn_t icn = ICN::LICHCLOD; - AGG::PlaySound(M82::CATSND02); - - while(le.HandleEvents() && frame < AGG::GetICNCount(icn)) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - Redraw(); - - it = targets.begin(); - for(; it != targets.end(); ++it) - { - Point pt2 = arena.catapult->GetTargetPosition(*it); - - if(Settings::Get().QVGA()) - { - pt2.x /= 2; - pt2.y /= 2; - } - pt2.x += area.x; - pt2.y += area.y; - - const Sprite & sprite = AGG::GetICN(icn, frame); - display.Blit(sprite, pt2.x + sprite.x(), pt2.y + sprite.y()); - } - - cursor.Show(); - display.Flip(); - - ++frame; - } - } -} - -void Battle2::Interface::RedrawActionRemoveMirrorImage(const Stats & mirror) -{ - DEBUG(DBG_BATTLE, DBG_WARN, "Battle2::Interface::RedrawActionRemoveMirrorImage: FIXME"); -} - -void Battle2::Interface::RedrawTargetsWithFrameAnimation(const u16 dst, const std::vector & targets, ICN::icn_t icn, M82::m82_t m82) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - u8 frame = 0; - std::vector::const_iterator it; - const Rect & center = arena.board[dst].GetPos(); - - cursor.SetThemes(Cursor::WAR_NONE); - - b_current = NULL; - for(it = targets.begin(); it != targets.end(); ++it) - if((*it).defender && (*it).damage) (*it).defender->ResetAnimFrame(AS_WNCE); - - if(M82::UNKNOWN != m82) AGG::PlaySound(m82); - - while(le.HandleEvents() && frame < AGG::GetICNCount(icn)) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - Redraw(); - - const Sprite & sprite = AGG::GetICN(icn, frame); - display.Blit(sprite, center.x + center.w / 2 + sprite.x(), center.y + center.h / 2 + sprite.y()); - cursor.Show(); - display.Flip(); - - for(it = targets.begin(); it != targets.end(); ++it) if((*it).defender && (*it).damage) - (*it).defender->IncreaseAnimFrame(false); - ++frame; - } - } - - for(it = targets.begin(); it != targets.end(); ++it) if((*it).defender) - { - (*it).defender->ResetAnimFrame(AS_IDLE); - b_current = NULL; - } -} - -void Battle2::Interface::RedrawTargetsWithFrameAnimation(const std::vector & targets, ICN::icn_t icn, M82::m82_t m82, bool wnce) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - u8 frame = 0; - std::vector::const_iterator it; - - cursor.SetThemes(Cursor::WAR_NONE); - - b_current = NULL; - - if(wnce) - for(it = targets.begin(); it != targets.end(); ++it) - if((*it).defender && (*it).damage) (*it).defender->ResetAnimFrame(AS_WNCE); - - if(M82::UNKNOWN != m82) AGG::PlaySound(m82); - - while(le.HandleEvents() && frame < AGG::GetICNCount(icn)) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - Redraw(); - - for(it = targets.begin(); it != targets.end(); ++it) if((*it).defender) - { - const Rect & pos = (*it).defender->GetCellPosition(); - bool reflect = false; - - switch(icn) - { - case ICN::SHIELD: reflect = (*it).defender->isReflect(); break; - default: break; - } - - const Sprite & sprite = AGG::GetICN(icn, frame, reflect); - display.Blit(sprite, pos.x + ((*it).defender->isWide() ? ((*it).defender->isReflect() ? pos.w : 0) : pos.w / 2) + sprite.x() - (reflect ? pos.w : 0), - pos.y + pos.h / 2 + sprite.y()); - } - cursor.Show(); - display.Flip(); - - if(wnce) - for(it = targets.begin(); it != targets.end(); ++it) if((*it).defender && (*it).damage) - (*it).defender->IncreaseAnimFrame(false); - ++frame; - } - } - - if(wnce) - for(it = targets.begin(); it != targets.end(); ++it) if((*it).defender) - { - (*it).defender->ResetAnimFrame(AS_IDLE); - b_current = NULL; - } -} - -void Battle2::Interface::RedrawTroopWithFrameAnimation(Stats & b, ICN::icn_t icn, M82::m82_t m82, bool pain) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - const Rect & pos = b.GetCellPosition(); - - u8 frame = 0; - bool reflect = false; - - switch(icn) - { - case ICN::SHIELD: reflect = b.isReflect(); break; - default: break; - } - - cursor.SetThemes(Cursor::WAR_NONE); - - if(pain) - { - b_current = NULL; - b.ResetAnimFrame(AS_WNCE); - } - - if(M82::UNKNOWN != m82) AGG::PlaySound(m82); - - while(le.HandleEvents() && frame < AGG::GetICNCount(icn)) - { - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_SPELL_DELAY)) - { - cursor.Hide(); - Redraw(); - const Sprite & sprite = AGG::GetICN(icn, frame, reflect); - display.Blit(sprite, pos.x + (b.isWide() ? (b.isReflect() ? pos.w : 0) : pos.w / 2) + sprite.x() - (reflect ? pos.w : 0), - pos.y + pos.h / 2 + sprite.y()); - cursor.Show(); - display.Flip(); - - if(pain) b.IncreaseAnimFrame(false); - ++frame; - } - } - - if(pain) - { - b.ResetAnimFrame(AS_IDLE); - b_current = NULL; - } -} - -void Battle2::Interface::RedrawBridgeAnimation(bool down) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - const Point & topleft = border.GetArea(); - - ICN::icn_t icn_castle = ICN::UNKNOWN; - - switch(arena.castle->GetRace()) - { - default: - case Race::BARB: icn_castle = ICN::CASTLEB; break; - case Race::KNGT: icn_castle = ICN::CASTLEK; break; - case Race::NECR: icn_castle = ICN::CASTLEN; break; - case Race::SORC: icn_castle = ICN::CASTLES; break; - case Race::WRLK: icn_castle = ICN::CASTLEW; break; - case Race::WZRD: icn_castle = ICN::CASTLEZ; break; - } - - u8 frame = down ? 23 : 21; - - if(down) AGG::PlaySound(M82::DRAWBRG); - - while(le.HandleEvents()) - { - if(down) - { - if(frame < 21) break; - } - else - { - if(frame > 23) break; - } - - CheckGlobalEvents(le); - - if(Game::AnimateInfrequent(Game::BATTLE_BRIDGE_DELAY)) - { - cursor.Hide(); - Redraw(); - const Sprite & sprite = AGG::GetICN(icn_castle, frame); - display.Blit(sprite, sprite.x() + topleft.x, sprite.y() + topleft.y); - cursor.Show(); - display.Flip(); - - if(down) - --frame; - else - ++frame; - } - } - - if(!down) AGG::PlaySound(M82::DRAWBRG); -} - -bool Battle2::ArmySetIdleAnimation(Army::army_t & army) -{ - bool res = false; - - for(u8 ii = 0; ii < army.Size(); ++ii) - { - Army::Troop & troop = army.At(ii); - if(troop.isValid()) - { - Stats* b = troop.GetBattleStats(); - if(b && b->isValid()) - { - if(b->isFinishAnimFrame()) - b->ResetAnimFrame(AS_IDLE); - else - if(b->isStartAnimFrame() && 3 > Rand::Get(1, 10)) - { - b->IncreaseAnimFrame(); - res = true; - } - } - } - } - - return res; -} - -bool Battle2::ArmyNextIdleAnimation(Army::army_t & army) -{ - bool res = false; - - for(u8 ii = 0; ii < army.Size(); ++ii) - { - Army::Troop & troop = army.At(ii); - if(troop.isValid()) - { - Stats* b = troop.GetBattleStats(); - if(b && b->isValid() && !b->isStartAnimFrame()) - { - b->IncreaseAnimFrame(false); - res = true; - } - } - } - - return res; -} - -bool Battle2::Interface::IdleTroopsAnimation(void) -{ - bool res = false; - - // set animation - if(Game::AnimateInfrequent(Game::BATTLE_IDLE_DELAY)) - { - if(ArmySetIdleAnimation(arena.army1)) res = true; - if(ArmySetIdleAnimation(arena.army2)) res = true; - } - else - // next animation - if(Game::AnimateInfrequent(Game::BATTLE_IDLE2_DELAY)) - { - if(ArmyNextIdleAnimation(arena.army1)) res = true; - if(ArmyNextIdleAnimation(arena.army2)) res = true; - } - - return res; -} - -void Battle2::Interface::CheckGlobalEvents(LocalEvent & le) -{ - // reset auto battle - if(le.KeyPress() && Settings::Get().AutoBattle()) ResetAutoBattle(); - - // animation opponents - if(Game::AnimateInfrequent(Game::BATTLE_OPPONENTS_DELAY)) - { - if(opponent1) - { - if(!opponent1->isStartFrame() || 2 > Rand::Get(1, 10)) opponent1->IncreaseAnimFrame(); - } - - if(opponent2) - { - if(!opponent2->isStartFrame() || 2 > Rand::Get(1, 10)) opponent2->IncreaseAnimFrame(); - } - humanturn_redraw = true; - } - - // animation flags - if(Game::AnimateInfrequent(Game::BATTLE_FLAGS_DELAY)) - { - if(opponent1 && opponent1->isFinishFrame()) opponent1->ResetAnimFrame(OP_IDLE); - if(opponent2 && opponent2->isFinishFrame()) opponent2->ResetAnimFrame(OP_IDLE); - - ++animation_frame; - humanturn_redraw = true; - } -} - -void Battle2::Interface::ProcessingHeroDialogResult(u8 res, Actions & a) -{ - const Settings & conf = Settings::Get(); - - switch(res) - { - //cast - case 1: - { - const HeroBase* hero = b_current ? b_current->GetCommander() : NULL; - if(hero) - { - if(hero->HaveSpellBook()) - { - std::string msg; - if(arena.isDisableCastSpell(Spell::NONE, &msg)) - Dialog::Message("", msg, Font::BIG, Dialog::OK); - else - { - Spell::spell_t spell = hero->OpenSpellBook(SpellBook::CMBT, true); - - if(arena.isDisableCastSpell(spell, &msg)) - Dialog::Message("", msg, Font::BIG, Dialog::OK); - else - if(hero->HaveSpellPoints(Spell::CostManaPoints(spell, hero))) - { - if(Spell::isApplyWithoutFocusObject(spell)) - { - a.AddedCastAction(spell, MAXU16); - humanturn_redraw = true; - humanturn_exit = true; - } - else - humanturn_spell = spell; - } - } - } - else - Dialog::Message("", _("No spells to cast."), Font::BIG, Dialog::OK); - } - } - break; - - // retreat - case 2: - if(b_current->GetCommander() && arena.CanRetreatOpponent(b_current->GetColor()) && - Dialog::YES == Dialog::Message("", _("Are you sure you want to retreat?"), Font::BIG, Dialog::YES | Dialog::NO)) - { - a.AddedRetreatAction(); - a.AddedEndAction(*b_current); - humanturn_exit = true; - } - break; - - //surrender - case 3: - { - const Army::army_t & army = arena.army1.GetColor() == conf.MyColor() ? arena.army1 : arena.army2; - const HeroBase* enemy = arena.army1.GetColor() == conf.MyColor() ? arena.army2.GetCommander() : arena.army1.GetCommander(); - const u32 cost = army.GetSurrenderCost(); - if(enemy && DialogBattleSurrender(*enemy, cost)) - { - if(world.GetKingdom(conf.MyColor()).GetFundsGold() < cost) - Dialog::Message("", _("You don't have enough gold!"), Font::BIG, Dialog::OK); - else - { - a.AddedSurrenderAction(); - a.AddedEndAction(*b_current); - humanturn_exit = true; - } - } - } - break; - - default: break; - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_interface.h b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_interface.h deleted file mode 100644 index 0895f60aa..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_interface.h +++ /dev/null @@ -1,217 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BATTLE2_INTERFACE_H -#define H2BATTLE2_INTERFACE_H - -#include -#include "icn.h" -#include "dialog.h" -#include "button.h" -#include "text.h" -#include "statusbar.h" -#include "gamedefs.h" - -namespace Battle2 -{ - class Arena; - class Stats; - class QueueMessage; - class Actions; - class Tower; - struct TargetInfo; - struct Result; - - void DialogBattleSettings(void); - bool DialogBattleSurrender(const HeroBase &, u32); - - enum { OP_IDLE, OP_SRRW, OP_CAST }; - - class OpponentSprite - { - public: - OpponentSprite(const Rect &, const HeroBase *, bool); - - const Rect & GetArea(void) const; - void Redraw(void) const; - void ResetAnimFrame(u8); - void IncreaseAnimFrame(bool loop = false); - bool isFinishFrame(void) const; - bool isStartFrame(void) const; - u8 GetColor(void) const; - const HeroBase* GetHero(void) const; - - protected: - const HeroBase *base; - ICN::icn_t icn; - u8 animframe; - u8 animframe_start; - u8 animframe_count; - bool reflect; - Rect pos; - }; - - struct Status - { - public: - Status(); - - void SetPosition(s16, s16); - void SetMessage(const std::string &, bool = false); - void Redraw(void); - const std::string & GetMessage(void) const; - - protected: - Point pos; - Text bar1; - Text bar2; - const Sprite & back1; - const Sprite & back2; - std::string message; - }; - - class Interface - { - public: - Interface(Arena &, s32); - ~Interface(); - - void Redraw(void); - void HumanTurn(const Stats &, Actions &); - - const Rect & GetArea(void) const; - - void SetStatus(const std::string &, bool = false); - void FadeArena(void); - - void RedrawActionAttackPart1(Stats &, Stats &, const std::vector &); - void RedrawActionAttackPart2(Stats &, std::vector &); - void RedrawActionSpellCastPart1(u8, u16, const std::string & name, const std::vector &); - void RedrawActionSpellCastPart2(u8, std::vector &); - void RedrawActionResistSpell(const Stats &); - void RedrawActionMonsterSpellCastStatus(const Stats &, const TargetInfo &); - void RedrawActionMove(Stats &, const std::vector &); - void RedrawActionFly(Stats &, u16); - void RedrawActionMorale(Stats &, bool); - void RedrawActionTowerPart1(Tower &, Stats &); - void RedrawActionTowerPart2(Tower &, TargetInfo &); - void RedrawActionCatapult(u8); - void RedrawActionTeleportSpell(Stats &, const u16); - void RedrawActionEarthQuakeSpell(const std::vector &); - void RedrawActionSummonElementalSpell(const Stats &); - void RedrawActionMirrorImageSpell(const Stats &, u16); - void RedrawActionRemoveMirrorImage(const Stats &); - void RedrawActionSkipStatus(const Stats &); - - void HumanBattleTurn(const Stats &, Actions &, std::string &); - void HumanCastSpellTurn(const Stats &, Actions &, std::string &); - - void RedrawBorder(void); - void RedrawCover(void); - void RedrawObjects(const u16) const; - void RedrawCastle1(void) const; - void RedrawCastle2(const u16) const; - void RedrawCastle3(void) const; - void RedrawKilled(void); - void RedrawInterface(void); - void RedrawOpponents(void) const; - void RedrawOpponentsFlags(void) const; - void RedrawArmies(void) const; - void RedrawTroopSprite(const Stats &, const Rect &) const; - void RedrawTroopCount(const Stats &, const Rect &) const; - void RedrawPocketControls(void) const; - - void RedrawActionWinces(std::vector &); - void RedrawActionKills(std::vector &); - void RedrawActionArrowSpell(const Stats &); - void RedrawActionColdRaySpell(Stats &); - void RedrawActionDisruptingRaySpell(Stats &); - void RedrawActionBloodLustSpell(Stats &); - void RedrawActionColdRingSpell(const u16, const std::vector &); - void RedrawActionElementalStormSpell(const std::vector &); - void RedrawActionArmageddonSpell(const std::vector &); - void RedrawActionResurrectSpell(Stats &, u8); - void RedrawActionLightningBoltSpell(Stats &); - void RedrawActionChainLightningSpell(const std::vector &); - - void RedrawTroopFrameAnimation(Stats &); - void RedrawTroopWithFrameAnimation(Stats &, ICN::icn_t, M82::m82_t, bool); - void RedrawTargetsWithFrameAnimation(const u16, const std::vector &, ICN::icn_t, M82::m82_t); - void RedrawTargetsWithFrameAnimation(const std::vector &, ICN::icn_t, M82::m82_t, bool); - void RedrawBridgeAnimation(bool down); - - bool IdleTroopsAnimation(void); - void CheckGlobalEvents(LocalEvent &); - - void SetAutoBattle(const Stats &, Actions &); - void ResetAutoBattle(void); - void ProcessingHeroDialogResult(u8, Actions &); - - void EventAutoSwitch(const Stats &, Actions &); - void EventShowOptions(void); - void ButtonAutoAction(const Stats &, Actions &); - void ButtonSettingsAction(void); - void ButtonSkipAction(Actions &); - void MouseLeftClickBoardAction(u16, s16, Actions &); - void MousePressRightBoardAction(u16, s16, Actions &); - - u16 GetBattleCursor(const Point &, std::string &); - u16 GetBattleSpellCursor(const Point &, std::string &); - u8 GetAllowSwordDirection(u16); - - protected: - Arena & arena; - Dialog::FrameBorder border; - Surface sf_hexagon; - Surface sf_shadow; - Surface sf_cursor; - ICN::icn_t icn_cbkg; - ICN::icn_t icn_frng; - - Button btn_auto; - Button btn_settings; - Button btn_skip; - Status status; - - OpponentSprite* opponent1; - OpponentSprite* opponent2; - - Rect rectBoard; - u8 humanturn_spell; - bool humanturn_exit; - bool humanturn_redraw; - u32 animation_frame; - u8 catapult_frame; - - const Stats* b_current; - const Stats* b_move; - const Stats* b_fly; - const Sprite* b_current_sprite; - Point p_move; - Point p_fly; - - u16 teleport_src; - Rect pocket_book; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_main.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_main.cpp deleted file mode 100644 index dfd815a29..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_main.cpp +++ /dev/null @@ -1,349 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "army.h" -#include "color.h" -#include "cursor.h" -#include "artifact.h" -#include "settings.h" -#include "heroes_base.h" -#include "battle_arena.h" -#include "skill.h" -#include "agg.h" -#include "world.h" -#include "kingdom.h" -#include "remoteclient.h" -#include "localclient.h" -#include "battle2.h" - -u16 DialogWithArtifact(const std::string &, const std::string &, const Artifact::artifact_t, const u16 = Dialog::OK); -void PlayPickupSound(void); - -namespace Battle2 -{ - void PickupArtifactsAction(HeroBase &, HeroBase &, bool); - void EagleEyeSkillAction(HeroBase &, const std::vector &, bool); - void NecromancySkillAction(Army::army_t &, u32, bool); -} - -Battle2::Result Battle2::Loader(Army::army_t & army1, Army::army_t & army2, s32 mapsindex) -{ - Settings & conf = Settings::Get(); - Color::color_t mycolor = conf.MyColor(); - - army1.BattleInit(); - army2.BattleInit(); - - if(IS_DEBUG(DBG_BATTLE , DBG_INFO)) - { - VERBOSE("Battle2::Loader: start, army1(" << Color::String(army1.GetColor()) << "), army2(" << Color::String(army2.GetColor()) << ")"); - army1.Dump(); - army2.Dump(); - } - - if(conf.ExtLowMemory()) - AGG::ICNRegistryEnable(true); - - Mixer::Reset(); - bool local = Game::LOCAL == army1.GetControl() || Game::LOCAL == army2.GetControl(); -#ifdef WITH_NET - if(Network::isLocalClient()) local = true; -#endif - - Arena arena(army1, army2, mapsindex, local); - - u16 turn = 1; - - Result result; - -#ifdef WITH_NET - if(Network::isLocalClient()) - FH2LocalClient::Get().BattleLoop(arena, result); - else -#endif - while(1) - { - arena.Turns(turn, result); - - if(result.army1 || result.army2) break; - - ++turn; - } - -#ifdef WITH_NET - if(Network::isRemoteClient()) - { - if(Game::REMOTE == army1.GetControl()) FH2RemoteClient::SendBattleResult(army1.GetColor(), result); - if(Game::REMOTE == army2.GetControl()) FH2RemoteClient::SendBattleResult(army2.GetColor(), result); - } -#endif - - if(conf.Music()) Mixer::Reset(); - conf.SetMyColor(mycolor); - - Army::army_t *army_wins = (result.army1 & RESULT_WINS ? &army1 : (result.army2 & RESULT_WINS ? &army2 : NULL)); - Army::army_t *army_loss = (result.army1 & RESULT_LOSS ? &army1 : (result.army2 & RESULT_LOSS ? &army2 : NULL)); - - // fix experience - if(army_wins && army_loss) - { - Army::army_t killed1, killed2; - army1.BattleExportKilled(killed1); - army2.BattleExportKilled(killed2); - result.exp1 = killed2.CalculateExperience(); - result.exp2 = killed1.CalculateExperience(); - } - - // fade arena - if(local) arena.FadeArena(); - - // dialog summary - if(local) arena.DialogBattleSummary(result); - - const u32 killed2 = army_loss ? army_loss->BattleKilled() : 0; - - army1.BattleQuit(); - army2.BattleQuit(); - - // pickup artifact - if(army_wins && army_wins->GetCommander() && - army_loss && army_loss->GetCommander() && - Skill::Primary::HEROES == army_wins->GetCommander()->GetType() && - Skill::Primary::HEROES == army_loss->GetCommander()->GetType()) - PickupArtifactsAction(*army_wins->GetCommander(), *army_loss->GetCommander(), local && (Game::LOCAL == army_wins->GetControl())); - - // eagle eye capability - if(army_wins && army_wins->GetCommander() && - army_loss && army_loss->GetCommander() && - army_wins->GetCommander()->GetLevelSkill(Skill::Secondary::EAGLEEYE) && - Skill::Primary::HEROES == army_loss->GetCommander()->GetType()) - EagleEyeSkillAction(*army_wins->GetCommander(), arena.GetUsageSpells(), local && (Game::LOCAL == army_wins->GetControl())); - - // necromancy capability - if(army_wins && army_wins->GetCommander() && - army_wins->GetCommander()->GetLevelSkill(Skill::Secondary::NECROMANCY)) - NecromancySkillAction(*army_wins, killed2, local && (Game::LOCAL == army_wins->GetControl())); - - // update army - if(army1.GetCommander() && Skill::Primary::HEROES == army1.GetCommander()->GetType()) - { - // hard reset army - if(!army1.isValid() || (result.army1 & RESULT_RETREAT)) army1.Reset(false); - } - - // update army - if(army2.GetCommander() && Skill::Primary::HEROES == army2.GetCommander()->GetType()) - { - // hard reset army - if(!army2.isValid() || (result.army2 & RESULT_RETREAT)) army2.Reset(false); - } - - if(conf.ExtLowMemory()) - { - AGG::ICNRegistryEnable(false); - AGG::ICNRegistryFreeObjects(); - } - - if(IS_DEBUG(DBG_BATTLE , DBG_INFO)) - { - VERBOSE("Battle2::Loader: end, army1(" << Color::String(army1.GetColor()) << "), army2(" << Color::String(army2.GetColor()) << ")"); - army1.Dump(); - army2.Dump(); - } - - DEBUG(DBG_BATTLE, DBG_INFO, "Battle2::Result: army1: " << (result.army1 & RESULT_WINS ? "wins" : "loss") << ", army2: " << (result.army2 & RESULT_WINS ? "wins" : "loss")); - - return result; -} - -void Battle2::PickupArtifactsAction(HeroBase & hero1, HeroBase & hero2, bool local) -{ - BagArtifacts & bag1 = hero1.GetBagArtifacts(); - BagArtifacts & bag2 = hero2.GetBagArtifacts(); - - for(u8 ii = 0; ii < bag2.size(); ++ii) - { - Artifact & art = bag2[ii]; - - if(art.isUltimate()) - { - art = Artifact::UNKNOWN; - } - else - if(art != Artifact::UNKNOWN && art != Artifact::MAGIC_BOOK) - { - BagArtifacts::iterator it = std::find(bag1.begin(), bag1.end(), Artifact::UNKNOWN); - if(bag1.end() != it) - { - *it = art; - if(local) - { - PlayPickupSound(); - DialogWithArtifact(_("You have captured an enemy artifact!"), art.GetName(), art()); - } - } - art = Artifact::UNKNOWN; - } - } -} - -void Battle2::EagleEyeSkillAction(HeroBase & hero, const std::vector & spells, bool local) -{ - if(spells.empty() || - !hero.HaveSpellBook()) return; - - std::vector new_spells; - new_spells.reserve(10); - - const u8 level = hero.GetLevelSkill(Skill::Secondary::EAGLEEYE); - const u8 value = Skill::Secondary::GetValues(Skill::Secondary::EAGLEEYE, level); - - // filter spells - for(std::vector::const_iterator it = spells.begin(); it != spells.end(); ++it) - { - if(!hero.HaveSpell(Spell::FromInt(*it))) - { - switch(level) - { - case Skill::Level::BASIC: - // 20% - if(3 > Spell::Level(*it) && value >= Rand::Get(1, 100)) new_spells.push_back(Spell::FromInt(*it)); - break; - case Skill::Level::ADVANCED: - // 30% - if(4 > Spell::Level(*it) && value >= Rand::Get(1, 100)) new_spells.push_back(Spell::FromInt(*it)); - break; - case Skill::Level::EXPERT: - // 40% - if(5 > Spell::Level(*it) && value >= Rand::Get(1, 100)) new_spells.push_back(Spell::FromInt(*it)); - break; - default: break; - } - } - } - - // add new spell - for(std::vector::const_iterator it = new_spells.begin(); it != new_spells.end(); ++it) - { - if(local) - { - std::string msg = _("Through eagle-eyed observation, %{name} is able to learn the magic spell %{spell}."); - String::Replace(msg, "%{name}", hero.GetName()); - String::Replace(msg, "%{spell}", Spell::GetName(*it)); - PlayPickupSound(); - Dialog::SpellInfo("", msg, *it); - } - hero.AppendSpellToBook(*it, true); - } -} - -void Battle2::NecromancySkillAction(Army::army_t & army1, u32 killed, bool local) -{ - if(0 == killed || - (army1.GetCount() == army1.Size() && !army1.HasMonster(Monster::SKELETON))) return; - - const HeroBase* hero = army1.GetCommander(); - - // check necromancy shrine build - u16 percent = 10 * world.GetKingdom(army1.GetColor()).GetCountNecromancyShrineBuild(); - - // check artifact - if(hero->HasArtifact(Artifact::SPADE_NECROMANCY)) percent += 10; - - // fix over 60% - if(percent > 60) percent = 60; - - percent += hero->GetSecondaryValues(Skill::Secondary::NECROMANCY); - - // hard fix overflow - if(percent > 90) percent = 90; - - const Monster skeleton(Monster::SKELETON); - const u32 count = Monster::GetCountFromHitPoints(Monster::SKELETON, skeleton.GetHitPoints() * killed * percent / 100); - army1.JoinTroop(skeleton, count); - - if(local) - { - std::string msg = _("Practicing the dark arts of necromancy, you are able to raise %{count} of the enemy's dead to return under your service as %{monster}"); - String::Replace(msg, "%{count}", count); - String::Replace(msg, "%{monster}", skeleton.GetMultiName()); - Surface sf1(40, 45); - const Sprite & sf2 = AGG::GetICN(ICN::MONS32, Monster::GetSpriteIndex(skeleton())); - sf1.SetColorKey(); - sf1.Blit(sf2, (sf1.w() - sf2.w()) / 2, 0); - std::string str; - String::AddInt(str, count); - Text text(str, Font::SMALL); - text.Blit((sf1.w() - text.w()) / 2, sf2.h() + 3, sf1); - PlayPickupSound(); - Dialog::SpriteInfo("", msg, sf1); - } - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::NecromancySkillAction: raise skeletons: " << count); -} - -u8 Battle2::Result::AttackerResult(void) const -{ - if(RESULT_SURRENDER & army1) return RESULT_SURRENDER; - else - if(RESULT_RETREAT & army1) return RESULT_RETREAT; - else - if(RESULT_LOSS & army1) return RESULT_LOSS; - else - if(RESULT_WINS & army1) return RESULT_WINS; - - return 0; -} - -u8 Battle2::Result::DefenderResult(void) const -{ - if(RESULT_SURRENDER & army2) return RESULT_SURRENDER; - else - if(RESULT_RETREAT & army2) return RESULT_RETREAT; - else - if(RESULT_LOSS & army2) return RESULT_LOSS; - else - if(RESULT_WINS & army2) return RESULT_WINS; - - return 0; -} - -u32 Battle2::Result::GetExperienceAttacker(void) const -{ - return exp1; -} - -u32 Battle2::Result::GetExperienceDefender(void) const -{ - return exp2; -} - -bool Battle2::Result::AttackerWins(void) const -{ - return army1 & RESULT_WINS; -} - -bool Battle2::Result::DefenderWins(void) const -{ - return army2 & RESULT_WINS; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_stats.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_stats.cpp deleted file mode 100644 index a05f90e8b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_stats.cpp +++ /dev/null @@ -1,2193 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "engine.h" -#include "agg.h" -#include "luck.h" -#include "morale.h" -#include "speed.h" -#include "heroes.h" -#include "settings.h" -#include "battle_arena.h" -#include "battle_cell.h" -#include "battle_interface.h" -#include "battle_stats.h" - -#ifdef WITH_XML -#include "xmlccwrap.h" -#endif - -void GetLinePoints(const Point & pt1, const Point & pt2, u16 step, std::vector & res); - -namespace Battle2 -{ - static MonsterInfo monsters_info[] = { - - { ICN::UNKNOWN , { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN }, - - // icn_file idle move fly1 fly2 fly3 shot0 shot1 shot2 shot3 attk0 attk1 attk2 attk3 wcne kill m82_attk m82_kill m82_move m82_wnce - { ICN::PEASANT , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 6}, {22, 6}, {28, 6}, {13, 3}, {34, 4}, M82::PSNTATTK, M82::PSNTKILL, M82::PSNTMOVE, M82::PSNTWNCE }, - { ICN::ARCHER , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 4}, {20, 4}, {24, 4}, {28, 4}, {32, 4}, {36, 3}, {39, 3}, {42, 3}, {13, 3}, {45, 6}, M82::ARCHATTK, M82::ARCHKILL, M82::ARCHMOVE, M82::ARCHWNCE }, - { ICN::ARCHER2 , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 4}, {20, 4}, {24, 4}, {28, 4}, {32, 4}, {36, 3}, {39, 3}, {42, 3}, {13, 3}, {45, 6}, M82::ARCHATTK, M82::ARCHKILL, M82::ARCHMOVE, M82::ARCHWNCE }, - { ICN::PIKEMAN , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {17, 3}, {20, 4}, {24, 6}, {13, 4}, {30, 6}, M82::PIKEATTK, M82::PIKEKILL, M82::PIKEMOVE, M82::PIKEWNCE }, - { ICN::PIKEMAN2, { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {17, 3}, {20, 4}, {24, 6}, {13, 4}, {30, 6}, M82::PIKEATTK, M82::PIKEKILL, M82::PIKEMOVE, M82::PIKEWNCE }, - { ICN::SWORDSMN, {39, 6}, { 2, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {12, 2}, {19, 5}, {14, 5}, {24, 5}, {36, 3}, {29, 7}, M82::SWDMATTK, M82::SWDMKILL, M82::SWDMMOVE, M82::SWDMWNCE }, - { ICN::SWORDSM2, {39, 6}, { 2, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {12, 2}, {19, 5}, {14, 5}, {24, 5}, {36, 3}, {29, 7}, M82::SWDMATTK, M82::SWDMKILL, M82::SWDMMOVE, M82::SWDMWNCE }, - { ICN::CAVALRYR, {19, 4}, { 1, 7}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 8, 1}, {12, 3}, { 9, 3}, {15, 2}, {28, 2}, {23, 5}, M82::CAVLATTK, M82::CAVLKILL, M82::CAVLMOVE, M82::CAVLWNCE }, - { ICN::CAVALRYB, {19, 4}, { 1, 7}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 8, 1}, {12, 3}, { 9, 3}, {15, 2}, {28, 2}, {23, 5}, M82::CAVLATTK, M82::CAVLKILL, M82::CAVLMOVE, M82::CAVLWNCE }, - { ICN::PALADIN , { 1,11}, {12, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {20, 2}, {22, 3}, {25, 3}, {28, 3}, {31, 2}, {34, 5}, M82::PLDNATTK, M82::PLDNKILL, M82::PLDNMOVE, M82::PLDNWNCE }, - { ICN::PALADIN2, { 1,11}, {12, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {20, 2}, {22, 3}, {25, 3}, {28, 3}, {31, 2}, {34, 5}, M82::PLDNATTK, M82::PLDNKILL, M82::PLDNMOVE, M82::PLDNWNCE }, - - // icn_file idle move fly1 fly2 fly3 shot0 shot1 shot2 shot3 attk0 attk1 attk2 attk3 wcne kill m82_attk m82_kill m82_move m82_wnce - { ICN::GOBLIN , {33, 7}, { 1, 9}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {10, 3}, {17, 4}, {13, 4}, {21, 4}, {25, 4}, {29, 4}, M82::GBLNATTK, M82::GBLNKILL, M82::GBLNMOVE, M82::GBLNWNCE }, - { ICN::ORC , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, {16,13}, { 0, 0}, { 0, 0}, { 0, 0}, {28, 2}, {30, 3}, {33, 4}, {37, 3}, {13, 3}, {40, 4}, M82::ORC_ATTK, M82::ORC_KILL, M82::ORC_MOVE, M82::ORC_WNCE }, - { ICN::ORC2 , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, {16,13}, { 0, 0}, { 0, 0}, { 0, 0}, {28, 2}, {30, 3}, {33, 4}, {37, 3}, {13, 3}, {40, 4}, M82::ORC_ATTK, M82::ORC_KILL, M82::ORC_MOVE, M82::ORC_WNCE }, - { ICN::WOLF , {20, 6}, { 7, 6}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {13, 3}, { 2, 5}, {16, 4}, {26, 3}, {28, 5}, M82::WOLFATTK, M82::WOLFKILL, M82::WOLFMOVE, M82::WOLFWNCE }, - { ICN::OGRE , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 6}, {22, 7}, {29, 8}, {13, 3}, {37, 4}, M82::OGREATTK, M82::OGREKILL, M82::OGREMOVE, M82::OGREWNCE }, - { ICN::OGRE2 , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 6}, {22, 7}, {29, 8}, {13, 3}, {37, 4}, M82::OGREATTK, M82::OGREKILL, M82::OGREMOVE, M82::OGREWNCE }, - { ICN::TROLL , {16, 7}, { 1,15}, { 0, 0}, { 0, 0}, { 0, 0}, {23, 5}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {48, 6}, {23, 6}, {29, 5}, {54, 3}, {57, 9}, M82::TRLLATTK, M82::TRLLKILL, M82::TRLLMOVE, M82::TRLLWNCE }, - { ICN::TROLL2 , {16, 7}, { 1,15}, { 0, 0}, { 0, 0}, { 0, 0}, {23, 5}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {48, 6}, {23, 6}, {29, 5}, {54, 3}, {57, 9}, M82::TRLLATTK, M82::TRLLKILL, M82::TRLLMOVE, M82::TRLLWNCE }, - { ICN::CYCLOPS , {30, 9}, { 1, 7}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 2}, {11, 2}, {21, 2}, { 0, 0}, {14, 3}, { 8, 3}, {18, 3}, {23, 2}, {25, 5}, M82::CYCLATTK, M82::CYCLKILL, M82::CYCLMOVE, M82::CYCLWNCE }, - - // icn_file idle move fly1 fly2 fly3 shot0 shot1 shot2 shot3 attk0 attk1 attk2 attk3 wcne kill m82_attk m82_kill m82_move m82_wnce - { ICN::SPRITE , {16, 9}, { 0, 0}, { 1, 3}, { 4, 4}, { 7, 2}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {30, 6}, {25, 5}, {36, 5}, { 9, 2}, {11, 5}, M82::SPRTATTK, M82::SPRTKILL, M82::SPRTMOVE, M82::SPRTWNCE }, - { ICN::DWARF , {44, 5}, { 1, 9}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {20, 7}, {10,10}, {27, 9}, {36, 8}, {49, 7}, M82::DWRFATTK, M82::DWRFKILL, M82::DWRFMOVE, M82::DWRFWNCE }, - { ICN::DWARF2 , {44, 5}, { 1, 9}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {20, 7}, {10,10}, {27, 9}, {36, 8}, {49, 7}, M82::DWRFATTK, M82::DWRFKILL, M82::DWRFMOVE, M82::DWRFWNCE }, - { ICN::ELF , {42, 6}, { 1,12}, { 0, 0}, { 0, 0}, { 0, 0}, {13,10}, { 0, 0}, { 0, 0}, { 0, 0}, {23, 3}, {26, 3}, {29, 3}, {32, 4}, {36, 2}, {38, 4}, M82::ELF_ATTK, M82::ELF_KILL, M82::ELF_MOVE, M82::ELF_WNCE }, - { ICN::ELF2 , {42, 6}, { 1,12}, { 0, 0}, { 0, 0}, { 0, 0}, {13,10}, { 0, 0}, { 0, 0}, { 0, 0}, {23, 3}, {26, 3}, {29, 3}, {32, 4}, {36, 2}, {38, 4}, M82::ELF_ATTK, M82::ELF_KILL, M82::ELF_MOVE, M82::ELF_WNCE }, - { ICN::DRUID , {46, 4}, { 3,11}, { 0, 0}, { 0, 0}, { 0, 0}, {14, 8}, {35, 4}, {22, 4}, {39, 5}, {14, 8}, {35, 4}, {22, 4}, {39, 4}, {44, 2}, {26, 9}, M82::DRUIATTK, M82::DRUIKILL, M82::DRUIMOVE, M82::DRUIWNCE }, - { ICN::DRUID2 , {46, 4}, { 3,11}, { 0, 0}, { 0, 0}, { 0, 0}, {14, 8}, {35, 4}, {22, 4}, {39, 5}, {14, 8}, {35, 4}, {22, 4}, {39, 4}, {44, 2}, {26, 9}, M82::DRUIATTK, M82::DRUIKILL, M82::DRUIMOVE, M82::DRUIWNCE }, - { ICN::UNICORN , { 1, 9}, {10, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {18, 9}, {27, 7}, {34, 7}, {41, 4}, {45, 7}, M82::UNICATTK, M82::UNICKILL, M82::UNICMOVE, M82::UNICWNCE }, - { ICN::PHOENIX , {30, 5}, { 0, 0}, { 1, 3}, { 4, 6}, { 0, 0}, { 0, 0}, {25, 3}, {23, 2}, {28, 2}, { 0, 0}, {13, 4}, {10, 4}, {17, 4}, {35, 2}, {37,11}, M82::PHOEATTK, M82::PHOEKILL, M82::PHOEMOVE, M82::PHOEWNCE }, - - // icn_file idle move fly1 fly2 fly3 shot0 shot1 shot2 shot3 attk0 attk1 attk2 attk3 wcne kill m82_attk m82_kill m82_move m82_wnce - { ICN::CENTAUR , {65, 6}, { 2, 6}, { 0, 0}, { 0, 0}, { 0, 0}, {18, 4}, {27, 3}, {22, 5}, {30, 3}, {33, 1}, {38, 4}, {34, 4}, {42, 4}, {46, 2}, {48, 7}, M82::CNTRATTK, M82::CNTRKILL, M82::CNTRMOVE, M82::CNTRWNCE }, - { ICN::GARGOYLE, { 1, 4}, { 0, 0}, { 5, 2}, { 7, 4}, {11, 1}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {14, 1}, {15, 4}, {19, 4}, {23, 4}, {12, 2}, {27, 5}, M82::GARGATTK, M82::GARGKILL, M82::GARGMOVE, M82::GARGWNCE }, - { ICN::GRIFFIN , {16, 9}, { 0, 0}, { 1, 3}, { 3, 3}, { 5, 2}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 7, 1}, { 8, 2}, {14, 2}, {11, 3}, { 9, 2}, {25, 9}, M82::GRIFATTK, M82::GRIFKILL, M82::GRIFMOVE, M82::GRIFWNCE }, - { ICN::MINOTAUR, { 1, 5}, { 6, 7}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {13, 3}, {20, 3}, {16, 4}, {23, 4}, {27, 2}, {29, 6}, M82::MINOATTK, M82::MINOKILL, M82::MINOMOVE, M82::MINOWNCE }, - { ICN::MINOTAU2, { 1, 5}, { 6, 7}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {13, 3}, {20, 3}, {16, 4}, {23, 4}, {27, 2}, {29, 6}, M82::MINOATTK, M82::MINOKILL, M82::MINOMOVE, M82::MINOWNCE }, - { ICN::HYDRA , {28,15}, { 1, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 9, 8}, { 9, 8}, { 9, 8}, {17, 5}, {21, 7}, M82::HYDRATTK, M82::HYDRKILL, M82::HYDRMOVE, M82::HYDRWNCE }, - { ICN::DRAGGREE, {41,13}, { 0, 0}, { 1, 4}, { 5, 3}, { 8, 5}, {13, 1}, {17, 3}, {23, 3}, {30, 2}, {13, 1}, {14, 3}, {20, 3}, {26, 4}, {32, 3}, {35, 6}, M82::DRGNATTK, M82::DRGNKILL, M82::DRGNMOVE, M82::DRGNWNCE }, - { ICN::DRAGRED , {41,13}, { 0, 0}, { 1, 4}, { 5, 3}, { 8, 5}, {13, 1}, {17, 3}, {23, 3}, {30, 2}, {13, 1}, {14, 3}, {20, 3}, {26, 4}, {32, 3}, {35, 6}, M82::DRGNATTK, M82::DRGNKILL, M82::DRGNMOVE, M82::DRGNWNCE }, - { ICN::DRAGBLAK, {41,13}, { 0, 0}, { 1, 4}, { 5, 3}, { 8, 5}, {13, 1}, {17, 3}, {23, 3}, {30, 2}, {13, 1}, {14, 3}, {20, 3}, {26, 4}, {32, 3}, {35, 6}, M82::DRGNATTK, M82::DRGNKILL, M82::DRGNMOVE, M82::DRGNWNCE }, - - // icn_file idle move fly1 fly2 fly3 shot0 shot1 shot2 shot3 attk0 attk1 attk2 attk3 wcne kill m82_attk m82_kill m82_move m82_wnce - { ICN::HALFLING, { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, {17, 5}, {22, 2}, {26, 1}, {27, 2}, {29, 1}, {30, 2}, {32, 3}, {35, 2}, {13, 4}, {37, 4}, M82::HALFATTK, M82::HALFKILL, M82::HALFMOVE, M82::HALFWNCE }, - { ICN::BOAR , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {15, 1}, {16, 3}, {19, 3}, {22, 2}, {13, 2}, {24, 5}, M82::BOARATTK, M82::BOARKILL, M82::BOARMOVE, M82::BOARWNCE }, - { ICN::GOLEM , {34, 6}, { 1,12}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {22, 4}, {13, 5}, {18, 4}, {32, 4}, {26, 6}, M82::GOLMATTK, M82::GOLMKILL, M82::GOLMMOVE, M82::GOLMWNCE }, - { ICN::GOLEM2 , {34, 6}, { 1,12}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {22, 4}, {13, 5}, {18, 4}, {32, 4}, {26, 6}, M82::GOLMATTK, M82::GOLMKILL, M82::GOLMMOVE, M82::GOLMWNCE }, - { ICN::ROC , {18, 7}, { 0, 0}, { 1, 3}, { 4, 3}, { 7, 1}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {14, 3}, { 8, 3}, {11, 3}, {17, 1}, {25, 9}, M82::ROC_ATTK, M82::ROC_KILL, M82::ROC_MOVE, M82::ROC_WNCE }, - { ICN::MAGE1 , { 1, 7}, {43, 8}, { 0, 0}, { 0, 0}, { 0, 0}, {18, 1}, {21, 2}, {19, 2}, {23, 4}, {27, 1}, {34, 3}, {28, 6}, {37, 6}, { 8, 3}, {11, 7}, M82::MAGEATTK, M82::MAGEKILL, M82::MAGEMOVE, M82::MAGEWNCE }, - { ICN::MAGE2 , { 1, 7}, {43, 8}, { 0, 0}, { 0, 0}, { 0, 0}, {18, 1}, {21, 2}, {19, 2}, {23, 4}, {27, 1}, {34, 3}, {28, 6}, {37, 6}, { 8, 3}, {11, 7}, M82::MAGEATTK, M82::MAGEKILL, M82::MAGEMOVE, M82::MAGEWNCE }, - { ICN::TITANBLU, { 1, 6}, { 7, 7}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {19, 5}, {14, 5}, {24, 5}, {29, 2}, {31, 7}, M82::TITNATTK, M82::TITNKILL, M82::TITNMOVE, M82::TITNWNCE }, - { ICN::TITANBLA, { 1, 6}, { 7, 7}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {45, 5}, {38, 5}, {50, 5}, { 0, 0}, {19, 5}, {14, 5}, {24, 5}, {29, 2}, {31, 7}, M82::TITNATTK, M82::TITNKILL, M82::TITNMOVE, M82::TITNWNCE }, - - // icn_file idle move fly1 fly2 fly3 shot0 shot1 shot2 shot3 attk0 attk1 attk2 attk3 wcne kill m82_attk m82_kill m82_move m82_wnce - { ICN::SKELETON, {35, 4}, { 3, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {20, 4}, {12, 4}, {16, 4}, {24, 3}, {27, 8}, M82::SKELATTK, M82::SKELKILL, M82::SKELMOVE, M82::SKELWNCE }, - { ICN::ZOMBIE , {14,12}, { 1,13}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {26, 5}, {31, 5}, {36, 5}, {40, 3}, {47, 7}, M82::ZOMBATTK, M82::ZOMBKILL, M82::ZOMBMOVE, M82::ZOMBWNCE }, - { ICN::ZOMBIE2 , {14,12}, { 1,13}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {26, 5}, {31, 5}, {36, 5}, {40, 3}, {47, 7}, M82::ZOMBATTK, M82::ZOMBKILL, M82::ZOMBMOVE, M82::ZOMBWNCE }, - { ICN::MUMMYW , { 1, 4}, { 5,12}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {21, 3}, {24, 3}, {27, 3}, {17, 4}, {30,10}, M82::MUMYATTK, M82::MUMYKILL, M82::MUMYMOVE, M82::MUMYWNCE }, - { ICN::MUMMY2 , { 1, 4}, { 5,12}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {21, 3}, {24, 3}, {27, 3}, {17, 4}, {30,10}, M82::MUMYATTK, M82::MUMYKILL, M82::MUMYMOVE, M82::MUMYWNCE }, - { ICN::VAMPIRE , { 1, 4}, { 0, 0}, { 5, 4}, { 9, 4}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {15, 4}, {19, 4}, {23, 5}, {13, 3}, {28, 8}, M82::VAMPATTK, M82::VAMPKILL, M82::VAMPMOVE, M82::VAMPWNCE }, - { ICN::VAMPIRE2, { 1, 4}, { 0, 0}, { 5, 4}, { 9, 4}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {15, 4}, {19, 4}, {23, 5}, {13, 3}, {28, 8}, M82::VAMPATTK, M82::VAMPKILL, M82::VAMPMOVE, M82::VAMPWNCE }, - { ICN::LICH , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {13, 5}, {18, 5}, {23, 5}, { 0, 0}, {13, 5}, {18, 5}, {23, 5}, {28, 3}, {31, 7}, M82::LICHATTK, M82::LICHKILL, M82::LICHMOVE, M82::LICHWNCE }, - { ICN::LICH2 , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {13, 5}, {18, 8}, {23, 5}, { 0, 0}, {13, 5}, {18, 5}, {23, 5}, {28, 3}, {31, 7}, M82::LICHATTK, M82::LICHKILL, M82::LICHMOVE, M82::LICHWNCE }, - { ICN::DRAGBONE, {22, 7}, { 0, 0}, { 1, 4}, { 5, 3}, { 8, 4}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {47, 5}, {12, 4}, {16, 4}, {20, 2}, {41, 6}, M82::BONEATTK, M82::BONEKILL, M82::BONEMOVE, M82::BONEWNCE }, - - // icn_file idle move fly1 fly2 fly3 shot0 shot1 shot2 shot3 attk0 attk1 attk2 attk3 wcne kill m82_attk m82_kill m82_move m82_wnce - { ICN::ROGUE , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 8}, {24,10}, {34, 9}, {13, 3}, {43, 7}, M82::ROGUATTK, M82::ROGUKILL, M82::ROGUMOVE, M82::ROGUWNCE }, - { ICN::NOMAD , { 1, 9}, {10, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {18, 2}, {26, 5}, {20, 6}, {31, 4}, {35, 2}, {37, 5}, M82::NMADATTK, M82::NMADKILL, M82::NMADMOVE, M82::NMADWNCE }, - { ICN::GHOST , { 1, 9}, { 0, 0}, { 3, 3}, { 6, 4}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {10, 3}, {13, 3}, {16, 4}, {10, 1}, {20, 8}, M82::GHSTATTK, M82::GHSTKILL, M82::GHSTMOVE, M82::GHSTWNCE }, - { ICN::GENIE , { 1, 9}, { 0, 0}, {10, 1}, {11, 4}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {26, 5}, {16, 5}, {21, 5}, {31, 2}, {33, 7}, M82::GENIATTK, M82::GENIKILL, M82::GENIMOVE, M82::GENIWNCE }, - { ICN::MEDUSA , {17, 7}, { 1,16}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {65,10}, {41,13}, {54,11}, {36, 2}, {24,12}, M82::MEDSATTK, M82::MEDSKILL, M82::MEDSMOVE, M82::MEDSWNCE }, - { ICN::EELEM , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 4}, {20, 5}, {25, 6}, {13, 3}, {31,11}, M82::EELMATTK, M82::EELMKILL, M82::EELMMOVE, M82::EELMWNCE }, - { ICN::AELEM , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 4}, {20, 5}, {25, 6}, {13, 3}, {31,11}, M82::AELMATTK, M82::AELMKILL, M82::AELMMOVE, M82::AELMWNCE }, - { ICN::FELEM , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 4}, {20, 5}, {25, 6}, {13, 3}, {31,11}, M82::FELMATTK, M82::FELMKILL, M82::FELMMOVE, M82::FELMWNCE }, - { ICN::WELEM , { 1, 4}, { 5, 8}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, {16, 4}, {20, 5}, {25, 6}, {13, 3}, {31,11}, M82::WELMATTK, M82::WELMKILL, M82::WELMMOVE, M82::WELMWNCE }, - - { ICN::UNKNOWN , { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN }, - { ICN::UNKNOWN , { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN }, - { ICN::UNKNOWN , { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN }, - { ICN::UNKNOWN , { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN }, - { ICN::UNKNOWN , { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0}, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN, M82::UNKNOWN }, - }; - - static u8 genie_enemy_half_percent = 10; -} - -void Battle2::UpdateMonsterAttributes(const std::string & spec) -{ -#ifdef WITH_XML - // parse battle.xml - TiXmlDocument doc; - const TiXmlElement* xml_battle = NULL; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_battle = doc.FirstChildElement("battle"))) - { - const TiXmlElement* xml_element; - int value; - - // genie - xml_element = xml_battle->FirstChildElement("genie"); - if(xml_element) - { - xml_element->Attribute("enemy_half_percent", &value); - if(value > 100) value = 100; - genie_enemy_half_percent = value; - } - } - else - VERBOSE(spec << ": " << doc.ErrorDesc()); -#endif -} - -void Battle2::UpdateMonsterInfoAnimation(const std::string & spec) -{ -#ifdef WITH_XML - // parse battle.xml - TiXmlDocument doc; - const TiXmlElement* xml_animation = NULL; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_animation = doc.FirstChildElement("animations"))) - { - const TiXmlElement* xml_icn = xml_animation->FirstChildElement("icn"); - for(; xml_icn; xml_icn = xml_icn->NextSiblingElement("icn")) - { - std::string icn_name(xml_icn->Attribute("name")); - String::Upper(icn_name); - // find icn name - ICN::icn_t icn = ICN::FromString(icn_name.c_str()); - if(icn == ICN::UNKNOWN) continue; - - // find monster info position - MonsterInfo* ptr = &monsters_info[1]; - while(ptr->icn_file != ICN::UNKNOWN && icn != ptr->icn_file) ++ptr; - if(ptr->icn_file == ICN::UNKNOWN) continue; - - const TiXmlElement *xml_anim = xml_icn->FirstChildElement("animation"); - int start, count; - const char* state; - - for(; xml_anim; xml_anim = xml_anim->NextSiblingElement("animation")) - { - state = xml_anim->Attribute("state"); - xml_anim->Attribute("start", &start); - xml_anim->Attribute("count", &count); - animframe_t frm; - frm.start = start; - frm.count = count; - - if(0 == std::strcmp("idle", state)) ptr->frm_idle = frm; - else - if(0 == std::strcmp("move", state)) ptr->frm_move = frm; - else - if(0 == std::strcmp("fly1", state)) ptr->frm_fly1 = frm; - else - if(0 == std::strcmp("fly2", state)) ptr->frm_fly2 = frm; - else - if(0 == std::strcmp("fly3", state)) ptr->frm_fly3 = frm; - else - if(0 == std::strcmp("shot0", state)) ptr->frm_shot0 = frm; - else - if(0 == std::strcmp("shot1", state)) ptr->frm_shot1 = frm; - else - if(0 == std::strcmp("shot2", state)) ptr->frm_shot2 = frm; - else - if(0 == std::strcmp("shot3", state)) ptr->frm_shot3 = frm; - else - if(0 == std::strcmp("attk0", state)) ptr->frm_attk0 = frm; - else - if(0 == std::strcmp("attk1", state)) ptr->frm_attk1 = frm; - else - if(0 == std::strcmp("attk2", state)) ptr->frm_attk2 = frm; - else - if(0 == std::strcmp("attk3", state)) ptr->frm_attk3 = frm; - else - if(0 == std::strcmp("wnce", state)) ptr->frm_wnce = frm; - else - if(0 == std::strcmp("kill", state)) ptr->frm_kill = frm; - } - } - } - else - VERBOSE(spec << ": " << doc.ErrorDesc()); -#endif -} - -Battle2::ModeDuration::ModeDuration() : std::pair(0, 0) -{ -} - -Battle2::ModeDuration::ModeDuration(u32 mode, u16 duration) : std::pair(mode, duration) -{ -} - -bool Battle2::ModeDuration::isMode(u32 mode) const -{ - return (first & mode); -} - -bool Battle2::ModeDuration::isZeroDuration(void) const -{ - return 0 == second; -} - -void Battle2::ModeDuration::DecreaseDuration(void) -{ - if(second) --second; -} - -Battle2::ModesAffected::ModesAffected() -{ - reserve(3); -} - -void Battle2::ModesAffected::AddMode(u32 mode, u16 duration) -{ - iterator it = std::find_if(begin(), end(), std::bind2nd(std::mem_fun_ref(&ModeDuration::isMode), mode)); - if(it == end()) - push_back(ModeDuration(mode, duration)); - else - (*it).second = duration; -} - -void Battle2::ModesAffected::RemoveMode(u32 mode) -{ - iterator it = std::find_if(begin(), end(), std::bind2nd(std::mem_fun_ref(&ModeDuration::isMode), mode)); - if(it != end()) - { - // erase(it) - if(it + 1 != end()) std::swap(*it, back()); - pop_back(); - } -} - -void Battle2::ModesAffected::DecreaseDuration(void) -{ - std::for_each(begin(), end(), std::mem_fun_ref(&ModeDuration::DecreaseDuration)); -} - -u32 Battle2::ModesAffected::FindZeroDuration(void) const -{ - const_iterator it = std::find_if(begin(), end(), std::mem_fun_ref(&ModeDuration::isZeroDuration)); - return it == end() ? 0 : (*it).first; -} - -Battle2::Stats::Stats(Army::Troop & t) - : troop(t), arena(NULL), id(0), position(0), hp(0), count(0), dead(0), shots(t.GetShots()), disruptingray(0), - reflect(false), mirror(NULL), animstate(0), animframe(0), animstep(1) -{ - id = (troop.GetColor() << 8) | troop.GetArmyIndex(); - count = troop.count; - hp = GetMonster().GetHitPoints() * count; - - contours[0] = NULL; - contours[1] = NULL; - contours[2] = NULL; - contours[3] = NULL; - - ResetAnimFrame(AS_IDLE); -} - -Battle2::Stats::~Stats() -{ - if(contours[0]) delete contours[0]; - if(contours[1]) delete contours[1]; - if(contours[2]) delete contours[2]; - if(contours[3]) delete contours[3]; - - // reset summon elemental and mirror image - if(Modes(CAP_SUMMONELEM) || Modes(CAP_MIRRORIMAGE)) - { - troop.count = 0; - } -} - -u16 Battle2::Stats::GetID(void) const -{ - return id; -} - -const Battle2::MonsterInfo & Battle2::Stats::GetMonsterInfo(void) const -{ - return monsters_info[troop.GetID()]; -} - -void Battle2::Stats::InitContours(void) -{ - const MonsterInfo & msi = GetMonsterInfo(); - const Sprite *sprite1 = &AGG::GetICN(msi.icn_file, msi.frm_idle.start, false); - const Sprite *sprite2 = &AGG::GetICN(msi.icn_file, msi.frm_idle.start, true); - - if(sprite1 && !contours[0]) - { - contours[0] = new Sprite(); - Surface::MakeContour(*contours[0], *sprite1, sprite1->GetColor(0xDA)); - } - - // revert - if(sprite2 && !contours[1]) - { - contours[1] = new Sprite(); - Surface::MakeContour(*contours[1], *sprite2, sprite2->GetColor(0xDA)); - } - - // create white black sprite - if(sprite1 && !contours[2]) - { - contours[2] = new Sprite(*sprite1); - contours[2]->GrayScale(); - } - if(sprite2 && !contours[3]) - { - contours[3] = new Sprite(*sprite2); - contours[3]->GrayScale(); - } -} - -void Battle2::Stats::SetPosition(u16 pos) -{ - position = pos; -} - -void Battle2::Stats::SetArena(Arena* a) -{ - arena = a; -} - -Monster Battle2::Stats::GetMonster(void) const -{ - return troop; -} - -void Battle2::Stats::SetReflection(bool r) -{ - if(isWide() && reflect != r) - position = GetTailIndex(); - - reflect = r; -} - -u8 Battle2::Stats::GetShots(void) const -{ - return shots; -} - -u16 Battle2::Stats::GetPosition(void) const -{ - return position; -} - -u16 Battle2::Stats::GetTailIndex(void) const -{ - return (isWide() && - Board::isValidDirection(position, reflect ? RIGHT : LEFT) ? - Board::GetIndexDirection(position, reflect ? RIGHT : LEFT) : MAXU16); -} - -void Battle2::Stats::SetMorale(s8 f) -{ - switch(f) - { - case Morale::TREASON: if(9 > Rand::Get(1, 16)) SetModes(MORALE_BAD); break; // 50% - case Morale::AWFUL: if(6 > Rand::Get(1, 15)) SetModes(MORALE_BAD); break; // 30% - case Morale::POOR: if(2 > Rand::Get(1, 15)) SetModes(MORALE_BAD); break; // 15% - case Morale::GOOD: if(2 > Rand::Get(1, 15)) SetModes(MORALE_GOOD); break; // 15% - case Morale::GREAT: if(6 > Rand::Get(1, 15)) SetModes(MORALE_GOOD); break; // 30% - case Morale::BLOOD: if(9 > Rand::Get(1, 16)) SetModes(MORALE_GOOD); break; // 50% - default: break; - } -} - -void Battle2::Stats::SetLuck(s8 f) -{ - //check bone dragon - const Army::army_t* enemy = arena->GetArmy(arena->GetOppositeColor(GetColor())); - - if(enemy && enemy->HasMonster(Monster::BONE_DRAGON)) --f; - - switch(f) - { - case Luck::CURSED: if(9 > Rand::Get(1, 16)) SetModes(LUCK_BAD); break; // 50% - case Luck::AWFUL: if(6 > Rand::Get(1, 15)) SetModes(LUCK_BAD); break; // 30% - case Luck::BAD: if(2 > Rand::Get(1, 15)) SetModes(LUCK_BAD); break; // 15% - case Luck::GOOD: if(2 > Rand::Get(1, 15)) SetModes(LUCK_GOOD); break; // 15% - case Luck::GREAT: if(6 > Rand::Get(1, 15)) SetModes(LUCK_GOOD); break; // 30% - case Luck::IRISH: if(9 > Rand::Get(1, 16)) SetModes(LUCK_GOOD); break; // 50% - default: break; - } -} - -bool Battle2::Stats::isFly(void) const -{ - return troop.isFly() && !Modes(SP_SLOW); -} - -bool Battle2::Stats::isWide(void) const -{ - return troop.isWide(); -} - -bool Battle2::Stats::isValid(void) const -{ - return count; -} - -bool Battle2::Stats::isReflect(void) const -{ - return reflect; -} - -u8 Battle2::Stats::GetObstaclesPenalty(const Stats & attacker) const -{ - if(!arena || Modes(CAP_TOWER) || attacker.Modes(CAP_TOWER)) return 0; - - // check golden bow artifact - const HeroBase* enemy = arena->army1.GetCommander(); - if(enemy && enemy->HasArtifact(Artifact::GOLDEN_BOW)) return 0; - - u8 result = 0; - - if(arena->castle) - { - // archery skill - if(enemy && Skill::Level::NONE != enemy->GetLevelSkill(Skill::Secondary::ARCHERY)) return 0; - - // check out of walls - if((position <= 8) || - (11 <= position && position <= 19) || - (22 <= position && position <= 29) || - (33 <= position && position <= 40) || - (44 <= position && position <= 50) || - (55 <= position && position <= 62) || - (66 <= position && position <= 73) || - (77 <= position && position <= 85) || - (88 <= position && position <= 96)) return 0; - - // check castle walls defensed - if(troop.GetColor() == arena->army2.GetColor()) - { - const Rect & pos1 = attacker.GetCellPosition(); - const Rect & pos2 = GetCellPosition(); - std::vector points; - - GetLinePoints(pos1, pos2, pos1.w / 3, points); - - std::vector::const_iterator it1 = points.begin(); - std::vector::const_iterator it2 = points.end(); - for(; it1 != it2; ++it1) - { - if(0 == arena->board[8].object && (arena->board[8].pos & *it1)) return 0; - else - if(0 == arena->board[29].object && (arena->board[29].pos & *it1)) return 0; - else - if(0 == arena->board[73].object && (arena->board[73].pos & *it1)) return 0; - else - if(0 == arena->board[96].object && (arena->board[96].pos & *it1)) return 0; - } - } - - result = 1; - } - else - if(Settings::Get().ExtBattleObjectsArchersPenalty()) - { - std::vector points; - std::vector indexes; - - Rect pos1 = attacker.GetCellPosition(); - Rect pos2 = GetCellPosition(); - - pos1.y += pos1.h / 2; - pos2.y += pos2.h / 2; - - GetLinePoints(pos1, pos2, pos1.w / 3, points); - arena->board.GetIndexesFromAbsPoints(indexes, points); - - if(indexes.size()) - { - for(u16 ii = 0; ii < indexes.size(); ++ii) - { - const u16 index = indexes[ii]; - - // obstacles - switch(arena->board[index].object) - { - // tree - case 0x82: - // trock - case 0x85: - // tree - case 0x89: - // rock - case 0x95: - case 0x96: - // stub - case 0x9A: - // dead tree - case 0x9B: - // tree - case 0x9C: ++result; break; - - default: break; - } - } - } - - if(enemy) - { - switch(enemy->GetLevelSkill(Skill::Secondary::ARCHERY)) - { - case Skill::Level::BASIC: if(result < 2) return 0; break; - case Skill::Level::ADVANCED: if(result < 3) return 0; break; - case Skill::Level::EXPERT: return 0; - default: break; - } - } - } - - return result; -} - -bool Battle2::Stats::isHandFighting(void) const -{ - if(count && !Modes(CAP_TOWER)) - { - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - const Cell* cell = arena->GetCell(position, dir); - const Stats* enemy = cell ? arena->GetTroopBoard(cell->index) : NULL; - if(enemy && (enemy->GetColor() != GetColor() || enemy->Modes(SP_HYPNOTIZE))) return true; - } - - if(isWide()) - { - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - const Cell* cell = arena->GetCell(GetTailIndex(), dir); - const Stats* enemy = cell ? arena->GetTroopBoard(cell->index) : NULL; - if(enemy && (enemy->GetColor() != GetColor() || enemy->Modes(SP_HYPNOTIZE))) return true; - } - } - } - - return false; -} - -bool Battle2::Stats::isHandFighting(const Stats & a, const Stats & b) -{ - if(a.isValid() && !a.Modes(CAP_TOWER)) - { - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - const Cell* cell = a.arena->GetCell(a.position, dir); - const Stats* enemy = cell ? a.arena->GetTroopBoard(cell->index) : NULL; - if(enemy && (enemy->GetColor() != a.GetColor() || enemy->Modes(SP_HYPNOTIZE)) && enemy->id == b.id) return true; - } - - if(a.isWide()) - { - for(direction_t dir = TOP_LEFT; dir < CENTER; ++dir) - { - const Cell* cell = a.arena->GetCell(a.GetTailIndex(), dir); - const Stats* enemy = cell ? a.arena->GetTroopBoard(cell->index) : NULL; - if(enemy && (enemy->GetColor() != a.GetColor() || enemy->Modes(SP_HYPNOTIZE)) && enemy->id == b.id) return true; - } - } - } - - return false; -} - -void Battle2::Stats::NewTurn(void) -{ - if(isResurectLife()) hp = GetMonster().GetHitPoints() * count; - - ResetModes(TR_RESPONSED); - ResetModes(TR_MOVED); - ResetModes(TR_SKIPMOVE); - ResetModes(TR_HARDSKIP); - ResetModes(MORALE_BAD); - ResetModes(MORALE_GOOD); - ResetModes(LUCK_BAD); - ResetModes(LUCK_GOOD); - - // decrease spell duration - affected.DecreaseDuration(); - - // remove spell duration - u32 mode = 0; - while(0 != (mode = affected.FindZeroDuration())) - { - affected.RemoveMode(mode); - ResetModes(mode); - - // cancel mirror image - if(mode == CAP_MIRRORIMAGE) - { - if(arena->interface) arena->interface->RedrawActionRemoveMirrorImage(*mirror); - Army::Troop & mirror_troop = mirror->troop; - mirror_troop.BattleQuit(); - mirror_troop.Reset(); - mirror = NULL; - } - } - - // define morale - if(troop.isAffectedByMorale()) - SetMorale(troop.GetMorale()); - - // define luck - SetLuck(troop.GetLuck()); -} - -u8 Battle2::Stats::GetSpeed(bool skip_standing_check) const -{ - if(!skip_standing_check && (!count || Modes(TR_MOVED | SP_BLIND | IS_PARALYZE_MAGIC))) return Speed::STANDING; - - const u8 speed = GetMonster().GetSpeed(); - - if(Modes(SP_HASTE)) return (Spell::GetExtraValue(Spell::HASTE) ? speed + Spell::GetExtraValue(Spell::HASTE) : Speed::GetOriginalFast(speed)); - else - if(Modes(SP_SLOW)) return (Spell::GetExtraValue(Spell::SLOW) ? speed - Spell::GetExtraValue(Spell::SLOW) : Speed::GetOriginalSlow(speed)); - - return speed; -} - -u32 Battle2::Stats::GetDamageMin(void) const -{ - return GetMonster().GetDamageMin() * count; -} - -u32 Battle2::Stats::GetDamageMax(void) const -{ - return GetMonster().GetDamageMax() * count; -} - -u32 Battle2::Stats::GetDamage(const Stats & enemy) const -{ - double dmg = 0; - - if(Modes(SP_BLESS)) - dmg = GetDamageMax(); - else - if(Modes(SP_CURSE)) - dmg = GetDamageMin(); - else - dmg = Rand::Get(GetDamageMin(), GetDamageMax()); - - if(troop.isArchers()) - { - if(isHandFighting()) - { - switch(troop()) - { - // skip - case Monster::MAGE: - case Monster::ARCHMAGE: - case Monster::TITAN: break; - - default: dmg /= 2; break; - } - } - else - { - // check skill archery +%10, +%25, +%50 - if(GetCommander()) - { - dmg += (dmg * GetCommander()->GetSecondaryValues(Skill::Secondary::ARCHERY) / 100); - } - - // check castle defense - if(enemy.GetObstaclesPenalty(*this)) dmg /= 2; - - // check spell shield - if(enemy.Modes(SP_SHIELD)) dmg /= Spell::GetExtraValue(Spell::SHIELD); - } - } - - // check luck x2 - if(Modes(LUCK_GOOD)) dmg *= 2; - else - if(Modes(LUCK_BAD)) dmg /= 2; - - // after blind - if(Modes(SP_BLIND)) dmg /= 2; - - // stone cap. - if(enemy.Modes(SP_STONE)) dmg /= 2; - - // check capability - switch(troop()) - { - case Monster::CRUSADER: - // double damage for undead - if(enemy.troop.isUndead()) dmg *= 2; - break; - - default: break; - } - - // approximate.. from faq - int r = GetAttack() - enemy.GetDefense(); - if(enemy.troop.isDragons() && Modes(SP_DRAGONSLAYER)) r+= Spell::GetExtraValue(Spell::DRAGONSLAYER); - dmg *= 1 + (0 < r ? 0.1 * std::min(r, 20) : 0.05 * std::max(r, -15)); - - switch(troop()) - { - case Monster::GENIE: - // 10% half - if(genie_enemy_half_percent >= Rand::Get(1, 100)) - { - dmg = enemy.hp / 2; - if(arena->interface) - { - std::string str(_("%{name} half the enemy troops!")); - String::Replace(str, "%{name}", GetName()); - arena->interface->SetStatus(str, true); - } - } - break; - - default: break; - } - - return dmg < 1 ? 1 : static_cast(dmg); -} - -u32 Battle2::Stats::HowMuchWillKilled(u32 dmg) const -{ - return dmg >= hp ? count : count - Monster::GetCountFromHitPoints(troop(), hp - dmg); -} - -u32 Battle2::Stats::ApplyDamage(u32 dmg) -{ - if(dmg && count) - { - u32 killed = HowMuchWillKilled(dmg); - - // kill mirror image (slave) - if(Modes(CAP_MIRRORIMAGE)) - { - if(arena->interface) arena->interface->RedrawActionRemoveMirrorImage(*this); - mirror->ResetModes(CAP_MIRROROWNER); - dmg = hp; - killed = count; - mirror = NULL; - } - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Stats::ApplyDamage: " << \ - GetName() << "(color: " << Color::String(GetColor()) << \ - ", pos: " << position << ", count: " << count << ", hp: " << hp << ")" << \ - " get damage: " << dmg << ", killed: " << killed); - - dead += (killed >= count ? count : killed); - count -= (killed >= count ? count : killed); - hp -= (dmg >= hp ? hp : dmg); - - if(! isValid()) PostKilledAction(); - - return killed; - } - - return 0; -} - -void Battle2::Stats::PostKilledAction(void) -{ - // kill mirror image (master) - if(Modes(CAP_MIRROROWNER)) - { - if(arena->interface) arena->interface->RedrawActionRemoveMirrorImage(*mirror); - modes = 0; - mirror->hp = 0; - mirror->count = 0; - mirror->mirror = NULL; - mirror->animstate = 0; - mirror->animframe = 0; - mirror = NULL; - ResetModes(CAP_MIRROROWNER); - } - - ResetModes(IS_MAGIC); - ResetModes(TR_RESPONSED); - ResetModes(TR_SKIPMOVE); - ResetModes(LUCK_GOOD); - ResetModes(LUCK_BAD); - ResetModes(MORALE_GOOD); - ResetModes(MORALE_BAD); - - SetModes(TR_MOVED); - - // save troop to graveyard - // skip mirror and summon - if(!Modes(CAP_MIRRORIMAGE) && !Modes(CAP_SUMMONELEM)) - arena->graveyard.AddTroopID(id); - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Stats::KilledAction: " << GetName() << " is killed"); - // possible also.. -} - -u32 Battle2::Stats::Resurrect(u32 points, bool allow_overflow, bool skip_dead) -{ - u32 resurrect = Monster::GetCountFromHitPoints(troop(), hp + points) - count; - - count += resurrect; - hp += points; - - if(allow_overflow) - { - if(troop.count < count) troop.count = count; - } - else - if(count > troop.count) - { - resurrect -= count - troop.count; - count = troop.count; - hp = count * GetMonster().GetHitPoints(); - } - - if(!skip_dead) - dead -= (resurrect < dead ? resurrect : dead); - - return resurrect; -} - -u32 Battle2::Stats::ApplyDamage(Stats & enemy, u32 dmg) -{ - const u32 killed = ApplyDamage(dmg); - - if(killed) switch(enemy.troop()) - { - case Monster::GHOST: - // grow troop - enemy.Resurrect(killed * enemy.GetMonster().GetHitPoints(), true, false); - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Stats::ApplyDamage: " << enemy.GetName() << " capability"); - break; - - case Monster::VAMPIRE_LORD: - // restore hit points - enemy.Resurrect(killed * GetMonster().GetHitPoints(), false, false); - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Stats::ApplyDamage: " << enemy.GetName() << " capability"); - break; - - default: break; - } - - // clean paralyze or stone magic - if(Modes(IS_PARALYZE_MAGIC)) - { - SetModes(TR_RESPONSED); - SetModes(TR_MOVED); - ResetModes(IS_PARALYZE_MAGIC); - affected.RemoveMode(IS_PARALYZE_MAGIC); - } - - return killed; -} - -bool Battle2::Stats::AllowApplySpell(u8 spell, const HeroBase* hero, std::string *msg) const -{ - if(Modes(SP_ANTIMAGIC)) return false; - - if((Modes(CAP_MIRRORIMAGE) || Modes(CAP_MIRROROWNER)) && - (spell == Spell::ANTIMAGIC || spell == Spell::MIRRORIMAGE)) return false; - - // check global - // if(arena->DisableCastSpell(spell, msg)) return false; // disable - recursion! - - if(hero && Spell::isApplyToFriends(spell) && GetColor() != hero->GetColor()) return false; - if(hero && Spell::isApplyToEnemies(spell) && GetColor() == hero->GetColor()) return false; - if(isMagicResist(spell, (hero ? hero->GetPower() : 0))) return false; - - const HeroBase* myhero = GetCommander(); - if(!myhero) return true; - - // check artifact - Artifact::artifact_t guard_art = Artifact::UNKNOWN; - switch(spell) - { - case Spell::CURSE: - case Spell::MASSCURSE: guard_art = Artifact::HOLY_PENDANT; break; - case Spell::HYPNOTIZE: guard_art = Artifact::PENDANT_FREE_WILL; break; - case Spell::DEATHRIPPLE: - case Spell::DEATHWAVE: guard_art = Artifact::PENDANT_LIFE; break; - case Spell::BERSERKER: guard_art = Artifact::SERENITY_PENDANT; break; - case Spell::BLIND: guard_art = Artifact::SEEING_EYE_PENDANT; break; - case Spell::PARALYZE: guard_art = Artifact::KINETIC_PENDANT; break; - case Spell::HOLYWORD: - case Spell::HOLYSHOUT: guard_art = Artifact::PENDANT_DEATH; break; - case Spell::DISPEL: guard_art = Artifact::WAND_NEGATION; break; - - default: break; - } - - if(Artifact::UNKNOWN != guard_art && myhero->HasArtifact(guard_art)) - { - if(msg) - { - *msg = _("The %{artifact} artifact is in effect for this battle, disabling %{spell} spell."); - String::Replace(*msg, "%{artifact}", Artifact::GetName(guard_art)); - String::Replace(*msg, "%{spell}", Spell::GetName(Spell::FromInt(spell))); - } - return false; - } - - return true; -} - -bool Battle2::Stats::ApplySpell(u8 spell, const HeroBase* hero, TargetInfo & target) -{ - if(! AllowApplySpell(spell, hero)) return false; - - DEBUG(DBG_BATTLE, DBG_TRACE, "Battle2::Stats::ApplySpell: " << Spell::GetName(Spell::FromInt(spell))); - - // save spell for "eagle eye" capability - arena->AddSpell(spell); - - u16 spoint = hero ? hero->GetPower() : 3; - - if(Spell::isDamage(spell)) - SpellApplyDamage(spell, spoint, hero, target); - else - if(Spell::isRestore(spell)) - SpellRestoreAction(spell, spoint, hero); - else - { - SpellModesAction(spell, spoint, hero); - } - - return true; -} - -void Battle2::Stats::Dump(void) const -{ - VERBOSE("\t" << GetName() << "(color: " << Color::String(GetColor()) << \ - ", pos: " << position << ", reflect: " << (reflect ? "true" : "false") << ", count: " << count << ", cell quality: " << GetCellQuality() << ")"); -} - -bool Battle2::Stats::AllowResponse(void) const -{ - return (isAlwayResponse() || (!Modes(TR_RESPONSED) && !Modes(IS_PARALYZE_MAGIC))); -} - -void Battle2::Stats::SetResponse(void) -{ - SetModes(TR_RESPONSED); -} - -void Battle2::Stats::PostAttackAction(Stats & enemy) -{ - switch(troop()) - { - case Monster::ARCHMAGE: - // 20% clean magic state - if(enemy.isValid() && enemy.Modes(IS_GOOD_MAGIC) && 3 > Rand::Get(1, 10)) enemy.ResetModes(IS_GOOD_MAGIC); - break; - - default: break; - } - - // decrease shots - if(isArchers()) - { - // check ammo cart artifact - const HeroBase* hero = GetCommander(); - if(!hero || !hero->HasArtifact(Artifact::AMMO_CART)) - --shots; - } - - // clean berserker spell - if(Modes(SP_BERSERKER)) - { - ResetModes(SP_BERSERKER); - affected.RemoveMode(SP_BERSERKER); - } - - // clean hypnotize spell - if(Modes(SP_HYPNOTIZE)) - { - ResetModes(SP_HYPNOTIZE); - affected.RemoveMode(SP_HYPNOTIZE); - } - if(enemy.Modes(SP_HYPNOTIZE)) - { - enemy.ResetModes(SP_HYPNOTIZE); - enemy.affected.RemoveMode(SP_HYPNOTIZE); - } - - // clean luck capability - ResetModes(LUCK_GOOD); - ResetModes(LUCK_BAD); -} - -void Battle2::Stats::ResetBlind(void) -{ - // remove blind action - if(Modes(SP_BLIND)) - { - SetModes(TR_MOVED); - ResetModes(SP_BLIND); - affected.RemoveMode(SP_BLIND); - } -} - -u16 Battle2::Stats::GetAttack(void) const -{ - u16 res = GetMonster().GetAttack() + - (GetCommander() ? GetCommander()->GetAttack() : 0); - - if(Modes(SP_BLOODLUST)) res += Spell::GetExtraValue(Spell::BLOODLUST); - - return res; -} - -u16 Battle2::Stats::GetDefense(void) const -{ - s16 res = GetMonster().GetDefense() + - (GetCommander() ? GetCommander()->GetDefense() : 0); - - if(Modes(SP_STONESKIN)) res += Spell::GetExtraValue(Spell::STONESKIN); - else - if(Modes(SP_STEELSKIN)) res += Spell::GetExtraValue(Spell::STEELSKIN); - - // extra - if(Modes(TR_HARDSKIP) && Settings::Get().ExtBattleSkipIncreaseDefense()) res += 2; - - // disrupting ray accumulate effect - if(disruptingray) res -= disruptingray * Spell::GetExtraValue(Spell::DISRUPTINGRAY); - if(0 > res) res = 1; - - return res; -} - -const char* Battle2::Stats::GetName(void) const -{ - return troop.GetName(); -} - -const char* Battle2::Stats::GetPluralName(u32 count) const -{ - return troop.GetPluralName(count); -} - -u16 Battle2::Stats::GetScoreQuality(const Stats & enemy) const -{ - u16 res = 0; - - switch(troop.GetLevel()) - { - case Monster::LEVEL1: res = 8; break; - case Monster::LEVEL2: res = 15; break; - case Monster::LEVEL3: res = 24; break; - case Monster::LEVEL4: res = 36; break; - default: break; - } - - if(troop.isFly()) res += res * 3 / 10; - if(troop.isArchers()) res += res * 5 / 10; - if(isTwiceAttack()) res += res * 2 / 10; - if(isResurectLife()) res += res * 1 / 10; - if(isDoubleCellAttack()) res += res * 1 / 10; - if(isHideAttack()) res += res * 4 / 10; - if(isAlwayResponse()) res -= res * 4 / 10; - - // attacker - switch(enemy.GetMonster().GetID()) - { - case Monster::GHOST: - // priority: from killed only - res = 1; - break; - - case Monster::VAMPIRE_LORD: - if(enemy.isHaveDamage()) - { - // alive priority - if(troop.isElemental() || troop.isUndead()) res /= 3; - } - break; - - default: break; - } - - return res ? res : 1; -} - -s32 Battle2::Stats::GetExtraQuality(s32 quality) const -{ - s32 res = 0; - - if(Modes(TR_RESPONSED)) res += quality / 2; - if(Modes(LUCK_BAD)) res += quality / 2; - if(Modes(LUCK_GOOD)) res -= quality / 2; - if(Modes(CAP_MIRRORIMAGE)) res += quality; - - return res; -} - -u32 Battle2::Stats::GetHitPoints(void) const -{ - return hp; -} - -u8 Battle2::Stats::GetControl(void) const -{ - return Modes(SP_BERSERKER) ? Game::AI : arena->GetArmy(GetColor())->GetControl(); -} - -bool Battle2::Stats::isArchers(void) const -{ - return troop.isArchers() && shots; -} - -void Battle2::Stats::SpellModesAction(u8 spell, u8 duration, const HeroBase* hero) -{ - if(hero) - { - if(hero->HasArtifact(Artifact::WIZARD_HAT)) duration += 10; - if(hero->HasArtifact(Artifact::ENCHANTED_HOURGLASS)) duration += 2; - } - - switch(spell) - { - case Spell::BLESS: - case Spell::MASSBLESS: - if(Modes(SP_CURSE)) - { - ResetModes(SP_CURSE); - affected.RemoveMode(SP_CURSE); - } - SetModes(SP_BLESS); - affected.AddMode(SP_BLESS, duration); - break; - - case Spell::BLOODLUST: - SetModes(SP_BLOODLUST); - affected.AddMode(SP_BLOODLUST, 3); - break; - - case Spell::CURSE: - case Spell::MASSCURSE: - if(Modes(SP_BLESS)) - { - ResetModes(SP_BLESS); - affected.RemoveMode(SP_BLESS); - } - SetModes(SP_CURSE); - affected.AddMode(SP_CURSE, duration); - break; - - case Spell::HASTE: - case Spell::MASSHASTE: - if(Modes(SP_SLOW)) - { - ResetModes(SP_SLOW); - affected.RemoveMode(SP_SLOW); - } - SetModes(SP_HASTE); - affected.AddMode(SP_HASTE, duration); - break; - - case Spell::DISPEL: - case Spell::MASSDISPEL: - if(Modes(IS_MAGIC)) - { - ResetModes(IS_MAGIC); - affected.RemoveMode(IS_MAGIC); - } - break; - - case Spell::SHIELD: - case Spell::MASSSHIELD: - SetModes(SP_SHIELD); - affected.AddMode(SP_SHIELD, duration); - break; - - case Spell::SLOW: - case Spell::MASSSLOW: - if(Modes(SP_HASTE)) - { - ResetModes(SP_HASTE); - affected.RemoveMode(SP_HASTE); - } - SetModes(SP_SLOW); - affected.AddMode(SP_SLOW, duration); - break; - - case Spell::STONESKIN: - if(Modes(SP_STEELSKIN)) - { - ResetModes(SP_STEELSKIN); - affected.RemoveMode(SP_STEELSKIN); - } - SetModes(SP_STONESKIN); - affected.AddMode(SP_STONESKIN, duration); - break; - - case Spell::BLIND: - SetModes(SP_BLIND); - affected.AddMode(SP_BLIND, duration); - break; - - case Spell::DRAGONSLAYER: - SetModes(SP_DRAGONSLAYER); - affected.AddMode(SP_DRAGONSLAYER, duration); - break; - - case Spell::STEELSKIN: - if(Modes(SP_STONESKIN)) - { - ResetModes(SP_STONESKIN); - affected.RemoveMode(SP_STONESKIN); - } - SetModes(SP_STEELSKIN); - affected.AddMode(SP_STEELSKIN, duration); - break; - - case Spell::ANTIMAGIC: - ResetModes(IS_MAGIC); - SetModes(SP_ANTIMAGIC); - affected.AddMode(SP_ANTIMAGIC, duration); - break; - - case Spell::PARALYZE: - SetModes(SP_PARALYZE); - affected.AddMode(SP_PARALYZE, duration); - break; - - case Spell::BERSERKER: - SetModes(SP_BERSERKER); - affected.AddMode(SP_BERSERKER, duration); - break; - - case Spell::HYPNOTIZE: - SetModes(SP_HYPNOTIZE); - affected.AddMode(SP_HYPNOTIZE, (hero && hero->HasArtifact(Artifact::GOLD_WATCH) ? duration * 2 : duration)); - break; - - case Spell::STONE: - SetModes(SP_STONE); - affected.AddMode(SP_STONE, duration); - break; - - case Spell::MIRRORIMAGE: - arena->SpellActionMirrorImage(*this); - affected.AddMode(CAP_MIRRORIMAGE, duration); - break; - - case Spell::DISRUPTINGRAY: - ++disruptingray; - break; - - default: break; - } -} - -void Battle2::Stats::SpellApplyDamage(u8 spell, u8 spoint, const HeroBase* hero, TargetInfo & target) -{ - u32 dmg = Spell::Damage(spell) * spoint; - - switch(troop()) - { - case Monster::IRON_GOLEM: - case Monster::STEEL_GOLEM: - switch(spell) - { - // 50% damage - case Spell::COLDRAY: - case Spell::COLDRING: - case Spell::FIREBALL: - case Spell::FIREBLAST: - case Spell::LIGHTNINGBOLT: - case Spell::CHAINLIGHTNING: - case Spell::ELEMENTALSTORM: - case Spell::ARMAGEDDON: - dmg /= 2; break; - default: break; - } - break; - - case Monster::WATER_ELEMENT: - switch(spell) - { - // 200% damage - case Spell::FIREBALL: - case Spell::FIREBLAST: - dmg *= 2; break; - default: break; - } - break; - - case Monster::AIR_ELEMENT: - switch(spell) - { - // 200% damage - case Spell::ELEMENTALSTORM: - case Spell::LIGHTNINGBOLT: - case Spell::CHAINLIGHTNING: - dmg *= 2; break; - default: break; - } - break; - - case Monster::FIRE_ELEMENT: - switch(spell) - { - // 200% damage - case Spell::COLDRAY: - case Spell::COLDRING: - dmg *= 2; break; - default: break; - } - break; - - default: break; - } - - // check artifact - if(hero) - { - const HeroBase* myhero = GetCommander(); - - switch(spell) - { - case Spell::COLDRAY: - case Spell::COLDRING: - // +50% - if(hero->HasArtifact(Artifact::EVERCOLD_ICICLE)) dmg += dmg / 2; - // -50% - if(myhero && myhero->HasArtifact(Artifact::ICE_CLOAK)) dmg /= 2; - if(myhero && myhero->HasArtifact(Artifact::HEART_ICE)) dmg /= 2; - // 100% - if(myhero && myhero->HasArtifact(Artifact::HEART_FIRE)) dmg *= 2; - break; - - case Spell::FIREBALL: - case Spell::FIREBLAST: - // +50% - if(hero->HasArtifact(Artifact::EVERHOT_LAVA_ROCK)) dmg += dmg / 2; - // -50% - if(myhero && myhero->HasArtifact(Artifact::FIRE_CLOAK)) dmg /= 2; - if(myhero && myhero->HasArtifact(Artifact::HEART_FIRE)) dmg /= 2; - // 100% - if(myhero && myhero->HasArtifact(Artifact::HEART_ICE)) dmg *= 2; - break; - - case Spell::LIGHTNINGBOLT: - // +50% - if(hero->HasArtifact(Artifact::LIGHTNING_ROD)) dmg += dmg / 2; - // -50% - if(myhero && myhero->HasArtifact(Artifact::LIGHTNING_HELM)) dmg /= 2; - break; - - case Spell::CHAINLIGHTNING: - // +50% - if(hero->HasArtifact(Artifact::LIGHTNING_ROD)) dmg += dmg / 2; - // -50% - if(myhero && myhero->HasArtifact(Artifact::LIGHTNING_HELM)) dmg /= 2; - // update orders damage - switch(target.damage) - { - case 0: break; - case 1: dmg /= 2; break; - case 2: dmg /= 4; break; - case 3: dmg /= 8; break; - default: break; - } - break; - - case Spell::ELEMENTALSTORM: - case Spell::ARMAGEDDON: - // -50% - if(myhero && myhero->HasArtifact(Artifact::BROACH_SHIELDING)) dmg /= 2; - break; - - default: break; - } - } - - // apply damage - if(dmg) - { - target.damage = dmg; - target.killed = ApplyDamage(dmg); - } -} - -void Battle2::Stats::SpellRestoreAction(u8 spell, u8 spoint, const HeroBase* hero) -{ - switch(spell) - { - case Spell::CURE: - case Spell::MASSCURE: - // clear bad magic - if(Modes(IS_BAD_MAGIC)) - { - ResetModes(IS_BAD_MAGIC); - affected.RemoveMode(IS_BAD_MAGIC); - } - // restore - hp += (Spell::Restore(spell) * spoint); - if(hp > count * GetMonster().GetHitPoints()) hp = count * GetMonster().GetHitPoints(); - break; - - case Spell::RESURRECT: - case Spell::ANIMATEDEAD: - case Spell::RESURRECTTRUE: - { - u32 restore = Spell::Resurrect(spell) * spoint; - // remove from graveyard - if(!isValid()) - { - arena->graveyard.RemoveTroopID(id); - ResetAnimFrame(AS_IDLE); - } - // restore hp - if(hero && hero->HasArtifact(Artifact::ANKH)) restore *= 2; - - const u16 res = Resurrect(restore, false, (Spell::RESURRECT == spell)); - - if(arena->interface) - { - std::string str(_("%{count} %{name} rise(s) from the dead!")); - String::Replace(str, "%{count}", res); - String::Replace(str, "%{name}", GetName()); - arena->interface->SetStatus(str, true); - } - } - break; - - default: break; - } -} - -bool Battle2::Stats::isTwiceAttack(void) const -{ - switch(troop()) - { - case Monster::WOLF: - case Monster::PALADIN: - case Monster::CRUSADER: - return true; - - case Monster::ELF: - case Monster::GRAND_ELF: - case Monster::RANGER: - return ! isHandFighting(); - - default: break; - } - - return false; -} - -bool Battle2::Stats::isResurectLife(void) const -{ - switch(troop()) - { - case Monster::TROLL: - case Monster::WAR_TROLL: - return true; - - default: break; - } - - return false; -} - -bool Battle2::Stats::isDoubleCellAttack(void) const -{ - switch(troop()) - { - case Monster::CYCLOPS: - case Monster::PHOENIX: - case Monster::GREEN_DRAGON: - case Monster::RED_DRAGON: - case Monster::BLACK_DRAGON: - return true; - - default: break; - } - - return false; -} - -bool Battle2::Stats::isMultiCellAttack(void) const -{ - switch(troop()) - { - case Monster::HYDRA: - return true; - - default: break; - } - - return false; - -} - -bool Battle2::Stats::isHideAttack(void) const -{ - switch(troop()) - { - case Monster::ROGUE: - case Monster::SPRITE: - case Monster::VAMPIRE: - case Monster::VAMPIRE_LORD: - case Monster::HYDRA: - return true; - - default: break; - } - - return false; -} - -bool Battle2::Stats::isAlwayResponse(void) const -{ - switch(troop()) - { - case Monster::GRIFFIN: - return true; - - default: break; - } - - return false; -} - -bool Battle2::Stats::isMagicResist(u8 spell, u8 spower) const -{ - return 100 == GetMagicResist(spell, spower); -} - -u8 Battle2::Stats::GetMagicResist(u8 spell, u8 spower) const -{ - if(Spell::isMindInfluence(spell) && - (troop.isUndead() || troop.isElemental() || - troop() == Monster::GIANT || troop() == Monster::TITAN)) return 100; - - if(Spell::isALiveOnly(spell) && - troop.isUndead()) return 100; - - if(Spell::isUndeadOnly(spell) && - !troop.isUndead()) return 100; - - if(Settings::Get().ExtBattleMagicTroopCanResist() && spell == GetSpellMagic(true)) - return 20; - - switch(troop()) - { - case Monster::ARCHMAGE: - if(Settings::Get().ExtBattleArchmageCanResistBadMagic() && - (Spell::isDamage(spell) || Spell::isApplyToEnemies(spell))) return 20; - break; - - // 25% unfortunatly - case Monster::DWARF: - case Monster::BATTLE_DWARF: - if(Spell::isDamage(spell) || Spell::isApplyToEnemies(spell)) return 25; - break; - - case Monster::GREEN_DRAGON: - case Monster::RED_DRAGON: - case Monster::BLACK_DRAGON: - return 100; - - case Monster::PHOENIX: - switch(spell) - { - case Spell::COLDRAY: - case Spell::COLDRING: - case Spell::FIREBALL: - case Spell::FIREBLAST: - case Spell::LIGHTNINGBOLT: - case Spell::CHAINLIGHTNING: - case Spell::ELEMENTALSTORM: - return 100; - default: break; - } - break; - - case Monster::CRUSADER: - switch(spell) - { - case Spell::CURSE: - case Spell::MASSCURSE: - return 100; - default: break; - } - break; - - case Monster::EARTH_ELEMENT: - switch(spell) - { - case Spell::METEORSHOWER: - case Spell::LIGHTNINGBOLT: - case Spell::CHAINLIGHTNING: - return 100; - default: break; - } - break; - - case Monster::AIR_ELEMENT: - switch(spell) - { - case Spell::METEORSHOWER: - return 100; - default: break; - } - break; - - case Monster::FIRE_ELEMENT: - switch(spell) - { - case Spell::FIREBALL: - case Spell::FIREBLAST: - return 100; - default: break; - } - break; - - case Monster::WATER_ELEMENT: - switch(spell) - { - case Spell::COLDRAY: - case Spell::COLDRING: - return 100; - default: break; - } - break; - - default: break; - } - - switch(spell) - { - case Spell::CURE: - case Spell::MASSCURE: - if(troop.isUndead()) return 100; - if(!isHaveDamage() && !(modes & IS_MAGIC)) return 100; - break; - - case Spell::RESURRECT: - case Spell::RESURRECTTRUE: - case Spell::ANIMATEDEAD: - if(!isHaveDamage()) return 100; - break; - - case Spell::DISPEL: - if(! (modes & IS_MAGIC)) return 100; - break; - - case Spell::HYPNOTIZE: - if(Spell::GetExtraValue(Spell::FromInt(spell)) * spower < hp) return 100; - break; - - default: break; - } - - return 0; -} - -bool Battle2::Stats::isMagicAttack(void) const -{ - return GetSpellMagic(true) != Spell::NONE; -} - - -u8 Battle2::Stats::GetSpellMagic(bool force) const -{ - switch(troop()) - { - case Monster::UNICORN: - // 20% blind - if(force || 3 > Rand::Get(1, 10)) return Spell::BLIND; - break; - - case Monster::CYCLOPS: - // 20% paralyze - if(force || 3 > Rand::Get(1, 10)) return Spell::PARALYZE; - break; - - case Monster::MUMMY: - // 20% curse - if(force || 3 > Rand::Get(1, 10)) return Spell::CURSE; - break; - - case Monster::ROYAL_MUMMY: - // 30% curse - if(force || 4 > Rand::Get(1, 10)) return Spell::CURSE; - break; - - /* skip: see Stats::PostAttackAction - case Monster::ARCHMAGE: - // 20% dispel - if(!force && 3 > Rand::Get(1, 10)) return Spell::DISPEL; - break; - */ - - case Monster::MEDUSA: - // 20% stone - if(force || 3 > Rand::Get(1, 10)) return Spell::STONE; - break; - - default: break; - } - - return Spell::NONE; -} - -bool Battle2::Stats::isHaveDamage(void) const -{ - return hp < troop.count * GetMonster().GetHitPoints(); -} - -u8 Battle2::Stats::GetFrameStart(void) const -{ - return animstep < 0 ? GetFrameState().start + GetFrameState().count - 1 : GetFrameState().start; -} - -u8 Battle2::Stats::GetFrameOffset(void) const -{ - return animframe - GetFrameStart(); -} - -u8 Battle2::Stats::GetFrameCount(void) const -{ - return GetFrameState().count; -} - -void Battle2::Stats::IncreaseAnimFrame(bool loop) -{ - if(! isFinishAnimFrame()) - animframe += animstep; - else - if(loop) - animframe = GetFrameStart(); -} - -bool Battle2::Stats::isStartAnimFrame(void) const -{ - return GetFrameStart() == animframe; -} - -bool Battle2::Stats::isFinishAnimFrame(void) const -{ - if(0 == GetFrameState().count) - return true; - else - if(animstep < 0) - return animframe <= GetFrameState().start; - else - if(animstep > 0) - return animframe >= GetFrameState().start + GetFrameState().count - 1; - - return true; -} - -const Battle2::animframe_t & Battle2::Stats::GetFrameState(u8 state) const -{ - const MonsterInfo & msi = GetMonsterInfo(); - - switch(state) - { - case AS_IDLE: return msi.frm_idle; - case AS_MOVE: return msi.frm_move; - case AS_FLY1: return msi.frm_fly1; - case AS_FLY2: return msi.frm_fly2; - case AS_FLY3: return msi.frm_fly3; - case AS_SHOT0: return msi.frm_shot0; - case AS_SHOT1: return msi.frm_shot1; - case AS_SHOT2: return msi.frm_shot2; - case AS_SHOT3: return msi.frm_shot3; - case AS_ATTK0: return msi.frm_attk0; - case AS_ATTK1: return msi.frm_attk1; - case AS_ATTK2: return msi.frm_attk2; - case AS_ATTK3: return msi.frm_attk3; - case AS_WNCE: return msi.frm_wnce; - case AS_KILL: return msi.frm_kill; - default: break; - } - - return msi.frm_idle; -} - -const Battle2::animframe_t & Battle2::Stats::GetFrameState(void) const -{ - return GetFrameState(animstate); -} - -void Battle2::Stats::ResetAnimFrame(u8 rule) -{ - animstep = 1; - animstate = rule; - animframe = GetFrameStart(); - - if(AS_FLY3 == rule && 0 == GetFrameState().count) - { - animstep = -1; - animstate = AS_FLY1; - animframe = GetFrameStart(); - } -} - -M82::m82_t Battle2::Stats::M82Attk(void) const -{ - if(isArchers() && !isHandFighting()) - { - switch(troop()) - { - case Monster::ARCHER: - case Monster::RANGER: return M82::ARCHSHOT; - case Monster::ORC: - case Monster::ORC_CHIEF: return M82::ORC_SHOT; - case Monster::TROLL: - case Monster::WAR_TROLL: return M82::TRLLSHOT; - case Monster::ELF: - case Monster::GRAND_ELF: return M82::ELF_SHOT; - case Monster::DRUID: - case Monster::GREATER_DRUID:return M82::DRUISHOT; - case Monster::CENTAUR: return M82::CNTRSHOT; - case Monster::HALFLING: return M82::HALFSHOT; - case Monster::MAGE: - case Monster::ARCHMAGE: return M82::MAGESHOT; - case Monster::TITAN: return M82::TITNSHOT; - case Monster::LICH: - case Monster::POWER_LICH: return M82::LICHSHOT; - default: break; - } - } - - return GetMonsterInfo().m82_attk; -} - -M82::m82_t Battle2::Stats::M82Kill(void) const -{ - return GetMonsterInfo().m82_kill; -} - -M82::m82_t Battle2::Stats::M82Move(void) const -{ - return GetMonsterInfo().m82_move; -} - -M82::m82_t Battle2::Stats::M82Wnce(void) const -{ - return GetMonsterInfo().m82_wnce; -} - -M82::m82_t Battle2::Stats::M82Expl(void) const -{ - switch(troop.GetID()) - { - case Monster::VAMPIRE: return M82::VAMPEXT1; - case Monster::VAMPIRE_LORD: return M82::VAMPEXT1; - case Monster::LICH: return M82::LICHEXPL; - case Monster::POWER_LICH: return M82::LICHEXPL; - - default: break; - } - - return M82::UNKNOWN; -} - -ICN::icn_t Battle2::Stats::ICNFile(void) const -{ - return GetMonsterInfo().icn_file; -} - -ICN::icn_t Battle2::Stats::ICNMiss(void) const -{ - switch(troop.GetID()) - { - case Monster::ARCHER: return ICN::ARCH_MSL; - case Monster::RANGER: return ICN::ARCH_MSL; - case Monster::ORC: return ICN::ORC__MSL; - case Monster::ORC_CHIEF: return ICN::ORC__MSL; - case Monster::TROLL: return ICN::TROLLMSL; - case Monster::WAR_TROLL: return ICN::TROLLMSL; - case Monster::ELF: return ICN::ELF__MSL; - case Monster::GRAND_ELF: return ICN::ELF__MSL; - case Monster::DRUID: return ICN::DRUIDMSL; - case Monster::GREATER_DRUID: return ICN::DRUIDMSL; - case Monster::CENTAUR: return ICN::ARCH_MSL; - case Monster::HALFLING: return ICN::HALFLMSL; - case Monster::MAGE: return ICN::DRUIDMSL; - case Monster::ARCHMAGE: return ICN::DRUIDMSL; - case Monster::TITAN: return ICN::TITANMSL; - case Monster::LICH: return ICN::LICH_MSL; - case Monster::POWER_LICH: return ICN::LICH_MSL; - - default: break; - } - - return ICN::UNKNOWN; -} - -u32 Battle2::Stats::GetCount(void) const -{ - return count; -} - -s32 Battle2::Stats::GetCellQuality(void) const -{ - return arena && arena->board.size() > position ? arena->board[position].quality : 0; -} - -const Rect & Battle2::Stats::GetCellPosition(void) const -{ - return arena->board[position].pos; -} - -bool Battle2::Stats::AppertainsArmy1(void) const -{ - return arena && arena->army1.GetColor() == troop.GetColor(); -} - -void Battle2::Stats::UpdateDirection(void) -{ - if(reflect && AppertainsArmy1()) - SetReflection(false); - else - if(!reflect && !AppertainsArmy1()) - SetReflection(true); -} - -void Battle2::Stats::UpdateDirection(const Stats & b) -{ - UpdateDirection(arena->board[b.position]); -} - -bool Battle2::Stats::UpdateDirection(const Cell & cell) -{ - bool need = arena && arena->board[position].pos.x > cell.pos.x; - - if(need != reflect) - { - SetReflection(need); - return true; - } - return false; -} - -s8 Battle2::Stats::GetStartMissileOffset(u8 state) const -{ - switch(troop.GetID()) - { - case Monster::ARCHER: - case Monster::RANGER: - switch(state) - { - case AS_SHOT1: return -15; - case AS_SHOT2: return -3; - case AS_SHOT3: return 10; - default: break; - } - break; - - case Monster::ORC: - case Monster::ORC_CHIEF: - return 5; - - case Monster::TROLL: - case Monster::WAR_TROLL: - return -20; - - case Monster::LICH: - case Monster::POWER_LICH: - switch(state) - { - case AS_SHOT1: return -30; - case AS_SHOT2: return -20; - case AS_SHOT3: return 0; - default: break; - } - break; - - case Monster::ELF: - case Monster::GRAND_ELF: - switch(state) - { - case AS_SHOT1: return -5; - case AS_SHOT2: return 0; - case AS_SHOT3: return 5; - default: break; - } - break; - - case Monster::CENTAUR: - switch(state) - { - case AS_SHOT1: return -20; - case AS_SHOT2: return -10; - case AS_SHOT3: return 5; - default: break; - } - break; - - case Monster::DRUID: - case Monster::GREATER_DRUID: - switch(state) - { - case AS_SHOT1: return -20; - case AS_SHOT2: return -5; - case AS_SHOT3: return 15; - default: break; - } - break; - - case Monster::HALFLING: - switch(state) - { - case AS_SHOT1: return -20; - case AS_SHOT2: return 10; - case AS_SHOT3: return 20; - default: break; - } - break; - - case Monster::MAGE: - case Monster::ARCHMAGE: - switch(state) - { - case AS_SHOT1: return -40; - case AS_SHOT2: return -10; - case AS_SHOT3: return 25; - default: break; - } - break; - - case Monster::TITAN: - switch(state) - { - case AS_SHOT1: return -80; - case AS_SHOT2: return -20; - case AS_SHOT3: return 15; - default: break; - } - break; - - default: break; - } - - return 0; -} - -u8 Battle2::Stats::GetColor(void) const -{ - return (Modes(SP_BERSERKER) ? 0 : Modes(SP_HYPNOTIZE) ? arena->GetOppositeColor(troop.GetColor()) : troop.GetColor()); -} - -const Army::army_t* Battle2::Stats::GetArmy(void) const -{ - return arena ? arena->GetArmy(GetColor()) : NULL; -} - -Army::army_t* Battle2::Stats::GetArmy(void) -{ - return arena ? arena->GetArmy(GetColor()) : NULL; -} - -const HeroBase* Battle2::Stats::GetCommander(void) const -{ - return GetArmy() ? GetArmy()->GetCommander() : NULL; -} - -HeroBase* Battle2::Stats::GetCommander(void) -{ - return GetArmy() ? GetArmy()->GetCommander() : NULL; -} - -u16 Battle2::Stats::AIGetAttackPosition(const std::vector & positions) const -{ - u16 res = MAXU16; - - if(isMultiCellAttack()) - { - res = arena->GetMaxQualityPosition(positions); - } - else - if(isDoubleCellAttack()) - { - std::vector enemies, results; - - enemies.reserve(6); - results.reserve(12); - - arena->GetArmyPositions(arena->GetOppositeColor(GetColor()), enemies); - - // get actual coord if enemy troop near placed - while(1 < enemies.size()) - { - const u16 cur = enemies.back(); - enemies.pop_back(); - - std::vector::const_iterator it1 = enemies.begin(); - std::vector::const_iterator it2 = enemies.end(); - for(; it1 != it2; ++it1) - { - // get near placed enemies - const direction_t dir = Board::GetDirection(cur, *it1); - - if(UNKNOWN != dir) - { - if(Board::isValidDirection(cur, Board::GetReflectDirection(dir))) - results.push_back(Board::GetIndexDirection(cur, Board::GetReflectDirection(dir))); - if(Board::isValidDirection(*it1, dir)) - results.push_back(Board::GetIndexDirection(*it1, dir)); - } - } - } - - if(results.size()) - { - // find passable results - std::vector passable; - arena->GetPassableQualityPositions(*this, passable); - - std::vector::iterator it1 = results.begin(); - std::vector::iterator it3 = it1; - - for (; it1 != results.end(); ++it1) - if(passable.end() != std::find(passable.begin(), passable.end(), *it1)) - *it3++ = *it1; - - if(it3 != results.end()) - results.resize(std::distance(results.begin(), it3)); - - // get max quality - if(results.size()) - { - res = arena->GetMaxQualityPosition(results); - } - } - } - - return res != MAXU16 ? res : Arena::GetShortDistance(position, positions); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_stats.h b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_stats.h deleted file mode 100644 index b66de1e24..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_stats.h +++ /dev/null @@ -1,242 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BATTLE2_STATS_H -#define H2BATTLE2_STATS_H - -#include -#include -#include "army.h" -#include "bitmodes.h" -#include "battle_arena.h" - -class Sprite; -class HeroBase; - -namespace Battle2 -{ - enum flags_t - { - TR_RESPONSED = 0x00000001, - TR_MOVED = 0x00000002, - TR_HARDSKIP = 0x00000004, - TR_SKIPMOVE = 0x00000008, - - LUCK_GOOD = 0x00000100, - LUCK_BAD = 0x00000200, - MORALE_GOOD = 0x00000400, - MORALE_BAD = 0x00000800, - - CAP_TOWER = 0x00001000, - CAP_SUMMONELEM = 0x00002000, - CAP_MIRROROWNER = 0x00004000, - CAP_MIRRORIMAGE = 0x00008000, - - SP_BLOODLUST = 0x00020000, - SP_BLESS = 0x00040000, - SP_HASTE = 0x00080000, - SP_SHIELD = 0x00100000, - SP_STONESKIN = 0x00200000, - SP_DRAGONSLAYER = 0x00400000, - SP_STEELSKIN = 0x00800000, - - SP_ANTIMAGIC = 0x01000000, - - SP_CURSE = 0x02000000, - SP_SLOW = 0x04000000, - SP_BERSERKER = 0x08000000, - SP_HYPNOTIZE = 0x10000000, - SP_BLIND = 0x20000000, - SP_PARALYZE = 0x40000000, - SP_STONE = 0x80000000, - - IS_GOOD_MAGIC = 0x00FE0000, - IS_PARALYZE_MAGIC=0xC0000000, - IS_MIND_MAGIC = 0x78000000, - IS_BAD_MAGIC = 0xFE000000, - IS_MAGIC = 0xFFFE0000, - - IS_RED_STATUS = IS_BAD_MAGIC, - IS_GREEN_STATUS = SP_SHIELD | SP_STEELSKIN | SP_STONESKIN | SP_DRAGONSLAYER | SP_BLOODLUST | SP_BLESS | SP_HASTE | SP_ANTIMAGIC - }; - - u8 GetCellTargets(const Stats &, const Stats &, std::vector &); - - struct ModeDuration : public std::pair - { - ModeDuration(); - ModeDuration(u32, u16); - - bool isMode(u32) const; - bool isZeroDuration(void) const; - void DecreaseDuration(void); - }; - - struct ModesAffected : public std::vector - { - ModesAffected(); - - void AddMode(u32, u16); - void RemoveMode(u32); - void DecreaseDuration(void); - - u32 FindZeroDuration(void) const; - }; - - // battle troop stats - struct Stats : public BitModes - { - Stats(Army::Troop &); - ~Stats(); - - void InitContours(void); - void SetPosition(u16); - void SetArena(Arena*); - void SetReflection(bool); - void SetMorale(s8); - void SetLuck(s8); - void NewTurn(void); - - bool isArchers(void) const; - bool isFly(void) const; - bool isWide(void) const; - bool isValid(void) const; - bool isHandFighting(void) const; - bool isReflect(void) const; - bool AllowResponse(void) const; - - void Dump(void) const; - - - u16 GetID(void) const; - - u32 GetCount(void) const; - s32 GetExtraQuality(s32) const; - u16 GetTailIndex(void) const; - u16 GetAttack(void) const; - u16 GetDefense(void) const; - u8 GetColor(void) const; - u8 GetSpeed(bool skip_standing_check = false) const; - const char* GetName(void) const; - const char* GetPluralName(u32) const; - u8 GetControl(void) const; - u32 GetDamage(const Stats &) const; - u32 GetDamageMin(void) const; - u32 GetDamageMax(void) const; - u16 GetScoreQuality(const Stats &) const; - u32 GetHitPoints(void) const; - u8 GetShots(void) const; - u16 GetPosition(void) const; - u32 ApplyDamage(Stats &, u32); - u32 ApplyDamage(u32); - bool ApplySpell(u8, const HeroBase* hero, TargetInfo &); - bool AllowApplySpell(u8, const HeroBase* hero, std::string* msg = NULL) const; - void PostAttackAction(Stats &); - void ResetBlind(void); - void SpellModesAction(u8, u8, const HeroBase*); - void SpellApplyDamage(u8, u8, const HeroBase*, TargetInfo &); - void SpellRestoreAction(u8, u8, const HeroBase*); - u32 Resurrect(u32, bool, bool); - - Monster GetMonster(void) const; - const MonsterInfo & GetMonsterInfo(void) const; - - const animframe_t & GetFrameState(void) const; - const animframe_t & GetFrameState(u8) const; - void IncreaseAnimFrame(bool loop = false); - bool isStartAnimFrame(void) const; - bool isFinishAnimFrame(void) const; - u8 GetFrameOffset(void) const; - u8 GetFrameStart(void) const; - u8 GetFrameCount(void) const; - - s8 GetStartMissileOffset(u8) const; - - M82::m82_t M82Attk(void) const; - M82::m82_t M82Kill(void) const; - M82::m82_t M82Move(void) const; - M82::m82_t M82Wnce(void) const; - M82::m82_t M82Expl(void) const; - - ICN::icn_t ICNFile(void) const; - ICN::icn_t ICNMiss(void) const; - - s32 GetCellQuality(void) const; - const Rect & GetCellPosition(void) const; - - u32 HowMuchWillKilled(u32) const; - u16 AIGetAttackPosition(const std::vector &) const; - - void SetResponse(void); - void ResetAnimFrame(u8); - void UpdateDirection(void); - void UpdateDirection(const Stats &); - bool UpdateDirection(const Cell &); - void PostKilledAction(void); - - bool AppertainsArmy1(void) const; - - bool isTwiceAttack(void) const; - bool isResurectLife(void) const; - bool isDoubleCellAttack(void) const; - bool isMultiCellAttack(void) const; - bool isHideAttack(void) const; - bool isAlwayResponse(void) const; - bool isMagicResist(u8, u8) const; - u8 GetMagicResist(u8, u8) const; - bool isMagicAttack(void) const; - u8 GetSpellMagic(bool force = false) const; - bool isHaveDamage(void) const; - u8 GetObstaclesPenalty(const Stats &) const; - - const Army::army_t* GetArmy(void) const; - Army::army_t* GetArmy(void); - - const HeroBase* GetCommander(void) const; - HeroBase* GetCommander(void); - - static bool isHandFighting(const Stats &, const Stats &); - - Army::Troop & troop; - Arena* arena; - - u16 id; - u16 position; - u32 hp; - u32 count; - u32 dead; - u8 shots; - u8 disruptingray; - bool reflect; - - Stats* mirror; - - u8 animstate; - u8 animframe; - s8 animstep; - - ModesAffected affected; - Sprite* contours[4]; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_tower.cpp b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_tower.cpp deleted file mode 100644 index 2cd04ab43..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_tower.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "castle.h" -#include "settings.h" -#include "battle_cell.h" -#include "battle_stats.h" -#include "battle_tower.h" - -Battle2::Tower::Tower(const Castle & castle, u8 twr, Arena & a) : Army::Troop(Monster::ARCHER), arena(a), type(twr), valid(true) -{ - count += castle.CountBuildings(); - count += castle.GetLevelMageGuild() - 1; - - if(count > 20) count = 20; - if(TWR_CENTER != type) count /= 2; - if(count == 0) count = 1; - - BattleInit(); - Stats* b = GetBattleStats(); - b->SetModes(CAP_TOWER); -} - -bool Battle2::Tower::isValid(void) const -{ - return valid; -} - -u8 Battle2::Tower::GetColor(void) const -{ - return arena.castle ? arena.castle->GetColor() : 0; -} - -Point Battle2::Tower::GetPortPosition(void) const -{ - Point res; - - switch(type) - { - case TWR_LEFT: res = Point(410, 70); break; - case TWR_RIGHT: res = Point(410, 320); break; - case TWR_CENTER:res = Point(560, 170); break; - default: break; - } - - if(Settings::Get().QVGA()) - { - res.x /= 2; - res.y /= 2; - } - - return res; -} - -void Battle2::Tower::Action(void) const -{ - const Stats* b = GetBattleStats(); - - arena.ResetBoard(); - arena.board.SetEnemyQuality(*b); - - const Stats* enemy = arena.GetEnemyMaxQuality(GetColor()); - - if(enemy) - { - Battle2::Action action; - action.SetID(MSG_BATTLE_TOWER); - action.Push(type); - action.Push(enemy->id); - arena.ApplyAction(action); - } -} - -void Battle2::Tower::SetDestroy(void) -{ - switch(type) - { - case TWR_LEFT: arena.board[19].object = 1; break; - case TWR_RIGHT: arena.board[85].object = 1; break; - default: break; - } - valid = false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_tower.h b/project/jni/application/fheroes2/src/fheroes2/battle2/battle_tower.h deleted file mode 100644 index b689c3bd2..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/battle2/battle_tower.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BATTLE2_TOWER_H -#define H2BATTLE2_TOWER_H - -#include "army_troop.h" -#include "gamedefs.h" -#include "battle_arena.h" - -class Castle; - -namespace Battle2 -{ - class Tower : public Army::Troop - { - public: - Tower(const Castle &, u8, Arena &); - - bool isValid(void) const; - u8 GetColor(void) const; - - void SetDestroy(void); - void Action(void) const; - Point GetPortPosition(void) const; - - private: - Arena & arena; - const u8 type; - bool valid; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/buildinginfo.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/buildinginfo.cpp deleted file mode 100644 index 95a69be9c..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/buildinginfo.cpp +++ /dev/null @@ -1,673 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "monster.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "world.h" -#include "kingdom.h" -#include "payment.h" -#include "profit.h" -#include "statusbar.h" -#include "buildinginfo.h" - -#ifdef WITH_XML -#include "xmlccwrap.h" -#endif - -struct buildstats_t -{ - const char* id1; - const u32 id2; - const u8 race; - cost_t cost; -}; - -static buildstats_t _builds[] = { - // id gold wood mercury ore sulfur crystal gems - { "thieves_guild", BUILD_THIEVESGUILD, Race::ALL, { 750, 5, 0, 0, 0, 0, 0 } }, - { "tavern", BUILD_TAVERN, Race::ALL, { 500, 5, 0, 0, 0, 0, 0 } }, - { "shipyard", BUILD_SHIPYARD, Race::ALL, {2000,20, 0, 0, 0, 0, 0 } }, - { "well", BUILD_WELL, Race::ALL, { 500, 0, 0, 0, 0, 0, 0 } }, - { "statue", BUILD_STATUE, Race::ALL, {1250, 0, 0, 5, 0, 0, 0 } }, - { "left_turret", BUILD_LEFTTURRET, Race::ALL, {1500, 0, 0, 5, 0, 0, 0 } }, - { "right_turret", BUILD_RIGHTTURRET, Race::ALL, {1500, 0, 0, 5, 0, 0, 0 } }, - { "marketplace", BUILD_MARKETPLACE, Race::ALL, { 500, 5, 0, 0, 0, 0, 0 } }, - { "moat", BUILD_MOAT, Race::ALL, { 750, 0, 0, 0, 0, 0, 0 } }, - { "castle", BUILD_CASTLE, Race::ALL, {5000,20, 0,20, 0, 0, 0 } }, - { "captain", BUILD_CAPTAIN, Race::ALL, { 500, 0, 0, 0, 0, 0, 0 } }, - { "mage_guild1", BUILD_MAGEGUILD1, Race::ALL, {2000, 5, 0, 5, 0, 0, 0 } }, - { "mage_guild2", BUILD_MAGEGUILD2, Race::ALL, {1000, 5, 4, 5, 4, 4, 4 } }, - { "mage_guild3", BUILD_MAGEGUILD3, Race::ALL, {1000, 5, 6, 5, 6, 6, 6 } }, - { "mage_guild4", BUILD_MAGEGUILD4, Race::ALL, {1000, 5, 8, 5, 8, 8, 8 } }, - { "mage_guild5", BUILD_MAGEGUILD5, Race::ALL, {1000, 5,10, 5,10,10,10 } }, - - { "farm", BUILD_WEL2, Race::KNGT, {1000, 0, 0, 0, 0, 0, 0 } }, - { "garbage_he", BUILD_WEL2, Race::BARB, {1000, 0, 0, 0, 0, 0, 0 } }, - { "crystal_gar", BUILD_WEL2, Race::SORC, {1000, 0, 0, 0, 0, 0, 0 } }, - { "waterfall", BUILD_WEL2, Race::WRLK, {1000, 0, 0, 0, 0, 0, 0 } }, - { "orchard", BUILD_WEL2, Race::WZRD, {1000, 0, 0, 0, 0, 0, 0 } }, - { "skull_pile", BUILD_WEL2, Race::NECR, {1000, 0, 0, 0, 0, 0, 0 } }, - - { "fortification", BUILD_SPEC, Race::KNGT, {1500, 5, 0,15, 0, 0, 0 } }, - { "coliseum", BUILD_SPEC, Race::BARB, {2000,10, 0,10, 0, 0, 0 } }, - { "rainbow", BUILD_SPEC, Race::SORC, {1500, 0, 0, 0, 0,10, 0 } }, - { "dungeon", BUILD_SPEC, Race::WRLK, {3000, 5, 0,10, 0, 0, 0 } }, - { "library", BUILD_SPEC, Race::WZRD, {1500, 5, 5, 5, 5, 5, 5 } }, - { "storm", BUILD_SPEC, Race::NECR, {1000, 0,10, 0,10, 0, 0 } }, - - { "shrine", BUILD_SHRINE, Race::NECR, {4000,10, 0, 0, 0,10, 0 } }, - - { "thatched_hut", DWELLING_MONSTER1, Race::KNGT, { 200, 0, 0, 0, 0, 0, 0 } }, - { "archery_range", DWELLING_MONSTER2, Race::KNGT, {1000, 0, 0, 0, 0, 0, 0 } }, - { "upg_archery_range", DWELLING_UPGRADE2, Race::KNGT, {1500, 5, 0, 0, 0, 0, 0 } }, - { "blacksmith", DWELLING_MONSTER3, Race::KNGT, {1000, 0, 0, 5, 0, 0, 0 } }, - { "upg_blacksmith", DWELLING_UPGRADE3, Race::KNGT, {1500, 0, 0, 5, 0, 0, 0 } }, - { "armory", DWELLING_MONSTER4, Race::KNGT, {2000,10, 0,10, 0, 0, 0 } }, - { "upg_armory", DWELLING_UPGRADE4, Race::KNGT, {2000, 5, 0, 5, 0, 0, 0 } }, - { "jousting_arena", DWELLING_MONSTER5, Race::KNGT, {3000,20, 0, 0, 0, 0, 0 } }, - { "upg_jousting_arena", DWELLING_UPGRADE5, Race::KNGT, {3000,10, 0, 0, 0, 0, 0 } }, - { "cathedral", DWELLING_MONSTER6, Race::KNGT, {5000,20, 0, 0, 0,20, 0 } }, - { "upg_cathedral", DWELLING_UPGRADE6, Race::KNGT, {5000,10, 0, 0, 0,10, 0 } }, - - { "hut", DWELLING_MONSTER1, Race::BARB, { 300, 0, 0, 0, 0, 0, 0 } }, - { "stick_hut", DWELLING_MONSTER2, Race::BARB, { 800, 5, 0, 0, 0, 0, 0 } }, - { "upg_stick_hut", DWELLING_UPGRADE2, Race::BARB, {1200, 5, 0, 0, 0, 0, 0 } }, - { "den", DWELLING_MONSTER3, Race::BARB, {1000, 0, 0, 0, 0, 0, 0 } }, - { "adobe", DWELLING_MONSTER4, Race::BARB, {2000,10, 0,10, 0, 0, 0 } }, - { "upg_adobe", DWELLING_UPGRADE4, Race::BARB, {3000, 5, 0, 5, 0, 0, 0 } }, - { "bridge", DWELLING_MONSTER5, Race::BARB, {4000, 0, 0,20, 0, 0, 0 } }, - { "upg_bridge", DWELLING_UPGRADE5, Race::BARB, {2000, 0, 0,10, 0, 0, 0 } }, - { "cyclop_pyramid", DWELLING_MONSTER6, Race::BARB, {6000, 0, 0,20, 0,20, 0 } }, - - { "treehouse", DWELLING_MONSTER1, Race::SORC, { 500, 5, 0, 0, 0, 0, 0 } }, - { "cottage", DWELLING_MONSTER2, Race::SORC, {1000, 5, 0, 0, 0, 0, 0 } }, - { "upg_cottage", DWELLING_UPGRADE2, Race::SORC, {1500, 5, 0, 0, 0, 0, 0 } }, - { "elves_arhery_range", DWELLING_MONSTER3, Race::SORC, {1500, 0, 0, 0, 0, 0, 0 } }, - { "upg_elves_archery_range", DWELLING_UPGRADE3, Race::SORC, {1500, 5, 0, 0, 0, 0, 0 } }, - { "stonehenge", DWELLING_MONSTER4, Race::SORC, {1500, 0, 0,10, 0, 0, 0 } }, - { "upd_stonehenge", DWELLING_UPGRADE4, Race::SORC, {1500, 0, 5, 0, 0, 0, 0 } }, - { "fenced_meadow", DWELLING_MONSTER5, Race::SORC, {3000,10, 0, 0, 0, 0,10 } }, - { "phoenix_red_tower", DWELLING_MONSTER6, Race::SORC, {10000, 0,20,30, 0, 0, 0 } }, - - { "cave", DWELLING_MONSTER1, Race::WRLK, { 500, 0, 0, 0, 0, 0, 0 } }, - { "crypt", DWELLING_MONSTER2, Race::WRLK, {1000, 0, 0,10, 0, 0, 0 } }, - { "nest", DWELLING_MONSTER3, Race::WRLK, {2000, 0, 0, 0, 0, 0, 0 } }, - { "maze", DWELLING_MONSTER4, Race::WRLK, {3000, 0, 0, 0, 0, 0,10 } }, - { "upg_maze", DWELLING_UPGRADE4, Race::WRLK, {2000, 0, 0, 0, 0, 0, 5 } }, - { "swamp", DWELLING_MONSTER5, Race::WRLK, {4000, 0, 0, 0,10, 0, 0 } }, - { "green_tower", DWELLING_MONSTER6, Race::WRLK, {15000,0, 0,30,20, 0, 0 } }, - { "red_tower", DWELLING_UPGRADE6, Race::WRLK, {5000, 0, 0, 5,10, 0, 0 } }, - { "black_tower", DWELLING_UPGRADE7, Race::WRLK, {5000, 0, 0, 5,10, 0, 0 } }, - - { "habitat", DWELLING_MONSTER1, Race::WZRD, { 400, 0, 0, 0, 0, 0, 0 } }, - { "pen", DWELLING_MONSTER2, Race::WZRD, { 800, 0, 0, 0, 0, 0, 0 } }, - { "foundry", DWELLING_MONSTER3, Race::WZRD, {1500, 5, 0, 5, 0, 0, 0 } }, - { "upg_foundry", DWELLING_UPGRADE3, Race::WZRD, {1500, 0, 5, 0, 0, 0, 0 } }, - { "cliff_nest", DWELLING_MONSTER4, Race::WZRD, {3000, 5, 0, 0, 0, 0, 0 } }, - { "ivory_tower", DWELLING_MONSTER5, Race::WZRD, {3500, 5, 5, 5, 5, 5, 5 } }, - { "upg_ivory_tower", DWELLING_UPGRADE5, Race::WZRD, {4000, 5, 0, 5, 0, 0, 0 } }, - { "cloud_castle", DWELLING_MONSTER6, Race::WZRD, {12500,5, 0, 5, 0, 0,20 } }, - { "upg_cloud_castle", DWELLING_UPGRADE6, Race::WZRD, {12500,5, 0, 5, 0, 0,20 } }, - - { "excavation", DWELLING_MONSTER1, Race::NECR, { 400, 0, 0, 0, 0, 0, 0 } }, - { "graveyard", DWELLING_MONSTER2, Race::NECR, {1000, 0, 0, 0, 0, 0, 0 } }, - { "upg_graveyard", DWELLING_UPGRADE2, Race::NECR, {1000, 0, 0, 0, 0, 0, 0 } }, - { "pyramid", DWELLING_MONSTER3, Race::NECR, {1500, 0, 0,10, 0, 0, 0 } }, - { "upg_pyramid", DWELLING_UPGRADE3, Race::NECR, {1500, 0, 0, 5, 0, 0, 0 } }, - { "mansion", DWELLING_MONSTER4, Race::NECR, {3000,10, 0, 0, 0, 0, 0 } }, - { "upg_mansion", DWELLING_UPGRADE4, Race::NECR, {4000, 5, 0, 0, 0,10,10 } }, - { "mausoleum", DWELLING_MONSTER5, Race::NECR, {4000,10, 0, 0,10, 0, 0 } }, - { "upg_mausoleum", DWELLING_UPGRADE5, Race::NECR, {3000, 0, 0, 5, 0, 5, 0 } }, - { "laboratory", DWELLING_MONSTER6, Race::NECR, {10000,10,5,10, 5, 5, 5 } }, - - // end - { NULL, BUILD_NOTHING, Race::BOMG, { 0, 0, 0, 0, 0, 0, 0 } }, -}; - -void BuildingInfo::UpdateCosts(const std::string & spec) -{ -#ifdef WITH_XML - // parse buildings.xml - TiXmlDocument doc; - const TiXmlElement* xml_buildings = NULL; - buildstats_t* ptr = &_builds[0]; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_buildings = doc.FirstChildElement("buildings"))) - { - while(ptr->id1) - { - const TiXmlElement* xml_building = xml_buildings->FirstChildElement(ptr->id1); - - if(xml_building) - { - cost_t & cost = ptr->cost; - int value; - - xml_building->Attribute("gold", &value); cost.gold = value; - xml_building->Attribute("wood", &value); cost.wood = value; - xml_building->Attribute("mercury", &value); cost.mercury = value; - xml_building->Attribute("ore", &value); cost.ore = value; - xml_building->Attribute("sulfur", &value); cost.sulfur = value; - xml_building->Attribute("crystal", &value); cost.crystal = value; - xml_building->Attribute("gems", &value); cost.gems = value; - } - - ++ptr; - } - } - else - VERBOSE(spec << ": " << doc.ErrorDesc()); -#endif -} - -void BuildingInfo::GetCost(u32 build, u8 race, payment_t & payment) -{ - const buildstats_t* ptr = &_builds[0]; - - while(ptr->id1 && !(ptr->id2 == build && (!race || (race & ptr->race)))) ++ptr; - - payment.Reset(); - - if(ptr) - { - payment.gold = ptr->cost.gold; - payment.wood = ptr->cost.wood; - payment.mercury = ptr->cost.mercury; - payment.ore = ptr->cost.ore; - payment.sulfur = ptr->cost.sulfur; - payment.crystal = ptr->cost.crystal; - payment.gems = ptr->cost.gems; - } -} - -u8 GetIndexBuildingSprite(u32 build) -{ - switch(build) - { - case DWELLING_MONSTER1: return 19; - case DWELLING_MONSTER2: return 20; - case DWELLING_MONSTER3: return 21; - case DWELLING_MONSTER4: return 22; - case DWELLING_MONSTER5: return 23; - case DWELLING_MONSTER6: return 24; - case DWELLING_UPGRADE2: return 25; - case DWELLING_UPGRADE3: return 26; - case DWELLING_UPGRADE4: return 27; - case DWELLING_UPGRADE5: return 28; - case DWELLING_UPGRADE6: return 29; - case DWELLING_UPGRADE7: return 30; - case BUILD_MAGEGUILD1: - case BUILD_MAGEGUILD2: - case BUILD_MAGEGUILD3: - case BUILD_MAGEGUILD4: - case BUILD_MAGEGUILD5: return 0; - case BUILD_THIEVESGUILD:return 1; - case BUILD_TAVERN: return 2; - case BUILD_SHIPYARD: return 3; - case BUILD_WELL: return 4; - case BUILD_CASTLE: return 6; - case BUILD_STATUE: return 7; - case BUILD_LEFTTURRET: return 8; - case BUILD_RIGHTTURRET: return 9; - case BUILD_MARKETPLACE: return 10; - case BUILD_WEL2: return 11; - case BUILD_MOAT: return 12; - case BUILD_SPEC: return 13; - case BUILD_CAPTAIN: return 15; - default: break; - } - - return 0; -} - -BuildingInfo::BuildingInfo(const Castle & c, building_t b) : castle(c), building(b), area(0, 0, 135, 57), disable(false) -{ - if(IsDwelling()) building = castle.GetActualDwelling(b); - - building = castle.isBuild(b) ? castle.GetUpgradeBuilding(b) : b; - // check upgrade 7 - building = castle.isBuild(building) ? castle.GetUpgradeBuilding(building) : building; - - if(IsDwelling()) - { - description = _("The %{building} produces %{monster}."); - String::Replace(description, "%{building}", Castle::GetStringBuilding(building, castle.GetRace())); - std::string name = Monster(castle.GetRace(), building).GetMultiName(); - String::Lower(name); - String::Replace(description, "%{monster}", name); - } - else - description = Castle::GetDescriptionBuilding(building, castle.GetRace()); - - switch(building) - { - case BUILD_WELL: - String::Replace(description, "%{count}", Castle::GetGrownWell()); - break; - - case BUILD_WEL2: - String::Replace(description, "%{count}", Castle::GetGrownWel2()); - break; - - case BUILD_CASTLE: - case BUILD_STATUE: - case BUILD_SPEC: - { - const payment_t profit = ProfitConditions::FromBuilding(building, castle.GetRace()); - String::Replace(description, "%{count}", profit.gold); - break; - } - - default: break; - } - - // necr and tavern check - if(Race::NECR == castle.GetRace() && BUILD_TAVERN == building && !Settings::Get().PriceLoyaltyVersion()) - disable = true; - - if(b == BUILD_CAPTAIN) - { - ICN::icn_t icn = ICN::UNKNOWN; - switch(castle.GetRace()) - { - case Race::BARB: icn = ICN::CSTLCAPB; break; - case Race::KNGT: icn = ICN::CSTLCAPK; break; - case Race::NECR: icn = ICN::CSTLCAPN; break; - case Race::SORC: icn = ICN::CSTLCAPS; break; - case Race::WRLK: icn = ICN::CSTLCAPW; break; - case Race::WZRD: icn = ICN::CSTLCAPZ; break; - default: break; - } - const Sprite & sprite = AGG::GetICN(icn, (building & BUILD_CAPTAIN ? 1 : 0)); - area.w = sprite.w(); - area.h = sprite.h(); - } -} - -u32 BuildingInfo::operator() (void) const -{ - return building; -} - -void BuildingInfo::SetPos(s16 x, s16 y) -{ - area.x = x; - area.y = y; -} - -const Rect & BuildingInfo::GetArea(void) const -{ - return area; -} - -bool BuildingInfo::AllowBuy(void) const -{ - return castle.AllowBuyBuilding(building); -} - -bool BuildingInfo::IsDisable(void) const -{ - return disable; -} - -bool BuildingInfo::IsDwelling(void) const -{ - switch(building) - { - case DWELLING_MONSTER1: - case DWELLING_MONSTER2: - case DWELLING_MONSTER3: - case DWELLING_MONSTER4: - case DWELLING_MONSTER5: - case DWELLING_MONSTER6: - case DWELLING_UPGRADE2: - case DWELLING_UPGRADE3: - case DWELLING_UPGRADE4: - case DWELLING_UPGRADE5: - case DWELLING_UPGRADE6: - case DWELLING_UPGRADE7: - return true; - default: break; - } - return false; -} - -void BuildingInfo::RedrawCaptain(void) -{ - Display & display = Display::Get(); - - switch(castle.GetRace()) - { - case Race::BARB: display.Blit(AGG::GetICN(ICN::CSTLCAPB, (building & BUILD_CAPTAIN ? 1 : 0)), area.x, area.y); break; - case Race::KNGT: display.Blit(AGG::GetICN(ICN::CSTLCAPK, (building & BUILD_CAPTAIN ? 1 : 0)), area.x, area.y); break; - case Race::NECR: display.Blit(AGG::GetICN(ICN::CSTLCAPN, (building & BUILD_CAPTAIN ? 1 : 0)), area.x, area.y); break; - case Race::SORC: display.Blit(AGG::GetICN(ICN::CSTLCAPS, (building & BUILD_CAPTAIN ? 1 : 0)), area.x, area.y); break; - case Race::WRLK: display.Blit(AGG::GetICN(ICN::CSTLCAPW, (building & BUILD_CAPTAIN ? 1 : 0)), area.x, area.y); break; - case Race::WZRD: display.Blit(AGG::GetICN(ICN::CSTLCAPZ, (building & BUILD_CAPTAIN ? 1 : 0)), area.x, area.y); break; - default: break; - } - - const Sprite & sprite_allow = AGG::GetICN(ICN::TOWNWIND, 11); - const Sprite & sprite_deny = AGG::GetICN(ICN::TOWNWIND, 12); - const Sprite & sprite_money = AGG::GetICN(ICN::TOWNWIND, 13); - Point dst_pt; - - bool allow_buy = AllowBuy(); - - // indicator - dst_pt.x = area.x + 65; - dst_pt.y = area.y + 60; - if(castle.isBuild(building)) display.Blit(sprite_allow, dst_pt); - else - if(! allow_buy) - { - payment_t payment; - GetCost(building, castle.GetRace(), payment); - (1 == payment.GetValidItems() && payment.gold && castle.AllowBuild()) ? display.Blit(sprite_money, dst_pt) : display.Blit(sprite_deny, dst_pt); - } -} - -void BuildingInfo::Redraw(void) -{ - if(BUILD_CAPTAIN == building) - { - RedrawCaptain(); - return; - } - - u8 index = GetIndexBuildingSprite(building); - Display & display = Display::Get(); - - display.Blit(AGG::GetICN(ICN::BLDGXTRA, 0), area.x, area.y); - - if(disable) - { - display.FillRect(0, 0, 0, Rect(area.x + 1, area.y + 1, area.w, area.h)); - return; - } - - switch(castle.GetRace()) - { - case Race::BARB: display.Blit(AGG::GetICN(ICN::CSTLBARB, index), area.x + 1, area.y + 1); break; - case Race::KNGT: display.Blit(AGG::GetICN(ICN::CSTLKNGT, index), area.x + 1, area.y + 1); break; - case Race::NECR: display.Blit(AGG::GetICN(ICN::CSTLNECR, index), area.x + 1, area.y + 1); break; - case Race::SORC: display.Blit(AGG::GetICN(ICN::CSTLSORC, index), area.x + 1, area.y + 1); break; - case Race::WRLK: display.Blit(AGG::GetICN(ICN::CSTLWRLK, index), area.x + 1, area.y + 1); break; - case Race::WZRD: display.Blit(AGG::GetICN(ICN::CSTLWZRD, index), area.x + 1, area.y + 1); break; - default: break; - } - - const Sprite & sprite_allow = AGG::GetICN(ICN::TOWNWIND, 11); - const Sprite & sprite_deny = AGG::GetICN(ICN::TOWNWIND, 12); - const Sprite & sprite_money = AGG::GetICN(ICN::TOWNWIND, 13); - Point dst_pt; - - bool allow_buy = AllowBuy(); - - // indicator - dst_pt.x = area.x + 115; - dst_pt.y = area.y + 40; - if(castle.isBuild(building)) display.Blit(sprite_allow, dst_pt); - else - if(! allow_buy) - { - payment_t payment; - GetCost(building, castle.GetRace(), payment); - (1 == payment.GetValidItems() && payment.gold && castle.AllowBuild()) ? display.Blit(sprite_money, dst_pt) : display.Blit(sprite_deny, dst_pt); - } - - // status bar - if(!castle.isBuild(building)) - { - dst_pt.x = area.x; - dst_pt.y = area.y + 58; - display.Blit(AGG::GetICN(ICN::CASLXTRA, allow_buy ? 1 : 2), dst_pt); - } - - // name - Text text(Castle::GetStringBuilding(building, castle.GetRace()), Font::SMALL); - dst_pt.x = area.x + 68 - text.w() / 2; - dst_pt.y = area.y + 59; - text.Blit(dst_pt); -} - - -const char* BuildingInfo::GetName(void) const -{ - return Castle::GetStringBuilding(building, castle.GetRace()); -} - -const std::string & BuildingInfo::GetDescription(void) const -{ - return description; -} - -bool BuildingInfo::QueueEventProcessing(void) -{ - if(disable) return false; - - LocalEvent & le = LocalEvent::Get(); - if(le.MouseClickLeft(area)) - { - if(!castle.isBuild(BUILD_CASTLE)) - Dialog::Message("", _("For this action it is necessary first to build a castle."), Font::BIG, Dialog::OK); - else - if(castle.isBuild(building)) - Dialog::Message(GetName(), GetDescription(), Font::BIG, Dialog::OK); - else - return DialogBuyBuilding(true); - } - else - if(le.MousePressRight(area)) - { - if(castle.isBuild(building)) - Dialog::Message(GetName(), GetDescription(), Font::BIG); - else - DialogBuyBuilding(false); - } - return false; -} - -bool BuildingInfo::DialogBuyBuilding(bool buttons) const -{ - Display & display = Display::Get(); - - const ICN::icn_t system = (Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM); - - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - - TextBox box1(description, Font::BIG, BOXAREA_WIDTH); - - // prepare requires build string - std::string str; - std::bitset<32> requires(castle.GetBuildingRequires(building)); - if(requires.any()) - { - u8 count = 0; - for(u8 pos = 0; pos < requires.size(); ++pos) - { - if(requires.test(pos)) - { - u32 value = 1; - value <<= pos; - - ++count; - - if(! castle.isBuild(value)) - { - str += Castle::GetStringBuilding(static_cast(value), castle.GetRace()); - if(count < requires.count()) str += ", "; - } - } - } - } - - bool requires_true = str.size(); - Text requires_text(_("Requires:"), Font::BIG); - TextBox box2(str, Font::BIG, BOXAREA_WIDTH); - - Resource::BoxSprite rbs(PaymentConditions::BuyBuilding(castle.GetRace(), building), BOXAREA_WIDTH); - - const Sprite & window_icons = AGG::GetICN(ICN::BLDGXTRA, 0); - const u8 space = Settings::Get().QVGA() ? 5 : 10; - Dialog::Box box(space + window_icons.h() + space + box1.h() + space + (requires_true ? requires_text.h() + box2.h() + space : 0) + rbs.GetArea().h, buttons); - const Rect & box_rt = box.GetArea(); - ICN::icn_t cstl_icn = ICN::UNKNOWN; - - switch(castle.GetRace()) - { - case Race::KNGT: cstl_icn = ICN::CSTLKNGT; break; - case Race::BARB: cstl_icn = ICN::CSTLBARB; break; - case Race::SORC: cstl_icn = ICN::CSTLSORC; break; - case Race::WRLK: cstl_icn = ICN::CSTLWRLK; break; - case Race::WZRD: cstl_icn = ICN::CSTLWZRD; break; - case Race::NECR: cstl_icn = ICN::CSTLNECR; break; - default: return Dialog::CANCEL; - } - - LocalEvent & le = LocalEvent::Get(); - - Point dst_pt; - - dst_pt.x = box_rt.x; - dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h(); - Button button1(dst_pt, system, 1, 2); - - dst_pt.x = box_rt.x + box_rt.w - AGG::GetICN(system, 3).w(); - dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 3).h(); - Button button2(dst_pt, system, 3, 4); - - dst_pt.x = box_rt.x + (box_rt.w - window_icons.w()) / 2; - dst_pt.y = box_rt.y + space; - display.Blit(window_icons, dst_pt); - - const Sprite & building_icons = AGG::GetICN(cstl_icn, GetIndexBuildingSprite(building)); - dst_pt.x = box_rt.x + (box_rt.w - building_icons.w()) / 2; - dst_pt.y += 1; - display.Blit(building_icons, dst_pt); - - Text text(GetName(), Font::SMALL); - dst_pt.x = box_rt.x + (box_rt.w - text.w()) / 2; - dst_pt.y += 57; - text.Blit(dst_pt); - - dst_pt.x = box_rt.x; - dst_pt.y = box_rt.y + space + window_icons.h() + space; - box1.Blit(dst_pt); - - dst_pt.y += box1.h() + space; - if(requires_true) - { - dst_pt.x = box_rt.x + (box_rt.w - requires_text.w()) / 2; - requires_text.Blit(dst_pt); - - dst_pt.x = box_rt.x; - dst_pt.y += requires_text.h(); - box2.Blit(dst_pt); - - dst_pt.y += box2.h() + space; - } - - rbs.SetPos(dst_pt.x, dst_pt.y); - rbs.Redraw(); - - if(buttons) - { - if(!AllowBuy()) button1.SetDisable(true); - - button1.Draw(); - button2.Draw(); - } - - cursor.Show(); - display.Flip(); - - // message loop - while(le.HandleEvents()) - { - if(!buttons && !le.MousePressRight()) break; - - le.MousePressLeft(button1) ? button1.PressDraw() : button1.ReleaseDraw(); - le.MousePressLeft(button2) ? button2.PressDraw() : button2.ReleaseDraw(); - - if(button1.isEnable() && - (Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || - le.MouseClickLeft(button1))) return true; - - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || - le.MouseClickLeft(button2)) break; - } - - return false; -} - -void BuildingInfo::SetStatusMessage(StatusBar & bar) const -{ - std::string str; - const char* name = GetName(); - - if(castle.isBuild(building)) - { - str = _("%{name} is already built"); - String::Replace(str, "%{name}", name); - } - else - { - const PaymentConditions::BuyBuilding paymentBuild(castle.GetRace(), building); - - if(!castle.AllowBuild()) - { - str = _("Cannot build. Already built here this turn."); - } - else - if(castle.AllowBuild() && ! world.GetMyKingdom().AllowPayment(paymentBuild)) - { - str = _("Cannot afford %{name}"); - String::Replace(str, "%{name}", name); - } - else - if(BUILD_SHIPYARD == building && !castle.HaveNearlySea()) - { - str = _("Cannot build %{name} because castle is too far from water."); - String::Replace(str, "%{name}", name); - } - else - if(!castle.AllowBuyBuilding(building)) - { - str = _("Cannot build %{name}"); - String::Replace(str, "%{name}", name); - } - else - { - str = _("Build %{name}"); - String::Replace(str, "%{name}", name); - } - } - - bar.ShowMessage(str); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/buildinginfo.h b/project/jni/application/fheroes2/src/fheroes2/castle/buildinginfo.h deleted file mode 100644 index 0388f040b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/buildinginfo.h +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BUILDINGINFO_H -#define H2BUILDINGINFO_H - -#include "castle.h" - -class StatusBar; - -class BuildingInfo -{ -public: - BuildingInfo(const Castle &, building_t); - - u32 operator() (void) const; - - void SetPos(s16, s16); - - const Rect & GetArea(void) const; - const char* GetName(void) const; - const std::string & GetDescription(void) const; - void SetStatusMessage(StatusBar &) const; - - bool AllowBuy(void) const; - bool IsDwelling(void) const; - bool IsDisable(void) const; - - void Redraw(void); - bool QueueEventProcessing(void); - bool DialogBuyBuilding(bool buttons) const; - - static void UpdateCosts(const std::string &); - static void GetCost(u32, u8, payment_t &); - -private: - void RedrawCaptain(void); - - const Castle & castle; - u32 building; - std::string description; - Rect area; - bool disable; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/captain.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/captain.cpp deleted file mode 100644 index 5cc0d70ac..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/captain.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "castle.h" -#include "luck.h" -#include "morale.h" -#include "captain.h" -#include "settings.h" - -Captain::Captain(const Castle & c) : home(c) -{ -} - -void Captain::LoadDefaults(void) -{ - if(Race::ALL & home.GetRace()) - { - u8 book, spell; - Skill::Primary::LoadDefaults(home.GetRace(), *this, book, spell); - SpellBookActivate(); - if(home.GetLevelMageGuild()) home.GetMageGuild().EducateHero(*this); - } -} - -bool Captain::isValid(void) const -{ - return home.isBuild(BUILD_CAPTAIN); -} - -u8 Captain::GetAttack(void) const -{ - return attack + GetAttackModificator(NULL); -} - -u8 Captain::GetDefense(void) const -{ - return defense + GetDefenseModificator(NULL); -} - -u8 Captain::GetPower(void) const -{ - return power + GetPowerModificator(NULL); -} - -u8 Captain::GetKnowledge(void) const -{ - return knowledge + GetKnowledgeModificator(NULL); -} - -s8 Captain::GetMorale(void) const -{ - s8 result = Morale::NORMAL; - - // global modificator - result += GetMoraleModificator(false, NULL); - - // result - if(result < Morale::AWFUL) return Morale::TREASON; - else - if(result < Morale::POOR) return Morale::AWFUL; - else - if(result < Morale::NORMAL) return Morale::POOR; - else - if(result < Morale::GOOD) return Morale::NORMAL; - else - if(result < Morale::GREAT) return Morale::GOOD; - else - if(result < Morale::BLOOD) return Morale::GREAT; - - return Morale::BLOOD; -} - -s8 Captain::GetLuck(void) const -{ - s8 result = Luck::NORMAL; - - // global modificator - result += GetLuckModificator(false, NULL); - - // result - if(result < Luck::AWFUL) return Luck::CURSED; - else - if(result < Luck::BAD) return Luck::AWFUL; - else - if(result < Luck::NORMAL) return Luck::BAD; - else - if(result < Luck::GOOD) return Luck::NORMAL; - else - if(result < Luck::GREAT) return Luck::GOOD; - else - if(result < Luck::IRISH) return Luck::GREAT; - - return Luck::IRISH; -} - -Race::race_t Captain::GetRace(void) const -{ - return home.GetRace(); -} - -Color::color_t Captain::GetColor(void) const -{ - return home.GetColor(); -} - -const std::string & Captain::GetName(void) const -{ - return home.GetName(); -} - -u8 Captain::GetType(void) const -{ - return Skill::Primary::CAPTAIN; -} - -u8 Captain::GetLevelSkill(const Skill::Secondary::skill_t skill) const -{ - return 0; -} - -u8 Captain::GetSecondaryValues(const Skill::Secondary::skill_t skill) const -{ - return 0; -} - -const Army::army_t & Captain::GetArmy(void) const -{ - return home.GetArmy(); -} - -Army::army_t & Captain::GetArmy(void) -{ - return const_cast(home.GetArmy()); -} - -u16 Captain::GetMaxSpellPoints(void) const -{ - return knowledge * 10; -} - -u8 Captain::GetControl(void) const -{ - return home.GetControl(); -} - -u16 Captain::GetIndex(void) const -{ - return home.GetIndex(); -} - -void Captain::PreBattleAction(void) -{ - SetSpellPoints(GetMaxSpellPoints()); -} - -const Castle* Captain::inCastle(void) const -{ - return &home; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/captain.h b/project/jni/application/fheroes2/src/fheroes2/castle/captain.h deleted file mode 100644 index 1c3d7f890..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/captain.h +++ /dev/null @@ -1,66 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2CAPTAIN_H -#define H2CAPTAIN_H - -#include "gamedefs.h" -#include "heroes_base.h" - -class Castle; - -class Captain : public HeroBase -{ - public: - Captain(const Castle &); - - void LoadDefaults(void); - bool isValid(void) const; - u8 GetAttack(void) const; - u8 GetDefense(void) const; - u8 GetPower(void) const; - u8 GetKnowledge(void) const; - s8 GetMorale(void) const; - s8 GetLuck(void) const; - Race::race_t GetRace(void) const; - Color::color_t GetColor(void) const; - const std::string & GetName(void) const; - u8 GetType(void) const; - u8 GetControl(void) const; - u16 GetIndex(void) const; - - const Castle* inCastle(void) const; - - u8 GetLevelSkill(const Skill::Secondary::skill_t) const; - u8 GetSecondaryValues(const Skill::Secondary::skill_t skill) const; - - const Army::army_t & GetArmy(void) const; - Army::army_t & GetArmy(void); - - u16 GetMaxSpellPoints(void) const; - - void PreBattleAction(void); - - private: - const Castle & home; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/castle.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/castle.cpp deleted file mode 100644 index b9e3e77d6..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/castle.cpp +++ /dev/null @@ -1,1730 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "difficulty.h" -#include "settings.h" -#include "payment.h" -#include "world.h" -#include "luck.h" -#include "morale.h" -#include "kingdom.h" -#include "maps_tiles.h" -#include "castle.h" -#include "localclient.h" - -u8 Castle::grown_well(2); -u8 Castle::grown_wel2(8); - -Castle::Castle() : captain(*this), mageguild(*this), army(&captain), castle_heroes(NULL) -{ -} - -Castle::Castle(s16 cx, s16 cy, const Race::race_t rc) : Position(Point(cx, cy)), race(rc), captain(*this), - color(Color::GRAY), building(0), mageguild(*this), - army(NULL), castle_heroes(NULL) -{ - std::fill(dwelling, dwelling + CASTLEMAXMONSTER, 0); - SetModes(ALLOWBUILD); - - mageguild.Builds(); -} - -void Castle::LoadFromMP2(const void *ptr) -{ - const u8 *ptr8 = static_cast(ptr); - u16 byte16 = 0; - - switch(*ptr8) - { - case 0x00: color = Color::BLUE; break; - case 0x01: color = Color::GREEN; break; - case 0x02: color = Color::RED; break; - case 0x03: color = Color::YELLOW; break; - case 0x04: color = Color::ORANGE; break; - case 0x05: color = Color::PURPLE; break; - default: color = Color::GRAY; break; - } - ++ptr8; - - // custom building - if(*ptr8) - { - ++ptr8; - - // building - byte16 = ReadLE16(ptr8); - if(0x0002 & byte16) building |= BUILD_THIEVESGUILD; - if(0x0004 & byte16) building |= BUILD_TAVERN; - if(0x0008 & byte16) building |= BUILD_SHIPYARD; - if(0x0010 & byte16) building |= BUILD_WELL; - if(0x0080 & byte16) building |= BUILD_STATUE; - if(0x0100 & byte16) building |= BUILD_LEFTTURRET; - if(0x0200 & byte16) building |= BUILD_RIGHTTURRET; - if(0x0400 & byte16) building |= BUILD_MARKETPLACE; - if(0x1000 & byte16) building |= BUILD_MOAT; - if(0x0800 & byte16) building |= BUILD_WEL2; - if(0x2000 & byte16) building |= BUILD_SPEC; - ++ptr8; - ++ptr8; - - // dwelling - byte16 = ReadLE16(ptr8); - if(0x0008 & byte16) building |= DWELLING_MONSTER1; - if(0x0010 & byte16) building |= DWELLING_MONSTER2; - if(0x0020 & byte16) building |= DWELLING_MONSTER3; - if(0x0040 & byte16) building |= DWELLING_MONSTER4; - if(0x0080 & byte16) building |= DWELLING_MONSTER5; - if(0x0100 & byte16) building |= DWELLING_MONSTER6; - if(0x0200 & byte16) building |= DWELLING_UPGRADE2; - if(0x0400 & byte16) building |= DWELLING_UPGRADE3; - if(0x0800 & byte16) building |= DWELLING_UPGRADE4; - if(0x1000 & byte16) building |= DWELLING_UPGRADE5; - if(0x2000 & byte16) building |= DWELLING_UPGRADE6; - ++ptr8; - ++ptr8; - - - // magic tower - if(0 < *ptr8) building |= BUILD_MAGEGUILD1; - if(1 < *ptr8) building |= BUILD_MAGEGUILD2; - if(2 < *ptr8) building |= BUILD_MAGEGUILD3; - if(3 < *ptr8) building |= BUILD_MAGEGUILD4; - if(4 < *ptr8) building |= BUILD_MAGEGUILD5; - ++ptr8; - } - else - { - ptr8 += 6; - - // default building - building |= DWELLING_MONSTER1; - u8 dwelling2 = 0; - switch(Settings::Get().GameDifficulty()) - { - case Difficulty::EASY: dwelling2 = 75; break; - case Difficulty::NORMAL: dwelling2 = 50; break; - case Difficulty::HARD: dwelling2 = 25; break; - case Difficulty::EXPERT: dwelling2 = 10; break; - default: break; - } - if(dwelling2 && dwelling2 >= Rand::Get(1, 100)) building |= DWELLING_MONSTER2; - } - - // custom troops - bool custom_troops = *ptr8; - if(custom_troops) - { - ++ptr8; - - // monster1 - army.At(0).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // monster2 - army.At(1).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // monster3 - army.At(2).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // monster4 - army.At(3).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // monster5 - army.At(4).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // count1 - byte16 = ReadLE16(ptr8); - army.At(0).SetCount(byte16); - ++ptr8; - ++ptr8; - - // count2 - byte16 = ReadLE16(ptr8); - army.At(1).SetCount(byte16); - ++ptr8; - ++ptr8; - - // count3 - byte16 = ReadLE16(ptr8); - army.At(2).SetCount(byte16); - ++ptr8; - ++ptr8; - - // count4 - byte16 = ReadLE16(ptr8); - army.At(3).SetCount(byte16); - ++ptr8; - ++ptr8; - - // count5 - byte16 = ReadLE16(ptr8); - army.At(4).SetCount(byte16); - ++ptr8; - ++ptr8; - } - else - { - ptr8 += 16; - } - - // captain - if(*ptr8) building |= BUILD_CAPTAIN; - ++ptr8; - - // custom name - ++ptr8; - name = std::string(_(reinterpret_cast(ptr8))); - ptr8 += 13; - - // race - const Race::race_t kingdom_race = Settings::Get().KingdomRace(color); - switch(*ptr8) - { - case 0x00: race = Race::KNGT; break; - case 0x01: race = Race::BARB; break; - case 0x02: race = Race::SORC; break; - case 0x03: race = Race::WRLK; break; - case 0x04: race = Race::WZRD; break; - case 0x05: race = Race::NECR; break; - default: race = (Color::GRAY != color && (Race::ALL & kingdom_race) ? kingdom_race : Race::Rand()); break; - } - ++ptr8; - - // castle - if(*ptr8) building |= BUILD_CASTLE; - ++ptr8; - - // allow upgrade to castle (0 - true, 1 - false) - (*ptr8 ? ResetModes(ALLOWCASTLE) : SetModes(ALLOWCASTLE)); - ++ptr8; - - // unknown 29 byte - // - - // dwelling pack - if(building & DWELLING_MONSTER1) dwelling[0] = Monster(race, DWELLING_MONSTER1).GetGrown(); - if(building & DWELLING_MONSTER2) dwelling[1] = Monster(race, DWELLING_MONSTER2).GetGrown(); - if(building & DWELLING_UPGRADE2) dwelling[1] = Monster(race, DWELLING_UPGRADE2).GetGrown(); - if(building & DWELLING_MONSTER3) dwelling[2] = Monster(race, DWELLING_MONSTER3).GetGrown(); - if(building & DWELLING_UPGRADE3) dwelling[2] = Monster(race, DWELLING_UPGRADE3).GetGrown(); - if(building & DWELLING_MONSTER4) dwelling[3] = Monster(race, DWELLING_MONSTER4).GetGrown(); - if(building & DWELLING_UPGRADE4) dwelling[3] = Monster(race, DWELLING_UPGRADE4).GetGrown(); - if(building & DWELLING_MONSTER5) dwelling[4] = Monster(race, DWELLING_MONSTER5).GetGrown(); - if(building & DWELLING_UPGRADE5) dwelling[4] = Monster(race, DWELLING_UPGRADE5).GetGrown(); - if(building & DWELLING_MONSTER6) dwelling[5] = Monster(race, DWELLING_MONSTER6).GetGrown(); - if(building & DWELLING_UPGRADE6) dwelling[5] = Monster(race, DWELLING_UPGRADE6).GetGrown(); - if(building & DWELLING_UPGRADE7) dwelling[5] = Monster(race, DWELLING_UPGRADE7).GetGrown(); - - // MageGuild - mageguild.Builds(); - if(captain.isValid()) mageguild.EducateHero(captain); - - // fix upgrade dwelling dependend from race - switch(race) - { - case Race::BARB: building &= ~(DWELLING_UPGRADE3 | DWELLING_UPGRADE6); break; - case Race::SORC: building &= ~(DWELLING_UPGRADE5 | DWELLING_UPGRADE6); break; - case Race::WRLK: building &= ~(DWELLING_UPGRADE2 | DWELLING_UPGRADE3 | DWELLING_UPGRADE5); break; - case Race::WZRD: building &= ~(DWELLING_UPGRADE2 | DWELLING_UPGRADE4); break; - case Race::NECR: building &= ~(DWELLING_UPGRADE6); break; - default: break; - } - - // fix captain - if(building & BUILD_CAPTAIN) - { - captain.LoadDefaults(); - army.SetCommander(&captain); - } - else - army.SetColor(color); - - // AI troops auto pack - if(!custom_troops && Game::AI == GetControl()) - AIJoinRNDArmy(); - - // fix shipyard - if(!HaveNearlySea()) building &= ~(BUILD_SHIPYARD); - - // remove tavern from necromancer castle - if(Race::NECR == race && !Settings::Get().PriceLoyaltyVersion()) - building &= ~BUILD_TAVERN; - - // end - DEBUG(DBG_GAME , DBG_INFO, "Castle::LoadFromMP2: " << (building & BUILD_CASTLE ? "castle" : "town") << ": " << name << ", color: " << Color::String(color) << ", race: " << Race::String(race)); -} - -u32 Castle::CountBuildings(void) const -{ - std::bitset<32> requires(building & (BUILD_THIEVESGUILD | BUILD_TAVERN | BUILD_SHIPYARD | BUILD_WELL | - BUILD_STATUE | BUILD_LEFTTURRET | BUILD_RIGHTTURRET | - BUILD_MARKETPLACE | BUILD_WEL2 | BUILD_MOAT | BUILD_SPEC | - BUILD_CAPTAIN | BUILD_CASTLE | BUILD_MAGEGUILD1 | DWELLING_MONSTER1 | - DWELLING_MONSTER2 | DWELLING_MONSTER3 | DWELLING_MONSTER4 | - DWELLING_MONSTER5 | DWELLING_MONSTER6)); - - return requires.count(); -} - -bool Castle::ContainCoord(const u16 ax, const u16 ay) const -{ - const Point & mp = GetCenter(); - return ((mp.x == ax && mp.y - 3 == ay) || (ax >= mp.x - 2 && ax <= mp.x + 2 && ay >= mp.y - 2 && ay <= mp.y + 1)); -} - -void Castle::ActionNewDay(void) -{ - castle_heroes = GetHeroes(); - - // for learns new spells need 1 day - if(castle_heroes && - GetLevelMageGuild()) mageguild.EducateHero(*castle_heroes); - - SetModes(ALLOWBUILD); -} - -void Castle::ActionNewWeek(void) -{ - u8 well = building & BUILD_WELL ? grown_well : 0; - u8 wel2 = building & BUILD_WEL2 ? grown_wel2 : 0; - - // dw 1 - if(building & DWELLING_MONSTER1) dwelling[0] += Monster(race, DWELLING_MONSTER1).GetGrown() + well + wel2; - // dw 2 - if(building & DWELLING_UPGRADE2) dwelling[1] += Monster(race, DWELLING_UPGRADE2).GetGrown() + well; - else - if(building & DWELLING_MONSTER2) dwelling[1] += Monster(race, DWELLING_MONSTER2).GetGrown() + well; - // dw 3 - if(building & DWELLING_UPGRADE3) dwelling[2] += Monster(race, DWELLING_UPGRADE3).GetGrown() + well; - else - if(building & DWELLING_MONSTER3) dwelling[2] += Monster(race, DWELLING_MONSTER3).GetGrown() + well; - // dw 4 - if(building & DWELLING_UPGRADE4) dwelling[3] += Monster(race, DWELLING_UPGRADE4).GetGrown() + well; - else - if(building & DWELLING_MONSTER4) dwelling[3] += Monster(race, DWELLING_MONSTER4).GetGrown() + well; - // dw 5 - if(building & DWELLING_UPGRADE5) dwelling[4] += Monster(race, DWELLING_UPGRADE5).GetGrown() + well; - else - if(building & DWELLING_MONSTER5) dwelling[4] += Monster(race, DWELLING_MONSTER5).GetGrown() + well; - // dw 6 - if(building & DWELLING_UPGRADE7) dwelling[5] += Monster(race, DWELLING_UPGRADE7).GetGrown() + well; - else - if(building & DWELLING_UPGRADE6) dwelling[5] += Monster(race, DWELLING_UPGRADE6).GetGrown() + well; - else - if(building & DWELLING_MONSTER6) dwelling[5] += Monster(race, DWELLING_MONSTER6).GetGrown() + well; -} - -void Castle::ActionNewMonth(void) -{ - if(world.GetWeekType() == Week::PLAGUE) - { - for(u8 ii = 0; ii < CASTLEMAXMONSTER; ++ii) if(dwelling[ii]) dwelling[ii] /= 2; - } -} - -// change castle color -void Castle::ChangeColor(Color::color_t cl) -{ - color = cl; - - // fix army - if(!isBuild(BUILD_CAPTAIN)) - army.SetColor(color); -} - -// return mage guild level -u8 Castle::GetLevelMageGuild(void) const -{ - if(building & BUILD_MAGEGUILD5) return 5; - else - if(building & BUILD_MAGEGUILD4) return 4; - else - if(building & BUILD_MAGEGUILD3) return 3; - else - if(building & BUILD_MAGEGUILD2) return 2; - else - if(building & BUILD_MAGEGUILD1) return 1; - - return 0; -} - -const MageGuild & Castle::GetMageGuild(void) const -{ - return mageguild; -} - -const char* Castle::GetStringBuilding(u32 build, Race::race_t race) -{ - const char* str_build[] = { _("Thieves' Guild"), _("Tavern"), _("Shipyard"), _("Well"), _("Statue"), _("Left Turret"), - _("Right Turret"), _("Marketplace"), _("Moat"), _("Castle"), _("Tent"), _("Captain's Quarters"), _("Mage Guild, Level 1"), - _("Mage Guild, Level 2"), _("Mage Guild, Level 3"), _("Mage Guild, Level 4"), _("Mage Guild, Level 5"), "Unknown" }; - - const char* str_wel2[] = { _("Farm"), _("Garbage Heap"), _("Crystal Garden"), _("Waterfall"), _("Orchard"), _("Skull Pile") }; - - const char* str_spec[] = { _("Fortifications"), _("Coliseum"), _("Rainbow"), _("Dungeon"), _("Library"), _("Storm") }; - - const char* str_dwelling[] = { - _("Thatched Hut"), _("Hut"), _("Treehouse"), _("Cave"), _("Habitat"), _("Excavation"), - _("Archery Range"), _("Stick Hut"), _("Cottage"), _("Crypt"), _("Pen"), _("Graveyard"), - _("Blacksmith"), _("Den"), _("Archery Range"), _("Nest"), _("Foundry"), _("Pyramid"), - _("Armory"), _("Adobe"), _("Stonehenge"), _("Maze"), _("Cliff Nest"), _("Mansion"), - _("Jousting Arena"), _("Bridge"), _("Fenced Meadow"), _("Swamp"), _("Ivory Tower"), _("Mausoleum"), - _("Cathedral"), _("Pyramid"), _("Red Tower"), _("Green Tower"), _("Cloud Castle"), _("Laboratory") }; - - const char* str_upgrade[] = { - _("Upg. Archery Range"), _("Upg. Stick Hut"), _("Upg. Cottage"), _("Crypt"), _("Pen"), _("Upg. Graveyard"), - _("Upg. Blacksmith"), _("Den"), _("Upg. Archery Range"), _("Nest"), _("Upg. Foundry"), _("Upg. Pyramid"), - _("Upg. Armory"), _("Upg. Adobe"), _("Upg. Stonehenge"), _("Upg. Maze"), _("Cliff Nest"), _("Upg. Mansion"), - _("Upg. Jousting Arena"), _("Upg. Bridge"), _("Fenced Meadow"), _("Swamp"), _("Upg. Ivory Tower"), _("Upg. Mausoleum"), - _("Upg. Cathedral"), _("Pyramid"), _("Red Tower"), _("Red Tower"), _("Upg. Cloud Castle"), _("Laboratory"), - "", "", "", _("Black Tower"), "", "" }; - - const char* shrine = _("Shrine"); - - u8 offset = 0; - - switch(race) - { - case Race::KNGT: offset = 0; break; - case Race::BARB: offset = 1; break; - case Race::SORC: offset = 2; break; - case Race::WRLK: offset = 3; break; - case Race::WZRD: offset = 4; break; - case Race::NECR: offset = 5; break; - default: break; - } - - if(Settings::Get().PriceLoyaltyVersion() && race == Race::NECR && build == BUILD_TAVERN) return shrine; - - switch(build) - { - case BUILD_THIEVESGUILD:return str_build[0]; - case BUILD_TAVERN: return str_build[1]; - case BUILD_SHIPYARD: return str_build[2]; - case BUILD_WELL: return str_build[3]; - case BUILD_STATUE: return str_build[4]; - case BUILD_LEFTTURRET: return str_build[5]; - case BUILD_RIGHTTURRET: return str_build[6]; - case BUILD_MARKETPLACE: return str_build[7]; - case BUILD_MOAT: return str_build[8]; - case BUILD_CASTLE: return str_build[9]; - case BUILD_TENT: return str_build[10]; - case BUILD_CAPTAIN: return str_build[11]; - case BUILD_MAGEGUILD1: return str_build[12]; - case BUILD_MAGEGUILD2: return str_build[13]; - case BUILD_MAGEGUILD3: return str_build[14]; - case BUILD_MAGEGUILD4: return str_build[15]; - case BUILD_MAGEGUILD5: return str_build[16]; - - case BUILD_SPEC: return str_spec[offset]; - case BUILD_WEL2: return str_wel2[offset]; - - case DWELLING_MONSTER1: return str_dwelling[offset]; - case DWELLING_MONSTER2: return str_dwelling[6 + offset]; - case DWELLING_MONSTER3: return str_dwelling[12 + offset]; - case DWELLING_MONSTER4: return str_dwelling[18 + offset]; - case DWELLING_MONSTER5: return str_dwelling[24 + offset]; - case DWELLING_MONSTER6: return str_dwelling[30 + offset]; - - case DWELLING_UPGRADE2: return str_upgrade[offset]; - case DWELLING_UPGRADE3: return str_upgrade[6 + offset]; - case DWELLING_UPGRADE4: return str_upgrade[12 + offset]; - case DWELLING_UPGRADE5: return str_upgrade[18 + offset]; - case DWELLING_UPGRADE6: return str_upgrade[24 + offset]; - case DWELLING_UPGRADE7: return str_upgrade[30 + offset]; - - default: break; - } - - return str_build[17]; -} - -const char* Castle::GetDescriptionBuilding(u32 build, Race::race_t race) -{ - const char* desc_build[] = { - _("The Thieves' Guild provides information on enemy players. Thieves' Guilds can also provide scouting information on enemy towns."), - _("The Tavern increases morale for troops defending the castle."), - _("The Shipyard allows ships to be built."), - _("The Well increases the growth rate of all dwellings by %{count} creatures per week."), - _("The Statue increases your town's income by %{count} per day."), - _("The Left Turret provides extra firepower during castle combat."), - _("The Right Turret provides extra firepower during castle combat."), - _("The Marketplace can be used to convert one type of resource into another. The more marketplaces you control, the better the exchange rate."), - _("The Moat slows attacking units. Any unit entering the moat must end its turn there and becomes more vulnerable to attack."), - _("The Castle improves town defense and increases income to %{count} gold per day."), - _("The Tent provides workers to build a castle, provided the materials and the gold are available."), - _("The Captain's Quarters provides a captain to assist in the castle's defense when no hero is present."), - _("The Mage Guild allows heroes to learn spells and replenish their spell points."), "Unknown" }; - - const char* desc_wel2[] = { - _("The Farm increases production of Peasants by %{count} per week."), - _("The Garbage Heap increases production of Goblins by %{count} per week."), - _("The Crystal Garden increases production of Sprites by %{count} per week."), - _("The Waterfall increases production of Centaurs by %{count} per week."), - _("The Orchard increases production of Halflings by %{count} per week."), - _("The Skull Pile increases production of Skeletons by %{count} per week.") }; - - const char* desc_spec[] = { - _("The Fortifications increase the toughness of the walls, increasing the number of turns it takes to knock them down."), - _("The Coliseum provides inspiring spectacles to defending troops, raising their morale by two during combat."), - _("The Rainbow increases the luck of the defending units by two."), - _("The Dungeon increases the income of the town by %{count} / day."), - _("The Library increases the number of spells in the Guild by one for each level of the guild."), - _("The Storm adds +2 to the power of spells of a defending spell caster.") }; - - const char* shrine_descr = _("The Shrine increases the necromancy skill of all your necromancers by 10 percent."); - - u8 offset = 0; - - switch(race) - { - case Race::KNGT: offset = 0; break; - case Race::BARB: offset = 1; break; - case Race::SORC: offset = 2; break; - case Race::WRLK: offset = 3; break; - case Race::WZRD: offset = 4; break; - case Race::NECR: offset = 5; break; - default: break; - } - - if(Settings::Get().PriceLoyaltyVersion() && race == Race::NECR && build == BUILD_TAVERN) return shrine_descr; - - switch(build) - { - case BUILD_THIEVESGUILD:return desc_build[0]; - case BUILD_TAVERN: return desc_build[1]; - case BUILD_SHIPYARD: return desc_build[2]; - case BUILD_WELL: return desc_build[3]; - case BUILD_STATUE: return desc_build[4]; - case BUILD_LEFTTURRET: return desc_build[5]; - case BUILD_RIGHTTURRET: return desc_build[6]; - case BUILD_MARKETPLACE: return desc_build[7]; - case BUILD_MOAT: return desc_build[8]; - case BUILD_CASTLE: return desc_build[9]; - case BUILD_TENT: return desc_build[10]; - case BUILD_CAPTAIN: return desc_build[11]; - case BUILD_MAGEGUILD1: - case BUILD_MAGEGUILD2: - case BUILD_MAGEGUILD3: - case BUILD_MAGEGUILD4: - case BUILD_MAGEGUILD5: return desc_build[12]; - - case BUILD_SPEC: return desc_spec[offset]; - case BUILD_WEL2: return desc_wel2[offset]; - - default: break; - } - - return desc_build[13]; -} - -bool Castle::AllowBuyHero(const Heroes & hero) -{ - return !GetHeroes() && world.GetKingdom(color).AllowRecruitHero(true, hero.GetLevel()); -} - -bool Castle::RecruitHero(Heroes* hero) -{ - if(!hero || !AllowBuyHero(*hero) || !hero->Recruit(*this)) return false; - - world.GetKingdom(color).OddFundsResource(PaymentConditions::RecruitHero(hero->GetLevel())); - castle_heroes = hero; - - // update spell book - if(GetLevelMageGuild()) mageguild.EducateHero(*castle_heroes); - - DEBUG(DBG_GAME , DBG_INFO, "Castle::RecruitHero: " << name << ", recruit: " << castle_heroes->GetName()); - -#ifdef WITH_NET - FH2LocalClient::SendCastleRecruitHero(*this, *castle_heroes); -#endif - return true; -} - -/* recruit monster from building to castle army */ -bool Castle::RecruitMonster(u32 dw, u16 count) -{ - u8 dw_index = 0; - - switch(dw) - { - case DWELLING_MONSTER1: dw_index = 0; break; - case DWELLING_MONSTER2: dw_index = 1; break; - case DWELLING_MONSTER3: dw_index = 2; break; - case DWELLING_MONSTER4: dw_index = 3; break; - case DWELLING_MONSTER5: dw_index = 4; break; - case DWELLING_MONSTER6: dw_index = 5; break; - default: return false; - } - - Monster ms = Monster(race, GetActualDwelling(dw)); - - // fix count - if(dwelling[dw_index] < count) count = dwelling[dw_index]; - - // buy - const Resource::funds_t paymentCosts(PaymentConditions::BuyMonster(ms()) * count); - Kingdom & kingdom = world.GetKingdom(color); - - if(! kingdom.AllowPayment(paymentCosts) || !army.JoinTroop(ms, count)) return false; - - kingdom.OddFundsResource(paymentCosts); - dwelling[dw_index] -= count; - - DEBUG(DBG_GAME , DBG_INFO, "Castle::RecruitMonster: " << name); - -#ifdef WITH_NET - FH2LocalClient::SendCastleRecruitMonster(*this, dw, count); -#endif - - return true; -} - -/* return current count monster in dwelling */ -u16 Castle::GetDwellingLivedCount(u32 dw) const -{ - switch(dw) - { - case DWELLING_MONSTER1: return dwelling[0]; - case DWELLING_MONSTER2: - case DWELLING_UPGRADE2: return dwelling[1]; - case DWELLING_MONSTER3: - case DWELLING_UPGRADE3: return dwelling[2]; - case DWELLING_MONSTER4: - case DWELLING_UPGRADE4: return dwelling[3]; - case DWELLING_MONSTER5: - case DWELLING_UPGRADE5: return dwelling[4]; - case DWELLING_MONSTER6: - case DWELLING_UPGRADE6: - case DWELLING_UPGRADE7: return dwelling[5]; - - default: break; - } - - return 0; -} - -/* return requires for building */ -u32 Castle::GetBuildingRequires(u32 build) const -{ - u32 requires = 0; - - switch(build) - { - case BUILD_SPEC: - switch(race) - { - case Race::WZRD: - requires |= BUILD_MAGEGUILD1; - break; - - default: - break; - } - break; - - case DWELLING_MONSTER2: - switch(race) - { - case Race::KNGT: - case Race::BARB: - case Race::WZRD: - case Race::WRLK: - case Race::NECR: - requires |= DWELLING_MONSTER1; - break; - - case Race::SORC: - requires |= DWELLING_MONSTER1; - requires |= BUILD_TAVERN; - break; - - default: - break; - } - break; - - case DWELLING_MONSTER3: - switch(race) - { - case Race::KNGT: - requires |= DWELLING_MONSTER1; - requires |= BUILD_WELL; - break; - - case Race::BARB: - case Race::SORC: - case Race::WZRD: - case Race::WRLK: - case Race::NECR: - requires |= DWELLING_MONSTER1; - break; - - default: - break; - } - break; - - case DWELLING_MONSTER4: - switch(race) - { - case Race::KNGT: - requires |= DWELLING_MONSTER1; - requires |= BUILD_TAVERN; - break; - - case Race::BARB: - requires |= DWELLING_MONSTER1; - break; - - case Race::SORC: - requires |= DWELLING_MONSTER2; - requires |= BUILD_MAGEGUILD1; - break; - - case Race::WZRD: - case Race::WRLK: - requires |= DWELLING_MONSTER2; - break; - - case Race::NECR: - requires |= DWELLING_MONSTER3; - requires |= BUILD_THIEVESGUILD; - break; - - default: - break; - } - break; - - case DWELLING_MONSTER5: - switch(race) - { - case Race::KNGT: - case Race::BARB: - requires |= DWELLING_MONSTER2; - requires |= DWELLING_MONSTER3; - requires |= DWELLING_MONSTER4; - break; - - case Race::SORC: - requires |= DWELLING_MONSTER4; - break; - - case Race::WRLK: - requires |= DWELLING_MONSTER3; - break; - - case Race::WZRD: - requires |= DWELLING_MONSTER3; - requires |= BUILD_MAGEGUILD1; - break; - - case Race::NECR: - requires |= DWELLING_MONSTER2; - requires |= BUILD_MAGEGUILD1; - break; - - default: - break; - } - break; - - case DWELLING_MONSTER6: - switch(race) - { - case Race::KNGT: - requires |= DWELLING_MONSTER2; - requires |= DWELLING_MONSTER3; - requires |= DWELLING_MONSTER4; - break; - - case Race::BARB: - case Race::SORC: - case Race::NECR: - requires |= DWELLING_MONSTER5; - break; - - case Race::WRLK: - case Race::WZRD: - requires |= DWELLING_MONSTER4; - requires |= DWELLING_MONSTER5; - break; - - default: - break; - } - break; - - case DWELLING_UPGRADE2: - switch(race) - { - case Race::KNGT: - case Race::BARB: - requires |= DWELLING_MONSTER2; - requires |= DWELLING_MONSTER3; - requires |= DWELLING_MONSTER4; - break; - - case Race::SORC: - requires |= DWELLING_MONSTER2; - requires |= BUILD_WELL; - break; - - case Race::NECR: - requires |= DWELLING_MONSTER2; - break; - - default: - break; - } - break; - - case DWELLING_UPGRADE3: - switch(race) - { - case Race::KNGT: - requires |= DWELLING_MONSTER2; - requires |= DWELLING_MONSTER3; - requires |= DWELLING_MONSTER4; - break; - - case Race::SORC: - requires |= DWELLING_MONSTER3; - requires |= DWELLING_MONSTER4; - break; - - case Race::WZRD: - requires |= DWELLING_MONSTER3; - requires |= BUILD_WELL; - break; - - case Race::NECR: - requires |= DWELLING_MONSTER3; - break; - - default: - break; - } - break; - - case DWELLING_UPGRADE4: - switch(race) - { - case Race::KNGT: - case Race::BARB: - requires |= DWELLING_MONSTER2; - requires |= DWELLING_MONSTER3; - requires |= DWELLING_MONSTER4; - break; - - case Race::SORC: - case Race::WRLK: - case Race::NECR: - requires |= DWELLING_MONSTER4; - break; - - default: - break; - } - break; - - case DWELLING_UPGRADE5: - switch(race) - { - case Race::KNGT: - requires |= DWELLING_MONSTER2; - requires |= DWELLING_MONSTER3; - requires |= DWELLING_MONSTER4; - requires |= DWELLING_MONSTER5; - break; - - case Race::BARB: - requires |= DWELLING_MONSTER5; - break; - - case Race::WZRD: - requires |= BUILD_SPEC; - requires |= DWELLING_MONSTER5; - break; - - case Race::NECR: - requires |= BUILD_MAGEGUILD2; - requires |= DWELLING_MONSTER5; - break; - - default: - break; - } - break; - - case DWELLING_UPGRADE6: - switch(race) - { - case Race::KNGT: - requires |= DWELLING_MONSTER2; - requires |= DWELLING_MONSTER3; - requires |= DWELLING_MONSTER4; - requires |= DWELLING_MONSTER6; - break; - - case Race::WRLK: - case Race::WZRD: - requires |= DWELLING_MONSTER6; - break; - - default: - break; - } - break; - - default: break; - } - - return requires; -} - -/* check allow buy building */ -bool Castle::AllowBuyBuilding(u32 build) const -{ - // check allow building - if(!Modes(ALLOWBUILD) || build & building) return false; - - switch(build) - { - // allow build castle - case BUILD_CASTLE: if(! Modes(ALLOWCASTLE)) return false; break; - - // buid shipyard only nearly sea - case BUILD_SHIPYARD: if(! HaveNearlySea()) return false; break; - - // check upgrade dwelling - case DWELLING_UPGRADE2: if((Race::WRLK | Race::WZRD) & race) return false; break; - case DWELLING_UPGRADE3: if((Race::BARB | Race::WRLK) & race) return false; break; - case DWELLING_UPGRADE4: if((Race::WZRD) & race) return false; break; - case DWELLING_UPGRADE5: if((Race::SORC | Race::WRLK) & race) return false; break; - case DWELLING_UPGRADE6: if((Race::BARB | Race::SORC | Race::NECR) & race) return false; break; - case DWELLING_UPGRADE7: if(Race::WRLK != race) return false; break; - - default: break; - } - - // check valid payment - if(! world.GetKingdom(color).AllowPayment(PaymentConditions::BuyBuilding(race, build))) return false; - - // check build requirements - std::bitset<32> requires(Castle::GetBuildingRequires(build)); - - if(requires.any()) - { - for(u8 pos = 0; pos < requires.size(); ++pos) - { - if(requires.test(pos)) - { - u32 value = 1; - value <<= pos; - - if(! (building & value)) return false; - } - } - } - - return true; -} - -/* buy building */ -bool Castle::BuyBuilding(u32 build) -{ - if(! AllowBuyBuilding(build)) return false; - -#ifdef WITH_NET - FH2LocalClient::SendCastleBuyBuilding(*this, build); -#endif - - world.GetKingdom(color).OddFundsResource(PaymentConditions::BuyBuilding(race, build)); - - // add build - building |= build; - - switch(build) - { - case BUILD_CASTLE: - Maps::UpdateSpritesFromTownToCastle(GetCenter()); - Maps::ClearFog(GetIndex(), Game::GetViewDistance(Game::VIEW_CASTLE), GetColor()); - break; - - case BUILD_MAGEGUILD1: - case BUILD_MAGEGUILD2: - case BUILD_MAGEGUILD3: - case BUILD_MAGEGUILD4: - case BUILD_MAGEGUILD5: - if(captain.isValid()) mageguild.EducateHero(captain); - if(castle_heroes) mageguild.EducateHero(*castle_heroes); - break; - - case BUILD_CAPTAIN: - captain.LoadDefaults(); - army.SetCommander(&captain); - break; - - case BUILD_SPEC: - // build library - if(mageguild.HaveLibraryCapability()) - { - if(captain.isValid()) mageguild.EducateHero(captain); - if(castle_heroes) mageguild.EducateHero(*castle_heroes); - } - break; - - case DWELLING_MONSTER1: dwelling[0] = Monster(race, DWELLING_MONSTER1).GetGrown(); break; - case DWELLING_MONSTER2: dwelling[1] = Monster(race, DWELLING_MONSTER2).GetGrown(); break; - case DWELLING_MONSTER3: dwelling[2] = Monster(race, DWELLING_MONSTER3).GetGrown(); break; - case DWELLING_MONSTER4: dwelling[3] = Monster(race, DWELLING_MONSTER4).GetGrown(); break; - case DWELLING_MONSTER5: dwelling[4] = Monster(race, DWELLING_MONSTER5).GetGrown(); break; - case DWELLING_MONSTER6: dwelling[5] = Monster(race, DWELLING_MONSTER6).GetGrown(); break; - default: break; - } - - // disable day build - ResetModes(ALLOWBUILD); - - DEBUG(DBG_GAME , DBG_INFO, "Castle::BuyBuilding: " << name << " build " << GetStringBuilding(build, race)); - return true; -} - -/* draw image castle to position */ -void Castle::DrawImageCastle(const Point & pt) -{ - const Maps::Tiles & tile = world.GetTiles(GetCenter()); - Display & display = Display::Get(); - - u8 index = 0; - Point dst_pt; - - // draw ground - switch(tile.GetGround()) - { - case Maps::Ground::GRASS: index = 0; break; - case Maps::Ground::SNOW: index = 10; break; - case Maps::Ground::SWAMP: index = 20; break; - case Maps::Ground::LAVA: index = 30; break; - case Maps::Ground::DESERT: index = 40; break; - case Maps::Ground::DIRT: index = 50; break; - case Maps::Ground::WASTELAND: index = 60; break; - case Maps::Ground::BEACH: index = 70; break; - - default: return; - } - - for(int ii = 0; ii < 5; ++ii) - { - const Sprite & sprite = AGG::GetICN(ICN::OBJNTWBA, index + ii); - dst_pt.x = pt.x + ii * 32 + sprite.x(); - dst_pt.y = pt.y + 3 * 32 + sprite.y(); - display.Blit(sprite, dst_pt); - } - - for(int ii = 0; ii < 5; ++ii) - { - const Sprite & sprite = AGG::GetICN(ICN::OBJNTWBA, index + 5 + ii); - dst_pt.x = pt.x + ii * 32 + sprite.x(); - dst_pt.y = pt.y + 4 * 32 + sprite.y(); - display.Blit(sprite, dst_pt); - } - - // draw castle - switch(race) - { - case Race::KNGT: index = 0; break; - case Race::BARB: index = 32; break; - case Race::SORC: index = 64; break; - case Race::WRLK: index = 96; break; - case Race::WZRD: index = 128; break; - case Race::NECR: index = 160; break; - default: break; - } - if(! (BUILD_CASTLE & building)) index += 16; - const Sprite & sprite2 = AGG::GetICN(ICN::OBJNTOWN, index); - dst_pt.x = pt.x + 2 * 32 + sprite2.x(); - dst_pt.y = pt.y + sprite2.y(); - display.Blit(sprite2, dst_pt); - for(int ii = 0; ii < 5; ++ii) - { - const Sprite & sprite = AGG::GetICN(ICN::OBJNTOWN, index + 1 + ii); - dst_pt.x = pt.x + ii * 32 + sprite.x(); - dst_pt.y = pt.y + 32 + sprite.y(); - display.Blit(sprite, dst_pt); - } - for(int ii = 0; ii < 5; ++ii) - { - const Sprite & sprite = AGG::GetICN(ICN::OBJNTOWN, index + 6 + ii); - dst_pt.x = pt.x + ii * 32 + sprite.x(); - dst_pt.y = pt.y + 2 * 32 + sprite.y(); - display.Blit(sprite, dst_pt); - } - for(int ii = 0; ii < 5; ++ii) - { - const Sprite & sprite = AGG::GetICN(ICN::OBJNTOWN, index + 11 + ii); - dst_pt.x = pt.x + ii * 32 + sprite.x(); - dst_pt.y = pt.y + 3 * 32 + sprite.y(); - display.Blit(sprite, dst_pt); - } -} - -ICN::icn_t Castle::GetICNBoat(const Race::race_t & race) -{ - switch(race) - { - case Race::BARB: return ICN::TWNBBOAT; - case Race::KNGT: return ICN::TWNKBOAT; - case Race::NECR: return ICN::TWNNBOAT; - case Race::SORC: return ICN::TWNSBOAT; - case Race::WRLK: return ICN::TWNWBOAT; - case Race::WZRD: return ICN::TWNZBOAT; - default: break; - } - - DEBUG(DBG_GAME , DBG_WARN, "Castle::GetICNBoat: return unknown"); - return ICN::UNKNOWN; -} - -/* get building name ICN */ -ICN::icn_t Castle::GetICNBuilding(u32 build, Race::race_t race) -{ - if(Race::BARB == race) - { - switch(build) - { - case BUILD_CASTLE: return ICN::TWNBCSTL; - case BUILD_TENT: return ICN::TWNBTENT; - case BUILD_SPEC: return ICN::TWNBSPEC; - case BUILD_CAPTAIN: return ICN::TWNBCAPT; - case BUILD_WEL2: return ICN::TWNBWEL2; - case BUILD_LEFTTURRET: return ICN::TWNBLTUR; - case BUILD_RIGHTTURRET: return ICN::TWNBRTUR; - case BUILD_MOAT: return ICN::TWNBMOAT; - case BUILD_MARKETPLACE: return ICN::TWNBMARK; - case BUILD_THIEVESGUILD:return ICN::TWNBTHIE; - case BUILD_TAVERN: return ICN::TWNBTVRN; - case BUILD_WELL: return ICN::TWNBWELL; - case BUILD_STATUE: return ICN::TWNBSTAT; - case BUILD_SHIPYARD: return ICN::TWNBDOCK; - case BUILD_MAGEGUILD1: - case BUILD_MAGEGUILD2: - case BUILD_MAGEGUILD3: - case BUILD_MAGEGUILD4: - case BUILD_MAGEGUILD5: return ICN::TWNBMAGE; - case DWELLING_MONSTER1: return ICN::TWNBDW_0; - case DWELLING_MONSTER2: return ICN::TWNBDW_1; - case DWELLING_UPGRADE2: return ICN::TWNBUP_1; - case DWELLING_MONSTER3: return ICN::TWNBDW_2; - case DWELLING_MONSTER4: return ICN::TWNBDW_3; - case DWELLING_UPGRADE4: return ICN::TWNBUP_3; - case DWELLING_MONSTER5: return ICN::TWNBDW_4; - case DWELLING_UPGRADE5: return ICN::TWNBUP_4; - case DWELLING_MONSTER6: return ICN::TWNBDW_5; - default: break; - } - } - else - if(Race::KNGT == race) - { - switch(build) - { - case BUILD_CASTLE: return ICN::TWNKCSTL; - case BUILD_TENT: return ICN::TWNKTENT; - case BUILD_SPEC: return ICN::TWNKSPEC; - case BUILD_CAPTAIN: return ICN::TWNKCAPT; - case BUILD_WEL2: return ICN::TWNKWEL2; - case BUILD_LEFTTURRET: return ICN::TWNKLTUR; - case BUILD_RIGHTTURRET: return ICN::TWNKRTUR; - case BUILD_MOAT: return ICN::TWNKMOAT; - case BUILD_MARKETPLACE: return ICN::TWNKMARK; - case BUILD_THIEVESGUILD:return ICN::TWNKTHIE; - case BUILD_TAVERN: return ICN::TWNKTVRN; - case BUILD_WELL: return ICN::TWNKWELL; - case BUILD_STATUE: return ICN::TWNKSTAT; - case BUILD_SHIPYARD: return ICN::TWNKDOCK; - case BUILD_MAGEGUILD1: - case BUILD_MAGEGUILD2: - case BUILD_MAGEGUILD3: - case BUILD_MAGEGUILD4: - case BUILD_MAGEGUILD5: return ICN::TWNKMAGE; - case DWELLING_MONSTER1: return ICN::TWNKDW_0; - case DWELLING_MONSTER2: return ICN::TWNKDW_1; - case DWELLING_UPGRADE2: return ICN::TWNKUP_1; - case DWELLING_MONSTER3: return ICN::TWNKDW_2; - case DWELLING_UPGRADE3: return ICN::TWNKUP_2; - case DWELLING_MONSTER4: return ICN::TWNKDW_3; - case DWELLING_UPGRADE4: return ICN::TWNKUP_3; - case DWELLING_MONSTER5: return ICN::TWNKDW_4; - case DWELLING_UPGRADE5: return ICN::TWNKUP_4; - case DWELLING_MONSTER6: return ICN::TWNKDW_5; - case DWELLING_UPGRADE6: return ICN::TWNKUP_5; - default: break; - } - } - else - if(Race::NECR == race) - { - switch(build) - { - case BUILD_CASTLE: return ICN::TWNNCSTL; - case BUILD_TENT: return ICN::TWNNTENT; - case BUILD_SPEC: return ICN::TWNNSPEC; - case BUILD_CAPTAIN: return ICN::TWNNCAPT; - case BUILD_WEL2: return ICN::TWNNWEL2; - case BUILD_LEFTTURRET: return ICN::TWNNLTUR; - case BUILD_RIGHTTURRET: return ICN::TWNNRTUR; - case BUILD_MOAT: return ICN::TWNNMOAT; - case BUILD_MARKETPLACE: return ICN::TWNNMARK; - case BUILD_THIEVESGUILD:return ICN::TWNNTHIE; - // shrine - case BUILD_TAVERN: if(Settings::Get().PriceLoyaltyVersion()) return ICN::TWNNTVRN; - break; - case BUILD_WELL: return ICN::TWNNWELL; - case BUILD_STATUE: return ICN::TWNNSTAT; - case BUILD_SHIPYARD: return ICN::TWNNDOCK; - case BUILD_MAGEGUILD1: - case BUILD_MAGEGUILD2: - case BUILD_MAGEGUILD3: - case BUILD_MAGEGUILD4: - case BUILD_MAGEGUILD5: return ICN::TWNNMAGE; - case DWELLING_MONSTER1: return ICN::TWNNDW_0; - case DWELLING_MONSTER2: return ICN::TWNNDW_1; - case DWELLING_UPGRADE2: return ICN::TWNNUP_1; - case DWELLING_MONSTER3: return ICN::TWNNDW_2; - case DWELLING_UPGRADE3: return ICN::TWNNUP_2; - case DWELLING_MONSTER4: return ICN::TWNNDW_3; - case DWELLING_UPGRADE4: return ICN::TWNNUP_3; - case DWELLING_MONSTER5: return ICN::TWNNDW_4; - case DWELLING_UPGRADE5: return ICN::TWNNUP_4; - case DWELLING_MONSTER6: return ICN::TWNNDW_5; - default: break; - } - } - else - if(Race::SORC == race) - { - switch(build) - { - case BUILD_CASTLE: return ICN::TWNSCSTL; - case BUILD_TENT: return ICN::TWNSTENT; - case BUILD_SPEC: return ICN::TWNSSPEC; - case BUILD_CAPTAIN: return ICN::TWNSCAPT; - case BUILD_WEL2: return ICN::TWNSWEL2; - case BUILD_LEFTTURRET: return ICN::TWNSLTUR; - case BUILD_RIGHTTURRET: return ICN::TWNSRTUR; - case BUILD_MOAT: return ICN::TWNSMOAT; - case BUILD_MARKETPLACE: return ICN::TWNSMARK; - case BUILD_THIEVESGUILD:return ICN::TWNSTHIE; - case BUILD_TAVERN: return ICN::TWNSTVRN; - case BUILD_WELL: return ICN::TWNSWELL; - case BUILD_STATUE: return ICN::TWNSSTAT; - case BUILD_SHIPYARD: return ICN::TWNSDOCK; - case BUILD_MAGEGUILD1: - case BUILD_MAGEGUILD2: - case BUILD_MAGEGUILD3: - case BUILD_MAGEGUILD4: - case BUILD_MAGEGUILD5: return ICN::TWNSMAGE; - case DWELLING_MONSTER1: return ICN::TWNSDW_0; - case DWELLING_MONSTER2: return ICN::TWNSDW_1; - case DWELLING_UPGRADE2: return ICN::TWNSUP_1; - case DWELLING_MONSTER3: return ICN::TWNSDW_2; - case DWELLING_UPGRADE3: return ICN::TWNSUP_2; - case DWELLING_MONSTER4: return ICN::TWNSDW_3; - case DWELLING_UPGRADE4: return ICN::TWNSUP_3; - case DWELLING_MONSTER5: return ICN::TWNSDW_4; - case DWELLING_MONSTER6: return ICN::TWNSDW_5; - default: break; - } - } - else - if(Race::WRLK == race) - { - switch(build) - { - case BUILD_CASTLE: return ICN::TWNWCSTL; - case BUILD_TENT: return ICN::TWNWTENT; - case BUILD_SPEC: return ICN::TWNWSPEC; - case BUILD_CAPTAIN: return ICN::TWNWCAPT; - case BUILD_WEL2: return ICN::TWNWWEL2; - case BUILD_LEFTTURRET: return ICN::TWNWLTUR; - case BUILD_RIGHTTURRET: return ICN::TWNWRTUR; - case BUILD_MOAT: return ICN::TWNWMOAT; - case BUILD_MARKETPLACE: return ICN::TWNWMARK; - case BUILD_THIEVESGUILD:return ICN::TWNWTHIE; - case BUILD_TAVERN: return ICN::TWNWTVRN; - case BUILD_WELL: return ICN::TWNWWELL; - case BUILD_STATUE: return ICN::TWNWSTAT; - case BUILD_SHIPYARD: return ICN::TWNWDOCK; - case BUILD_MAGEGUILD1: - case BUILD_MAGEGUILD2: - case BUILD_MAGEGUILD3: - case BUILD_MAGEGUILD4: - case BUILD_MAGEGUILD5: return ICN::TWNWMAGE; - case DWELLING_MONSTER1: return ICN::TWNWDW_0; - case DWELLING_MONSTER2: return ICN::TWNWDW_1; - case DWELLING_MONSTER3: return ICN::TWNWDW_2; - case DWELLING_MONSTER4: return ICN::TWNWDW_3; - case DWELLING_UPGRADE4: return ICN::TWNWUP_3; - case DWELLING_MONSTER5: return ICN::TWNWDW_4; - case DWELLING_MONSTER6: return ICN::TWNWDW_5; - case DWELLING_UPGRADE6: return ICN::TWNWUP_5; - case DWELLING_UPGRADE7: return ICN::TWNWUP5B; - default: break; - } - } - else - if(Race::WZRD == race) - { - switch(build) - { - case BUILD_CASTLE: return ICN::TWNZCSTL; - case BUILD_TENT: return ICN::TWNZTENT; - case BUILD_SPEC: return ICN::TWNZSPEC; - case BUILD_CAPTAIN: return ICN::TWNZCAPT; - case BUILD_WEL2: return ICN::TWNZWEL2; - case BUILD_LEFTTURRET: return ICN::TWNZLTUR; - case BUILD_RIGHTTURRET: return ICN::TWNZRTUR; - case BUILD_MOAT: return ICN::TWNZMOAT; - case BUILD_MARKETPLACE: return ICN::TWNZMARK; - case BUILD_THIEVESGUILD:return ICN::TWNZTHIE; - case BUILD_TAVERN: return ICN::TWNZTVRN; - case BUILD_WELL: return ICN::TWNZWELL; - case BUILD_STATUE: return ICN::TWNZSTAT; - case BUILD_SHIPYARD: return ICN::TWNZDOCK; - case BUILD_MAGEGUILD1: - case BUILD_MAGEGUILD2: - case BUILD_MAGEGUILD3: - case BUILD_MAGEGUILD4: - case BUILD_MAGEGUILD5: return ICN::TWNZMAGE; - case DWELLING_MONSTER1: return ICN::TWNZDW_0; - case DWELLING_MONSTER2: return ICN::TWNZDW_1; - case DWELLING_MONSTER3: return ICN::TWNZDW_2; - case DWELLING_UPGRADE3: return ICN::TWNZUP_2; - case DWELLING_MONSTER4: return ICN::TWNZDW_3; - case DWELLING_MONSTER5: return ICN::TWNZDW_4; - case DWELLING_UPGRADE5: return ICN::TWNZUP_4; - case DWELLING_MONSTER6: return ICN::TWNZDW_5; - case DWELLING_UPGRADE6: return ICN::TWNZUP_5; - default: break; - } - } - - std::cout << "Castle::GetICNBuilding: return unknown, race: " << Race::String(race) << ", build: " << Castle::GetStringBuilding(build, race) << ", " << build << std::endl; - - return ICN::UNKNOWN; -} - -const Heroes* Castle::GetHeroes(void) const -{ - const Heroes* hero = world.GetHeroes(GetIndex()); - return hero && Color::GRAY != hero->GetColor() ? hero : NULL; -} - -Heroes* Castle::GetHeroes(void) -{ - Heroes* hero = world.GetHeroes(GetIndex()); - return hero && Color::GRAY != hero->GetColor() ? hero : NULL; -} - -bool Castle::HaveNearlySea(void) const -{ - // check nearest ocean - const s32 index = GetIndex() + world.w() * 2; - const Maps::Tiles & left = world.GetTiles(index - 1); - const Maps::Tiles & right = world.GetTiles(index + 1); - const Maps::Tiles & center = world.GetTiles(index); - - return Maps::Ground::WATER == left.GetGround() || Maps::Ground::WATER == right.GetGround() || Maps::Ground::WATER == center.GetGround(); -} - -bool TilePresentBoat(const Maps::Tiles & tile) -{ - return (Maps::Ground::WATER == tile.GetGround() && - (tile.GetObject() == MP2::OBJ_BOAT || tile.GetObject() == MP2::OBJ_HEROES)); -} - -bool Castle::PresentBoat(void) const -{ - // 2 cell down - const s32 index = GetIndex() + world.w() * 2; - const u16 max = world.w() * world.h(); - - if(index + 1 < max) - { - const Maps::Tiles & left = world.GetTiles(index - 1); - const Maps::Tiles & right = world.GetTiles(index + 1); - const Maps::Tiles & center = world.GetTiles(index); - - if(TilePresentBoat(left) || TilePresentBoat(right) || TilePresentBoat(center)) return true; - } - return false; -} - -u32 Castle::GetActualDwelling(u32 build) const -{ - switch(build) - { - case DWELLING_MONSTER2: return building & DWELLING_UPGRADE2 ? DWELLING_UPGRADE2 : build; - case DWELLING_MONSTER3: return building & DWELLING_UPGRADE3 ? DWELLING_UPGRADE3 : build; - case DWELLING_MONSTER4: return building & DWELLING_UPGRADE4 ? DWELLING_UPGRADE4 : build; - case DWELLING_MONSTER5: return building & DWELLING_UPGRADE5 ? DWELLING_UPGRADE5 : build; - case DWELLING_UPGRADE6: return building & DWELLING_UPGRADE7 ? DWELLING_UPGRADE7 : build; - case DWELLING_MONSTER6: return building & DWELLING_UPGRADE7 ? DWELLING_UPGRADE7 : (building & DWELLING_UPGRADE6 ? DWELLING_UPGRADE6 : build); - default: break; - } - return build; -} - -u32 Castle::GetUpgradeBuilding(u32 build) const -{ - switch(build) - { - case BUILD_TENT: return BUILD_CASTLE; - case BUILD_MAGEGUILD1: return BUILD_MAGEGUILD2; - case BUILD_MAGEGUILD2: return BUILD_MAGEGUILD3; - case BUILD_MAGEGUILD3: return BUILD_MAGEGUILD4; - case BUILD_MAGEGUILD4: return BUILD_MAGEGUILD5; - default: break; - } - - if(Race::BARB == race) - { - switch(build) - { - case DWELLING_MONSTER2: return DWELLING_UPGRADE2; - case DWELLING_MONSTER4: return DWELLING_UPGRADE4; - case DWELLING_MONSTER5: return DWELLING_UPGRADE5; - default: break; - } - } - else - if(Race::KNGT == race) - { - switch(build) - { - case DWELLING_MONSTER2: return DWELLING_UPGRADE2; - case DWELLING_MONSTER3: return DWELLING_UPGRADE3; - case DWELLING_MONSTER4: return DWELLING_UPGRADE4; - case DWELLING_MONSTER5: return DWELLING_UPGRADE5; - case DWELLING_MONSTER6: return DWELLING_UPGRADE6; - default: break; - } - } - else - if(Race::NECR == race) - { - switch(build) - { - case DWELLING_MONSTER2: return DWELLING_UPGRADE2; - case DWELLING_MONSTER3: return DWELLING_UPGRADE3; - case DWELLING_MONSTER4: return DWELLING_UPGRADE4; - case DWELLING_MONSTER5: return DWELLING_UPGRADE5; - default: break; - } - } - else - if(Race::SORC == race) - { - switch(build) - { - case DWELLING_MONSTER2: return DWELLING_UPGRADE2; - case DWELLING_MONSTER3: return DWELLING_UPGRADE3; - case DWELLING_MONSTER4: return DWELLING_UPGRADE4; - default: break; - } - } - else - if(Race::WRLK == race) - { - switch(build) - { - case DWELLING_MONSTER4: return DWELLING_UPGRADE4; - case DWELLING_MONSTER6: return DWELLING_UPGRADE6; - case DWELLING_UPGRADE6: return DWELLING_UPGRADE7; - default: break; - } - } - else - if(Race::WZRD == race) - { - switch(build) - { - case DWELLING_MONSTER3: return DWELLING_UPGRADE3; - case DWELLING_MONSTER5: return DWELLING_UPGRADE5; - case DWELLING_MONSTER6: return DWELLING_UPGRADE6; - default: break; - } - } - - return build; -} - -bool Castle::PredicateIsCapital(const Castle *castle) -{ - return castle && castle->Modes(CAPITAL); -} - -bool Castle::PredicateIsCastle(const Castle* castle) -{ - return castle && castle->isCastle(); -} - -bool Castle::PredicateIsTown(const Castle* castle) -{ - return castle && !castle->isCastle(); -} - -bool Castle::PredicateIsBuildMarketplace(const Castle* castle) -{ - return castle && castle->isBuild(BUILD_MARKETPLACE); -} - -void Castle::Dump(void) const -{ - std::cout << "name : " << name << std::endl; - std::cout << "race : " << Race::String(race) << std::endl; - std::cout << "color : " << Color::String(color) << std::endl; - std::cout << "build : " << "0x" << std::hex << building << std::dec << std::endl; - std::cout << "present heroes : " << (GetHeroes() ? "yes" : "no") << std::endl; - std::cout << "present boat : " << (PresentBoat() ? "yes" : "no") << std::endl; - std::cout << "nearly sea : " << (HaveNearlySea() ? "yes" : "no") << std::endl; - std::cout << "is castle : " << (isCastle() ? "yes" : "no") << std::endl; -} - -s8 Castle::GetAttackModificator(std::string *strs) const -{ - return 0; -} - -s8 Castle::GetDefenseModificator(std::string *strs) const -{ - return 0; -} - -s8 Castle::GetPowerModificator(std::string *strs) const -{ - s8 result = 0; - - if(Race::NECR == race && isBuild(BUILD_SPEC)) - { - const u8 mod = 2; - result += mod; - if(strs) - { - strs->append(GetStringBuilding(BUILD_SPEC, race)); - StringAppendModifiers(*strs, mod); - } - } - - return result; -} - -s8 Castle::GetKnowledgeModificator(std::string *strs) const -{ - return 0; -} - -s8 Castle::GetMoraleModificator(std::string *strs) const -{ - s8 result(Morale::NORMAL); - - // and tavern - if(Race::NECR != race && isBuild(BUILD_TAVERN)) - { - const u8 mod = 1; - result += mod; - if(strs) - { - strs->append(GetStringBuilding(BUILD_TAVERN, race)); - StringAppendModifiers(*strs, mod); - } - } - - // and barbarian coliseum - if(Race::BARB == race && isBuild(BUILD_SPEC)) - { - const u8 mod = 2; - result += mod; - if(strs) - { - strs->append(GetStringBuilding(BUILD_SPEC, race)); - StringAppendModifiers(*strs, mod); - } - } - - return result; -} - -s8 Castle::GetLuckModificator(std::string *strs) const -{ - s8 result(Luck::NORMAL); - - if(Race::SORC == race && isBuild(BUILD_SPEC)) - { - const u8 mod = 2; - result += mod; - if(strs) - { - strs->append(Castle::GetStringBuilding(BUILD_SPEC, race)); - StringAppendModifiers(*strs, mod); - } - } - - return result; -} - -void Castle::RecruitAllMonster(void) -{ - if(isBuild(DWELLING_MONSTER6)) RecruitMonster(DWELLING_MONSTER6, MAXU16); - if(isBuild(DWELLING_MONSTER5)) RecruitMonster(DWELLING_MONSTER5, MAXU16); - if(isBuild(DWELLING_MONSTER4)) RecruitMonster(DWELLING_MONSTER4, MAXU16); - if(isBuild(DWELLING_MONSTER3)) RecruitMonster(DWELLING_MONSTER3, MAXU16); - if(isBuild(DWELLING_MONSTER2)) RecruitMonster(DWELLING_MONSTER2, MAXU16); - if(isBuild(DWELLING_MONSTER1)) RecruitMonster(DWELLING_MONSTER1, MAXU16); -} - -const Army::army_t & Castle::GetArmy(void) const -{ - return army; -} - -Army::army_t & Castle::GetArmy(void) -{ - return army; -} - -void Castle::MergeArmies(void) -{ - Heroes *hero = GetHeroes(); - - if(hero && army.isValid() && (GetControl() == Game::AI || Settings::Get().ExtBattleMergeArmies())) - hero->GetArmy().JoinStrongestFromArmy(army); -} - -const Army::army_t & Castle::GetActualArmy(void) const -{ - const Heroes *heroes = GetHeroes(); - return heroes ? heroes->GetArmy() : army; -} - -Army::army_t & Castle::GetActualArmy(void) -{ - Heroes *heroes = GetHeroes(); - return heroes ? heroes->GetArmy() : army; -} - -bool Castle::AllowBuyBoat(void) const -{ - // check payment and present other boat - return (HaveNearlySea() && world.GetMyKingdom().AllowPayment(PaymentConditions::BuyBoat()) && !PresentBoat()); -} - -bool Castle::BuyBoat(void) -{ - if(!AllowBuyBoat()) return false; - if(Game::LOCAL == world.GetKingdom(color).Control()) AGG::PlaySound(M82::BUILDTWN); - - const s32 index = GetIndex() + world.w() * 2; - Maps::Tiles & left = world.GetTiles(index - 1); - Maps::Tiles & right = world.GetTiles(index + 1); - Maps::Tiles & center = world.GetTiles(index); - - if(MP2::OBJ_ZERO == left.GetObject() && Maps::Ground::WATER == left.GetGround()) - { - world.GetMyKingdom().OddFundsResource(PaymentConditions::BuyBoat()); - - left.SetObject(MP2::OBJ_BOAT); -#ifdef WITH_NET - FH2LocalClient::SendCastleBuyBoat(*this, left.GetIndex()); -#endif - } - else - if(MP2::OBJ_ZERO == right.GetObject() && Maps::Ground::WATER == right.GetGround()) - { - world.GetMyKingdom().OddFundsResource(PaymentConditions::BuyBoat()); - - right.SetObject(MP2::OBJ_BOAT); -#ifdef WITH_NET - FH2LocalClient::SendCastleBuyBoat(*this, right.GetIndex()); -#endif - } - else - if(MP2::OBJ_ZERO == center.GetObject() && Maps::Ground::WATER == center.GetGround()) - { - world.GetMyKingdom().OddFundsResource(PaymentConditions::BuyBoat()); - - center.SetObject(MP2::OBJ_BOAT); -#ifdef WITH_NET - FH2LocalClient::SendCastleBuyBoat(*this, center.GetIndex()); -#endif - } - - return true; -} - -u8 Castle::GetControl(void) const -{ - return world.GetKingdom(color).Control(); -} - -bool Castle::isNecromancyShrineBuild(void) const -{ - return Settings::Get().PriceLoyaltyVersion() && - race == Race::NECR && (BUILD_TAVERN & building); -} - -u8 Castle::GetGrownWell(void) -{ - return grown_well; -} - -u8 Castle::GetGrownWel2(void) -{ - return grown_wel2; -} - -void Castle::Scoute(void) const -{ - Maps::ClearFog(GetIndex(), Game::GetViewDistance(isCastle() ? Game::VIEW_CASTLE : Game::VIEW_TOWN), color); -} - -#ifdef WITH_XML -#include "xmlccwrap.h" - -void Castle::UpdateExtraGrowth(const TiXmlElement* xml) -{ - int value; - xml->Attribute("well", &value); - grown_well = value; - - xml->Attribute("wel", &value); - grown_wel2 = value; -} -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/castle.h b/project/jni/application/fheroes2/src/fheroes2/castle/castle.h deleted file mode 100644 index 94fa5cd8d..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/castle.h +++ /dev/null @@ -1,213 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2CASTLE_H -#define H2CASTLE_H - -#include -#include -#include -#include "mageguild.h" -#include "color.h" -#include "captain.h" -#include "dialog.h" -#include "race.h" -#include "army.h" -#include "bitmodes.h" -#include "heroes.h" -#include "game_io.h" -#include "position.h" - -class Heroes; -namespace Maps { class Tiles; } - -enum building_t -{ - BUILD_NOTHING = 0x00000000, - BUILD_THIEVESGUILD = 0x00000001, - BUILD_TAVERN = 0x00000002, - BUILD_SHIPYARD = 0x00000004, - BUILD_WELL = 0x00000008, - BUILD_STATUE = 0x00000010, - BUILD_LEFTTURRET = 0x00000020, - BUILD_RIGHTTURRET = 0x00000040, - BUILD_MARKETPLACE = 0x00000080, - BUILD_WEL2 = 0x00000100, // Farm, Garbage He, Crystal Gar, Waterfall, Orchard, Skull Pile - BUILD_MOAT = 0x00000200, - BUILD_SPEC = 0x00000400, // Fortification, Coliseum, Rainbow, Dungeon, Library, Storm - BUILD_CASTLE = 0x00000800, - BUILD_CAPTAIN = 0x00001000, - BUILD_SHRINE = 0x00002000, - BUILD_MAGEGUILD1 = 0x00004000, - BUILD_MAGEGUILD2 = 0x00008000, - BUILD_MAGEGUILD3 = 0x00010000, - BUILD_MAGEGUILD4 = 0x00020000, - BUILD_MAGEGUILD5 = 0x00040000, - BUILD_TENT = 0x00080000, // deprecated - DWELLING_MONSTER1 = 0x00100000, - DWELLING_MONSTER2 = 0x00200000, - DWELLING_MONSTER3 = 0x00400000, - DWELLING_MONSTER4 = 0x00800000, - DWELLING_MONSTER5 = 0x01000000, - DWELLING_MONSTER6 = 0x02000000, - DWELLING_UPGRADE2 = 0x04000000, - DWELLING_UPGRADE3 = 0x08000000, - DWELLING_UPGRADE4 = 0x10000000, - DWELLING_UPGRADE5 = 0x20000000, - DWELLING_UPGRADE6 = 0x40000000, - DWELLING_UPGRADE7 = 0x80000000 // black dragon -}; - -class Castle : public Maps::Position, public BitModes -{ -public: - enum flags_t - { - ALLOWCASTLE = 0x0002, - // = 0x0004, - ALLOWBUILD = 0x0008, - // - 0x0010, - CAPITAL = 0x0020 - }; - - Castle(); - Castle(s16 cx, s16 cy, const Race::race_t rs); - void LoadFromMP2(const void *ptr); - - Captain &GetCaptain() { return captain; } - - bool isCastle(void) const{ return building & BUILD_CASTLE; } - bool isCapital(void) const{ return Modes(CAPITAL); } - bool HaveNearlySea(void) const; - bool PresentBoat(void) const; - bool RecruitMonster(u32 dw, u16 count); - bool AllowBuyHero(const Heroes &); - bool ContainCoord(const u16 ax, const u16 ay) const; - bool isNecromancyShrineBuild(void) const; - - u32 CountBuildings(void) const; - - bool RecruitHero(Heroes*); - const Heroes* GetHeroes(void) const; - Heroes* GetHeroes(void); - - Race::race_t GetRace(void) const{ return race; } - Color::color_t GetColor(void) const{ return color; } - const std::string & GetName(void) const{ return name; } - u8 GetControl(void) const; - u8 GetLevelMageGuild(void) const; - const MageGuild & GetMageGuild(void) const; - - const Army::army_t & GetArmy(void) const; - Army::army_t & GetArmy(void); - const Army::army_t & GetActualArmy(void) const; - Army::army_t & GetActualArmy(void); - void MergeArmies(void); - u16 GetDwellingLivedCount(u32) const; - u32 GetActualDwelling(u32) const; - void RecruitAllMonster(void); - - void ChangeColor(Color::color_t cl); - - void ActionNewDay(void); - void ActionNewWeek(void); - void ActionNewMonth(void); - - void DrawImageCastle(const Point & pt); - - Dialog::answer_t OpenDialog(bool readonly = false, bool fade = false); - - s8 GetAttackModificator(std::string *strs) const; - s8 GetDefenseModificator(std::string *strs) const; - s8 GetPowerModificator(std::string *strs) const; - s8 GetKnowledgeModificator(std::string *strs) const; - s8 GetMoraleModificator(std::string *strs) const; - s8 GetLuckModificator(std::string *strs) const; - - bool AllowBuild(void) const{ return Modes(ALLOWBUILD); } - bool AllowBuyBuilding(u32) const; - bool isBuild(u32 bd) const{ return building & bd; } - bool BuyBuilding(u32); - bool AllowBuyBoat(void) const; - bool BuyBoat(void); - u32 GetBuildingRequires(u32) const; - - void Scoute(void) const; - - static const char* GetStringBuilding(u32, Race::race_t = Race::BOMG); - static const char* GetDescriptionBuilding(u32, Race::race_t = Race::BOMG); - static ICN::icn_t GetICNBuilding(u32, Race::race_t); - static ICN::icn_t GetICNBoat(const Race::race_t & race); - u32 GetUpgradeBuilding(u32) const; - - static bool PredicateIsCastle(const Castle *castle); - static bool PredicateIsTown(const Castle *castle); - static bool PredicateIsBuildMarketplace(const Castle *castle); - static bool PredicateIsCapital(const Castle *castle); - - static u8 GetGrownWell(void); - static u8 GetGrownWel2(void); -#ifdef WITH_XML - static void UpdateExtraGrowth(const TiXmlElement*); -#endif - - void Dump(void) const; - - void AIDefense(void); - void AIDevelopment(void); - void AIJoinRNDArmy(void); - - Dialog::answer_t DialogBuyHero(const Heroes*); - Dialog::answer_t DialogBuyCaptain(bool fixed = true) const; - Dialog::answer_t DialogBuyCastle(bool fixed = true) const; - -private: - void RedrawResourcePanel(const Point &); - Rect GetCoordBuilding(building_t building, const Point & pt); - u32 OpenTown(void); - void OpenTavern(void); - void OpenThievesGuild(void); - void OpenWell(void); - void OpenMageGuild(void); - void WellRedrawInfoArea(const Point & cur_pt); - static void RedrawAllBuilding(const Castle &, const Point &, const std::vector &); - static void RedrawAnimationBuilding(const Castle &, const Point &, const std::vector &, u32 build); - -private: - friend class Game::IO; - - Race::race_t race; - Captain captain; - - Color::color_t color; - std::string name; - u32 building; - - MageGuild mageguild; - u16 dwelling[CASTLEMAXMONSTER]; - Army::army_t army; - Heroes * castle_heroes; - - static u8 grown_well; - static u8 grown_wel2; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/castle_ai.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/castle_ai.cpp deleted file mode 100644 index e2f5af411..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/castle_ai.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "world.h" -#include "kingdom.h" -#include "heroes.h" -#include "castle.h" - -void Castle::AIJoinRNDArmy(void) -{ - const Monster mon1(race, DWELLING_MONSTER1); - const Monster mon2(race, DWELLING_MONSTER2); - const Monster mon3(race, DWELLING_MONSTER3); - - switch(Rand::Get(1, 4)) - { - case 1: - army.JoinTroop(mon1, mon1.GetRNDSize(false) * 3); - army.JoinTroop(mon2, mon2.GetRNDSize(false)); - break; - - case 2: - army.JoinTroop(mon1, mon1.GetRNDSize(false) * 2); - army.JoinTroop(mon2, mon2.GetRNDSize(false) * 2); - break; - - case 3: - army.JoinTroop(mon1, mon1.GetRNDSize(false) * 2); - army.JoinTroop(mon2, mon2.GetRNDSize(false)); - army.JoinTroop(mon3, mon3.GetRNDSize(false) * 2 / 3); - break; - - default: - army.JoinTroop(mon1, mon1.GetRNDSize(false)); - army.JoinTroop(mon3, mon3.GetRNDSize(false)); - break; - } -} - -void Castle::AIDefense(void) -{ - if(isCastle()) - { - if(!isBuild(BUILD_LEFTTURRET)) BuyBuilding(BUILD_LEFTTURRET); - if(!isBuild(BUILD_RIGHTTURRET)) BuyBuilding(BUILD_RIGHTTURRET); - if(!isBuild(BUILD_MOAT)) BuyBuilding(BUILD_MOAT); - if(!isBuild(BUILD_CAPTAIN) && NULL == GetHeroes()) BuyBuilding(BUILD_CAPTAIN); - if(!isBuild(BUILD_TAVERN) && Race::KNGT == GetRace()) BuyBuilding(BUILD_TAVERN); - if(!isBuild(BUILD_SPEC)) BuyBuilding(BUILD_SPEC); - } - RecruitAllMonster(); -} - -void Castle::AIDevelopment(void) -{ - if(world.GetKingdom(GetColor()).GetHeroes().size() && isCastle() && isCapital()) - { - if(!isBuild(BUILD_STATUE)) BuyBuilding(BUILD_STATUE); - if(!isBuild(BUILD_SPEC) && Race::WRLK == race) BuyBuilding(BUILD_SPEC); - if(!isBuild(BUILD_TAVERN) && Race::KNGT == race) BuyBuilding(BUILD_TAVERN); - if(!isBuild(BUILD_MAGEGUILD1) && ((Race::SORC | Race::WZRD | Race::WRLK | Race::NECR) & race)) BuyBuilding(BUILD_MAGEGUILD1); - if(!isBuild(BUILD_WELL)) BuyBuilding(BUILD_WELL); - - if(!isBuild(DWELLING_MONSTER1)) BuyBuilding(DWELLING_MONSTER1); - if(!isBuild(DWELLING_MONSTER2)) BuyBuilding(DWELLING_MONSTER2); - if(!isBuild(DWELLING_MONSTER3)) BuyBuilding(DWELLING_MONSTER3); - if(!isBuild(DWELLING_MONSTER4)) BuyBuilding(DWELLING_MONSTER4); - - if(!isBuild(BUILD_THIEVESGUILD) && ((Race::NECR) & race)) BuyBuilding(BUILD_THIEVESGUILD); - if(!isBuild(BUILD_MARKETPLACE)) BuyBuilding(BUILD_MARKETPLACE); - - if(!isBuild(BUILD_MAGEGUILD1)) BuyBuilding(BUILD_MAGEGUILD1); - if(!isBuild(BUILD_MAGEGUILD2) && ((Race::SORC | Race::WZRD | Race::WRLK | Race::NECR) & race)) BuyBuilding(BUILD_MAGEGUILD2); - - if(!isBuild(DWELLING_UPGRADE2)) BuyBuilding(DWELLING_UPGRADE2); - if(!isBuild(DWELLING_UPGRADE3)) BuyBuilding(DWELLING_UPGRADE3); - if(!isBuild(DWELLING_UPGRADE4)) BuyBuilding(DWELLING_UPGRADE4); - - if(!isBuild(BUILD_LEFTTURRET)) BuyBuilding(BUILD_LEFTTURRET); - if(!isBuild(BUILD_RIGHTTURRET)) BuyBuilding(BUILD_RIGHTTURRET); - if(!isBuild(BUILD_MOAT)) BuyBuilding(BUILD_MOAT); - if(!isBuild(BUILD_CAPTAIN)) BuyBuilding(BUILD_CAPTAIN); - - if(!isBuild(BUILD_MAGEGUILD2)) BuyBuilding(BUILD_MAGEGUILD2); - - if(!isBuild(DWELLING_MONSTER5)) BuyBuilding(DWELLING_MONSTER5); - if(!isBuild(DWELLING_MONSTER6)) BuyBuilding(DWELLING_MONSTER6); - - if(!isBuild(BUILD_MAGEGUILD3)) BuyBuilding(BUILD_MAGEGUILD3); - - if(!isBuild(DWELLING_UPGRADE5)) BuyBuilding(DWELLING_UPGRADE5); - if(!isBuild(DWELLING_UPGRADE6)) BuyBuilding(DWELLING_UPGRADE6); - } - else - // build castle only monday or tuesday or for capital - if(3 > world.GetDay() || !isCastle() || isCapital()) BuyBuilding(BUILD_CASTLE); - - // last day and buy monster - if(world.LastDay()) RecruitAllMonster(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/castle_building.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/castle_building.cpp deleted file mode 100644 index 8555a6a60..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/castle_building.cpp +++ /dev/null @@ -1,620 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "castle.h" -#include "settings.h" -#include "cursor.h" -#include "game.h" - -void CastleRedrawTownName(const Castle &, const Point &); -void CastleRedrawCurrentBuilding(const Castle &, const Point &, const std::vector &, u32 build); -void CastleRedrawBuilding(const Castle &, const Point &, u32 build, u32 frame, u8 alpha); -void CastleRedrawBuildingExtended(const Castle &, const Point &, u32 build, u32 frame); - -Rect Castle::GetCoordBuilding(building_t building, const Point & pt) -{ - switch(building) - { - case BUILD_THIEVESGUILD: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 0, pt.y + 130, 50, 60); - case Race::BARB: return Rect(pt.x + 478, pt.y + 100, 76, 42); - case Race::SORC: return Rect(pt.x + 423, pt.y + 165, 65, 49); - case Race::WRLK: return Rect(pt.x + 525, pt.y + 109, 60, 48); - case Race::WZRD: return Rect(pt.x + 507, pt.y + 55, 47, 42); - case Race::NECR: return Rect(pt.x + 291, pt.y + 134, 43, 59); - default: break; - } - break; - - case BUILD_TAVERN: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 350, pt.y + 110, 46, 56); - case Race::BARB: return Rect(pt.x + 0, pt.y + 205, 125, 60); - case Race::SORC: return Rect(pt.x + 494, pt.y + 140, 131, 87); - case Race::WRLK: return Rect(pt.x + 479, pt.y + 100, 39, 52); - case Race::WZRD: return Rect(pt.x, pt.y + 160, 118, 50); - // shrine - case Race::NECR: if(Settings::Get().PriceLoyaltyVersion()) return Rect(pt.x + 453, pt.y + 36, 55, 96); - default: break; - } - break; - - case BUILD_SHIPYARD: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 537, pt.y + 221, 103, 33); - case Race::BARB: return Rect(pt.x + 535, pt.y + 210, 105, 45); - case Race::SORC: return Rect(pt.x + 0, pt.y + 220, 134, 35); - case Race::WRLK: return Rect(pt.x + 520, pt.y + 206, 120, 47); - case Race::WZRD: return Rect(pt.x, pt.y + 218, 185, 35); - case Race::NECR: return Rect(pt.x + 516, pt.y + 221, 124, 28); - default: break; - } - break; - - case BUILD_WELL: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 194, pt.y + 225, 29, 27); - case Race::BARB: return Rect(pt.x + 272, pt.y + 215, 44, 32); - case Race::SORC: return Rect(pt.x + 346, pt.y + 209, 43, 25); - case Race::WRLK: return Rect(pt.x + 348, pt.y + 221, 63, 30); - case Race::WZRD: return Rect(pt.x + 254, pt.y + 143, 19, 28); - case Race::NECR: return Rect(pt.x + 217, pt.y + 225, 23, 26); - default: break; - } - break; - - case BUILD_STATUE: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 480, pt.y + 205, 45, 50); - case Race::BARB: return Rect(pt.x + 470, pt.y + 180, 30, 58); - case Race::SORC: return Rect(pt.x + 158, pt.y + 173, 17, 58); - case Race::WRLK: return Rect(pt.x + 473, pt.y + 172, 45, 51); - case Race::WZRD: return Rect(pt.x + 464, pt.y + 58, 26, 62); - case Race::NECR: return Rect(pt.x + 374, pt.y + 174, 26, 70); - default: break; - } - break; - - case BUILD_MARKETPLACE: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 220, pt.y + 144, 115, 20); - case Race::BARB: return Rect(pt.x + 224, pt.y + 168, 52, 36); - case Race::SORC: return Rect(pt.x + 412, pt.y + 122, 56, 40); - case Race::WRLK: return Rect(pt.x + 391, pt.y + 185, 70, 26); - case Race::WZRD: return Rect(pt.x + 254, pt.y + 176, 105, 39); - case Race::NECR: return Rect(pt.x + 415, pt.y + 216, 85, 35); - default: break; - } - break; - - case BUILD_WEL2: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 288, pt.y + 97, 63, 18); - case Race::BARB: return Rect(pt.x + 252, pt.y + 120, 44, 16); - case Race::SORC: return Rect(pt.x + 135, pt.y + 200, 63, 31); - case Race::WRLK: return Rect(pt.x + 69, pt.y + 46, 24, 124); - case Race::WZRD: return Rect(pt.x + 234, pt.y + 225, 107, 22); - case Race::NECR: return Rect(pt.x + 275, pt.y + 206, 68, 39); - default: break; - } - break; - - case BUILD_MOAT: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 53, pt.y + 150, 93, 30); - case Race::BARB: return Rect(pt.x + 113, pt.y + 155, 106, 30); - case Race::SORC: return Rect(pt.x + 143, pt.y + 169, 98, 11); - case Race::WRLK: return Rect(pt.x + 327, pt.y + 166, 66, 17); - case Race::WZRD: return Rect(pt.x, pt.y + 91, 198, 11); - case Race::NECR: return Rect(pt.x + 336, pt.y + 169, 71, 15); - default: break; - } - break; - - case BUILD_SPEC: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 0, pt.y + 80, 250, 20); - case Race::BARB: return Rect(pt.x + 223, pt.y + 79, 124, 27); - case Race::SORC: return Rect(pt.x + 147, pt.y + 0, 252, 30); - case Race::WRLK: return Rect(pt.x, pt.y + 162, 70, 77); - case Race::WZRD: return Rect(pt.x + 304, pt.y + 111, 95, 50); - case Race::NECR: return Rect(pt.x, pt.y, 640, 54); - default: break; - } - break; - - case BUILD_CASTLE: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 0, pt.y + 55, 290, 85); - case Race::BARB: return Rect(pt.x + 0, pt.y + 88, 202, 62); - case Race::SORC: return Rect(pt.x + 0, pt.y + 67, 198, 100); - case Race::WRLK: return Rect(pt.x + 268, pt.y + 35, 131, 129); - case Race::WZRD: return Rect(pt.x, pt.y + 48, 187, 39); - case Race::NECR: return Rect(pt.x + 322, pt.y + 63, 73, 97); - default: break; - } - break; - - case BUILD_CAPTAIN: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 293, pt.y + 109, 48, 27); - case Race::BARB: return Rect(pt.x + 210, pt.y + 104, 40, 35); - case Race::SORC: return Rect(pt.x + 238, pt.y + 136, 32, 34); - case Race::WRLK: return Rect(pt.x + 420, pt.y + 102, 52, 60); - case Race::WZRD: return Rect(pt.x + 210, pt.y + 55, 28, 32); - case Race::NECR: return Rect(pt.x + 423, pt.y + 126, 41, 46); - default: break; - } - break; - - case BUILD_MAGEGUILD1: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 398, pt.y + 150, 58, 30); - case Race::BARB: return Rect(pt.x + 348, pt.y + 118, 50, 25); - case Race::SORC: return Rect(pt.x + 285, pt.y + 32, 55, 129); - case Race::WRLK: return Rect(pt.x + 590, pt.y + 135, 50, 35); - case Race::WZRD: return Rect(pt.x + 583, pt.y + 93, 57, 28); - case Race::NECR: return Rect(pt.x + 565, pt.y + 131, 73, 74); - default: break; - } - break; - - case BUILD_MAGEGUILD2: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 398, pt.y + 128, 58, 52); - case Race::BARB: return Rect(pt.x + 348, pt.y + 94, 50, 49); - case Race::SORC: return Rect(pt.x + 285, pt.y + 32, 55, 129); - case Race::WRLK: return Rect(pt.x + 590, pt.y + 108, 50, 60); - case Race::WZRD: return Rect(pt.x + 585, pt.y + 69, 55, 50); - case Race::NECR: return Rect(pt.x + 568, pt.y + 102, 62, 104); - default: break; - } - break; - - case BUILD_MAGEGUILD3: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 398, pt.y + 105, 58, 75); - case Race::BARB: return Rect(pt.x + 348, pt.y + 72, 50, 72); - case Race::SORC: return Rect(pt.x + 285, pt.y + 32, 55, 129); - case Race::WRLK: return Rect(pt.x + 590, pt.y + 77, 50, 90); - case Race::WZRD: return Rect(pt.x + 585, pt.y + 44, 55, 78); - case Race::NECR: return Rect(pt.x + 570, pt.y + 79, 56, 130); - default: break; - } - break; - - case BUILD_MAGEGUILD4: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 398, pt.y + 85, 58, 95); - case Race::BARB: return Rect(pt.x + 348, pt.y + 48, 50, 96); - case Race::SORC: return Rect(pt.x + 285, pt.y + 32, 55, 129); - case Race::WRLK: return Rect(pt.x + 590, pt.y + 45, 50, 125); - case Race::WZRD: return Rect(pt.x + 585, pt.y + 20, 54, 102); - case Race::NECR: return Rect(pt.x + 570, pt.y + 61, 60, 146); - default: break; - } - break; - - case BUILD_MAGEGUILD5: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 398, pt.y + 55, 58, 125); - case Race::BARB: return Rect(pt.x + 348, pt.y + 20, 50, 124); - case Race::SORC: return Rect(pt.x + 285, pt.y + 32, 55, 129); - case Race::WRLK: return Rect(pt.x + 590, pt.y + 14, 50, 155); - case Race::WZRD: return Rect(pt.x + 585 , pt.y, 57, 122); - case Race::NECR: return Rect(pt.x + 570, pt.y + 45, 61, 162); - default: break; - } - break; - - case BUILD_TENT: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 82, pt.y + 132, 42, 30); - case Race::BARB: return Rect(pt.x + 53, pt.y + 119, 67, 35); - case Race::SORC: return Rect(pt.x + 88, pt.y + 145, 62, 36); - case Race::WRLK: return Rect(pt.x + 308, pt.y + 140, 52, 28); - case Race::WZRD: return Rect(pt.x + 60, pt.y + 68, 46, 33); - case Race::NECR: return Rect(pt.x + 333, pt.y + 131, 49, 51); - default: break; - } - break; - - case DWELLING_MONSTER1: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 195, pt.y + 175, 50, 40); - case Race::BARB: return Rect(pt.x + 258, pt.y + 142, 71, 41); - case Race::SORC: return Rect(pt.x + 478, pt.y + 70, 92, 62); - case Race::WRLK: return Rect(pt.x, pt.y + 63, 68, 53); - case Race::WZRD: return Rect(pt.x + 459, pt.y + 181, 45, 32); - case Race::NECR: return Rect(pt.x + 404, pt.y + 181, 56, 25); - default: break; - } - break; - - case DWELLING_MONSTER2: - case DWELLING_UPGRADE2: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 145, pt.y + 155, 58, 20); - case Race::BARB: return Rect(pt.x + 152, pt.y + 190, 68, 50); - case Race::SORC: return Rect(pt.x + 345, pt.y + 149, 70, 56); - case Race::WRLK: return Rect(pt.x + 248, pt.y + 192, 60, 55); - case Race::WZRD: return Rect(pt.x + 253, pt.y + 69, 90, 29); - case Race::NECR: return Rect(pt.x + 147, pt.y + 184, 92, 32); - default: break; - } - break; - - case DWELLING_MONSTER3: - case DWELLING_UPGRADE3: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 250, pt.y + 177, 70, 50); - case Race::BARB: return Rect(pt.x + 582, pt.y + 81, 58, 40); - case Race::SORC: return Rect(pt.x + 90, pt.y + 180, 56, 21); - case Race::WRLK: return Rect(pt.x + 504, pt.y + 53, 38, 30); - case Race::WZRD: return Rect(pt.x + 156, pt.y + 139, 74, 51); - case Race::NECR: return Rect(pt.x + 108, pt.y + 69, 117, 91); - default: break; - } - break; - - case DWELLING_MONSTER4: - case DWELLING_UPGRADE4: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 328, pt.y + 195, 100, 50); - case Race::BARB: return Rect(pt.x + 509, pt.y + 148, 123, 57); - case Race::SORC: return Rect(pt.x + 208, pt.y + 182, 127, 55); - case Race::WRLK: return Rect(pt.x + 154, pt.y + 168, 171, 36); - case Race::WZRD: return Rect(pt.x + 593, pt.y + 187, 47, 28); - case Race::NECR: return Rect(pt.x, pt.y + 154, 140, 74); - default: break; - } - break; - - case DWELLING_MONSTER5: - case DWELLING_UPGRADE5: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 0, pt.y + 200, 150, 55); - case Race::BARB: return Rect(pt.x + 331, pt.y + 186, 121, 44); - case Race::SORC: return Rect(pt.x + 345, pt.y + 231, 165, 21); - case Race::WRLK: return Rect(pt.x + 149, pt.y + 98, 95, 58); - case Race::WZRD: return Rect(pt.x + 417, pt.y + 25, 35, 140); - case Race::NECR: return Rect(pt.x + 235, pt.y + 136, 53, 70); - default: break; - } - break; - - case DWELLING_MONSTER6: - case DWELLING_UPGRADE6: - case DWELLING_UPGRADE7: - switch(race) - { - case Race::KNGT: return Rect(pt.x + 465, pt.y + 85, 175, 110); - case Race::BARB: return Rect(pt.x + 407, pt.y + 13, 109, 80); - case Race::SORC: return Rect(pt.x + 202, pt.y + 38, 42, 65); - case Race::WRLK: return Rect(pt.x + 98, pt.y + 25, 55, 229); - case Race::WZRD: return Rect(pt.x + 196, pt.y + 7, 129, 38); - case Race::NECR: return Rect(pt.x + 468, pt.y + 112, 92, 78); - default: break; - } - break; - - default: break; - } - - return Rect(); -} - -void Castle::RedrawAnimationBuilding(const Castle & castle, const Point & dst_pt, const std::vector & orders, u32 build) -{ - CastleRedrawCurrentBuilding(castle, dst_pt, orders, build); -} - -void Castle::RedrawAllBuilding(const Castle & castle, const Point & dst_pt, const std::vector & orders) -{ - CastleRedrawCurrentBuilding(castle, dst_pt, orders, BUILD_NOTHING); - CastleRedrawTownName(castle, dst_pt); -} - -void CastleRedrawTownName(const Castle & castle, const Point & dst) -{ - const Sprite & ramka = AGG::GetICN(ICN::TOWNNAME, 0); - Point dst_pt(dst.x + 320 - ramka.w() / 2, dst.y + 248); - Display::Get().Blit(ramka, dst_pt); - - Text text(castle.GetName(), Font::SMALL); - dst_pt.x = dst.x + 320 - text.w() / 2; - dst_pt.y = dst.y + 248; - text.Blit(dst_pt); -} - -void CastleRedrawCurrentBuilding(const Castle & castle, const Point & dst_pt, const std::vector & orders, u32 build) -{ - static u32 frame = 0; - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - - // before redraw - switch(castle.GetRace()) - { - case Race::KNGT: - { - const Sprite & townbkg = AGG::GetICN(ICN::TOWNBKG0, 0); - display.Blit(townbkg, dst_pt); - } - break; - case Race::BARB: - { - const Sprite & townbkg = AGG::GetICN(ICN::TOWNBKG1, 0); - display.Blit(townbkg, dst_pt); - - const Sprite & sprite0 = AGG::GetICN(ICN::TWNBEXT1, 1 + frame % 5); - display.Blit(sprite0, dst_pt.x + sprite0.x(), dst_pt.y + sprite0.y()); - } - break; - case Race::SORC: - { - const Sprite & townbkg = AGG::GetICN(ICN::TOWNBKG2, 0); - display.Blit(townbkg, dst_pt); - } - break; - case Race::WRLK: - { - const Sprite & townbkg = AGG::GetICN(ICN::TOWNBKG3, 0); - display.Blit(townbkg, dst_pt); - } - break; - case Race::WZRD: - { - const Sprite & townbkg = AGG::GetICN(ICN::TOWNBKG4, 0); - display.Blit(townbkg, dst_pt); - } - break; - case Race::NECR: - { - const Sprite & townbkg = AGG::GetICN(ICN::TOWNBKG5, 0); - display.Blit(townbkg, dst_pt); - } - break; - default: break; - } - - // sea anime - if(Race::WZRD == castle.GetRace() || (!castle.isBuild(BUILD_SHIPYARD) && castle.HaveNearlySea())) - { - const Sprite * sprite50 = NULL; - const Sprite * sprite51 = NULL; - - switch(castle.GetRace()) - { - case Race::KNGT: - sprite50 = &AGG::GetICN(ICN::TWNKEXT0, 0); - sprite51 = &AGG::GetICN(ICN::TWNKEXT0, 1 + frame % 5); - break; - case Race::BARB: - sprite50 = &AGG::GetICN(ICN::TWNBEXT0, 0); - sprite51 = &AGG::GetICN(ICN::TWNBEXT0, 1 + frame % 5); - break; - case Race::SORC: - sprite50 = &AGG::GetICN(ICN::TWNSEXT0, 0); - sprite51 = &AGG::GetICN(ICN::TWNSEXT0, 1 + frame % 5); - break; - case Race::NECR: - sprite50 = &AGG::GetICN(ICN::TWNNEXT0, 0); - sprite51 = &AGG::GetICN(ICN::TWNNEXT0, 1 + frame % 5); - break; - case Race::WRLK: - sprite50 = &AGG::GetICN(ICN::TWNWEXT0, 0); - sprite51 = &AGG::GetICN(ICN::TWNWEXT0, 1 + frame % 5); - break; - case Race::WZRD: - sprite50 = &AGG::GetICN(ICN::TWNZEXT0, 0); - sprite51 = &AGG::GetICN(ICN::TWNZEXT0, 1 + frame % 5); - break; - default: - break; - } - - if(sprite50) display.Blit(*sprite50, dst_pt.x + sprite50->x(), dst_pt.y + sprite50->y()); - - if(sprite51) display.Blit(*sprite51, dst_pt.x + sprite51->x(), dst_pt.y + sprite51->y()); - } - - // redraw all builds - if(BUILD_NOTHING == build) - { - for(u8 ii = 0; ii < orders.size(); ++ii) - { - const u32 & build2 = orders[ii]; - - if(castle.isBuild(build2)) - { - CastleRedrawBuilding(castle, dst_pt, build2, frame, 0); - CastleRedrawBuildingExtended(castle, dst_pt, build2, frame); - } - } - } - // redraw build with alpha - else - if(orders.end() != std::find(orders.begin(), orders.end(), build)) - { - LocalEvent & le = LocalEvent::Get(); - u8 alpha = 1; - - while(le.HandleEvents() && alpha < 250) - { - if(Game::AnimateInfrequent(Game::CASTLE_BUILD_DELAY)) - { - cursor.Hide(); - - for(u8 ii = 0; ii < orders.size(); ++ii) - { - const u32 & build2 = orders[ii]; - - if(castle.isBuild(build2)) - { - CastleRedrawBuilding(castle, dst_pt, build2, frame, 0); - CastleRedrawBuildingExtended(castle, dst_pt, build2, frame); - } - else - if(build2 == build) - { - CastleRedrawBuilding(castle, dst_pt, build2, frame, alpha); - CastleRedrawTownName(castle, dst_pt); - alpha += 10; - } - } - - CastleRedrawTownName(castle, dst_pt); - - cursor.Show(); - display.Flip(); - } - ++frame; - } - - cursor.Hide(); - } - - ++frame; -} - -void CastleRedrawBuilding(const Castle & castle, const Point & dst_pt, u32 build, u32 frame, u8 alpha) -{ - Display & display = Display::Get(); - - // correct build - switch(build) - { - case DWELLING_MONSTER2: - case DWELLING_MONSTER3: - case DWELLING_MONSTER4: - case DWELLING_MONSTER5: - case DWELLING_MONSTER6: build = castle.GetActualDwelling(build); break; - - default: break; - } - - const ICN::icn_t icn = Castle::GetICNBuilding(build, castle.GetRace()); - u8 index = 0; - - // correct index - switch(build) - { - case BUILD_MAGEGUILD1: index = 0; break; - case BUILD_MAGEGUILD2: index = Race::NECR == castle.GetRace() ? 6 : 1; break; - case BUILD_MAGEGUILD3: index = Race::NECR == castle.GetRace() ? 12 : 2; break; - case BUILD_MAGEGUILD4: index = Race::NECR == castle.GetRace() ? 18 : 3; break; - case BUILD_MAGEGUILD5: index = Race::NECR == castle.GetRace() ? 24 : 4; break; - default: break; - } - - // simple first sprite - const Sprite & sprite1 = AGG::GetICN(icn, index); - if(alpha) - sprite1.BlitSpriteWithAlpha(display, alpha, dst_pt.x + sprite1.x(), dst_pt.y + sprite1.y()); - else - display.Blit(sprite1, dst_pt.x + sprite1.x(), dst_pt.y + sprite1.y()); - - // second anime sprite - if(const u16 index2 = ICN::AnimationFrame(icn, index, frame)) - { - const Sprite & sprite2 = AGG::GetICN(icn, index2); - if(alpha) - sprite2.BlitSpriteWithAlpha(display, alpha, dst_pt.x + sprite2.x(), dst_pt.y + sprite2.y()); - else - display.Blit(sprite2, dst_pt.x + sprite2.x(), dst_pt.y + sprite2.y()); - } -} - -void CastleRedrawBuildingExtended(const Castle & castle, const Point & dst_pt, u32 build, u32 frame) -{ - Display & display = Display::Get(); - ICN::icn_t icn = Castle::GetICNBuilding(build, castle.GetRace()); - - // shipyard - if(BUILD_SHIPYARD == build) - { - // boat - if(castle.PresentBoat()) - { - const ICN::icn_t icn2 = castle.GetICNBoat(castle.GetRace()); - - const Sprite & sprite40 = AGG::GetICN(icn2, 0); - display.Blit(sprite40, dst_pt.x + sprite40.x(), dst_pt.y + sprite40.y()); - - if(const u16 index2 = ICN::AnimationFrame(icn2, 0, frame)) - { - const Sprite & sprite41 = AGG::GetICN(icn2, index2); - display.Blit(sprite41, dst_pt.x + sprite41.x(), dst_pt.y + sprite41.y()); - } - } - else - { - if(const u16 index2 = ICN::AnimationFrame(icn, 0, frame)) - { - const Sprite & sprite3 = AGG::GetICN(icn, index2); - display.Blit(sprite3, dst_pt.x + sprite3.x(), dst_pt.y + sprite3.y()); - } - } - } - else - // sorc and anime wel2 or statue - if(Race::SORC == castle.GetRace() && BUILD_WEL2 == build) - { - const ICN::icn_t icn2 = castle.isBuild(BUILD_STATUE) ? ICN::TWNSEXT1 : icn; - - const Sprite & sprite20 = AGG::GetICN(icn2, 0); - display.Blit(sprite20, dst_pt.x + sprite20.x(), dst_pt.y + sprite20.y()); - - if(const u16 index2 = ICN::AnimationFrame(icn2, 0, frame)) - { - const Sprite & sprite21 = AGG::GetICN(icn2, index2); - display.Blit(sprite21, dst_pt.x + sprite21.x(), dst_pt.y + sprite21.y()); - } - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/castle_dialog.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/castle_dialog.cpp deleted file mode 100644 index 2c9c8bc36..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/castle_dialog.cpp +++ /dev/null @@ -1,1083 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "agg.h" -#include "button.h" -#include "world.h" -#include "cursor.h" -#include "settings.h" -#include "resource.h" -#include "castle.h" -#include "heroes.h" -#include "payment.h" -#include "profit.h" -#include "kingdom.h" -#include "tools.h" -#include "text.h" -#include "portrait.h" -#include "dialog.h" -#include "statusbar.h" -#include "selectarmybar.h" -#include "pocketpc.h" - -void PackOrdersBuilding(const Castle & castle, std::vector & orders_building) -{ - switch(castle.GetRace()) - { - case Race::KNGT: - orders_building.push_back(BUILD_CASTLE); - orders_building.push_back(BUILD_WEL2); - orders_building.push_back(BUILD_CAPTAIN); - orders_building.push_back(BUILD_LEFTTURRET); - orders_building.push_back(BUILD_RIGHTTURRET); - orders_building.push_back(BUILD_MOAT); - orders_building.push_back(BUILD_MARKETPLACE); - orders_building.push_back(DWELLING_MONSTER2); - orders_building.push_back(BUILD_THIEVESGUILD); - orders_building.push_back(BUILD_TAVERN); - orders_building.push_back(BUILD_MAGEGUILD1); - orders_building.push_back(BUILD_MAGEGUILD2); - orders_building.push_back(BUILD_MAGEGUILD3); - orders_building.push_back(BUILD_MAGEGUILD4); - orders_building.push_back(BUILD_MAGEGUILD5); - orders_building.push_back(DWELLING_MONSTER5); - orders_building.push_back(DWELLING_MONSTER6); - orders_building.push_back(DWELLING_MONSTER1); - orders_building.push_back(DWELLING_MONSTER3); - orders_building.push_back(DWELLING_MONSTER4); - orders_building.push_back(BUILD_WELL); - orders_building.push_back(BUILD_STATUE); - orders_building.push_back(BUILD_SHIPYARD); - break; - case Race::BARB: - orders_building.push_back(BUILD_SPEC); - orders_building.push_back(BUILD_WEL2); - orders_building.push_back(DWELLING_MONSTER6); - orders_building.push_back(BUILD_MAGEGUILD1); - orders_building.push_back(BUILD_MAGEGUILD2); - orders_building.push_back(BUILD_MAGEGUILD3); - orders_building.push_back(BUILD_MAGEGUILD4); - orders_building.push_back(BUILD_MAGEGUILD5); - orders_building.push_back(BUILD_CAPTAIN); - orders_building.push_back(BUILD_CASTLE); - orders_building.push_back(BUILD_LEFTTURRET); - orders_building.push_back(BUILD_RIGHTTURRET); - orders_building.push_back(BUILD_MOAT); - orders_building.push_back(DWELLING_MONSTER3); - orders_building.push_back(BUILD_THIEVESGUILD); - orders_building.push_back(BUILD_TAVERN); - orders_building.push_back(DWELLING_MONSTER1); - orders_building.push_back(BUILD_MARKETPLACE); - orders_building.push_back(DWELLING_MONSTER2); - orders_building.push_back(DWELLING_MONSTER4); - orders_building.push_back(DWELLING_MONSTER5); - orders_building.push_back(BUILD_WELL); - orders_building.push_back(BUILD_STATUE); - orders_building.push_back(BUILD_SHIPYARD); - break; - case Race::SORC: - orders_building.push_back(BUILD_SPEC); - orders_building.push_back(DWELLING_MONSTER6); - orders_building.push_back(BUILD_MAGEGUILD1); - orders_building.push_back(BUILD_MAGEGUILD2); - orders_building.push_back(BUILD_MAGEGUILD3); - orders_building.push_back(BUILD_MAGEGUILD4); - orders_building.push_back(BUILD_MAGEGUILD5); - orders_building.push_back(BUILD_CAPTAIN); - orders_building.push_back(BUILD_CASTLE); - orders_building.push_back(BUILD_LEFTTURRET); - orders_building.push_back(BUILD_RIGHTTURRET); - orders_building.push_back(BUILD_MOAT); - orders_building.push_back(DWELLING_MONSTER3); - orders_building.push_back(BUILD_SHIPYARD); - orders_building.push_back(BUILD_MARKETPLACE); - orders_building.push_back(DWELLING_MONSTER2); - orders_building.push_back(BUILD_THIEVESGUILD); - orders_building.push_back(DWELLING_MONSTER1); - orders_building.push_back(BUILD_TAVERN); - orders_building.push_back(BUILD_STATUE); - orders_building.push_back(BUILD_WEL2); - orders_building.push_back(DWELLING_MONSTER4); - orders_building.push_back(BUILD_WELL); - orders_building.push_back(DWELLING_MONSTER5); - break; - case Race::WRLK: - orders_building.push_back(DWELLING_MONSTER5); - orders_building.push_back(DWELLING_MONSTER3); - orders_building.push_back(BUILD_CASTLE); - orders_building.push_back(BUILD_LEFTTURRET); - orders_building.push_back(BUILD_RIGHTTURRET); - orders_building.push_back(BUILD_CAPTAIN); - orders_building.push_back(BUILD_MOAT); - orders_building.push_back(BUILD_SHIPYARD); - orders_building.push_back(BUILD_MAGEGUILD1); - orders_building.push_back(BUILD_MAGEGUILD2); - orders_building.push_back(BUILD_MAGEGUILD3); - orders_building.push_back(BUILD_MAGEGUILD4); - orders_building.push_back(BUILD_MAGEGUILD5); - orders_building.push_back(BUILD_TAVERN); - orders_building.push_back(BUILD_THIEVESGUILD); - orders_building.push_back(BUILD_MARKETPLACE); - orders_building.push_back(BUILD_STATUE); - orders_building.push_back(DWELLING_MONSTER1); - orders_building.push_back(BUILD_WEL2); - orders_building.push_back(BUILD_SPEC); - orders_building.push_back(DWELLING_MONSTER4); - orders_building.push_back(DWELLING_MONSTER2); - orders_building.push_back(DWELLING_MONSTER6); - orders_building.push_back(BUILD_WELL); - break; - case Race::WZRD: - orders_building.push_back(DWELLING_MONSTER6); - orders_building.push_back(BUILD_CASTLE); - orders_building.push_back(BUILD_LEFTTURRET); - orders_building.push_back(BUILD_RIGHTTURRET); - orders_building.push_back(BUILD_MOAT); - orders_building.push_back(BUILD_CAPTAIN); - orders_building.push_back(DWELLING_MONSTER2); - orders_building.push_back(BUILD_THIEVESGUILD); - orders_building.push_back(BUILD_TAVERN); - orders_building.push_back(BUILD_SHIPYARD); - orders_building.push_back(BUILD_WELL); - orders_building.push_back(BUILD_SPEC); - orders_building.push_back(DWELLING_MONSTER3); - orders_building.push_back(DWELLING_MONSTER5); - orders_building.push_back(BUILD_MAGEGUILD1); - orders_building.push_back(BUILD_MAGEGUILD2); - orders_building.push_back(BUILD_MAGEGUILD3); - orders_building.push_back(BUILD_MAGEGUILD4); - orders_building.push_back(BUILD_MAGEGUILD5); - orders_building.push_back(BUILD_STATUE); - orders_building.push_back(DWELLING_MONSTER1); - orders_building.push_back(DWELLING_MONSTER4); - orders_building.push_back(BUILD_MARKETPLACE); - orders_building.push_back(BUILD_WEL2); - break; - case Race::NECR: - orders_building.push_back(BUILD_SPEC); - if(Settings::Get().PriceLoyaltyVersion()) orders_building.push_back(BUILD_TAVERN); // shrine - orders_building.push_back(BUILD_CASTLE); - orders_building.push_back(BUILD_CAPTAIN); - orders_building.push_back(BUILD_LEFTTURRET); - orders_building.push_back(BUILD_RIGHTTURRET); - orders_building.push_back(DWELLING_MONSTER6); - orders_building.push_back(BUILD_MOAT); - orders_building.push_back(DWELLING_MONSTER1); - orders_building.push_back(BUILD_SHIPYARD); - orders_building.push_back(BUILD_THIEVESGUILD); - orders_building.push_back(BUILD_TAVERN); - orders_building.push_back(DWELLING_MONSTER3); - orders_building.push_back(DWELLING_MONSTER5); - orders_building.push_back(DWELLING_MONSTER2); - orders_building.push_back(DWELLING_MONSTER4); - orders_building.push_back(BUILD_MAGEGUILD1); - orders_building.push_back(BUILD_MAGEGUILD2); - orders_building.push_back(BUILD_MAGEGUILD3); - orders_building.push_back(BUILD_MAGEGUILD4); - orders_building.push_back(BUILD_MAGEGUILD5); - orders_building.push_back(BUILD_WEL2); - orders_building.push_back(BUILD_MARKETPLACE); - orders_building.push_back(BUILD_STATUE); - orders_building.push_back(BUILD_WELL); - break; - default: break; - } -} - -Dialog::answer_t Castle::OpenDialog(bool readonly, bool fade) -{ - Settings & conf = Settings::Get(); - - if(conf.QVGA()) return PocketPC::CastleOpenDialog(*this); - - const bool interface = conf.EvilInterface(); - if(conf.DynamicInterface()) - conf.SetEvilInterface(GetRace() & (Race::BARB | Race::WRLK | Race::NECR)); - - Display & display = Display::Get(); - castle_heroes = GetHeroes(); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Dialog::FrameBorder background; - background.SetPosition((display.w() - 640 - BORDERWIDTH * 2) / 2, (display.h() - 480 - BORDERWIDTH * 2) / 2, 640, 480); - background.Redraw(); - - // fade - if(conf.ExtUseFade()) display.Fade(); - - const Point cur_pt(background.GetArea().x, background.GetArea().y); - Point dst_pt(cur_pt); - - // button prev castle - dst_pt.y += 480 - 19; - Button buttonPrevCastle(dst_pt, ICN::SMALLBAR, 1, 2); - - // bottom small bar - const Sprite & bar = AGG::GetICN(ICN::SMALLBAR, 0); - dst_pt.x += buttonPrevCastle.w; - display.Blit(bar, dst_pt); - - StatusBar statusBar; - statusBar.SetFont(Font::BIG); - statusBar.SetCenter(dst_pt.x + bar.w() / 2, dst_pt.y + 11); - - // button next castle - dst_pt.x += bar.w(); - Button buttonNextCastle(dst_pt, ICN::SMALLBAR, 3, 4); - - // strip grid - dst_pt.x = cur_pt.x; - dst_pt.y = cur_pt.y + 256; - - display.Blit(AGG::GetICN(ICN::STRIP, 0), dst_pt); - - // color crest - const Sprite & crest = AGG::GetICN(ICN::CREST, Color::GetIndex(color)); - - dst_pt.x = cur_pt.x + 5; - dst_pt.y = cur_pt.y + 262; - const Rect rectSign(dst_pt, crest.w(), crest.h()); - std::string str_date = _("Month: %{month}, Week: %{week}, Day: %{day}"); - String::Replace(str_date, "%{month}", world.GetMonth()); - String::Replace(str_date, "%{week}", world.GetWeek()); - String::Replace(str_date, "%{day}", world.GetDay()); - - display.Blit(crest, dst_pt); - - // castle troops selector - dst_pt.x = cur_pt.x + 112; - dst_pt.y = cur_pt.y + 262; - - SelectArmyBar selectCaptainArmy; - selectCaptainArmy.SetArmy(army); - selectCaptainArmy.SetPos(dst_pt); - selectCaptainArmy.SetInterval(6); - selectCaptainArmy.SetBackgroundSprite(AGG::GetICN(ICN::STRIP, 2)); - selectCaptainArmy.SetCursorSprite(AGG::GetICN(ICN::STRIP, 1)); - selectCaptainArmy.SetCastle(*this); - selectCaptainArmy.Redraw(); - - // portrait heroes or captain or sign - dst_pt.x = cur_pt.x + 5; - dst_pt.y = cur_pt.y + 361; - - const Rect rectHeroPortrait(dst_pt.x, dst_pt.y, 100, 92); - - if(castle_heroes) - display.Blit(Portrait::Hero((*castle_heroes), Portrait::BIG), dst_pt); - else - if(isBuild(BUILD_CAPTAIN)) - display.Blit(Portrait::Captain(race, Portrait::BIG), dst_pt); - else - display.Blit(AGG::GetICN(ICN::STRIP, 3), dst_pt); - - // castle_heroes troops background - dst_pt.x = cur_pt.x + 112; - dst_pt.y = cur_pt.y + 361; - - SelectArmyBar selectHeroesArmy; - selectHeroesArmy.SetPos(dst_pt); - selectHeroesArmy.SetInterval(6); - selectHeroesArmy.SetBackgroundSprite(AGG::GetICN(ICN::STRIP, 2)); - selectHeroesArmy.SetCursorSprite(AGG::GetICN(ICN::STRIP, 1)); - selectHeroesArmy.SetSaveLastTroop(); - selectHeroesArmy.SetCastle(*this); - - if(castle_heroes) - { - castle_heroes->MovePointsScaleFixed(); - selectHeroesArmy.SetArmy(castle_heroes->GetArmy()); - selectHeroesArmy.Redraw(); - } - else - display.Blit(AGG::GetICN(ICN::STRIP, 11), dst_pt); - - // resource - RedrawResourcePanel(cur_pt); - - // button exit - dst_pt.x = cur_pt.x + 553; - dst_pt.y = cur_pt.y + 428; - Button buttonExit(dst_pt, ICN::SWAPBTN, 0, 1); - - const Rect coordBuildingThievesGuild(GetCoordBuilding(BUILD_THIEVESGUILD, cur_pt)); - const Rect coordBuildingTavern(GetCoordBuilding(BUILD_TAVERN, cur_pt)); - const Rect coordBuildingShipyard(GetCoordBuilding(BUILD_SHIPYARD, cur_pt)); - const Rect coordBuildingWell(GetCoordBuilding(BUILD_WELL, cur_pt)); - const Rect coordBuildingStatue(GetCoordBuilding(BUILD_STATUE, cur_pt)); - const Rect coordBuildingMarketplace(GetCoordBuilding(BUILD_MARKETPLACE, cur_pt)); - const Rect coordBuildingWel2(GetCoordBuilding(BUILD_WEL2, cur_pt)); - const Rect coordBuildingMoat(GetCoordBuilding(BUILD_MOAT, cur_pt)); - const Rect coordBuildingSpec(GetCoordBuilding(BUILD_SPEC, cur_pt)); - const Rect coordBuildingCastle(GetCoordBuilding(BUILD_CASTLE, cur_pt)); - const Rect coordBuildingCaptain(GetCoordBuilding(BUILD_CAPTAIN, cur_pt)); - const Rect coordBuildingTent(GetCoordBuilding(BUILD_TENT, cur_pt)); - - const Rect coordDwellingMonster1(GetCoordBuilding(DWELLING_MONSTER1, cur_pt)); - const Rect coordDwellingMonster2(GetCoordBuilding(DWELLING_MONSTER2, cur_pt)); - const Rect coordDwellingMonster3(GetCoordBuilding(DWELLING_MONSTER3, cur_pt)); - const Rect coordDwellingMonster4(GetCoordBuilding(DWELLING_MONSTER4, cur_pt)); - const Rect coordDwellingMonster5(GetCoordBuilding(DWELLING_MONSTER5, cur_pt)); - const Rect coordDwellingMonster6(GetCoordBuilding(DWELLING_MONSTER6, cur_pt)); - - // orders draw building - std::vector orders_building; - orders_building.reserve(25); - - PackOrdersBuilding(*this, orders_building); - - // update extra description - payment_t profit; - std::string description_well = GetDescriptionBuilding(BUILD_WELL, race); - std::string description_wel2 = GetDescriptionBuilding(BUILD_WEL2, race); - std::string description_castle = GetDescriptionBuilding(BUILD_CASTLE, race); - std::string description_statue = GetDescriptionBuilding(BUILD_STATUE, race); - std::string description_spec = GetDescriptionBuilding(BUILD_SPEC, race); - String::Replace(description_well, "%{count}", grown_well); - String::Replace(description_wel2, "%{count}", grown_wel2); - profit = ProfitConditions::FromBuilding(BUILD_CASTLE, race); - String::Replace(description_castle, "%{count}", profit.gold); - profit = ProfitConditions::FromBuilding(BUILD_STATUE, race); - String::Replace(description_statue, "%{count}", profit.gold); - profit = ProfitConditions::FromBuilding(BUILD_SPEC, race); - String::Replace(description_spec, "%{count}", profit.gold); - - // draw building - RedrawAllBuilding(*this, cur_pt, orders_building); - - if(2 > world.GetMyKingdom().GetCastles().size() || readonly) - { - buttonPrevCastle.Press(); - buttonPrevCastle.SetDisable(true); - - buttonNextCastle.Press(); - buttonNextCastle.SetDisable(true); - } - - buttonPrevCastle.Draw(); - buttonNextCastle.Draw(); - buttonExit.Draw(); - - Mixer::Reset(); - AGG::PlayMusic(MUS::FromRace(race)); - - LocalEvent & le = LocalEvent::Get(); - - cursor.Show(); - - display.Flip(); - - Dialog::answer_t result = Dialog::ZERO; - - bool army_redraw = false; - - // dialog menu loop - while(le.HandleEvents()) - { - // exit - if(le.MouseClickLeft(buttonExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)){ result = Dialog::CANCEL; break; } - - if(buttonPrevCastle.isEnable()) le.MousePressLeft(buttonPrevCastle) ? buttonPrevCastle.PressDraw() : buttonPrevCastle.ReleaseDraw(); - if(buttonNextCastle.isEnable()) le.MousePressLeft(buttonNextCastle) ? buttonNextCastle.PressDraw() : buttonNextCastle.ReleaseDraw(); - - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - - // selector troops event - if(castle_heroes && selectHeroesArmy.isValid()) - { - if(le.MouseCursor(selectCaptainArmy.GetArea()) || le.MouseCursor(selectHeroesArmy.GetArea())) - SelectArmyBar::QueueEventProcessing(selectCaptainArmy, selectHeroesArmy); - } - else - { - if(le.MouseCursor(selectCaptainArmy.GetArea())) - SelectArmyBar::QueueEventProcessing(selectCaptainArmy); - } - - // view hero - if(!readonly && castle_heroes && le.MouseClickLeft(rectHeroPortrait)) - { - const std::vector & myHeroes = world.GetMyKingdom().GetHeroes(); - Dialog::answer_t result = Dialog::ZERO; - - std::vector::const_iterator it = std::find(myHeroes.begin(), myHeroes.end(), castle_heroes); - bool need_fade = (640 == display.w() && 480 == display.h()); - - while(Dialog::CANCEL != result) - { - Display::Get().Flip(); - cursor.Hide(); - - result = (*it)->OpenDialog(false, need_fade); - if(need_fade) need_fade = false; - - switch(result) - { - case Dialog::PREV: - if(it == myHeroes.begin()) it = myHeroes.end(); - --it; - break; - - case Dialog::NEXT: - ++it; - if(it == myHeroes.end()) it = myHeroes.begin(); - break; - - default: break; - } - cursor.Show(); - } - - cursor.Hide(); - if(selectCaptainArmy.isSelected()) selectCaptainArmy.Reset(); - if(selectHeroesArmy.isSelected()) selectHeroesArmy.Reset(); - selectHeroesArmy.Redraw(); - cursor.Show(); - display.Flip(); - } - - // prev castle - if(buttonPrevCastle.isEnable() && le.MouseClickLeft(buttonPrevCastle)){ result = Dialog::PREV; break; } - else - // next castle - if(buttonNextCastle.isEnable() && le.MouseClickLeft(buttonNextCastle)){ result = Dialog::NEXT; break; } - else - // left click building - if((building & BUILD_THIEVESGUILD) && le.MouseClickLeft(coordBuildingThievesGuild)) - Dialog::ThievesGuild(false); - else - if((building & BUILD_TAVERN) && le.MouseClickLeft(coordBuildingTavern)) - { - if(Race::NECR == race && conf.PriceLoyaltyVersion()) - Dialog::Message(GetStringBuilding(BUILD_TAVERN, race), GetDescriptionBuilding(BUILD_TAVERN, race), Font::BIG, Dialog::OK); - else - OpenTavern(); - } - else - if(!readonly && (building & BUILD_SHIPYARD) && le.MouseClickLeft(coordBuildingShipyard)) - { - cursor.Hide(); - - if(Dialog::OK == Dialog::BuyBoat(AllowBuyBoat())) - { - BuyBoat(); - RedrawResourcePanel(cur_pt); - // RedrawResourcePanel destroy sprite buttonExit - if(buttonExit.isPressed()) buttonExit.Draw(); - } - cursor.Show(); - display.Flip(); - } - else - if((building & BUILD_WELL) && le.MouseClickLeft(coordBuildingWell)) - { - if(readonly) - Dialog::Message(GetStringBuilding(BUILD_WELL, race), description_well, Font::BIG, Dialog::OK); - else - { - OpenWell(); - army_redraw = true; - } - } - else - if((building & BUILD_STATUE) && le.MouseClickLeft(coordBuildingStatue)) - Dialog::Message(GetStringBuilding(BUILD_STATUE), description_statue, Font::BIG, Dialog::OK); - else - if((building & BUILD_MARKETPLACE) && le.MouseClickLeft(coordBuildingMarketplace)) - { - if(readonly) - Dialog::Message(GetStringBuilding(BUILD_MARKETPLACE, race), GetDescriptionBuilding(BUILD_MARKETPLACE), Font::BIG, Dialog::OK); - else - { - cursor.Hide(); - Dialog::Marketplace(); - cursor.Show(); - display.Flip(); - RedrawResourcePanel(cur_pt); - // RedrawResourcePanel destroy sprite buttonExit - if(buttonExit.isPressed()) buttonExit.Draw(); - } - } - else - if((building & BUILD_WEL2) && le.MouseClickLeft(coordBuildingWel2)) - Dialog::Message(GetStringBuilding(BUILD_WEL2, race), description_wel2, Font::BIG, Dialog::OK); - else - if((building & BUILD_MOAT) && le.MouseClickLeft(coordBuildingMoat)) - Dialog::Message(GetStringBuilding(BUILD_MOAT), GetDescriptionBuilding(BUILD_MOAT), Font::BIG, Dialog::OK); - else - if((building & BUILD_SPEC) && le.MouseClickLeft(coordBuildingSpec)) - Dialog::Message(GetStringBuilding(BUILD_SPEC, race), description_spec, Font::BIG, Dialog::OK); - else - if(readonly && - (((building & BUILD_CASTLE) && le.MouseClickLeft(coordBuildingCastle)) || - (!(building & BUILD_CASTLE) && le.MouseClickLeft(coordBuildingTent)))) - Dialog::Message(GetStringBuilding(BUILD_CASTLE, race), description_castle, Font::BIG, Dialog::OK); - else - if(building & BUILD_CASTLE && le.MouseClickLeft(coordBuildingCastle)) - { - const Heroes * prev = castle_heroes; - const u32 build = OpenTown(); - const bool buyhero = ((castle_heroes != prev) && (castle_heroes != NULL)); - - if(BUILD_NOTHING != build) - { - cursor.Hide(); - - if(selectCaptainArmy.isSelected()) selectCaptainArmy.Reset(); - - // play sound - AGG::PlaySound(M82::BUILDTWN); - - RedrawAnimationBuilding(*this, cur_pt, orders_building, build); - BuyBuilding(build); - RedrawResourcePanel(cur_pt); - - if(BUILD_CAPTAIN == build && ! castle_heroes) - display.Blit(Portrait::Captain(race, Portrait::BIG), cur_pt.x + 5, cur_pt.y + 361); - - // RedrawResourcePanel destroy sprite buttonExit - if(buttonExit.isPressed()) buttonExit.Draw(); - - cursor.Show(); - display.Flip(); - } - - if(castle_heroes) - { - cursor.Hide(); - - if(selectHeroesArmy.isSelected()) selectHeroesArmy.Reset(); - - if(buyhero) - { - const Rect rt(0, 98, 552, 107); - Surface sf(rt.w, rt.h); - sf.SetColorKey(); - sf.Blit(AGG::GetICN(ICN::STRIP, 0), rt, 0, 0); - const Surface & port = Portrait::Hero((*castle_heroes), Portrait::BIG); - sf.Blit(port, 6, 6); - selectHeroesArmy.SetArmy(castle_heroes->GetArmy()); - selectHeroesArmy.SetPos(112, 5); - selectHeroesArmy.Redraw(sf); - selectHeroesArmy.SetPos(cur_pt.x + 112, cur_pt.y + 361); - - AGG::PlaySound(M82::BUILDTWN); - RedrawResourcePanel(cur_pt); - - LocalEvent & le = LocalEvent::Get(); - u8 alpha = 0; - - while(le.HandleEvents() && alpha < 250) - { - if(Game::AnimateInfrequent(Game::CASTLE_BUYHERO_DELAY)) - { - cursor.Hide(); - sf.SetAlpha(alpha); - display.Blit(sf, cur_pt.x, cur_pt.y + 356); - cursor.Show(); - display.Flip(); - alpha += 10; - } - } - - cursor.Hide(); - display.Blit(AGG::GetICN(ICN::STRIP, 0), cur_pt.x, cur_pt.y + 256); - display.Blit(Portrait::Hero((*castle_heroes), Portrait::BIG), cur_pt.x + 5, cur_pt.y + 361); - selectHeroesArmy.Redraw(); - } - - cursor.Show(); - display.Flip(); - } - } - else - // buy castle - if(!(building & BUILD_CASTLE) && le.MouseClickLeft(coordBuildingTent)) - { - if(!Modes(ALLOWCASTLE)) - { - Dialog::Message(_("Town"), _("This town may not be upgraded to a castle."), Font::BIG, Dialog::OK); - } - else - if(Dialog::OK == DialogBuyCastle(true)) - { - cursor.Hide(); - - // play sound - AGG::PlaySound(M82::BUILDTWN); - - RedrawAnimationBuilding(*this, cur_pt, orders_building, BUILD_CASTLE); - BuyBuilding(BUILD_CASTLE); - RedrawResourcePanel(cur_pt); - - // RedrawResourcePanel destroy sprite buttonExit - if(buttonExit.isPressed()) buttonExit.Draw(); - - cursor.Show(); - display.Flip(); - } - } - else - // captain - if((building & BUILD_CAPTAIN) && le.MouseClickLeft(coordBuildingCaptain)) - Dialog::Message(GetStringBuilding(BUILD_CAPTAIN), GetDescriptionBuilding(BUILD_CAPTAIN), Font::BIG, Dialog::OK); - else - // left click mage guild - if((building & (BUILD_MAGEGUILD5 | BUILD_MAGEGUILD4 | BUILD_MAGEGUILD3 | BUILD_MAGEGUILD2 | BUILD_MAGEGUILD1)) && - le.MouseClickLeft(GetCoordBuilding(BUILD_MAGEGUILD5, cur_pt))) - { - // buy spell book - if(!castle_heroes || (*castle_heroes).HasArtifact(Artifact::MAGIC_BOOK)) - OpenMageGuild(); - else - if((*castle_heroes).BuySpellBook(&mageguild)) - army_redraw = true; - } - else - // left click dwelling monster - if(!readonly && (building & DWELLING_MONSTER1) && le.MouseClickLeft(coordDwellingMonster1) && - Castle::RecruitMonster(DWELLING_MONSTER1, Dialog::RecruitMonster(Monster(race, DWELLING_MONSTER1), dwelling[0]))) - army_redraw = true; - else - if(!readonly && (building & DWELLING_MONSTER2) && le.MouseClickLeft(coordDwellingMonster2) && - Castle::RecruitMonster(DWELLING_MONSTER2, Dialog::RecruitMonster(Monster(race, GetActualDwelling(DWELLING_MONSTER2)), dwelling[1]))) - army_redraw = true; - else - if(!readonly && (building & DWELLING_MONSTER3) && le.MouseClickLeft(coordDwellingMonster3) && - Castle::RecruitMonster(DWELLING_MONSTER3, Dialog::RecruitMonster(Monster(race, GetActualDwelling(DWELLING_MONSTER3)), dwelling[2]))) - army_redraw = true; - else - if(!readonly && (building & DWELLING_MONSTER4) && le.MouseClickLeft(coordDwellingMonster4) && - Castle::RecruitMonster(DWELLING_MONSTER4, Dialog::RecruitMonster(Monster(race, GetActualDwelling(DWELLING_MONSTER4)), dwelling[3]))) - army_redraw = true; - else - if(!readonly && (building & DWELLING_MONSTER5) && le.MouseClickLeft(coordDwellingMonster5) && - Castle::RecruitMonster(DWELLING_MONSTER5, Dialog::RecruitMonster(Monster(race, GetActualDwelling(DWELLING_MONSTER5)), dwelling[4]))) - army_redraw = true; - else - if(!readonly && (building & DWELLING_MONSTER6) && le.MouseClickLeft(coordDwellingMonster6) && - Castle::RecruitMonster(DWELLING_MONSTER6, Dialog::RecruitMonster(Monster(race, GetActualDwelling(DWELLING_MONSTER6)), dwelling[5]))) - army_redraw = true; - - if(army_redraw) - { - cursor.Hide(); - selectCaptainArmy.Redraw(); - RedrawResourcePanel(cur_pt); - // RedrawResourcePanel destroy sprite buttonExit - if(buttonExit.isPressed()) buttonExit.Draw(); - cursor.Show(); - display.Flip(); - army_redraw = false; - } - - // right press building - if(building & BUILD_THIEVESGUILD && le.MousePressRight(coordBuildingThievesGuild)) Dialog::Message(GetStringBuilding(BUILD_THIEVESGUILD), GetDescriptionBuilding(BUILD_THIEVESGUILD), Font::BIG); - else - if(building & BUILD_TAVERN && le.MousePressRight(coordBuildingTavern)) Dialog::Message(GetStringBuilding(BUILD_TAVERN, race), GetDescriptionBuilding(BUILD_TAVERN, race), Font::BIG); - else - if(building & BUILD_SHIPYARD && le.MousePressRight(coordBuildingShipyard)) Dialog::Message(GetStringBuilding(BUILD_SHIPYARD), GetDescriptionBuilding(BUILD_SHIPYARD), Font::BIG); - else - if(building & BUILD_WELL && le.MousePressRight(coordBuildingWell)) Dialog::Message(GetStringBuilding(BUILD_WELL), description_well, Font::BIG); - else - if(building & BUILD_STATUE && le.MousePressRight(coordBuildingStatue)) Dialog::Message(GetStringBuilding(BUILD_STATUE), description_statue, Font::BIG); - else - if(building & BUILD_MARKETPLACE && le.MousePressRight(coordBuildingMarketplace)) Dialog::Message(GetStringBuilding(BUILD_MARKETPLACE), GetDescriptionBuilding(BUILD_MARKETPLACE), Font::BIG); - else - if(building & BUILD_WEL2 && le.MousePressRight(coordBuildingWel2)) Dialog::Message(GetStringBuilding(BUILD_WEL2, race), description_wel2, Font::BIG); - else - if(building & BUILD_MOAT && le.MousePressRight(coordBuildingMoat)) Dialog::Message(GetStringBuilding(BUILD_MOAT), GetDescriptionBuilding(BUILD_MOAT), Font::BIG); - else - if(building & BUILD_SPEC && le.MousePressRight(coordBuildingSpec)) Dialog::Message(GetStringBuilding(BUILD_SPEC, race), description_spec, Font::BIG); - else - if(building & BUILD_CASTLE && le.MousePressRight(coordBuildingCastle)) Dialog::Message(GetStringBuilding(BUILD_CASTLE), description_castle, Font::BIG); - else - if(!(building & BUILD_CASTLE) && le.MousePressRight(coordBuildingTent)) Dialog::Message(GetStringBuilding(BUILD_TENT), GetDescriptionBuilding(BUILD_TENT), Font::BIG); - else - if(building & BUILD_CAPTAIN && le.MousePressRight(coordBuildingCaptain)) Dialog::Message(GetStringBuilding(BUILD_CAPTAIN), GetDescriptionBuilding(BUILD_CAPTAIN), Font::BIG); - else - // right press mage guild - if(building & (BUILD_MAGEGUILD5 | BUILD_MAGEGUILD4 | BUILD_MAGEGUILD3 | BUILD_MAGEGUILD2 | BUILD_MAGEGUILD1) && - le.MousePressRight(GetCoordBuilding(BUILD_MAGEGUILD5, cur_pt))) Dialog::Message(GetStringBuilding(BUILD_MAGEGUILD1), GetDescriptionBuilding(BUILD_MAGEGUILD1), Font::BIG); - else - // right press dwelling monster - if(building & DWELLING_MONSTER1 && le.MousePressRight(coordDwellingMonster1)) - Dialog::DwellingInfo(Monster(race, DWELLING_MONSTER1), dwelling[0]); - else - if(building & DWELLING_MONSTER2 && le.MousePressRight(coordDwellingMonster2)) - Dialog::DwellingInfo(Monster(race, GetActualDwelling(DWELLING_MONSTER2)), dwelling[1]); - else - if(building & DWELLING_MONSTER3 && le.MousePressRight(coordDwellingMonster3)) - Dialog::DwellingInfo(Monster(race, GetActualDwelling(DWELLING_MONSTER3)), dwelling[2]); - else - if(building & DWELLING_MONSTER4 && le.MousePressRight(coordDwellingMonster4)) - Dialog::DwellingInfo(Monster(race, GetActualDwelling(DWELLING_MONSTER4)), dwelling[3]); - else - if(building & DWELLING_MONSTER5 && le.MousePressRight(coordDwellingMonster5)) - Dialog::DwellingInfo(Monster(race, GetActualDwelling(DWELLING_MONSTER5)), dwelling[4]); - else - if(building & DWELLING_MONSTER6 && le.MousePressRight(coordDwellingMonster6)) - Dialog::DwellingInfo(Monster(race, GetActualDwelling(DWELLING_MONSTER6)), dwelling[5]); - - // status message exit - if(le.MouseCursor(buttonExit)) statusBar.ShowMessage(isCastle() ? _("Exit castle") : _("Exit town")); - else - // status message prev castle - if(le.MouseCursor(buttonPrevCastle)) statusBar.ShowMessage(_("Show previous town")); - else - // status message next castle - if(le.MouseCursor(buttonNextCastle)) statusBar.ShowMessage(_("Show next town")); - else - // status message over sign - if(le.MouseCursor(rectSign)) statusBar.ShowMessage(str_date); - else - // status message view hero - if(castle_heroes && le.MouseCursor(rectHeroPortrait)) statusBar.ShowMessage(_("View Hero")); - else - // building - if(building & BUILD_THIEVESGUILD && le.MouseCursor(coordBuildingThievesGuild)) statusBar.ShowMessage(GetStringBuilding(BUILD_THIEVESGUILD)); - else - if(building & BUILD_TAVERN && le.MouseCursor(coordBuildingTavern)) statusBar.ShowMessage(GetStringBuilding(BUILD_TAVERN, race)); - else - if(building & BUILD_SHIPYARD && le.MouseCursor(coordBuildingShipyard)) statusBar.ShowMessage(GetStringBuilding(BUILD_SHIPYARD)); - else - if(building & BUILD_WELL && le.MouseCursor(coordBuildingWell)) statusBar.ShowMessage(GetStringBuilding(BUILD_WELL)); - else - if(building & BUILD_STATUE && le.MouseCursor(coordBuildingStatue)) statusBar.ShowMessage(GetStringBuilding(BUILD_STATUE)); - else - if(building & BUILD_MARKETPLACE && le.MouseCursor(coordBuildingMarketplace)) statusBar.ShowMessage(GetStringBuilding(BUILD_MARKETPLACE)); - else - if(building & BUILD_WEL2 && le.MouseCursor(coordBuildingWel2)) statusBar.ShowMessage(GetStringBuilding(BUILD_WEL2, race)); - else - if(building & BUILD_MOAT && le.MouseCursor(coordBuildingMoat)) statusBar.ShowMessage(GetStringBuilding(BUILD_MOAT)); - else - if(building & BUILD_SPEC && le.MouseCursor(coordBuildingSpec)) statusBar.ShowMessage(GetStringBuilding(BUILD_SPEC, race)); - else - if(building & BUILD_CASTLE && le.MouseCursor(coordBuildingCastle)) statusBar.ShowMessage(GetStringBuilding(BUILD_CASTLE)); - else - if(!(building & BUILD_CASTLE) && le.MouseCursor(coordBuildingTent)) statusBar.ShowMessage(GetStringBuilding(BUILD_TENT)); - else - if(building & BUILD_CAPTAIN && le.MouseCursor(coordBuildingCaptain)) statusBar.ShowMessage(GetStringBuilding(BUILD_CAPTAIN)); - else - // mage guild - if(building & BUILD_MAGEGUILD5 && le.MouseCursor(GetCoordBuilding(BUILD_MAGEGUILD5, cur_pt))) statusBar.ShowMessage(GetStringBuilding(BUILD_MAGEGUILD5)); - else - if(building & BUILD_MAGEGUILD4 && le.MouseCursor(GetCoordBuilding(BUILD_MAGEGUILD4, cur_pt))) statusBar.ShowMessage(GetStringBuilding(BUILD_MAGEGUILD4)); - else - if(building & BUILD_MAGEGUILD3 && le.MouseCursor(GetCoordBuilding(BUILD_MAGEGUILD3, cur_pt))) statusBar.ShowMessage(GetStringBuilding(BUILD_MAGEGUILD3)); - else - if(building & BUILD_MAGEGUILD2 && le.MouseCursor(GetCoordBuilding(BUILD_MAGEGUILD2, cur_pt))) statusBar.ShowMessage(GetStringBuilding(BUILD_MAGEGUILD2)); - else - if(building & BUILD_MAGEGUILD1 && le.MouseCursor(GetCoordBuilding(BUILD_MAGEGUILD1, cur_pt))) statusBar.ShowMessage(GetStringBuilding(BUILD_MAGEGUILD1)); - else - // dwelling monster - if(building & DWELLING_MONSTER1 && le.MouseCursor(coordDwellingMonster1)) statusBar.ShowMessage(Monster(race, DWELLING_MONSTER1).GetName()); - else - if(building & DWELLING_MONSTER2 && le.MouseCursor(coordDwellingMonster2)) statusBar.ShowMessage(Monster(race, DWELLING_UPGRADE2 & building ? DWELLING_UPGRADE2 : DWELLING_MONSTER2).GetName()); - else - if(building & DWELLING_MONSTER3 && le.MouseCursor(coordDwellingMonster3)) statusBar.ShowMessage(Monster(race, DWELLING_UPGRADE3 & building ? DWELLING_UPGRADE3 : DWELLING_MONSTER3).GetName()); - else - if(building & DWELLING_MONSTER4 && le.MouseCursor(coordDwellingMonster4)) statusBar.ShowMessage(Monster(race, DWELLING_UPGRADE4 & building ? DWELLING_UPGRADE4 : DWELLING_MONSTER4).GetName()); - else - if(building & DWELLING_MONSTER5 && le.MouseCursor(coordDwellingMonster5)) statusBar.ShowMessage(Monster(race, DWELLING_UPGRADE5 & building ? DWELLING_UPGRADE5 : DWELLING_MONSTER5).GetName()); - else - if(building & DWELLING_MONSTER6 && le.MouseCursor(coordDwellingMonster6)) statusBar.ShowMessage(Monster(race, DWELLING_UPGRADE6 & building ? (DWELLING_UPGRADE7 & building ? DWELLING_UPGRADE7 : DWELLING_UPGRADE6) : DWELLING_MONSTER6).GetName()); - else - // status message over castle troops - if(le.MouseCursor(selectCaptainArmy.GetArea())) - { - const s8 index1 = selectCaptainArmy.GetIndexFromCoord(le.GetMouseCursor()); - if(0 <= index1) - { - const Army::Troop & troop1 = army.At(index1); - const std::string & monster1 = troop1.GetName(); - std::string str; - - if(selectCaptainArmy.isSelected()) - { - const u8 index2 = selectCaptainArmy.Selected(); - const Army::Troop & troop2 = army.At(index2); - const std::string & monster2 = troop2.GetName(); - - if(index1 == index2) - { - str = _("View %{name}"); - String::Replace(str, "%{name}", monster1); - } - else - if(troop1.isValid() && troop2.isValid()) - { - str = troop1() == troop2() ? _("Combine %{name} armies") : _("Exchange %{name2} with %{name}"); - String::Replace(str, "%{name}", monster1); - String::Replace(str, "%{name2}", monster2); - } - else - { - str = _("Move and right click Redistribute %{name}"); - String::Replace(str, "%{name}", monster2); - } - } - else - if(castle_heroes && selectHeroesArmy.isSelected()) - { - const u8 index2 = selectHeroesArmy.Selected(); - const Army::Troop & troop2 = castle_heroes->GetArmy().At(index2); - const std::string & monster2 = troop2.GetName(); - - if(selectHeroesArmy.SaveLastTroop() && !troop1.isValid()) - str = _("Cannot move last army to garrison"); - else - if(troop1.isValid() && troop2.isValid()) - { - str = troop1() == troop2() ? _("Combine %{name} armies") : _("Exchange %{name2} with %{name}"); - String::Replace(str, "%{name}", monster1); - String::Replace(str, "%{name2}", monster2); - } - else - { - str = _("Move and right click Redistribute %{name}"); - String::Replace(str, "%{name}", monster2); - } - } - else - if(troop1.isValid()) - { - str = _("Select %{name}"); - String::Replace(str, "%{name}", monster1); - } - else - str = _("Empty"); - - statusBar.ShowMessage(str); - } - } - else - // status message over castle_heroes troops - if(castle_heroes && le.MouseCursor(selectHeroesArmy.GetArea())) - { - const s8 index1 = selectHeroesArmy.GetIndexFromCoord(le.GetMouseCursor()); - if(0 <= index1) - { - const Army::Troop & troop1 = castle_heroes->GetArmy().At(index1); - const std::string & monster1 = troop1.GetName(); - std::string str; - - if(selectHeroesArmy.isSelected()) - { - const u8 index2 = selectHeroesArmy.Selected(); - const Army::Troop & troop2 = castle_heroes->GetArmy().At(index2); - const std::string & monster2 = troop2.GetName(); - - if(index1 == index2) - { - str = _("View %{name}"); - String::Replace(str, "%{name}", monster1); - } - else - if(troop1.isValid() && troop2.isValid()) - { - str = troop1() == troop2() ? _("Combine %{name} armies") : _("Exchange %{name2} with %{name}"); - String::Replace(str, "%{name}", monster1); - String::Replace(str, "%{name2}", monster2); - } - else - { - str = _("Move and right click Redistribute %{name}"); - String::Replace(str, "%{name}", monster2); - } - } - else - if(selectCaptainArmy.isSelected()) - { - const u8 index2 = selectCaptainArmy.Selected(); - const Army::Troop & troop2 = army.At(index2); - const std::string & monster2 = troop2.GetName(); - - if(troop1.isValid() && troop2.isValid()) - { - str = troop1() == troop2() ? _("Combine %{name} armies") : _("Exchange %{name2} with %{name}"); - String::Replace(str, "%{name}", monster1); - String::Replace(str, "%{name2}", monster2); - } - else - { - str = _("Move and right click Redistribute %{name}"); - String::Replace(str, "%{name}", monster2); - } - } - else - if(troop1.isValid()) - { - str = _("Select %{name}"); - String::Replace(str, "%{name}", monster1); - } - else - str = _("Empty"); - - statusBar.ShowMessage(str); - } - } - else - { - std::string str; - str = _("Empty"); - statusBar.ShowMessage(str); - } - - // animation sprite - if(Game::AnimateInfrequent(Game::CASTLE_AROUND_DELAY)) - { - cursor.Hide(); - RedrawAllBuilding(*this, cur_pt, orders_building); - cursor.Show(); - display.Flip(); - } - } - - if(castle_heroes && conf.ExtHeroRecalculateMovement()) - castle_heroes->RecalculateMovePoints(); - - if(conf.DynamicInterface()) - conf.SetEvilInterface(interface); - - return result; -} - -/* redraw resource info panel */ -void Castle::RedrawResourcePanel(const Point & pt) -{ - Display & display = Display::Get(); - const Resource::funds_t & resource = world.GetMyKingdom().GetFundsResource(); - - Point dst_pt = pt; - - Rect src_rt(dst_pt.x + 552, dst_pt.y + 262, 82, 192); - display.FillRect(0, 0, 0, src_rt); - - std::string count; - Text text; - - // sprite wood - dst_pt.x = src_rt.x + 1; - dst_pt.y = src_rt.y + 10; - const Sprite & wood = AGG::GetICN(ICN::RESOURCE, 0); - display.Blit(wood, dst_pt); - - // count wood - count.erase(); - String::AddInt(count, resource.wood); - text.Set(count, Font::SMALL); - dst_pt.y += 22; - text.Blit(dst_pt.x + (wood.w() - text.w()) / 2, dst_pt.y); - - // sprite sulfur - dst_pt.x = src_rt.x + 42; - dst_pt.y = src_rt.y + 6; - const Sprite & sulfur = AGG::GetICN(ICN::RESOURCE, 3); - display.Blit(sulfur, dst_pt); - - // count sulfur - count.erase(); - String::AddInt(count, resource.sulfur); - text.Set(count); - dst_pt.y += 26; - text.Blit(dst_pt.x + (sulfur.w() - text.w()) / 2, dst_pt.y); - - // sprite crystal - dst_pt.x = src_rt.x + 1; - dst_pt.y = src_rt.y + 45; - const Sprite & crystal = AGG::GetICN(ICN::RESOURCE, 4); - display.Blit(crystal, dst_pt); - - // count crystal - count.erase(); - String::AddInt(count, resource.crystal); - text.Set(count); - dst_pt.y += 33; - text.Blit(dst_pt.x + (crystal.w() - text.w()) / 2, dst_pt.y); - - // sprite mercury - dst_pt.x = src_rt.x + 44; - dst_pt.y = src_rt.y + 47; - const Sprite & mercury = AGG::GetICN(ICN::RESOURCE, 1); - display.Blit(mercury, dst_pt); - - // count mercury - count.erase(); - String::AddInt(count, resource.mercury); - text.Set(count); - dst_pt.y += 34; - text.Blit(dst_pt.x + (mercury.w() - text.w()) / 2, dst_pt.y); - - // sprite ore - dst_pt.x = src_rt.x + 1; - dst_pt.y = src_rt.y + 92; - const Sprite & ore = AGG::GetICN(ICN::RESOURCE, 2); - display.Blit(ore, dst_pt); - - // count ore - count.erase(); - String::AddInt(count, resource.ore); - text.Set(count); - dst_pt.y += 26; - text.Blit(dst_pt.x + (ore.w() - text.w()) / 2, dst_pt.y); - - // sprite gems - dst_pt.x = src_rt.x + 45; - dst_pt.y = src_rt.y + 92; - const Sprite & gems = AGG::GetICN(ICN::RESOURCE, 5); - display.Blit(gems, dst_pt); - - // count gems - count.erase(); - String::AddInt(count, resource.gems); - text.Set(count); - dst_pt.y += 26; - text.Blit(dst_pt.x + (gems.w() - text.w()) / 2, dst_pt.y); - - // sprite gold - dst_pt.x = src_rt.x + 6; - dst_pt.y = src_rt.y + 130; - const Sprite & gold = AGG::GetICN(ICN::RESOURCE, 6); - display.Blit(gold, dst_pt); - - // count gold - count.erase(); - String::AddInt(count, resource.gold); - text.Set(count); - dst_pt.y += 24; - text.Blit(dst_pt.x + (gold.w() - text.w()) / 2, dst_pt.y); - - // sprite button exit - dst_pt.x = src_rt.x + 1; - dst_pt.y = src_rt.y + 166; - const Sprite & exit = AGG::GetICN(ICN::SWAPBTN, 0); - display.Blit(exit, dst_pt); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/castle_mageguild.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/castle_mageguild.cpp deleted file mode 100644 index 83ec3fcab..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/castle_mageguild.cpp +++ /dev/null @@ -1,220 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "castle.h" -#include "settings.h" -#include "mageguild.h" -#include "text.h" - -RowSpells::RowSpells(const Point & pos, const MageGuild & guild, u8 lvl) -{ - bool hide = guild.GetLevel() < lvl; - const Sprite & roll_show = AGG::GetICN(ICN::TOWNWIND, 0); - const Sprite & roll_hide = AGG::GetICN(ICN::TOWNWIND, 1); - const Sprite & roll = (hide ? roll_hide : roll_show); - - u8 count = 0; - - switch(lvl) - { - case 1: - case 2: count = 3; break; - case 3: - case 4: count = 2; break; - case 5: count = 1; break; - default: break; - } - - for(u8 ii = 0; ii < count; ++ii) - coords.push_back(Rect(pos.x + coords.size() * (Settings::Get().QVGA() ? 72 : 110) - roll.w() / 2, pos.y, roll.w(), roll.h())); - - if(guild.HaveLibraryCapability()) - { - if(! hide && guild.isLibraryBuild()) - coords.push_back(Rect(pos.x + coords.size() * (Settings::Get().QVGA() ? 72 : 110) - roll_show.w() / 2, pos.y, roll_show.w(), roll_show.h())); - else - coords.push_back(Rect(pos.x + coords.size() * (Settings::Get().QVGA() ? 72 : 110) - roll_hide.w() / 2, pos.y, roll_hide.w(), roll_hide.h())); - } - - guild.GetSpells(spells, lvl); - spells.resize(coords.size(), Spell::NONE); -} - -void RowSpells::Redraw(void) -{ - const Sprite & roll_show = AGG::GetICN(ICN::TOWNWIND, 0); - const Sprite & roll_hide = AGG::GetICN(ICN::TOWNWIND, 1); - - Display & display = Display::Get(); - - std::vector::const_iterator it1 = coords.begin(); - std::vector::const_iterator it2 = coords.end(); - - for(; it1 != it2; ++it1) - { - const Rect & dst = (*it1); - const Spell::spell_t & spell = spells[it1 - coords.begin()]; - - // roll hide - if(dst.w < roll_show.w() || Spell::NONE == spell) - { - display.Blit(roll_hide, dst); - } - // roll show - else - { - display.Blit(roll_show, dst); - - const Sprite & icon = AGG::GetICN(ICN::SPELLS, Spell::IndexSprite(spell)); - - if(Settings::Get().QVGA()) - { - display.Blit(icon, dst.x + 2 + (dst.w - icon.w()) / 2, dst.y + 20 - icon.h() / 2); - } - else - { - display.Blit(icon, dst.x + 5 + (dst.w - icon.w()) / 2, dst.y + 40 - icon.h() / 2); - - TextBox text(Spell::GetName(spell), Font::SMALL, 73); - text.Blit(dst.x + 19, dst.y + 62); - } - } - } -} - -void RowSpells::QueueEventProcessing(void) -{ - LocalEvent & le = LocalEvent::Get(); - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - - if(le.MouseClickLeft() || le.MousePressRight()) - { - std::vector::const_iterator it = std::find_if(coords.begin(), coords.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())); - if(it != coords.end()) - { - const Spell::spell_t & spell = spells[it - coords.begin()]; - if(Spell::NONE != spell) - { - cursor.Hide(); - Dialog::SpellInfo(spell, !le.MousePressRight()); - cursor.Show(); - display.Flip(); - } - } - } -} - -void Castle::OpenMageGuild(void) -{ - Display & display = Display::Get(); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - 640 - BORDERWIDTH * 2) / 2, (display.h() - 480 - BORDERWIDTH * 2) / 2, 640, 480); - frameborder.Redraw(); - - const Point cur_pt(frameborder.GetArea().x, frameborder.GetArea().y); - Point dst_pt(cur_pt); - - display.Blit(AGG::GetICN(ICN::STONEBAK, 0), dst_pt); - - std::string message; - Text text; - - // bar - dst_pt.x = cur_pt.x; - dst_pt.y = cur_pt.y + 461; - display.Blit(AGG::GetICN(ICN::WELLXTRA, 2), dst_pt); - - // text bar - text.Set(_("The above spells have been added to your book."), Font::BIG); - dst_pt.x = cur_pt.x + 280 - text.w() / 2; - dst_pt.y = cur_pt.y + 461; - text.Blit(dst_pt); - - const u8 level = mageguild.GetLevel(); - // sprite - ICN::icn_t icn = ICN::UNKNOWN; - switch(race) - { - case Race::KNGT: icn = ICN::MAGEGLDK; break; - case Race::BARB: icn = ICN::MAGEGLDB; break; - case Race::SORC: icn = ICN::MAGEGLDS; break; - case Race::WRLK: icn = ICN::MAGEGLDW; break; - case Race::WZRD: icn = ICN::MAGEGLDZ; break; - case Race::NECR: icn = ICN::MAGEGLDN; break; - default: break; - } - const Sprite & sprite = AGG::GetICN(icn, level - 1); - dst_pt.x = cur_pt.x + 90 - sprite.w() / 2; - dst_pt.y = cur_pt.y + 290 - sprite.h(); - display.Blit(sprite, dst_pt); - - RowSpells spells5(Point(cur_pt.x + 250, cur_pt.y + 10), mageguild, 5); - RowSpells spells4(Point(cur_pt.x + 250, cur_pt.y + 95), mageguild, 4); - RowSpells spells3(Point(cur_pt.x + 250, cur_pt.y + 180), mageguild, 3); - RowSpells spells2(Point(cur_pt.x + 250, cur_pt.y + 265), mageguild, 2); - RowSpells spells1(Point(cur_pt.x + 250, cur_pt.y + 350), mageguild, 1); - - spells1.Redraw(); - spells2.Redraw(); - spells3.Redraw(); - spells4.Redraw(); - spells5.Redraw(); - - // button exit - dst_pt.x = cur_pt.x + 578; - dst_pt.y = cur_pt.y + 461; - Button buttonExit(dst_pt, ICN::WELLXTRA, 0, 1); - - buttonExit.Draw(); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - - if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) break; - - spells1.QueueEventProcessing(); - spells2.QueueEventProcessing(); - spells3.QueueEventProcessing(); - spells4.QueueEventProcessing(); - spells5.QueueEventProcessing(); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/castle_tavern.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/castle_tavern.cpp deleted file mode 100644 index bf0609af3..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/castle_tavern.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "button.h" -#include "world.h" -#include "cursor.h" -#include "settings.h" -#include "resource.h" -#include "castle.h" -#include "heroes.h" -#include "kingdom.h" -#include "text.h" - -void Castle::OpenTavern(void) -{ - const std::string & header = _("A generous tip for the barkeep yields the following rumor:"); - const ICN::icn_t system = (Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM); - const ICN::icn_t tavwin = ICN::TAVWIN; - const std::string & tavern = GetStringBuilding(BUILD_TAVERN); - const std::string & message = world.GetRumors(); - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - - Text text(tavern, Font::BIG); - const Sprite & s1 = AGG::GetICN(tavwin, 0); - TextBox box1(header, Font::BIG, BOXAREA_WIDTH); - TextBox box2(message, Font::BIG, BOXAREA_WIDTH); - - Dialog::Box box(text.h() + 10 + s1.h() + 13 + box1.h() + 20 + box2.h(), true); - - const Rect & pos = box.GetArea(); - Point dst_pt(pos.x, pos.y); - - text.Blit(pos.x + (pos.w - text.w()) / 2, dst_pt.y); - - dst_pt.x = pos.x + (pos.w - s1.w()) / 2; - dst_pt.y += 10 + text.h(); - display.Blit(s1, dst_pt); - - dst_pt.x += 3; - dst_pt.y += 3; - - const Sprite & s20 = AGG::GetICN(tavwin, 1); - display.Blit(s20, dst_pt); - - if(const u16 index = ICN::AnimationFrame(tavwin, 0)) - { - const Sprite & s21 = AGG::GetICN(tavwin, index); - display.Blit(s21, dst_pt.x + s21.x(), dst_pt.y + s21.y()); - } - - box1.Blit(pos.x, dst_pt.y + s1.h() + 10); - box2.Blit(pos.x, dst_pt.y + s1.h() + 10 + box1.h() + 20); - - // button yes - const Sprite & s4 = AGG::GetICN(system, 5); - Button buttonYes(pos.x + (pos.w - s4.w()) / 2, pos.y + pos.h - s4.h(), system, 5, 6); - - buttonYes.Draw(); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - u32 frame = 0; - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonYes) ? buttonYes.PressDraw() : buttonYes.ReleaseDraw(); - - if(le.MouseClickLeft(buttonYes) || HotKeyCloseWindow) break; - - - // animation - if(Game::AnimateInfrequent(Game::CASTLE_TAVERN_DELAY)) - { - cursor.Hide(); - - display.Blit(s20, dst_pt); - - if(const u16 index = ICN::AnimationFrame(tavwin, 0, frame++)) - { - const Sprite & s22 = AGG::GetICN(tavwin, index); - display.Blit(s22, dst_pt.x + s22.x(), dst_pt.y + s22.y()); - } - - cursor.Show(); - display.Flip(); - } - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/castle_town.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/castle_town.cpp deleted file mode 100644 index f65f20690..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/castle_town.cpp +++ /dev/null @@ -1,611 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "agg.h" -#include "world.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "castle.h" -#include "dialog.h" -#include "heroes.h" -#include "text.h" -#include "statusbar.h" -#include "payment.h" -#include "buildinginfo.h" -#include "kingdom.h" -#include "localclient.h" - -Dialog::answer_t Castle::DialogBuyHero(const Heroes* hero) -{ - if(!hero) return Dialog::CANCEL; - - const ICN::icn_t system = (Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM); - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - const Sprite & portrait_frame = AGG::GetICN(ICN::SURRENDR, 4); - - Text text(_("Recruit Hero"), Font::BIG); - - u8 count = hero->GetCountArtifacts(); - if(hero->HasArtifact(Artifact::MAGIC_BOOK)) count--; - - std::string str = _("%{name} is a level %{value} %{race}"); - - // FIXME: It is necessary to consider locale features for numerals (with getext). - if(count) - { - str += " "; - str += count > 1 ? _(" with %{count} artifacts") : _(" with one artifact"); - } - - String::Replace(str, "%{name}", hero->GetName()); - String::Replace(str, "%{value}", hero->GetLevel()); - String::Replace(str, "%{race}", Race::String(hero->GetRace())); - String::Replace(str, "%{count}", count); - - TextBox box2(str, Font::BIG, BOXAREA_WIDTH); - - Resource::BoxSprite rbs(PaymentConditions::RecruitHero(hero->GetLevel()), BOXAREA_WIDTH); - - Dialog::Box box(text.h() + spacer + portrait_frame.h() + spacer + box2.h() + spacer + rbs.GetArea().h, true); - const Rect & box_rt = box.GetArea(); - LocalEvent & le = LocalEvent::Get(); - Point dst_pt; - - dst_pt.x = box_rt.x + (box_rt.w - text.w()) / 2; - dst_pt.y = box_rt.y; - text.Blit(dst_pt); - - //portrait and frame - dst_pt.x = box_rt.x + (box_rt.w - portrait_frame.w()) / 2; - dst_pt.y = dst_pt.y + text.h() + spacer; - display.Blit(portrait_frame, dst_pt); - - dst_pt.x = dst_pt.x + 5; - dst_pt.y = dst_pt.y + 5; - display.Blit(hero->GetPortrait101x93(), dst_pt); - - dst_pt.x = box_rt.x; - dst_pt.y = dst_pt.y + portrait_frame.h() + spacer; - box2.Blit(dst_pt); - - rbs.SetPos(dst_pt.x, dst_pt.y + box2.h() + spacer); - rbs.Redraw(); - - dst_pt.x = box_rt.x; - dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h(); - Button button1(dst_pt, system, 1, 2); - - if(! AllowBuyHero(*hero)) - { - button1.Press(); - button1.SetDisable(true); - } - - dst_pt.x = box_rt.x + box_rt.w - AGG::GetICN(system, 3).w(); - dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 3).h(); - Button button2(dst_pt, system, 3, 4); - - button1.Draw(); - button2.Draw(); - - cursor.Show(); - display.Flip(); - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(button1) ? button1.PressDraw() : button1.ReleaseDraw(); - le.MousePressLeft(button2) ? button2.PressDraw() : button2.ReleaseDraw(); - - if(button1.isEnable() && - (le.MouseClickLeft(button1) || - Game::HotKeyPress(Game::EVENT_DEFAULT_READY))) return Dialog::OK; - - if(le.MouseClickLeft(button2) || - Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break; - } - - return Dialog::CANCEL; -} - -Dialog::answer_t Castle::DialogBuyCastle(bool buttons) const -{ - BuildingInfo info(*this, BUILD_CASTLE); - return info.DialogBuyBuilding(buttons) ? Dialog::OK : Dialog::CANCEL; -} - -u32 Castle::OpenTown(void) -{ - Display & display = Display::Get(); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - - Dialog::FrameBorder background; - background.SetPosition((display.w() - 640 - BORDERWIDTH * 2) / 2, (display.h() - 480 - BORDERWIDTH * 2) / 2, 640, 480); - background.Redraw(); - - const Point cur_pt(background.GetArea().x, background.GetArea().y); - Point dst_pt(cur_pt); - - display.Blit(AGG::GetICN(ICN::CASLWIND, 0), dst_pt); - - // hide captain options - if(! (building & BUILD_CAPTAIN)) - { - dst_pt.x = 530; - dst_pt.y = 163; - const Rect rect(dst_pt, 110, 84); - dst_pt.x += cur_pt.x; - dst_pt.y += cur_pt.y; - - display.Blit(AGG::GetICN(ICN::STONEBAK, 0), rect, dst_pt); - } - - // draw castle sprite - dst_pt.x = cur_pt.x + 460; - dst_pt.y = cur_pt.y + 0; - DrawImageCastle(dst_pt); - - // - ICN::icn_t icn = ICN::UNKNOWN; - - switch(race) - { - case Race::BARB: icn = ICN::CSTLBARB; break; - case Race::KNGT: icn = ICN::CSTLKNGT; break; - case Race::NECR: icn = ICN::CSTLNECR; break; - case Race::SORC: icn = ICN::CSTLSORC; break; - case Race::WRLK: icn = ICN::CSTLWRLK; break; - case Race::WZRD: icn = ICN::CSTLWZRD; break; - default: return BUILD_NOTHING; - } - - BuildingInfo dwelling1(*this, DWELLING_MONSTER1); - dwelling1.SetPos(cur_pt.x + 5, cur_pt.y + 2); - dwelling1.Redraw(); - - BuildingInfo dwelling2(*this, DWELLING_MONSTER2); - dwelling2.SetPos(cur_pt.x + 149, cur_pt.y + 2); - dwelling2.Redraw(); - - BuildingInfo dwelling3(*this, DWELLING_MONSTER3); - dwelling3.SetPos(cur_pt.x + 293, cur_pt.y + 2); - dwelling3.Redraw(); - - BuildingInfo dwelling4(*this, DWELLING_MONSTER4); - dwelling4.SetPos(cur_pt.x + 5, cur_pt.y + 77); - dwelling4.Redraw(); - - BuildingInfo dwelling5(*this, DWELLING_MONSTER5); - dwelling5.SetPos(cur_pt.x + 149, cur_pt.y + 77); - dwelling5.Redraw(); - - BuildingInfo dwelling6(*this, DWELLING_MONSTER6); - dwelling6.SetPos(cur_pt.x + 293, cur_pt.y + 77); - dwelling6.Redraw(); - - // mage guild - building_t level = BUILD_NOTHING; - switch(GetLevelMageGuild()) - { - case 0: level = BUILD_MAGEGUILD1; break; - case 1: level = BUILD_MAGEGUILD2; break; - case 2: level = BUILD_MAGEGUILD3; break; - case 3: level = BUILD_MAGEGUILD4; break; - default:level = BUILD_MAGEGUILD5; break; - } - BuildingInfo buildingMageGuild(*this, level); - buildingMageGuild.SetPos(cur_pt.x + 5, cur_pt.y + 157); - buildingMageGuild.Redraw(); - - // tavern - BuildingInfo buildingTavern(*this, BUILD_TAVERN); - buildingTavern.SetPos(cur_pt.x + 149, cur_pt.y + 157); - buildingTavern.Redraw(); - - // thieves guild - BuildingInfo buildingThievesGuild(*this, BUILD_THIEVESGUILD); - buildingThievesGuild.SetPos(cur_pt.x + 293, cur_pt.y + 157); - buildingThievesGuild.Redraw(); - - // shipyard - BuildingInfo buildingShipyard(*this, BUILD_SHIPYARD); - buildingShipyard.SetPos(cur_pt.x + 5, cur_pt.y + 232); - buildingShipyard.Redraw(); - - // statue - BuildingInfo buildingStatue(*this, BUILD_STATUE); - buildingStatue.SetPos(cur_pt.x + 149, cur_pt.y + 232); - buildingStatue.Redraw(); - - // marketplace - BuildingInfo buildingMarketplace(*this, BUILD_MARKETPLACE); - buildingMarketplace.SetPos(cur_pt.x + 293, cur_pt.y + 232); - buildingMarketplace.Redraw(); - - // well - BuildingInfo buildingWell(*this, BUILD_WELL); - buildingWell.SetPos(cur_pt.x + 5, cur_pt.y + 307); - buildingWell.Redraw(); - - // wel2 - BuildingInfo buildingWel2(*this, BUILD_WEL2); - buildingWel2.SetPos(cur_pt.x + 149, cur_pt.y + 307); - buildingWel2.Redraw(); - - // spec - BuildingInfo buildingSpec(*this, BUILD_SPEC); - buildingSpec.SetPos(cur_pt.x + 293, cur_pt.y + 307); - buildingSpec.Redraw(); - - // left turret - BuildingInfo buildingLTurret(*this, BUILD_LEFTTURRET); - buildingLTurret.SetPos(cur_pt.x + 5, cur_pt.y + 387); - buildingLTurret.Redraw(); - - // right turret - BuildingInfo buildingRTurret(*this, BUILD_RIGHTTURRET); - buildingRTurret.SetPos(cur_pt.x + 149, cur_pt.y + 387); - buildingRTurret.Redraw(); - - // moat - BuildingInfo buildingMoat(*this, BUILD_MOAT); - buildingMoat.SetPos(cur_pt.x + 293, cur_pt.y + 387); - buildingMoat.Redraw(); - - // captain - BuildingInfo buildingCaptain(*this, BUILD_CAPTAIN); - buildingCaptain.SetPos(cur_pt.x + 444, cur_pt.y + 165); - buildingCaptain.Redraw(); - - // combat format - const Sprite & spriteSpreadArmyFormat = AGG::GetICN(ICN::HSICONS, 9); - const Sprite & spriteGroupedArmyFormat = AGG::GetICN(ICN::HSICONS, 10); - const Rect rectSpreadArmyFormat(cur_pt.x + 550, cur_pt.y + 220, spriteSpreadArmyFormat.w(), spriteSpreadArmyFormat.h()); - const Rect rectGroupedArmyFormat(cur_pt.x + 585, cur_pt.y + 220, spriteGroupedArmyFormat.w(), spriteGroupedArmyFormat.h()); - const std::string descriptionSpreadArmyFormat(_("'Spread' combat formation spreads your armies from the top to the bottom of the battlefield, with at least one empty space between each army.")); - const std::string descriptionGroupedArmyFormat(_("'Grouped' combat formation bunches your army toget her in the center of your side of the battlefield.")); - const Point pointSpreadArmyFormat(rectSpreadArmyFormat.x - 1, rectSpreadArmyFormat.y - 1); - const Point pointGroupedArmyFormat(rectGroupedArmyFormat.x - 1, rectGroupedArmyFormat.y - 1); - SpriteCursor cursorFormat(AGG::GetICN(ICN::HSICONS, 11), Army::FORMAT_SPREAD == army.GetCombatFormat() ? pointSpreadArmyFormat : pointGroupedArmyFormat); - if(isBuild(BUILD_CAPTAIN)) - { - Text text(_("Attack Skill") + std::string(" "), Font::SMALL); - dst_pt.x = cur_pt.x + 535; - dst_pt.y = cur_pt.y + 168; - text.Blit(dst_pt); - - std::string message; - String::AddInt(message, captain.GetAttack()); - text.Set(message); - dst_pt.x += 90; - text.Blit(dst_pt); - - text.Set(_("Defense Skill") + std::string(" ")); - dst_pt.x = cur_pt.x + 535; - dst_pt.y += 12; - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, captain.GetDefense()); - text.Set(message); - dst_pt.x += 90; - text.Blit(dst_pt); - - text.Set(_("Spell Power") + std::string(" ")); - dst_pt.x = cur_pt.x + 535; - dst_pt.y += 12; - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, captain.GetPower()); - text.Set(message); - dst_pt.x += 90; - text.Blit(dst_pt); - - text.Set(_("Knowledge") + std::string(" ")); - dst_pt.x = cur_pt.x + 535; - dst_pt.y += 12; - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, captain.GetKnowledge()); - text.Set(message); - dst_pt.x += 90; - text.Blit(dst_pt); - - display.Blit(spriteSpreadArmyFormat, rectSpreadArmyFormat.x, rectSpreadArmyFormat.y); - display.Blit(spriteGroupedArmyFormat, rectGroupedArmyFormat.x, rectGroupedArmyFormat.y); - - cursorFormat.Show(Army::FORMAT_SPREAD == army.GetCombatFormat() ? pointSpreadArmyFormat : pointGroupedArmyFormat); - } - - Kingdom & kingdom = world.GetKingdom(GetColor()); - - Heroes* hero1 = kingdom.GetRecruits().GetHero1(); - Heroes* hero2 = kingdom.GetRecruits().GetHero2(); - - const bool many_hero1 = hero1 ? !kingdom.AllowRecruitHero(false, hero1->GetLevel()) : false; - const bool many_hero2 = hero2 ? !kingdom.AllowRecruitHero(false, hero2->GetLevel()) : false; - const bool allow_buy_hero1 = hero1 ? AllowBuyHero(*hero1) : false; - const bool allow_buy_hero2 = hero2 ? AllowBuyHero(*hero2) : false; - - // first hero - dst_pt.x = cur_pt.x + 443; - dst_pt.y = cur_pt.y + 260; - const Rect rectHero1(dst_pt, 102, 93); - if(hero1) - { - display.Blit(hero1->GetPortrait101x93(), dst_pt); - } - else - display.FillRect(0, 0, 0, rectHero1); - // indicator - if(many_hero1 || !allow_buy_hero1) - { - dst_pt.x += 83; - dst_pt.y += 75; - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), dst_pt); - } - - // second hero - dst_pt.x = cur_pt.x + 443; - dst_pt.y = cur_pt.y + 362; - const Rect rectHero2(dst_pt, 102, 94); - if(hero2) - { - display.Blit(hero2->GetPortrait101x93(), dst_pt); - } - else - display.FillRect(0, 0, 0, rectHero2); - // indicator - if(many_hero2 || !allow_buy_hero2) - { - dst_pt.x += 83; - dst_pt.y += 75; - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), dst_pt); - } - - // bottom bar - dst_pt.x = cur_pt.x; - dst_pt.y = cur_pt.y + 461; - const Sprite & bar = AGG::GetICN(ICN::CASLBAR, 0); - display.Blit(bar, dst_pt); - - StatusBar statusBar; - statusBar.SetCenter(dst_pt.x + bar.w() / 2, dst_pt.y + 11); - - // redraw resource panel - RedrawResourcePanel(cur_pt); - - // button exit - dst_pt.x = cur_pt.x + 554; - dst_pt.y = cur_pt.y + 428; - Button buttonExit(dst_pt, ICN::SWAPBTN, 0, 1); - - buttonExit.Draw(); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - - if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) break; - - // click left - if(le.MouseCursor(dwelling1.GetArea()) && dwelling1.QueueEventProcessing()) return dwelling1(); - else - if(le.MouseCursor(dwelling2.GetArea()) && dwelling2.QueueEventProcessing()) return dwelling2(); - else - if(le.MouseCursor(dwelling3.GetArea()) && dwelling3.QueueEventProcessing()) return dwelling3(); - else - if(le.MouseCursor(dwelling4.GetArea()) && dwelling4.QueueEventProcessing()) return dwelling4(); - else - if(le.MouseCursor(dwelling5.GetArea()) && dwelling5.QueueEventProcessing()) return dwelling5(); - else - if(le.MouseCursor(dwelling6.GetArea()) && dwelling6.QueueEventProcessing()) return dwelling6(); - else - if(le.MouseCursor(buildingMageGuild.GetArea()) && buildingMageGuild.QueueEventProcessing()) return buildingMageGuild(); - else - if(le.MouseCursor(buildingTavern.GetArea()) && buildingTavern.QueueEventProcessing()) return BUILD_TAVERN; - else - if(le.MouseCursor(buildingThievesGuild.GetArea()) && buildingThievesGuild.QueueEventProcessing()) return BUILD_THIEVESGUILD; - else - if(le.MouseCursor(buildingShipyard.GetArea()) && buildingShipyard.QueueEventProcessing()) return BUILD_SHIPYARD; - else - if(le.MouseCursor(buildingStatue.GetArea()) && buildingStatue.QueueEventProcessing()) return BUILD_STATUE; - else - if(le.MouseCursor(buildingMarketplace.GetArea()) && buildingMarketplace.QueueEventProcessing()) return BUILD_MARKETPLACE; - else - if(le.MouseCursor(buildingWell.GetArea()) && buildingWell.QueueEventProcessing()) return BUILD_WELL; - else - if(le.MouseCursor(buildingWel2.GetArea()) && buildingWel2.QueueEventProcessing()) return BUILD_WEL2; - else - if(le.MouseCursor(buildingSpec.GetArea()) && buildingSpec.QueueEventProcessing()) return BUILD_SPEC; - else - if(le.MouseCursor(buildingLTurret.GetArea()) && buildingLTurret.QueueEventProcessing()) return BUILD_LEFTTURRET; - else - if(le.MouseCursor(buildingRTurret.GetArea()) && buildingRTurret.QueueEventProcessing()) return BUILD_RIGHTTURRET; - else - if(le.MouseCursor(buildingMoat.GetArea()) && buildingMoat.QueueEventProcessing()) return BUILD_MOAT; - else - if(le.MouseCursor(buildingCaptain.GetArea()) && buildingCaptain.QueueEventProcessing()) return BUILD_CAPTAIN; - else - if(hero1 && le.MouseClickLeft(rectHero1) && - Dialog::OK == DialogBuyHero(hero1)) - { - RecruitHero(hero1); - - return BUILD_NOTHING; - } - else - if(hero2 && le.MouseClickLeft(rectHero2) && - Dialog::OK == DialogBuyHero(hero2)) - { - RecruitHero(hero2); - - return BUILD_NOTHING; - } - else - if(isBuild(BUILD_CAPTAIN)) - { - if(le.MouseClickLeft(rectSpreadArmyFormat) && Army::FORMAT_SPREAD != army.GetCombatFormat()) - { - cursor.Hide(); - cursorFormat.Move(pointSpreadArmyFormat); - cursor.Show(); - display.Flip(); - army.SetCombatFormat(Army::FORMAT_SPREAD); -#ifdef WITH_NET - FH2LocalClient::SendArmyCombatFormation(army); -#endif - } - else - if(le.MouseClickLeft(rectGroupedArmyFormat) && Army::FORMAT_SPREAD == army.GetCombatFormat()) - { - cursor.Hide(); - cursorFormat.Move(pointGroupedArmyFormat); - cursor.Show(); - display.Flip(); - army.SetCombatFormat(Army::FORMAT_GROUPED); -#ifdef WITH_NET - FH2LocalClient::SendArmyCombatFormation(army); -#endif - } - } - - - // right - if(le.MousePressRight(rectSpreadArmyFormat)) Dialog::Message(_("Spread Formation"), descriptionSpreadArmyFormat, Font::BIG); - else - if(le.MousePressRight(rectGroupedArmyFormat)) Dialog::Message(_("Grouped Formation"), descriptionGroupedArmyFormat, Font::BIG); - else - if(hero1 && le.MousePressRight(rectHero1)){ hero1->OpenDialog(true); cursor.Show(); display.Flip(); } - else - if(hero2 && le.MousePressRight(rectHero2)){ hero2->OpenDialog(true); cursor.Show(); display.Flip(); } - - // status info - if(le.MouseCursor(dwelling1.GetArea())) dwelling1.SetStatusMessage(statusBar); - else - if(le.MouseCursor(dwelling2.GetArea())) dwelling2.SetStatusMessage(statusBar); - else - if(le.MouseCursor(dwelling3.GetArea())) dwelling3.SetStatusMessage(statusBar); - else - if(le.MouseCursor(dwelling4.GetArea())) dwelling4.SetStatusMessage(statusBar); - else - if(le.MouseCursor(dwelling5.GetArea())) dwelling5.SetStatusMessage(statusBar); - else - if(le.MouseCursor(dwelling6.GetArea())) dwelling6.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingMageGuild.GetArea())) buildingMageGuild.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingTavern.GetArea()) && !buildingTavern.IsDisable()) buildingTavern.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingThievesGuild.GetArea())) buildingThievesGuild.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingShipyard.GetArea())) buildingShipyard.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingStatue.GetArea())) buildingStatue.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingMarketplace.GetArea())) buildingMarketplace.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingWell.GetArea())) buildingWell.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingWel2.GetArea())) buildingWel2.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingSpec.GetArea())) buildingSpec.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingLTurret.GetArea())) buildingLTurret.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingRTurret.GetArea())) buildingRTurret.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingMoat.GetArea())) buildingMoat.SetStatusMessage(statusBar); - else - if(le.MouseCursor(buildingCaptain.GetArea())) buildingCaptain.SetStatusMessage(statusBar); - else - if(hero1 && le.MouseCursor(rectHero1)) - { - if(many_hero1) - statusBar.ShowMessage(_("Cannot recruit - you have too many Heroes.")); - else - if(castle_heroes) - statusBar.ShowMessage(_("Cannot recruit - you already have a Hero in this town.")); - else - if(! allow_buy_hero1) - statusBar.ShowMessage(_("Cannot afford a Hero")); - else - { - std::string str = _("Recruit %{name} the %{race}"); - String::Replace(str, "%{name}", hero1->GetName()); - String::Replace(str, "%{race}", Race::String(hero1->GetRace())); - statusBar.ShowMessage(str); - } - } - else - if(hero2 && le.MouseCursor(rectHero2)) - { - if(many_hero2) - statusBar.ShowMessage(_("Cannot recruit - you have too many Heroes.")); - else - if(castle_heroes) - statusBar.ShowMessage(_("Cannot recruit - you already have a Hero in this town.")); - else - if(! allow_buy_hero2) - statusBar.ShowMessage(_("Cannot afford a Hero")); - else - { - std::string str = _("Recruit %{name} the %{race}"); - String::Replace(str, "%{name}", hero2->GetName()); - String::Replace(str, "%{race}", Race::String(hero2->GetRace())); - statusBar.ShowMessage(str); - } - } - else - if(le.MouseCursor(rectSpreadArmyFormat)) - statusBar.ShowMessage(_("Set garrison combat formation to 'Spread'")); - else - if(le.MouseCursor(rectGroupedArmyFormat)) - statusBar.ShowMessage(_("Set garrison combat formation to 'Grouped'")); - else - // clear all - statusBar.ShowMessage(_("Castle Options")); - } - - return BUILD_NOTHING; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/castle_well.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/castle_well.cpp deleted file mode 100644 index 18ffafb40..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/castle_well.cpp +++ /dev/null @@ -1,333 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "speed.h" -#include "settings.h" -#include "castle.h" -#include "text.h" - -void Castle::OpenWell(void) -{ - Display & display = Display::Get(); - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - 640 - BORDERWIDTH * 2) / 2, (display.h() - 480 - BORDERWIDTH * 2) / 2, 640, 480); - frameborder.Redraw(); - - const Point cur_pt(frameborder.GetArea().x, frameborder.GetArea().y); - - Point dst_pt(cur_pt); - - // button exit - dst_pt.x = cur_pt.x + 578; - dst_pt.y = cur_pt.y + 461; - Button buttonExit(dst_pt, ICN::WELLXTRA, 0, 1); - - const Rect rectMonster1(cur_pt.x + 20, cur_pt.y + 18, 288, 124); - const Rect rectMonster2(cur_pt.x + 20, cur_pt.y + 168, 288, 124); - const Rect rectMonster3(cur_pt.x + 20, cur_pt.y + 318, 288, 124); - const Rect rectMonster4(cur_pt.x + 334, cur_pt.y + 18, 288, 124); - const Rect rectMonster5(cur_pt.x + 334, cur_pt.y + 168, 288, 124); - const Rect rectMonster6(cur_pt.x + 334, cur_pt.y + 318, 288, 124); - - buttonExit.Draw(); - - WellRedrawInfoArea(cur_pt); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - - // loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - - if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) break; - - // extended version (click - buy dialog monster) - if(Settings::Get().ExtAllowBuyFromWell()) - { - if(building & DWELLING_MONSTER1 && le.MouseClickLeft(rectMonster1) && - Castle::RecruitMonster(DWELLING_MONSTER1, Dialog::RecruitMonster( - Monster(race, DWELLING_MONSTER1), dwelling[0]))) - { - cursor.Hide(); - WellRedrawInfoArea(cur_pt); - cursor.Show(); - display.Flip(); - } - else - if(building & DWELLING_MONSTER2 && le.MouseClickLeft(rectMonster2) && - Castle::RecruitMonster(DWELLING_MONSTER2, Dialog::RecruitMonster( - Monster(race, GetActualDwelling(DWELLING_MONSTER2)), dwelling[1]))) - { - cursor.Hide(); - WellRedrawInfoArea(cur_pt); - cursor.Show(); - display.Flip(); - } - else - if(building & DWELLING_MONSTER3 && le.MouseClickLeft(rectMonster3) && - Castle::RecruitMonster(DWELLING_MONSTER3, Dialog::RecruitMonster( - Monster(race, GetActualDwelling(DWELLING_MONSTER3)), dwelling[2]))) - { - cursor.Hide(); - WellRedrawInfoArea(cur_pt); - cursor.Show(); - display.Flip(); - } - else - if(building & DWELLING_MONSTER4 && le.MouseClickLeft(rectMonster4) && - Castle::RecruitMonster(DWELLING_MONSTER4, Dialog::RecruitMonster( - Monster(race, GetActualDwelling(DWELLING_MONSTER4)), dwelling[3]))) - { - cursor.Hide(); - WellRedrawInfoArea(cur_pt); - cursor.Show(); - display.Flip(); - } - else - if(building & DWELLING_MONSTER5 && le.MouseClickLeft(rectMonster5) && - Castle::RecruitMonster(DWELLING_MONSTER5, Dialog::RecruitMonster( - Monster(race, GetActualDwelling(DWELLING_MONSTER5)), dwelling[4]))) - { - cursor.Hide(); - WellRedrawInfoArea(cur_pt); - cursor.Show(); - display.Flip(); - } - else - if(building & DWELLING_MONSTER6 && le.MouseClickLeft(rectMonster6) && - Castle::RecruitMonster(DWELLING_MONSTER6, Dialog::RecruitMonster( - Monster(race, GetActualDwelling(DWELLING_MONSTER6)), dwelling[5]))) - { - cursor.Hide(); - WellRedrawInfoArea(cur_pt); - cursor.Show(); - display.Flip(); - } - } - } -} - -void Castle::WellRedrawInfoArea(const Point & cur_pt) -{ - Display & display = Display::Get(); - display.Blit(AGG::GetICN(ICN::WELLBKG, 0), cur_pt); - - Text text; - Point dst_pt, pt; - - text.Set(_("Town Population Information and Statistics"), Font::BIG); - dst_pt.x = cur_pt.x + 280 - text.w() / 2; - dst_pt.y = cur_pt.y + 462; - text.Blit(dst_pt); - - u32 dw = DWELLING_MONSTER1; - - while(dw <= DWELLING_MONSTER6) - { - bool present = false; - u32 dw_orig = DWELLING_MONSTER1; - u8 icnindex = 0; - u16 available = 0; - - switch(dw) - { - case DWELLING_MONSTER1: - pt.x = cur_pt.x; - pt.y = cur_pt.y; - present = DWELLING_MONSTER1 & building; - icnindex = 19; - available = dwelling[0]; - break; - case DWELLING_MONSTER2: - pt.x = cur_pt.x; - pt.y = cur_pt.y + 150; - present = DWELLING_MONSTER2 & building; - dw_orig = GetActualDwelling(DWELLING_MONSTER2); - icnindex = DWELLING_UPGRADE2 & building ? 25 : 20; - available = dwelling[1]; - break; - case DWELLING_MONSTER3: - pt.x = cur_pt.x; - pt.y = cur_pt.y + 300; - present = DWELLING_MONSTER3 & building; - dw_orig = GetActualDwelling(DWELLING_MONSTER3); - icnindex = DWELLING_UPGRADE3 & building ? 26 : 21; - available = dwelling[2]; - break; - case DWELLING_MONSTER4: - pt.x = cur_pt.x + 314; - pt.y = cur_pt.y + 1; - present = DWELLING_MONSTER4 & building; - dw_orig = GetActualDwelling(DWELLING_MONSTER4); - icnindex = DWELLING_UPGRADE4 & building ? 27 : 22; - available = dwelling[3]; - break; - case DWELLING_MONSTER5: - pt.x = cur_pt.x + 314; - pt.y = cur_pt.y + 151; - present = DWELLING_MONSTER5 & building; - dw_orig = GetActualDwelling(DWELLING_MONSTER5); - icnindex = DWELLING_UPGRADE5 & building ? 28 : 23; - available = dwelling[4]; - break; - case DWELLING_MONSTER6: - pt.x = cur_pt.x + 314; - pt.y = cur_pt.y + 301; - present = DWELLING_MONSTER6 & building; - dw_orig = GetActualDwelling(DWELLING_MONSTER6); - icnindex = DWELLING_UPGRADE7 & building ? 30 : (DWELLING_UPGRADE6 & building ? 29 : 24); - available = dwelling[5]; - break; - default: - break; - } - - const Monster monster(race, dw_orig); - - ICN::icn_t icnname = ICN::UNKNOWN; - - switch(race) - { - case Race::BARB: icnname = ICN::CSTLBARB; break; - case Race::KNGT: icnname = ICN::CSTLKNGT; break; - case Race::SORC: icnname = ICN::CSTLSORC; break; - case Race::WRLK: icnname = ICN::CSTLWRLK; break; - case Race::WZRD: icnname = ICN::CSTLWZRD; break; - case Race::NECR: icnname = ICN::CSTLNECR; break; - default: break; - } - - // sprite - dst_pt.x = pt.x + 21; - dst_pt.y = pt.y + 35; - display.Blit(AGG::GetICN(icnname, icnindex), dst_pt); - // text - text.Set(GetStringBuilding(dw_orig, race), Font::SMALL); - dst_pt.x = pt.x + 86 - text.w() / 2; - dst_pt.y = pt.y + 103; - text.Blit(dst_pt); - // monster - const Sprite & smonster = AGG::GetICN(monster.ICNMonh(), 0); - dst_pt.x = pt.x + 193 - smonster.w() / 2; - dst_pt.y = pt.y + 124 - smonster.h(); - display.Blit(smonster, dst_pt); - // name - text.Set(monster.GetMultiName()); - dst_pt.x = pt.x + 122 - text.w() / 2; - dst_pt.y = pt.y + 16; - text.Blit(dst_pt); - // attack - std::string str; - str = _("Attack"); - str += ": "; - String::AddInt(str, monster.GetAttack()); - text.Set(str); - dst_pt.x = pt.x + 268 - text.w() / 2; - dst_pt.y = pt.y + 22; - text.Blit(dst_pt); - // defense - str = _("Defense"); - str += ": "; - String::AddInt(str, monster.GetDefense()); - text.Set(str); - dst_pt.x = pt.x + 268 - text.w() / 2; - dst_pt.y = pt.y + 34; - text.Blit(dst_pt); - // damage - str = _("Damg"); - str += ": "; - String::AddInt(str, monster.GetDamageMin()); - str += "-"; - String::AddInt(str, monster.GetDamageMax()); - text.Set(str); - dst_pt.x = pt.x + 268 - text.w() / 2; - dst_pt.y = pt.y + 46; - text.Blit(dst_pt); - // hp - str = _("HP"); - str += ": "; - String::AddInt(str, monster.GetHitPoints()); - text.Set(str); - dst_pt.x = pt.x + 268 - text.w() / 2; - dst_pt.y = pt.y + 58; - text.Blit(dst_pt); - // speed - str = _("Speed"); - str += ": "; - text.Set(str); - dst_pt.x = pt.x + 268 - text.w() / 2; - dst_pt.y = pt.y + 78; - text.Blit(dst_pt); - text.Set(Speed::String(monster.GetSpeed())); - dst_pt.x = pt.x + 268 - text.w() / 2; - dst_pt.y = pt.y + 90; - text.Blit(dst_pt); - - if(present) - { - u8 grown = monster.GetGrown(); - grown += building & BUILD_WELL ? grown_well : 0; - if(DWELLING_MONSTER1 & dw) grown += building & BUILD_WEL2 ? grown_wel2 : 0; - - text.Set(_("Growth")); - dst_pt.x = pt.x + 268 - text.w() / 2; - dst_pt.y = pt.y + 110; - text.Blit(dst_pt); - str = "+ "; - String::AddInt(str, grown); - str += " / "; - str += _("week"); - text.Set(str); - dst_pt.x = pt.x + 268 - text.w() / 2; - dst_pt.y = pt.y + 122; - text.Blit(dst_pt); - - str = _("Available"); - str += ": "; - text.Set(str); - dst_pt.x = pt.x + 44; - dst_pt.y = pt.y + 122; - text.Blit(dst_pt); - str.clear(); - String::AddInt(str, available); - text.Set(str, Font::BIG); - dst_pt.x = pt.x + 129 - text.w() / 2; - dst_pt.y = pt.y + 119; - text.Blit(dst_pt); - } - - dw <<= 1; - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/mageguild.cpp b/project/jni/application/fheroes2/src/fheroes2/castle/mageguild.cpp deleted file mode 100644 index 9ac0041b5..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/mageguild.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "castle.h" -#include "heroes_base.h" -#include "settings.h" -#include "mageguild.h" - -Spell::spell_t GetUniqueCombatSpellCompatibility(const std::vector &, u8 race, u8 level); -Spell::spell_t GetCombatSpellCompatibility(u8 race, u8 level); - -MageGuild::MageGuild(const Castle & cstl) : home(cstl) -{ -} - -void MageGuild::Builds(void) -{ - general.spells.clear(); - library.spells.clear(); - - // level 5 - general.Append(7 > Rand::Get(1, 10) ? Spell::RandCombat(5) : Spell::RandAdventure(5)); - - // level 4 - general.Append(GetCombatSpellCompatibility(home.GetRace(), 4)); - general.Append(Spell::RandAdventure(4)); - - // level 3 - general.Append(GetCombatSpellCompatibility(home.GetRace(), 3)); - general.Append(Spell::RandAdventure(3)); - - // level 2 - general.Append(GetCombatSpellCompatibility(home.GetRace(), 2)); - general.Append(GetUniqueCombatSpellCompatibility(general.spells, home.GetRace(), 2)); - general.Append(Spell::RandAdventure(2)); - - // level 1 - general.Append(GetCombatSpellCompatibility(home.GetRace(), 1)); - general.Append(GetUniqueCombatSpellCompatibility(general.spells, home.GetRace(), 1)); - general.Append(Spell::RandAdventure(1)); - - if(HaveLibraryCapability()) - { - library.Append(GetUniqueCombatSpellCompatibility(general.spells, home.GetRace(), 1)); - library.Append(GetUniqueCombatSpellCompatibility(general.spells, home.GetRace(), 2)); - library.Append(GetUniqueCombatSpellCompatibility(general.spells, home.GetRace(), 3)); - library.Append(GetUniqueCombatSpellCompatibility(general.spells, home.GetRace(), 4)); - library.Append(GetUniqueCombatSpellCompatibility(general.spells, home.GetRace(), 5)); - } -} - -bool MageGuild::isLibraryBuild(void) const -{ - return home.GetRace() == Race::WZRD && home.isBuild(BUILD_SPEC); -} - -bool MageGuild::HaveLibraryCapability(void) const -{ - return home.GetRace() == Race::WZRD; -} - -u8 MageGuild::GetLevel(void) const -{ - return home.GetLevelMageGuild(); -} - -void MageGuild::GetSpells(std::vector & spells, u8 level) const -{ - if(home.GetLevelMageGuild() >= level) - { - general.GetSpells(spells, level); - if(isLibraryBuild()) library.GetSpells(spells, level); - } -} - -void MageGuild::EducateHero(HeroBase & hero) const -{ - if(hero.HaveSpellBook() && GetLevel()) - { - std::vector spells; - - for(u8 level = 1; level <= 5; ++level) if(level <= GetLevel()) - { - general.GetSpells(spells, level); - if(isLibraryBuild()) library.GetSpells(spells, level); - } - - std::vector::const_iterator it1 = spells.begin(); - std::vector::const_iterator it2 = spells.end(); - for(; it1 != it2; ++it1) hero.AppendSpellToBook(*it1); - } -} - -Spell::spell_t GetUniqueCombatSpellCompatibility(const std::vector & spells, u8 race, u8 lvl) -{ - Spell::spell_t spell = GetCombatSpellCompatibility(race, lvl); - while(spells.end() != std::find(spells.begin(), spells.end(), spell)) spell = GetCombatSpellCompatibility(race, lvl); - return spell; -} - -Spell::spell_t GetCombatSpellCompatibility(u8 race, u8 lvl) -{ - Spell::spell_t spell = Spell::RandCombat(lvl); - while(!Spell::isRaceCompatible(spell, race)) spell = Spell::RandCombat(lvl); - return spell; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/mageguild.h b/project/jni/application/fheroes2/src/fheroes2/castle/mageguild.h deleted file mode 100644 index fdbe96238..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/mageguild.h +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2MAGEGUILD_H -#define H2MAGEGUILD_H - -#include "gamedefs.h" -#include "game_io.h" -#include "spell_storage.h" - -class Castle; -class HeroBase; - -class MageGuild -{ - public: - MageGuild(const Castle &); - - void Builds(void); - void EducateHero(HeroBase &) const; - - bool isLibraryBuild(void) const; - bool HaveLibraryCapability(void) const; - u8 GetLevel(void) const; - void GetSpells(std::vector &, u8) const; - - private: - friend class Game::IO; - - const Castle & home; - - SpellStorage general; - SpellStorage library; -}; - -class RowSpells -{ -public: - RowSpells(const Point &, const MageGuild &, u8); - void Redraw(void); - void QueueEventProcessing(void); - -private: - std::vector coords; - std::vector spells; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/castle/marketplace.h b/project/jni/application/fheroes2/src/fheroes2/castle/marketplace.h deleted file mode 100644 index c0e160063..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/castle/marketplace.h +++ /dev/null @@ -1,103 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef MARKETPLACE_H -#define MARKETPLACE_H - -// change uncostly to costly -#define COSTLY_UNCOSTLY1 5 -#define COSTLY_UNCOSTLY2 4 -#define COSTLY_UNCOSTLY3 3 -#define COSTLY_UNCOSTLY4 2 -#define COSTLY_UNCOSTLY5 2 -#define COSTLY_UNCOSTLY6 2 -#define COSTLY_UNCOSTLY7 2 -#define COSTLY_UNCOSTLY8 2 -#define COSTLY_UNCOSTLY9 1 - -// change costly to uncostly -#define UNCOSTLY_COSTLY1 20 -#define UNCOSTLY_COSTLY2 14 -#define UNCOSTLY_COSTLY3 10 -#define UNCOSTLY_COSTLY4 8 -#define UNCOSTLY_COSTLY5 7 -#define UNCOSTLY_COSTLY6 6 -#define UNCOSTLY_COSTLY7 5 -#define UNCOSTLY_COSTLY8 5 -#define UNCOSTLY_COSTLY9 4 - -// change interchangeable -#define COSTLY_COSTLY1 10 -#define COSTLY_COSTLY2 7 -#define COSTLY_COSTLY3 5 -#define COSTLY_COSTLY4 4 -#define COSTLY_COSTLY5 4 -#define COSTLY_COSTLY6 3 -#define COSTLY_COSTLY7 3 -#define COSTLY_COSTLY8 3 -#define COSTLY_COSTLY9 2 - -// sale uncostly -#define SALE_UNCOSTLY1 25 -#define SALE_UNCOSTLY2 37 -#define SALE_UNCOSTLY3 50 -#define SALE_UNCOSTLY4 62 -#define SALE_UNCOSTLY5 74 -#define SALE_UNCOSTLY6 87 -#define SALE_UNCOSTLY7 100 -#define SALE_UNCOSTLY8 112 -#define SALE_UNCOSTLY9 124 - -// sale costly -#define SALE_COSTLY1 50 -#define SALE_COSTLY2 74 -#define SALE_COSTLY3 100 -#define SALE_COSTLY4 124 -#define SALE_COSTLY5 149 -#define SALE_COSTLY6 175 -#define SALE_COSTLY7 200 -#define SALE_COSTLY8 224 -#define SALE_COSTLY9 249 - -// buy uncostly -#define BUY_UNCOSTLY1 2500 -#define BUY_UNCOSTLY2 1667 -#define BUY_UNCOSTLY3 1250 -#define BUY_UNCOSTLY4 1000 -#define BUY_UNCOSTLY5 834 -#define BUY_UNCOSTLY6 715 -#define BUY_UNCOSTLY7 625 -#define BUY_UNCOSTLY8 556 -#define BUY_UNCOSTLY9 500 - -// buy costly -#define BUY_COSTLY1 5000 -#define BUY_COSTLY2 3334 -#define BUY_COSTLY3 2500 -#define BUY_COSTLY4 2000 -#define BUY_COSTLY5 1667 -#define BUY_COSTLY6 1429 -#define BUY_COSTLY7 1250 -#define BUY_COSTLY8 1112 -#define BUY_COSTLY9 1000 - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog.h b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog.h deleted file mode 100644 index 7a05cf23b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog.h +++ /dev/null @@ -1,171 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2DIALOG_H -#define H2DIALOG_H - -#include -#include -#include -#include "gamedefs.h" -#include "monster.h" -#include "spell.h" -#include "skill.h" -#include "text.h" -#include "game.h" -#include "resource.h" - -#define SHADOWWIDTH 16 -#define BOXAREA_WIDTH 245 - -class Castle; -class Heroes; -class Surface; -class SpriteCursor; - -namespace Army -{ - class Troop; - class BattleTroop; -} - -namespace Maps -{ - class FileInfo; - class Tiles; -} - -namespace Dialog -{ - enum answer_t - { - ZERO = 0x0000, - YES = 0x0001, - OK = 0x0002, - NO = 0x0004, - CANCEL = 0x0008, - DISMISS = 0x0010, - UPGRADE = 0x0020, - MAX = 0x0040, - PREV = 0x0080, - NEXT = 0x0100, - - WORLD = 0x0200, - PUZZLE = 0x0400, - INFO = 0x0800, - DIG = 0x1000, - - READONLY= 0x2000, - BATTLE = 0x4000, - BUTTONS = (YES|OK|NO|CANCEL) - }; - - answer_t AdventureOptions(const bool enabledig); - Game::menu_t FileOptions(void); - u8 SystemOptions(void); - - bool SelectFileLoad(std::string &); - bool SelectFileSave(std::string &); - - // show info cell maps - void QuickInfo(const Maps::Tiles & tile); - void QuickInfo(const Castle & castle); - void QuickInfo(const Heroes & heroes); - - // buttons: OK : CANCEL : OK|CANCEL : YES|NO - u16 Message(const std::string &header, const std::string &message, Font::type_t ft, u16 buttons = 0); - - void ExtSettings(void); - - // other info - Skill::Secondary::skill_t LevelUpSelectSkill(const std::string &header, const Skill::Secondary & sec1, const Skill::Secondary & sec2); - bool SelectGoldOrExp(const std::string &header, const std::string &message, const u16 gold, const u16 expr); - - void SpellInfo(const Spell::spell_t, const bool ok_button = true); - void SpellInfo(const std::string &, const std::string &, const Spell::spell_t, const bool ok_button = true); - void SecondarySkillInfo(const Skill::Secondary::skill_t, const Skill::Level::type_t, const bool ok_button = true); - void SecondarySkillInfo(const std::string &, const std::string &, const Skill::Secondary::skill_t, const Skill::Level::type_t, const bool ok_button = true); - void PrimarySkillInfo(const std::string &, const std::string &, const Skill::Primary::skill_t); - u16 SpriteInfo(const std::string &, const std::string &, const Surface &, u16 buttons = Dialog::OK); - u16 ResourceInfo(const std::string &, const std::string &, const Resource::funds_t &, u16 buttons = Dialog::OK); - - Skill::Primary::skill_t SelectSkillFromArena(void); - - // redistribute count - bool SelectCount(const std::string &header, u32 min, u32 max, u32 & res); - bool InputString(const std::string &, std::string &); - - // recruit monster - u16 RecruitMonster(const Monster & monster, u16 available); - void DwellingInfo(const Monster & monster, u16 available); - bool SetGuardian(Heroes &, Army::Troop &, bool readonly); - - // army info - answer_t ArmyInfo(const Army::Troop & troop, u16 flags); - // dialog marketplace - void Marketplace(bool fromTradingPost = false); - - // dialog buy boat - answer_t BuyBoat(bool enable); - - // puzzle - void PuzzleMaps(void); - - // thieves guild - void ThievesGuild(bool oracle); - - void GameInfo(void); - -class Box : protected Background -{ -public: - Box(u16 height, bool buttons = false); - ~Box(); - - const Rect & GetArea(void){ return area; }; - -private: - Rect area; -}; - -class FrameBorder : protected Background -{ -public: - FrameBorder(); - ~FrameBorder(); - - bool isValid(void) const; - - void SetSize(u16, u16); - void SetPosition(s16, s16, u16 = 0, u16 = 0); - void Redraw(void); - const Rect & GetRect(void) const; - const Rect & GetArea(void) const; - const Rect & GetTop(void) const; - -private: - Rect area; - Rect top; -}; - -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_adventure.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_adventure.cpp deleted file mode 100644 index 9aa9e4dd4..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_adventure.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "dialog.h" - -Dialog::answer_t Dialog::AdventureOptions(const bool enabledig) -{ - Display & display = Display::Get(); - - // preload - const ICN::icn_t apanbkg = Settings::Get().EvilInterface() ? ICN::APANBKGE : ICN::APANBKG; - const ICN::icn_t apanel = Settings::Get().EvilInterface() ? ICN::APANELE : ICN::APANEL; - - AGG::PreloadObject(apanbkg); - AGG::PreloadObject(apanel); - - // cursor - Cursor & cursor = Cursor::Get(); - const Cursor::themes_t oldcursor = cursor.Themes(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - // image box - const Sprite &box = AGG::GetICN(apanbkg, 0); - - Rect rb((display.w() - box.w()) / 2, (display.h() - box.h()) / 2, box.w(), box.h()); - Background back(rb); - back.Save(); - - display.Blit(box, rb.x, rb.y); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonWorld(rb.x + 62, rb.y + 30, apanel, 0, 1); - Button buttonPuzzle(rb.x + 195, rb.y + 30, apanel, 2, 3); - Button buttonInfo(rb.x + 62, rb.y + 107, apanel, 4, 5); - Button buttonDig(rb.x + 195, rb.y + 107, apanel, 6, 7); - Button buttonCancel(rb.x + 128, rb.y + 184, apanel, 8, 9); - - if(! enabledig) buttonDig.SetDisable(true); - - buttonWorld.Draw(); - buttonPuzzle.Draw(); - buttonInfo.Draw(); - buttonDig.Draw(); - buttonCancel.Draw(); - - cursor.Show(); - display.Flip(); - - Dialog::answer_t result = Dialog::ZERO; - - // dialog menu loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonWorld) ? buttonWorld.PressDraw() : buttonWorld.ReleaseDraw(); - le.MousePressLeft(buttonPuzzle) ? buttonPuzzle.PressDraw() : buttonPuzzle.ReleaseDraw(); - le.MousePressLeft(buttonInfo) ? buttonInfo.PressDraw() : buttonInfo.ReleaseDraw(); - le.MousePressLeft(buttonDig) ? buttonDig.PressDraw() : buttonDig.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - - if(le.MouseClickLeft(buttonWorld)){ result = Dialog::WORLD; break; } - if(le.MouseClickLeft(buttonPuzzle)){ result = Dialog::PUZZLE; break; } - if(le.MouseClickLeft(buttonInfo)){ result = Dialog::INFO; break; } - if(le.MouseClickLeft(buttonDig) && buttonDig.isEnable()){ result = Dialog::DIG; break; } - if(le.MouseClickLeft(buttonCancel) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)){ result = Dialog::CANCEL; break; } - - // right info - if(le.MousePressRight(buttonWorld)) Dialog::Message("", _("View the entire world."), Font::BIG); - if(le.MousePressRight(buttonPuzzle)) Dialog::Message("", _("View the obelisk puzzle."), Font::BIG); - if(le.MousePressRight(buttonInfo)) Dialog::Message("", _("View information on the scenario you are currently playing."), Font::BIG); - if(le.MousePressRight(buttonDig)) Dialog::Message("", _("Dig for the Ultimate Artifact."), Font::BIG); - if(le.MousePressRight(buttonCancel)) Dialog::Message("", _("Exit this menu without doing anything."), Font::BIG); - } - - // restore background - cursor.Hide(); - back.Restore(); - cursor.SetThemes(oldcursor); - cursor.Show(); - display.Flip(); - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_arena.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_arena.cpp deleted file mode 100644 index 7b191eefe..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_arena.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" - -void InfoSkillClear(const Rect &, const Rect &, const Rect &, const Rect &); -void InfoSkillSelect(Skill::Primary::skill_t, const Rect &, const Rect &, const Rect &, const Rect &); -Skill::Primary::skill_t InfoSkillNext(Skill::Primary::skill_t); -Skill::Primary::skill_t InfoSkillPrev(Skill::Primary::skill_t); - -Skill::Primary::skill_t Dialog::SelectSkillFromArena(void) -{ - Display & display = Display::Get(); - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // cursor - Cursor & cursor = Cursor::Get(); - Cursor::themes_t oldthemes = cursor.Themes(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - TextBox textbox(_("You enter the arena and face a pack of vicious lions. You handily defeat them, to the wild cheers of the crowd. Impressed by your skill, the aged trainer of gladiators agrees to train you in a skill of your choice."), Font::BIG, BOXAREA_WIDTH); - const Sprite & sprite = AGG::GetICN(ICN::XPRIMARY, 0); - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - - Dialog::Box box(textbox.h() + spacer + sprite.h() + 15, true); - - const Rect & box_rt = box.GetArea(); - Point dst_pt = box_rt; - - textbox.Blit(dst_pt); - dst_pt.y += textbox.h() + spacer; - - Skill::Primary::skill_t res = Skill::Primary::ATTACK; - const Rect rect1(dst_pt.x + box_rt.w / 2 - 2 * sprite.w() - 30, dst_pt.y, sprite.w(), sprite.h()); - const Rect rect2(dst_pt.x + box_rt.w / 2 - sprite.w() - 10, dst_pt.y, sprite.w(), sprite.h()); - const Rect rect3(dst_pt.x + box_rt.w / 2 + 10, dst_pt.y, sprite.w(), sprite.h()); - const Rect rect4(dst_pt.x + box_rt.w / 2 + sprite.w() + 30, dst_pt.y, sprite.w(), sprite.h()); - - InfoSkillClear(rect1, rect2, rect3, rect4); - InfoSkillSelect(res, rect1, rect2, rect3, rect4); - - // info texts - Text text(Skill::Primary::String(Skill::Primary::ATTACK), Font::SMALL); - dst_pt.x = rect1.x + (rect1.w - text.w()) / 2; - dst_pt.y = rect1.y + rect1.h + 5; - text.Blit(dst_pt); - - text.Set(Skill::Primary::String(Skill::Primary::DEFENSE)); - dst_pt.x = rect2.x + (rect2.w - text.w()) / 2; - dst_pt.y = rect2.y + rect2.h + 5; - text.Blit(dst_pt); - - text.Set(Skill::Primary::String(Skill::Primary::POWER)); - dst_pt.x = rect3.x + (rect3.w - text.w()) / 2; - dst_pt.y = rect3.y + rect3.h + 5; - text.Blit(dst_pt); - - text.Set(Skill::Primary::String(Skill::Primary::KNOWLEDGE)); - dst_pt.x = rect4.x + (rect4.w - text.w()) / 2; - dst_pt.y = rect4.y + rect4.h + 5; - text.Blit(dst_pt); - - // buttons - dst_pt.x = box_rt.x + (box_rt.w - AGG::GetICN(system, 1).w()) / 2; - dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h(); - Button buttonOk(dst_pt, system, 1, 2); - - LocalEvent & le = LocalEvent::Get(); - bool redraw = false; - - buttonOk.Draw(); - cursor.Show(); - display.Flip(); - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - - if(Game::HotKeyPress(Game::EVENT_DEFAULT_LEFT) && Skill::Primary::UNKNOWN != InfoSkillPrev(res)) - { - res = InfoSkillPrev(res); - redraw = true; - } - else - if(Game::HotKeyPress(Game::EVENT_DEFAULT_RIGHT) && Skill::Primary::UNKNOWN != InfoSkillNext(res)) - { - res = InfoSkillNext(res); - redraw = true; - } - else - if(le.MouseClickLeft(rect1)) - { - res = Skill::Primary::ATTACK; - redraw = true; - } - else - if(le.MouseClickLeft(rect2)) - { - res = Skill::Primary::DEFENSE; - redraw = true; - } - else - if(le.MouseClickLeft(rect3)) - { - res = Skill::Primary::POWER; - redraw = true; - } - else - if(le.MouseClickLeft(rect4)) - { - res = Skill::Primary::KNOWLEDGE; - redraw = true; - } - - if(redraw) - { - cursor.Hide(); - InfoSkillClear(rect1, rect2, rect3, rect4); - InfoSkillSelect(res, rect1, rect2, rect3, rect4); - cursor.Show(); - display.Flip(); - redraw = false; - } - - if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || le.MouseClickLeft(buttonOk)) break; - } - - cursor.Hide(); - cursor.SetThemes(oldthemes); - cursor.Show(); - - return res; -} - -void InfoSkillClear(const Rect & rect1, const Rect & rect2, const Rect & rect3, const Rect & rect4) -{ - Display & display = Display::Get(); - - display.Blit(AGG::GetICN(ICN::XPRIMARY, 0), rect1); - display.Blit(AGG::GetICN(ICN::XPRIMARY, 1), rect2); - display.Blit(AGG::GetICN(ICN::XPRIMARY, 2), rect3); - display.Blit(AGG::GetICN(ICN::XPRIMARY, 3), rect4); -} - -void InfoSkillSelect(Skill::Primary::skill_t skill, const Rect & rect1, const Rect & rect2, const Rect & rect3, const Rect & rect4) -{ - Display & display = Display::Get(); - - switch(skill) - { - case Skill::Primary::ATTACK: display.Blit(AGG::GetICN(ICN::XPRIMARY, 4), rect1); break; - case Skill::Primary::DEFENSE: display.Blit(AGG::GetICN(ICN::XPRIMARY, 5), rect2); break; - case Skill::Primary::POWER: display.Blit(AGG::GetICN(ICN::XPRIMARY, 6), rect3); break; - case Skill::Primary::KNOWLEDGE: display.Blit(AGG::GetICN(ICN::XPRIMARY, 7), rect4); break; - default: break; - } -} - -Skill::Primary::skill_t InfoSkillNext(Skill::Primary::skill_t skill) -{ - switch(skill) - { - case Skill::Primary::ATTACK: return Skill::Primary::DEFENSE; - case Skill::Primary::DEFENSE: return Skill::Primary::POWER; - case Skill::Primary::POWER: return Skill::Primary::KNOWLEDGE; - default: break; - } - - return Skill::Primary::UNKNOWN; -} - -Skill::Primary::skill_t InfoSkillPrev(Skill::Primary::skill_t skill) -{ - switch(skill) - { - case Skill::Primary::DEFENSE: return Skill::Primary::ATTACK; - case Skill::Primary::POWER: return Skill::Primary::DEFENSE; - case Skill::Primary::KNOWLEDGE: return Skill::Primary::POWER; - default: break; - } - - return Skill::Primary::UNKNOWN; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_armyinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_armyinfo.cpp deleted file mode 100644 index 315c1e2b1..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_armyinfo.cpp +++ /dev/null @@ -1,406 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "monster.h" -#include "morale.h" -#include "speed.h" -#include "luck.h" -#include "army.h" -#include "skill.h" -#include "dialog.h" -#include "game.h" -#include "battle_stats.h" -#include "payment.h" -#include "pocketpc.h" - -void DrawMonsterStats(const Point &, const Army::Troop &); -void DrawBattleStats(const Point &, const Battle2::Stats &); - -Dialog::answer_t Dialog::ArmyInfo(const Army::Troop & troop, u16 flags) -{ - if(Settings::Get().QVGA()) return PocketPC::DialogArmyInfo(troop, flags); - Display & display = Display::Get(); - - const ICN::icn_t viewarmy = Settings::Get().EvilInterface() ? ICN::VIEWARME : ICN::VIEWARMY; - const Surface & sprite_dialog = AGG::GetICN(viewarmy, 0); - const Monster & mons = static_cast(troop); - const Battle2::Stats* battle = troop.GetBattleStats(); - Rect pos_rt; - - pos_rt.x = (display.w() - sprite_dialog.w()) / 2; - pos_rt.y = (display.h() - sprite_dialog.h()) / 2; - pos_rt.w = sprite_dialog.w(); - pos_rt.h = sprite_dialog.h(); - - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Background back(pos_rt); - back.Save(); - display.Blit(sprite_dialog, pos_rt.x, pos_rt.y); - - Point dst_pt; - Text text; - std::string message; - - dst_pt.x = pos_rt.x + 400; - dst_pt.y = pos_rt.y + 40; - - DrawMonsterStats(dst_pt, troop); - - if(battle) - { - dst_pt.x = pos_rt.x + 400; - dst_pt.y = pos_rt.y + 210; - - DrawBattleStats(dst_pt, *battle); - } - - // name - text.Set(troop.GetName(), Font::BIG); - dst_pt.x = pos_rt.x + 140 - text.w() / 2; - dst_pt.y = pos_rt.y + 40; - text.Blit(dst_pt); - - // count - String::AddInt(message, (battle ? battle->GetCount() : troop.GetCount())); - text.Set(message); - dst_pt.x = pos_rt.x + 140 - text.w() / 2; - dst_pt.y = pos_rt.y + 225; - text.Blit(dst_pt); - - const Sprite & frame = AGG::GetICN(troop.ICNMonh(), 0); - display.Blit(frame, pos_rt.x + (pos_rt.w / 2 - frame.w()) / 2, pos_rt.y + 180 - frame.h()); - - // button upgrade - dst_pt.x = pos_rt.x + 284; - dst_pt.y = pos_rt.y + 190; - Button buttonUpgrade(dst_pt, viewarmy, 5, 6); - - // button dismiss - dst_pt.x = pos_rt.x + 284; - dst_pt.y = pos_rt.y + 222; - Button buttonDismiss(dst_pt, viewarmy, 1, 2); - - // button exit - dst_pt.x = pos_rt.x + 410; - dst_pt.y = pos_rt.y + 222; - Button buttonExit(dst_pt, viewarmy, 3, 4); - - if(READONLY & flags) - { - buttonDismiss.Press(); - buttonDismiss.SetDisable(true); - } - - if(!battle && mons.isAllowUpgrade()) - { - if(UPGRADE & flags) - { - buttonUpgrade.SetDisable(false); - buttonUpgrade.Draw(); - } - else if(READONLY & flags) - { - buttonUpgrade.Press(); - buttonUpgrade.SetDisable(true); - buttonUpgrade.Draw(); - } - else buttonUpgrade.SetDisable(true); - } - else buttonUpgrade.SetDisable(true); - - if(BUTTONS & flags) - { - if(!battle) buttonDismiss.Draw(); - buttonExit.Draw(); - } - - LocalEvent & le = LocalEvent::Get(); - Dialog::answer_t result = Dialog::ZERO; - - cursor.Show(); - display.Flip(); - - // dialog menu loop - while(le.HandleEvents()) - { - if(flags & BUTTONS) - { - if(buttonUpgrade.isEnable()) le.MousePressLeft(buttonUpgrade) ? (buttonUpgrade).PressDraw() : (buttonUpgrade).ReleaseDraw(); - if(buttonDismiss.isEnable()) le.MousePressLeft(buttonDismiss) ? (buttonDismiss).PressDraw() : (buttonDismiss).ReleaseDraw(); - le.MousePressLeft(buttonExit) ? (buttonExit).PressDraw() : (buttonExit).ReleaseDraw(); - - // upgrade - if(buttonUpgrade.isEnable() && le.MouseClickLeft(buttonUpgrade)) - { - PaymentConditions::UpgradeMonster payment(troop()); - payment *= troop.GetCount(); - if(Dialog::YES == Dialog::ResourceInfo("", _("Your troops can be upgraded, but it will cost you dearly. Do you wish to upgrade them?"), payment, Dialog::YES|Dialog::NO)) - { - result = Dialog::UPGRADE; - break; - } - } - else - // dismiss - if(buttonDismiss.isEnable() && le.MouseClickLeft(buttonDismiss) && - Dialog::YES == Dialog::Message("", _("Are you sure you want to dismiss this army?"), Font::BIG, Dialog::YES | Dialog::NO)) - { - result = Dialog::DISMISS; - break; - } - else - // exit - if(le.MouseClickLeft(buttonExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)){ result = Dialog::CANCEL; break; } - } - else - { - if(!le.MousePressRight()) break; - } - } - - cursor.Hide(); - back.Restore(); - - return result; -} - -void DrawMonsterStats(const Point & dst, const Army::Troop & troop) -{ - Point dst_pt; - std::string message; - Text text; - const Monster & mons = static_cast(troop); - const Battle2::Stats* battle = troop.GetBattleStats(); - bool commander = troop.MasterSkill(); - bool pda = Settings::Get().QVGA(); - - // attack - message = _("Attack"); - message += ":"; - text.Set(message); - dst_pt.x = dst.x - text.w(); - dst_pt.y = dst.y; - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, mons.GetAttack()); - - if(commander) - { - message += " ("; - String::AddInt(message, troop.GetAttack()); - message += ")"; - } - else - // added ext. battle info - if(battle && mons.GetAttack() != battle->GetAttack()) - { - message += " ("; - String::AddInt(message, battle->GetAttack()); - message += ")"; - } - - const u8 ox = 15; - - text.Set(message); - dst_pt.x = dst.x + ox; - text.Blit(dst_pt); - - // defense - message = _("Defense"); - message += ":"; - text.Set(message); - dst_pt.x = dst.x - text.w(); - dst_pt.y += (pda ? 14 : 18); - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, mons.GetDefense()); - - if(commander) - { - message += " ("; - String::AddInt(message, troop.GetDefense()); - message += ")"; - } - else - // added ext. battle info - if(battle && mons.GetDefense() != battle->GetDefense()) - { - message += " ("; - String::AddInt(message, battle->GetDefense()); - message += ")"; - } - - text.Set(message); - dst_pt.x = dst.x + ox; - text.Blit(dst_pt); - - // shot - if(mons.isArchers()) - { - message = battle ? _("Shots Left") : _("Shots"); - message += ":"; - text.Set(message); - dst_pt.x = dst.x - text.w(); - dst_pt.y += (pda ? 14 : 18); - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, battle ? battle->GetShots() : mons.GetShots()); - text.Set(message); - dst_pt.x = dst.x + ox; - text.Blit(dst_pt); - } - - // damage - message = _("Damage"); - message += ":"; - text.Set(message); - dst_pt.x = dst.x - text.w(); - dst_pt.y += (pda ? 14 : 18); - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, mons.GetDamageMin()); - message += " - "; - String::AddInt(message, mons.GetDamageMax()); - text.Set(message); - dst_pt.x = dst.x + ox; - text.Blit(dst_pt); - - // hp - message = _("Hit Points"); - message += ":"; - text.Set(message); - dst_pt.x = dst.x - text.w(); - dst_pt.y += (pda ? 14 : 18); - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, mons.GetHitPoints()); - text.Set(message); - dst_pt.x = dst.x + ox; - text.Blit(dst_pt); - - if(battle && battle->isValid()) - { - message = _("Hit Points Left"); - message += ":"; - text.Set(message); - dst_pt.x = dst.x - text.w(); - dst_pt.y += (pda ? 14 : 18); - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, battle->GetHitPoints() - (battle->GetCount() - 1) * mons.GetHitPoints()); - text.Set(message); - dst_pt.x = dst.x + ox; - text.Blit(dst_pt); - } - - // speed - message = _("Speed"); - message += ":"; - text.Set(message); - dst_pt.x = dst.x - text.w(); - dst_pt.y += (pda ? 14 : 18); - text.Blit(dst_pt); - - message = Speed::String(battle ? battle->GetSpeed(true) : mons.GetSpeed()); - message += " ("; - String::AddInt(message, battle ? battle->GetSpeed(true) : mons.GetSpeed()); - message += ")"; - text.Set(message); - dst_pt.x = dst.x + ox; - text.Blit(dst_pt); - - // morale - message = _("Morale"); - message += ":"; - text.Set(message); - dst_pt.x = dst.x - text.w(); - dst_pt.y += (pda ? 14 : 18); - text.Blit(dst_pt); - - text.Set(Morale::String(troop.GetMorale())); - dst_pt.x = dst.x + ox; - text.Blit(dst_pt); - - // luck - message = _("Luck"); - message += ":"; - text.Set(message); - dst_pt.x = dst.x - text.w(); - dst_pt.y += (pda ? 14 : 18); - text.Blit(dst_pt); - - text.Set(Luck::String(troop.GetLuck())); - dst_pt.x = dst.x + ox; - text.Blit(dst_pt); -} - -void DrawBattleStats(const Point & dst, const Battle2::Stats & b) -{ - std::vector modes; - modes.reserve(4); - - if(b.Modes(Battle2::SP_BLOODLUST)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 9)); - if(b.Modes(Battle2::SP_BLESS)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 3)); - if(b.Modes(Battle2::SP_HASTE)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 0)); - if(b.Modes(Battle2::SP_SHIELD)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 10)); - if(b.Modes(Battle2::SP_STONESKIN)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 13)); - if(b.Modes(Battle2::SP_DRAGONSLAYER)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 8)); - if(b.Modes(Battle2::SP_STEELSKIN)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 14)); - if(b.Modes(Battle2::SP_ANTIMAGIC)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 12)); - if(b.Modes(Battle2::SP_CURSE)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 4)); - if(b.Modes(Battle2::SP_SLOW)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 1)); - if(b.Modes(Battle2::SP_BERSERKER)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 5)); - if(b.Modes(Battle2::SP_HYPNOTIZE)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 7)); - if(b.Modes(Battle2::SP_BLIND)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 2)); - if(b.Modes(Battle2::SP_PARALYZE)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 6)); - if(b.Modes(Battle2::SP_STONE)) modes.push_back(&AGG::GetICN(ICN::SPELLINF, 11)); - - if(modes.size()) - { - std::vector::const_iterator it; - u16 ow = 0; - for(it = modes.begin(); it != modes.end(); ++it) - { - ow += (*it)->w() + 4; - } - ow -= 4; - ow = dst.x - ow / 2; - for(it = modes.begin(); it != modes.end(); ++it) - { - Display::Get().Blit(**it, ow, dst.y); - ow += (*it)->w() + 4; - } - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_box.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_box.cpp deleted file mode 100644 index e6f32c95b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_box.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "cursor.h" -#include "settings.h" -#include "dialog.h" - -#define BUTTON_HEIGHT 40 -#define BOX_WIDTH 306 -#define BOX_TOP 99 -#define BOX_MIDDLE 45 -#define BOX_BOTTOM 81 -#define BOXE_TOP 88 -#define BOXE_MIDDLE 45 -#define BOXE_BOTTOM 81 -#define BOXAREA_TOP 35 -#define BOXAREA_MIDDLE 10 -#define BOXAREA_BOTTOM 35 - -void BoxRedraw(s16 posx, s16 posy, u8 count); - -Dialog::Box::Box(u16 height, bool buttons) -{ - Display & display = Display::Get(); - - if(buttons) height += BUTTON_HEIGHT; - - bool evil = Settings::Get().EvilInterface(); - const u8 count_middle = (height <= BOXAREA_TOP + BOXAREA_BOTTOM ? 0 : 1 + (height - BOXAREA_TOP - BOXAREA_BOTTOM) / BOXAREA_MIDDLE); - const u16 height_middle = count_middle * BOXAREA_MIDDLE; - const u16 height_top_bottom = (evil ? BOXE_TOP + BOXE_BOTTOM : BOX_TOP + BOX_BOTTOM); - - area.w = BOXAREA_WIDTH; - area.h = BOXAREA_TOP + BOXAREA_BOTTOM + height_middle; - - s16 posx = (display.w() - BOX_WIDTH) / 2; - s16 posy = (display.h() - height_top_bottom - height_middle) / 2; - - if(Settings::Get().QVGA() && height > display.h()) - posy = display.h() - area.h - ((evil ? BOXE_TOP : BOX_TOP) - BOXAREA_TOP); - - Save(posx, posy, BOX_WIDTH, height_top_bottom + height_middle); - - area.x = Rect::x + 36; - area.y = Rect::y + (evil ? BOXE_TOP - BOXAREA_TOP : BOX_TOP - BOXAREA_TOP); - - BoxRedraw(Rect::x, Rect::y, count_middle); -} - -Dialog::Box::~Box() -{ - if(Cursor::Get().isVisible()) - { - Cursor::Get().Hide(); - Background::Restore(); - Cursor::Get().Show(); - } - else - Background::Restore(); - Display::Get().Flip(); -} - -void BoxRedraw(s16 posx, s16 posy, u8 count) -{ - Display & display = Display::Get(); - const ICN::icn_t buybuild = Settings::Get().EvilInterface() ? ICN::BUYBUILE : ICN::BUYBUILD; - - // left top sprite - Point pt(posx, posy); - if(!Settings::Get().EvilInterface()) ++pt.x; - display.Blit(AGG::GetICN(buybuild, 4), pt); - - // right top sprite - pt.x = posx + AGG::GetICN(buybuild, 4).w(); - display.Blit(AGG::GetICN(buybuild, 0), pt); - - pt.y += AGG::GetICN(buybuild, 4).h(); - for(int i = 0; i < count; ++i) - { - // left middle sprite - pt.x = posx; - const Sprite & sl = AGG::GetICN(buybuild, 5); - display.Blit(sl, Rect(0, 10, sl.w(), BOXAREA_MIDDLE), pt); - - // right middle sprite - pt.x += sl.w(); - if(!Settings::Get().EvilInterface()) pt.x -= 1; - const Sprite & sr = AGG::GetICN(buybuild, 1); - display.Blit(sr, Rect(0, 10, sr.w(), BOXAREA_MIDDLE), pt); - pt.y += BOXAREA_MIDDLE; - } - - // right bottom sprite - display.Blit(AGG::GetICN(buybuild, 2), pt); - - // left bottom sprite - pt.x = posx; - display.Blit(AGG::GetICN(buybuild, 6), pt); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_buyboat.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_buyboat.cpp deleted file mode 100644 index 2e1138441..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_buyboat.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "world.h" -#include "button.h" -#include "cursor.h" -#include "castle.h" -#include "kingdom.h" -#include "settings.h" -#include "dialog.h" -#include "payment.h" - -Dialog::answer_t Dialog::BuyBoat(bool enable) -{ - Display & display = Display::Get(); - - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - - Resource::BoxSprite rbs(PaymentConditions::BuyBoat(), BOXAREA_WIDTH); - - const Sprite & sprite = AGG::GetICN(ICN::BOATWIND, 0); - Text text(_("Build a new ship:"), Font::BIG); - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - - Dialog::Box box(text.h() + spacer + sprite.h() + spacer + text.h() + spacer + rbs.GetArea().h - 20, true); - - const Rect & box_rt = box.GetArea(); - Point dst_pt; - dst_pt.x = box_rt.x + (box_rt.w - text.w()) / 2; - dst_pt.y = box_rt.y; - text.Blit(dst_pt); - - dst_pt.x = box_rt.x + (box_rt.w - sprite.w()) / 2; - dst_pt.y = box_rt.y + text.h() + spacer; - display.Blit(sprite, dst_pt); - - text.Set(_("Resource cost:"), Font::BIG); - dst_pt.x = box_rt.x + (box_rt.w - text.w()) / 2; - dst_pt.y = dst_pt.y + sprite.h() + spacer; - text.Blit(dst_pt); - - rbs.SetPos(box_rt.x, dst_pt.y + spacer); - rbs.Redraw(); - - // buttons - dst_pt.x = box_rt.x; - dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h(); - Button button1(dst_pt, system, 1, 2); - - dst_pt.x = box_rt.x + box_rt.w - AGG::GetICN(system, 3).w(); - dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 3).h(); - Button button2(dst_pt, system, 3, 4); - - if(!enable) - { - button1.Press(); - button1.SetDisable(true); - } - - button1.Draw(); - button2.Draw(); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - - // message loop - while(le.HandleEvents()) - { - if(button1.isEnable()) le.MousePressLeft(button1) ? button1.PressDraw() : button1.ReleaseDraw(); - le.MousePressLeft(button2) ? button2.PressDraw() : button2.ReleaseDraw(); - - if(button1.isEnable() && - (Game::HotKeyPress(Game::EVENT_DEFAULT_READY) ||le.MouseClickLeft(button1))) return Dialog::OK; - - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || - le.MouseClickLeft(button2)) return Dialog::CANCEL; - } - - return Dialog::ZERO; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_chest.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_chest.cpp deleted file mode 100644 index 478233bd1..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_chest.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" - -bool Dialog::SelectGoldOrExp(const std::string &header, const std::string &message, const u16 gold, const u16 expr) -{ - Display & display = Display::Get(); - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // preload - AGG::PreloadObject(system); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite & sprite_gold = AGG::GetICN(ICN::RESOURCE, 6); - const Sprite & sprite_expr = AGG::GetICN(ICN::EXPMRL, 4); - - Point pt; - TextBox box1(header, Font::YELLOW_BIG, BOXAREA_WIDTH); - TextBox box2(message, Font::BIG, BOXAREA_WIDTH); - - Text text; - std::string str; - String::AddInt(str, gold); - text.Set(str, Font::SMALL); - - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - - Box box(box1.h() + spacer + box2.h() + spacer + sprite_expr.h() + 2 + text.h(), true); - - pt.x = box.GetArea().x + box.GetArea().w / 2 - AGG::GetICN(system, 9).w() - 20; - pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 5).h(); - Button button_yes(pt, system, 5, 6); - - pt.x = box.GetArea().x + box.GetArea().w / 2 + 20; - pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 7).h(); - Button button_no(pt, system, 7, 8); - - Rect pos = box.GetArea(); - - if(header.size()) box1.Blit(pos); - pos.y += box1.h() + spacer; - - if(message.size()) box2.Blit(pos); - pos.y += box2.h() + spacer; - - pos.y += sprite_expr.h(); - // sprite1 - pos.x = box.GetArea().x + box.GetArea().w / 2 - sprite_gold.w() - 30; - display.Blit(sprite_gold, pos.x, pos.y - sprite_gold.h()); - // text - text.Blit(pos.x + (sprite_gold.w() - text.w()) / 2, pos.y + 2); - - // sprite2 - pos.x = box.GetArea().x + box.GetArea().w / 2 + 30; - display.Blit(sprite_expr, pos.x, pos.y - sprite_expr.h()); - // text - str.clear(); - String::AddInt(str, expr); - text.Set(str, Font::SMALL); - text.Blit(pos.x + (sprite_expr.w() - text.w()) / 2, pos.y + 2); - - button_yes.Draw(); - button_no.Draw(); - - cursor.Show(); - display.Flip(); - LocalEvent & le = LocalEvent::Get(); - bool result = false; - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(button_yes) ? button_yes.PressDraw() : button_yes.ReleaseDraw(); - le.MousePressLeft(button_no) ? button_no.PressDraw() : button_no.ReleaseDraw(); - - if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || le.MouseClickLeft(button_yes)){ result = true; break; } - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(button_no)){ result = false; break; } - } - - cursor.Hide(); - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_file.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_file.cpp deleted file mode 100644 index a31b7eee2..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_file.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "dialog.h" - -Game::menu_t Dialog::FileOptions(void) -{ - Display & display = Display::Get(); - // preload - const ICN::icn_t cpanbkg = Settings::Get().EvilInterface() ? ICN::CPANBKGE : ICN::CPANBKG; - const ICN::icn_t cpanel = Settings::Get().EvilInterface() ? ICN::CPANELE : ICN::CPANEL; - - AGG::PreloadObject(cpanbkg); - AGG::PreloadObject(cpanel); - - // cursor - Cursor & cursor = Cursor::Get(); - const Cursor::themes_t oldcursor = cursor.Themes(); - cursor.Hide(); - cursor.SetThemes(Cursor::POINTER); - - // image box - const Sprite &box = AGG::GetICN(cpanbkg, 0); - - Rect rb((display.w() - box.w()) / 2, (display.h() - box.h()) / 2, box.w(), box.h()); - Background back(rb); - back.Save(); - - display.Blit(box, rb.x, rb.y); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonNew(rb.x + 62, rb.y + 31, cpanel, 0, 1); - Button buttonLoad(rb.x + 195, rb.y + 31, cpanel, 2, 3); - Button buttonSave(rb.x + 62, rb.y + 107, cpanel, 4, 5); - Button buttonQuit(rb.x + 195, rb.y + 107, cpanel, 6, 7); - Button buttonCancel(rb.x + 128, rb.y + 184, cpanel, 8, 9); - - buttonNew.Draw(); - buttonLoad.Draw(); - buttonSave.Draw(); - buttonQuit.Draw(); - buttonCancel.Draw(); - - cursor.Show(); - display.Flip(); - - Game::menu_t result = Game::QUITGAME; - - // dialog menu loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonNew) ? buttonNew.PressDraw() : buttonNew.ReleaseDraw(); - le.MousePressLeft(buttonLoad) ? buttonLoad.PressDraw() : buttonLoad.ReleaseDraw(); - le.MousePressLeft(buttonSave) ? buttonSave.PressDraw() : buttonSave.ReleaseDraw(); - le.MousePressLeft(buttonQuit) ? buttonQuit.PressDraw() : buttonQuit.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - - if(le.MouseClickLeft(buttonNew)) { result = Game::NEWGAME; break; } - if(le.MouseClickLeft(buttonLoad)){ result = Game::LOADGAME; break; } - if(le.MouseClickLeft(buttonSave)){ result = Game::SAVEGAME; break; } - if(le.MouseClickLeft(buttonQuit)){ result = Game::QUITGAME; break; } - if(le.MouseClickLeft(buttonCancel) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)){ result = Game::CANCEL; break; } - } - - // restore background - cursor.Hide(); - back.Restore(); - cursor.SetThemes(oldcursor); - cursor.Show(); - display.Flip(); - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_frameborder.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_frameborder.cpp deleted file mode 100644 index 3398e59ad..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_frameborder.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "dialog.h" - -#define LIMITWIDTH BORDERWIDTH * 4 -#define ANGLEWIDTH 44 - -void DrawBorder(s16, s16, u16, u16, Surface &); - -Dialog::FrameBorder::FrameBorder() -{ -} - -bool Dialog::FrameBorder::isValid(void) const -{ - return Background::isValid(); -} - -void Dialog::FrameBorder::SetSize(u16 encw, u16 ench) -{ - Display & display = Display::Get(); - if(display.w() < encw || display.h() < ench || encw < LIMITWIDTH || ench < LIMITWIDTH) - DEBUG(DBG_GAME , DBG_WARN, "Dialog::FrameBorder: size out of range"); - - Rect::w = encw + 2 * BORDERWIDTH; - Rect::h = ench + 2 * BORDERWIDTH; - area.w = encw; - area.h = ench; -} - -void Dialog::FrameBorder::SetPosition(s16 posx, s16 posy, u16 encw, u16 ench) -{ - if(Background::isValid()) Background::Restore(); - - if(encw && ench) - { - Background::Save(posx, posy, encw + 2 * BORDERWIDTH, ench + 2 * BORDERWIDTH); - area.w = encw; - area.h = ench; - } - else - Background::Save(posx, posy); - - area.x = posx + BORDERWIDTH; - area.y = posy + BORDERWIDTH; - top = Rect(posx, posy, area.w, BORDERWIDTH); -} - -const Rect & Dialog::FrameBorder::GetTop(void) const -{ - return top; -} - -const Rect & Dialog::FrameBorder::GetRect(void) const -{ - return Background::GetRect(); -} - -const Rect & Dialog::FrameBorder::GetArea(void) const -{ - return area; -} - -void Dialog::FrameBorder::Redraw(void) -{ - DrawBorder(GetRect().x, GetRect().y, GetRect().w, GetRect().h, Display::Get()); -} - -Dialog::FrameBorder::~FrameBorder() -{ - if(Cursor::Get().isVisible()){ Cursor::Get().Hide(); }; - Background::Restore(); -} - -void DrawBorder(s16 posx, s16 posy, u16 posw, u16 posh, Surface & sf) -{ - const Sprite & surdbkg = (Settings::Get().EvilInterface() ? AGG::GetICN(ICN::SURDRBKE, 0) : AGG::GetICN(ICN::SURDRBKG, 0)); - Rect src_rt; - Point dst_pt; - - // top left angle - src_rt = Rect(SHADOWWIDTH, 0, ANGLEWIDTH, BORDERWIDTH); - dst_pt = Point(posx, posy); - sf.Blit(surdbkg, src_rt, dst_pt); - - // top bar - src_rt = Rect(SHADOWWIDTH + ANGLEWIDTH + 20, 0, BORDERWIDTH * 2, BORDERWIDTH); - dst_pt = Point(posx + ANGLEWIDTH, posy); - while(dst_pt.x < posx + posw - BORDERWIDTH * 2) - { - sf.Blit(surdbkg, src_rt, dst_pt); - dst_pt.x += src_rt.w; - } - - // top right angle - src_rt = Rect(surdbkg.w() - ANGLEWIDTH, 0, ANGLEWIDTH, BORDERWIDTH); - dst_pt = Point(posx + posw - src_rt.w, posy); - sf.Blit(surdbkg, src_rt, dst_pt); - - // bottom left angle - src_rt = Rect(SHADOWWIDTH, surdbkg.h() - SHADOWWIDTH - BORDERWIDTH, ANGLEWIDTH, BORDERWIDTH); - dst_pt = Point(posx, posy + posh - src_rt.h); - sf.Blit(surdbkg, src_rt, dst_pt); - - // bottom bar - src_rt = Rect(SHADOWWIDTH + ANGLEWIDTH, surdbkg.h() - SHADOWWIDTH - BORDERWIDTH, BORDERWIDTH * 2, BORDERWIDTH); - dst_pt = Point(posx + ANGLEWIDTH, posy + posh - src_rt.h); - while(dst_pt.x < posx + posw - BORDERWIDTH * 2) - { - sf.Blit(surdbkg, src_rt, dst_pt); - dst_pt.x += src_rt.w; - } - - // bottom right angle - src_rt = Rect(surdbkg.w() - ANGLEWIDTH, surdbkg.h() - SHADOWWIDTH - BORDERWIDTH, ANGLEWIDTH, BORDERWIDTH); - dst_pt = Point(posx + posw - src_rt.w, posy + posh - src_rt.h); - sf.Blit(surdbkg, src_rt, dst_pt); - - // left top angle - src_rt = Rect(SHADOWWIDTH, 0, BORDERWIDTH, ANGLEWIDTH); - dst_pt = Point(posx, posy); - sf.Blit(surdbkg, src_rt, dst_pt); - - // left bar - src_rt = Rect(SHADOWWIDTH, ANGLEWIDTH, BORDERWIDTH, BORDERWIDTH * 2); - dst_pt = Point(posx, posy + ANGLEWIDTH); - while(dst_pt.y < posy + posh - BORDERWIDTH * 3) - { - sf.Blit(surdbkg, src_rt, dst_pt); - dst_pt.y += src_rt.h; - } - - // left bottom angle - src_rt = Rect(SHADOWWIDTH, surdbkg.h() - SHADOWWIDTH - ANGLEWIDTH, BORDERWIDTH, ANGLEWIDTH); - dst_pt = Point(posx, posy + posh - src_rt.h); - sf.Blit(surdbkg, src_rt, dst_pt); - - // right top angle - src_rt = Rect(surdbkg.w() - BORDERWIDTH, 0, BORDERWIDTH, ANGLEWIDTH); - dst_pt = Point(posx + posw - src_rt.w, posy); - sf.Blit(surdbkg, src_rt, dst_pt); - - // right bar - src_rt = Rect(surdbkg.w() - BORDERWIDTH, ANGLEWIDTH, BORDERWIDTH, ANGLEWIDTH); - dst_pt = Point(posx + posw - src_rt.w, posy + ANGLEWIDTH); - while(dst_pt.y < posy + posh - BORDERWIDTH * 3) - { - sf.Blit(surdbkg, src_rt, dst_pt); - dst_pt.y += src_rt.h; - } - - // right bottom angle - src_rt = Rect(surdbkg.w() - BORDERWIDTH, surdbkg.h() - SHADOWWIDTH - ANGLEWIDTH, BORDERWIDTH, ANGLEWIDTH); - dst_pt = Point(posx + posw - src_rt.w, posy + posh - src_rt.h); - sf.Blit(surdbkg, src_rt, dst_pt); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_gameinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_gameinfo.cpp deleted file mode 100644 index 67bf1464f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_gameinfo.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "maps.h" -#include "game.h" -#include "game_over.h" -#include "dialog.h" - -void Dialog::GameInfo(void) -{ - // FIXME: QVGA version - if(Settings::Get().QVGA()) - { - Dialog::Message("", _("For the QVGA version is not available."), Font::SMALL, Dialog::OK); - return; - } - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - Settings & conf = Settings::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite & dlg = AGG::GetICN(ICN::SCENIBKG, 0); - const Point pt((display.w() - dlg.w()) / 2, (display.h() - dlg.h()) / 2); - Background back(pt, dlg.w(), dlg.h()); - - back.Save(); - display.Blit(dlg, pt); - - TextBox text; - std::string msg; - - text.Set(conf.MapsName(), Font::BIG, 350); - text.Blit(pt.x + 52, pt.y + 30); - - text.Set(_("Map\nDifficulty"), Font::SMALL, 80); - text.Blit(pt.x + 50, pt.y + 54); - - text.Set(_("Game\nDifficulty"), Font::SMALL, 80); - text.Blit(pt.x + 140, pt.y + 54); - - text.Set(_("Rating"), Font::SMALL, 80); - text.Blit(pt.x + 230, pt.y + 61); - - text.Set(_("Map Size"), Font::SMALL, 80); - text.Blit(pt.x + 322, pt.y + 61); - - text.Set(Difficulty::String(conf.MapsDifficulty()), Font::SMALL, 80); - text.Blit(pt.x + 50, pt.y + 80); - - text.Set(Difficulty::String(conf.GameDifficulty()), Font::SMALL, 80); - text.Blit(pt.x + 140, pt.y + 80); - - std::string str; - String::AddInt(str, Game::GetRating()); - str.append(" %"); - text.Set(str, Font::SMALL, 80); - text.Blit(pt.x + 230, pt.y + 80); - - text.Set(Maps::SizeString(conf.MapsWidth()), Font::SMALL, 80); - text.Blit(pt.x + 322, pt.y + 80); - - text.Set(conf.MapsDescription(), Font::SMALL, 350); - text.Blit(pt.x + 52, pt.y + 105); - - text.Set(_("Opponents"), Font::SMALL, 350); - text.Blit(pt.x + 52, pt.y + 150); - - Point dst(pt.x + 40, pt.y + 165); - Game::Scenario::RedrawOpponentsInfo(dst); - - text.Set(_("Class"), Font::SMALL, 350); - text.Blit(pt.x + 52, pt.y + 225); - - dst.y = pt.y + 240; - Game::Scenario::RedrawClassInfo(dst); - - text.Set(_("Victory\nConditions"), Font::SMALL, 80); - text.Blit(pt.x + 40, pt.y + 345); - - GameOver::GetActualDescription(conf.ConditionWins(), msg); - text.Set(msg, Font::SMALL, 272); - text.Blit(pt.x + 130, pt.y + 348); - - text.Set(_("Loss\nConditions"), Font::SMALL, 80); - text.Blit(pt.x + 40, pt.y + 390); - - GameOver::GetActualDescription(conf.ConditionLoss(), msg); - text.Set(msg, Font::SMALL, 272); - text.Blit(pt.x + 130, pt.y + 396); - - str = "score: "; - String::AddInt(str, Game::GetGameOverScores()); - text.Set(str, Font::YELLOW_SMALL, 80); - text.Blit(pt.x + 415 - text.w(), pt.y + 434); - - Button button(pt.x + 180, pt.y + 425, ICN::SYSTEM, 1, 2); - button.Draw(); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(button) ? button.PressDraw() : button.ReleaseDraw(); - - if(le.MouseClickLeft(button) || - HotKeyCloseWindow) break; - } - - cursor.Hide(); - back.Restore(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_guardian.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_guardian.cpp deleted file mode 100644 index 37ad69161..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_guardian.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "heroes.h" -#include "portrait.h" -#include "button.h" -#include "selectarmybar.h" -#include "heroes_indicator.h" -#include "army_troop.h" -#include "dialog.h" - -class ArmyCell : public Rect -{ -public: - ArmyCell(const Army::Troop & t, const Surface & bg, const Surface & cr, const Point & pt, const bool & ro) - : Rect(pt.x, pt.y, bg.w(), bg.h()), select(false), troop(t), back(bg), curs(cr), readonly(ro) {}; - - void Redraw(void) - { - Display & display = Display::Get(); - - display.Blit(back, *this); - if(troop.isValid()) - { - const Sprite & mons32 = AGG::GetICN(ICN::MONS32, Monster::GetSpriteIndex(troop())); - display.Blit(mons32, x + (back.w() - mons32.w()) / 2, y + back.h() - mons32.h() - 11); - - if(readonly) - display.Blit(AGG::GetICN(ICN::LOCATORS, 24), x + 33, y + 5); - - std::string str; - String::AddInt(str, troop.GetCount()); - Text text(str, Font::SMALL); - text.Blit(x + (back.w() - text.w()) / 2, y + back.h() - 11); - } - - if(select) - display.Blit(curs, *this); - }; - - bool select; - const Army::Troop & troop; - const Surface & back; - const Surface & curs; - const bool & readonly; -}; - -bool Dialog::SetGuardian(Heroes & hero, Army::Troop & troop, bool readonly) -{ - Display & display = Display::Get(); - //const Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 230; - const u16 window_h = 160; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - Point dst_pt; - const Rect & area = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), area); - - // portrait - const Sprite & window = AGG::GetICN(ICN::BRCREST, 6); - dst_pt.x = area.x + 3; - dst_pt.y = area.y + 5; - display.Blit(window, dst_pt); - display.Blit(Portrait::Get(hero, Portrait::MEDIUM), dst_pt.x + 4, dst_pt.y + 4); - - // indicators - dst_pt.x = area.x + 185; - dst_pt.y = area.y + 5; - MoraleIndicator moraleIndicator(hero); - moraleIndicator.SetPos(dst_pt); - moraleIndicator.Redraw(); - - dst_pt.x = area.x + 185; - dst_pt.y = area.y + 35; - LuckIndicator luckIndicator(hero); - luckIndicator.SetPos(dst_pt); - luckIndicator.Redraw(); - - // army bar - dst_pt.x = area.x + 3; - dst_pt.y = area.y + 73; - - const Sprite &backSprite = AGG::GetICN(ICN::SWAPWIN, 0); - const Rect rt(36, 267, 43, 53); - Surface sfb(rt.w, rt.h); - sfb.Blit(backSprite, rt, 0, 0); - Surface sfc(rt.w, rt.h - 10); - Cursor::DrawCursor(sfc, 0x10, true); - - SelectArmyBar selectArmy; - selectArmy.SetArmy(hero.GetArmy()); - selectArmy.SetPos(dst_pt); - selectArmy.SetInterval(2); - selectArmy.SetBackgroundSprite(sfb); - selectArmy.SetCursorSprite(sfc); - selectArmy.SetUseMons32Sprite(); - selectArmy.SetSaveLastTroop(); - selectArmy.Redraw(); - - // guardian - dst_pt.x = area.x + 93; - dst_pt.y = area.y + 17; - ArmyCell guardian(troop, sfb, sfc, dst_pt, readonly); - guardian.Redraw(); - - // label - Text text(_("Set Guardian"), Font::SMALL); - text.Blit(area.x + (area.w - text.w()) / 2, area.y + 3); - - ButtonGroups btnGroups(area, Dialog::OK); - btnGroups.Draw(); - - const Army::Troop shadow(troop); - - cursor.Show(); - display.Flip(); - - // message loop - u16 buttons = Dialog::ZERO; - - while(buttons == Dialog::ZERO && le.HandleEvents()) - { - buttons = btnGroups.QueueEventProcessing(); - - if(le.MouseCursor(selectArmy.GetArea())) - { - if(guardian.select && le.MouseClickLeft(selectArmy.GetArea())) - { - Army::Troop & troop1 = hero.GetArmy().At(selectArmy.GetIndexFromCoord(le.GetMouseCursor())); - - // combine - if(troop1() == troop()) - { - troop1.SetCount(troop.GetCount() + troop1.GetCount()); - troop.Reset(); - } - else - if(troop1.GetCount() >= MAXU16) - Dialog::Message("", _("Your army too big!"), Font::BIG, Dialog::OK); - // swap - else - { - Army::SwapTroops(troop1, troop); - } - - guardian.select = false; - cursor.Hide(); - } - else - if(SelectArmyBar::QueueEventProcessing(selectArmy)) - { - guardian.select = false; - cursor.Hide(); - } - } - else - if(le.MouseCursor(moraleIndicator.GetArea())) - MoraleIndicator::QueueEventProcessing(moraleIndicator); - else - if(le.MouseCursor(luckIndicator.GetArea())) - LuckIndicator::QueueEventProcessing(luckIndicator); - else - if(le.MouseClickLeft(guardian)) - { - if(guardian.select) - { - Dialog::ArmyInfo(troop, Dialog::READONLY | Dialog::BUTTONS); - cursor.Hide(); - } - else - if(selectArmy.isSelected() && !readonly && !selectArmy.SaveLastTroop()) - { - Army::Troop & troop1 = hero.GetArmy().At(selectArmy.Selected()); - - // combine - if(troop1() == troop()) - { - if(troop1.GetCount() + troop.GetCount() < MAXU16) - { - troop.SetCount(troop1.GetCount() + troop.GetCount()); - troop1.Reset(); - } - else - { - troop1.SetCount(troop1.GetCount() + troop.GetCount() - MAXU16); - troop.SetCount(MAXU16); - } - } - else - if(troop1.GetCount() >= MAXU16) - Dialog::Message("", _("Your army too big!"), Font::BIG, Dialog::OK); - // swap - else - { - Army::SwapTroops(troop1, troop); - } - - selectArmy.Reset(); - cursor.Hide(); - } - else - // select - if(troop.isValid() && !readonly) - { - selectArmy.Reset(); - guardian.select = true; - cursor.Hide(); - } - } - else - if(le.MousePressRight(guardian) && troop.isValid()) - { - selectArmy.Reset(); - Dialog::ArmyInfo(troop, 0); - cursor.Hide(); - } - - if(!cursor.isVisible()) - { - guardian.Redraw(); - moraleIndicator.Redraw(); - luckIndicator.Redraw(); - selectArmy.Redraw(); - cursor.Show(); - display.Flip(); - } - } - - return shadow() != troop() || shadow.GetCount() != troop.GetCount(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_levelup.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_levelup.cpp deleted file mode 100644 index b2d6cd0ba..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_levelup.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" - -Skill::Secondary::skill_t Dialog::LevelUpSelectSkill(const std::string & header, const Skill::Secondary & sec1, const Skill::Secondary & sec2) -{ - Display & display = Display::Get(); - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // preload - AGG::PreloadObject(system); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite &sprite_frame = AGG::GetICN(ICN::SECSKILL, 15); - const Sprite & sprite_skill1 = AGG::GetICN(ICN::SECSKILL, Skill::Secondary::GetIndexSprite1(sec1.Skill())); - const Sprite & sprite_skill2 = AGG::GetICN(ICN::SECSKILL, Skill::Secondary::GetIndexSprite1(sec2.Skill())); - - Point pt; - std::string message = _("You may learn either %{level1} %{skill1} or %{level2} %{skill2}."); - String::Replace(message, "%{level1}", Skill::Level::String(sec1.Level())); - String::Replace(message, "%{skill1}", Skill::Secondary::String(sec1.Skill())); - String::Replace(message, "%{level2}", Skill::Level::String(sec2.Level())); - String::Replace(message, "%{skill2}", Skill::Secondary::String(sec2.Skill())); - - TextBox box1(header, Font::BIG, BOXAREA_WIDTH); - TextBox box2(message, Font::BIG, BOXAREA_WIDTH); - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - - Box box(box1.h() + spacer + box2.h() + 10 + sprite_frame.h(), true); - - pt.x = box.GetArea().x + box.GetArea().w / 2 - AGG::GetICN(system, 9).w() - 20; - pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 9).h(); - Button button_learn1(pt, system, 9, 10); - - pt.x = box.GetArea().x + box.GetArea().w / 2 + 20; - pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 9).h(); - Button button_learn2(pt, system, 9, 10); - - Rect pos = box.GetArea(); - - if(header.size()) box1.Blit(pos); - pos.y += box1.h() + spacer; - - if(message.size()) box2.Blit(pos); - pos.y += box2.h() + spacer; - - // sprite1 - pos.x = box.GetArea().x + box.GetArea().w / 2 - sprite_frame.w() - 20; - display.Blit(sprite_frame, pos); - pos.x += 3; - Rect rect_image1(pos, sprite_skill1.w(), sprite_skill1.h()); - display.Blit(sprite_skill1, pos.x, pos.y + 3); - - Text text; - // text - text.Set(Skill::Secondary::String(sec1.Skill()), Font::SMALL); - text.Blit(pos.x + (sprite_skill1.w() - text.w()) / 2, pos.y + 5); - text.Set(Skill::Level::String(sec1.Level()), Font::SMALL); - text.Blit(pos.x + (sprite_skill1.w() - text.w()) / 2, pos.y + sprite_skill1.h() - 12); - - // sprite2 - pos.x = box.GetArea().x + box.GetArea().w / 2 + 20; - display.Blit(sprite_frame, pos); - pos.x += 3; - Rect rect_image2(pos, sprite_skill2.w(), sprite_skill2.h()); - display.Blit(sprite_skill2, pos.x, pos.y + 3); - // text - Text name_skill2(Skill::Secondary::String(sec2.Skill()), Font::SMALL); - name_skill2.Blit(pos.x + (sprite_skill2.w() - name_skill2.w()) / 2, pos.y + 5); - Text name_level2(Skill::Level::String(sec2.Level()), Font::SMALL); - name_level2.Blit(pos.x + (sprite_skill2.w() - name_level2.w()) / 2, pos.y + sprite_skill2.h() - 12); - - button_learn1.Draw(); - button_learn2.Draw(); - - cursor.Show(); - display.Flip(); - LocalEvent & le = LocalEvent::Get(); - Skill::Secondary::skill_t result = Skill::Secondary::UNKNOWN; - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(button_learn1) ? button_learn1.PressDraw() : button_learn1.ReleaseDraw(); - le.MousePressLeft(button_learn2) ? button_learn2.PressDraw() : button_learn2.ReleaseDraw(); - - if(le.MouseClickLeft(button_learn1) || Game::HotKeyPress(Game::EVENT_DEFAULT_LEFT)){ result = sec1.Skill(); break; } - if(le.MouseClickLeft(button_learn2) || Game::HotKeyPress(Game::EVENT_DEFAULT_RIGHT)){ result = sec2.Skill(); break; } - - if(le.MouseClickLeft(rect_image1)){ cursor.Hide(); SecondarySkillInfo(sec1.Skill(), sec1.Level()); cursor.Show(); display.Flip(); } - else - if(le.MouseClickLeft(rect_image2)){ cursor.Hide(); SecondarySkillInfo(sec2.Skill(), sec2.Level()); cursor.Show(); display.Flip(); } - - if(le.MousePressRight(rect_image1)){ cursor.Hide(); SecondarySkillInfo(sec1.Skill(), sec1.Level(), false); cursor.Show(); display.Flip(); } - else - if(le.MousePressRight(rect_image2)){ cursor.Hide(); SecondarySkillInfo(sec2.Skill(), sec2.Level(), false); cursor.Show(); display.Flip(); } - } - - cursor.Hide(); - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_marketplace.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_marketplace.cpp deleted file mode 100644 index f2a4503d7..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_marketplace.cpp +++ /dev/null @@ -1,847 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "button.h" -#include "world.h" -#include "cursor.h" -#include "settings.h" -#include "resource.h" -#include "kingdom.h" -#include "splitter.h" -#include "marketplace.h" -#include "dialog.h" -#include "localclient.h" - -void RedrawFromResource(const Point & pt, const Resource::funds_t & rs); -void RedrawToResource(const Point & pt, bool showcost, bool tradingPost, u8 from_resource = 0); -void GetStringTradeCosts(std::string & str, u8 rs_from, u8 rs_to, bool tradingPost); -u16 GetTradeCosts(u8 rs_from, u8 rs_to, bool tradingPost); - -class TradeWindowGUI -{ -public: - TradeWindowGUI(const Rect & rt) : - pos_rt(rt), back(rt.x - 5, rt.y + 15, rt.w + 10, 160), - tradpost(Settings::Get().EvilInterface() ? ICN::TRADPOSE : ICN::TRADPOST) - { - back.Save(); - - buttonTrade.SetPos(pos_rt.x + (pos_rt.w - AGG::GetICN(tradpost, 17).w()) / 2, pos_rt.y + 150); - buttonLeft.SetPos(pos_rt.x + 11, pos_rt.y + 129); - buttonRight.SetPos(pos_rt.x + 220, pos_rt.y + 129); - - buttonTrade.SetSprite(tradpost, 15, 16); - buttonLeft.SetSprite(tradpost, 3, 4); - buttonRight.SetSprite(tradpost, 5, 6); - - splitter.SetSprite(AGG::GetICN(tradpost, 2)); - splitter.SetArea(Rect(pos_rt.x + (pos_rt.w - AGG::GetICN(tradpost, 1).w()) / 2 + 22, pos_rt.y + 132, 188, 10)); - splitter.Hide(); - splitter.SetOrientation(Splitter::HORIZONTAL); - - TextBox(_("Please inspect our fine wares. If you feel like offering a trade, click on the items you wish to trade with and for."), Font::BIG, Rect(pos_rt.x, pos_rt.y + 30, pos_rt.w, 100)); - - textSell.SetFont(Font::SMALL); - textBuy.SetFont(Font::SMALL); - }; - - void RedrawInfoBuySell(u32 count_sell, u32 count_buy); - void ShowTradeArea(u8 resourceFrom, u8 resourceTo, u32 max_buy, u32 max_sell, u32 count_buy, u32 count_sell, bool fromTradingPost); - - Button buttonTrade; - Button buttonLeft; - Button buttonRight; - Splitter splitter; - -private: - Rect pos_rt; - Background back; - ICN::icn_t tradpost; - - TextSprite textSell; - TextSprite textBuy; -}; - -void TradeWindowGUI::ShowTradeArea(u8 resourceFrom, u8 resourceTo, u32 max_buy, u32 max_sell, u32 count_buy, u32 count_sell, bool fromTradingPost) -{ - Cursor &cursor = Cursor::Get(); - Display &display = Display::Get(); - - if(resourceFrom == resourceTo || (Resource::GOLD != resourceTo && 0 == max_buy)) - { - cursor.Hide(); - back.Restore(); - Rect dst_rt(pos_rt.x, pos_rt.y + 30, pos_rt.w, 100); - TextBox(_("You have received quite a bargain. I expect to make no profit on the deal. Can I interest you in any of my other wares?"), Font::BIG, dst_rt); - buttonTrade.SetDisable(true); - buttonLeft.SetDisable(true); - buttonRight.SetDisable(true); - cursor.Show(); - display.Flip(); - } - else - { - cursor.Hide(); - back.Restore(); - - Point dst_pt; - const Sprite & bar = AGG::GetICN(tradpost, 1); - dst_pt.x = pos_rt.x + (pos_rt.w - bar.w()) / 2 - 2; - dst_pt.y = pos_rt.y + 128; - display.Blit(bar, dst_pt); - splitter.SetRange(0, (Resource::GOLD == resourceTo ? max_sell : max_buy)); - Resource::resource_t rs_from = static_cast(resourceFrom); - Resource::resource_t rs_to = static_cast(resourceTo); - u16 exchange_rate = GetTradeCosts(resourceFrom, resourceTo, fromTradingPost); - std::string message; - if(Resource::GOLD == resourceTo) - { - message = _("I can offer you %{count} for 1 unit of %{resfrom}."); - String::Replace(message, "%{count}", exchange_rate); - String::Replace(message, "%{resfrom}", Resource::String(rs_from)); - } - else - { - message = _("I can offer you 1 unit of %{resto} for %{count} units of %{resfrom}."); - String::Replace(message, "%{resto}", Resource::String(rs_to)); - String::Replace(message, "%{resfrom}", Resource::String(rs_from)); - String::Replace(message, "%{count}", exchange_rate); - } - TextBox(message, Font::BIG, Rect(pos_rt.x, pos_rt.y + 30, pos_rt.w, 100)); - const Sprite & sprite_from = AGG::GetICN(ICN::RESOURCE, Resource::GetIndexSprite2(rs_from)); - dst_pt.x = pos_rt.x + pos_rt.w / 2 - 70 - sprite_from.w() / 2; - dst_pt.y = pos_rt.y + 115 - sprite_from.h(); - display.Blit(sprite_from, dst_pt); - message.clear(); - String::AddInt(message, count_sell); - const Sprite & sprite_to = AGG::GetICN(ICN::RESOURCE, Resource::GetIndexSprite2(rs_to)); - dst_pt.x = pos_rt.x + pos_rt.w / 2 + 70 - sprite_to.w() / 2; - dst_pt.y = pos_rt.y + 115 - sprite_to.h(); - display.Blit(sprite_to, dst_pt); - message.clear(); - String::AddInt(message, count_buy); - const Sprite & sprite_fromto = AGG::GetICN(tradpost, 0); - dst_pt.x = pos_rt.x + pos_rt.w / 2 - sprite_fromto.w() / 2; - dst_pt.y = pos_rt.y + 90; - display.Blit(sprite_fromto, dst_pt); - Text text(_("Qty to trade"), Font::SMALL); - dst_pt.x = pos_rt.x + (pos_rt.w - text.w()) / 2; - dst_pt.y = pos_rt.y + 110; - text.Blit(dst_pt); - - buttonTrade.SetDisable(false); - buttonLeft.SetDisable(false); - buttonRight.SetDisable(false); - - buttonTrade.Draw(); - buttonLeft.Draw(); - buttonRight.Draw(); - - RedrawInfoBuySell(count_sell, count_buy); - cursor.Show(); - display.Flip(); - } -} - -void TradeWindowGUI::RedrawInfoBuySell(u32 count_sell, u32 count_buy) -{ - Point dst_pt; - std::string message; - - String::AddInt(message, count_sell); - textSell.Hide(); - textSell.SetText(message); - dst_pt.x = pos_rt.x + pos_rt.w / 2 - 70 - textSell.w() / 2; - dst_pt.y = pos_rt.y + 116; - textSell.SetPos(dst_pt); - textSell.Show(); - - message.clear(); - String::AddInt(message, count_buy); - textBuy.Hide(); - textBuy.SetText(message); - dst_pt.x = pos_rt.x + pos_rt.w / 2 + 70 - textBuy.w() / 2; - dst_pt.y = pos_rt.y + 116; - textBuy.SetPos(dst_pt); - textBuy.Show(); -} - -void Dialog::Marketplace(bool fromTradingPost) -{ - Display & display = Display::Get(); - const ICN::icn_t tradpost = Settings::Get().EvilInterface() ? ICN::TRADPOSE : ICN::TRADPOST; - const std::string & header = _("Marketplace"); - - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Dialog::Box box(260, true); - - const Rect & pos_rt = box.GetArea(); - Point dst_pt(pos_rt.x, pos_rt.y); - Rect dst_rt(pos_rt); - Text text; - - // header - text.Set(header, Font::BIG); - dst_pt.x = pos_rt.x + (pos_rt.w - text.w()) / 2; - dst_pt.y = pos_rt.y; - text.Blit(dst_pt); - - TradeWindowGUI gui(pos_rt); - - Kingdom & kingdom = world.GetMyKingdom(); - const Sprite & spritecursor = AGG::GetICN(tradpost, 14); - - const std::string & header_from = _("Your Resources"); - - Resource::funds_t fundsFrom = kingdom.GetFundsResource(); - u8 resourceFrom = 0; - const Point pt1(pos_rt.x, pos_rt.y + 190); - std::vector rectsFrom(7); - rectsFrom[0] = Rect(pt1.x, pt1.y, 34, 34); // wood - rectsFrom[1] = Rect(pt1.x + 37, pt1.y, 34, 34); // mercury - rectsFrom[2] = Rect(pt1.x + 74, pt1.y, 34, 34); // ore - rectsFrom[3] = Rect(pt1.x, pt1.y + 37, 34, 34); // sulfur - rectsFrom[4] = Rect(pt1.x + 37, pt1.y + 37, 34, 34);// crystal - rectsFrom[5] = Rect(pt1.x + 74, pt1.y + 37, 34, 34);// gems - rectsFrom[6] = Rect(pt1.x + 37, pt1.y + 74, 34, 34);// gold - SpriteCursor cursorFrom(spritecursor); - text.Set(header_from, Font::SMALL); - dst_pt.x = pt1.x + (108 - text.w()) / 2; - dst_pt.y = pt1.y - 15; - text.Blit(dst_pt); - RedrawFromResource(pt1, fundsFrom); - - const std::string & header_to = _("Available Trades"); - - Resource::funds_t fundsTo; - u8 resourceTo = 0; - const Point pt2(138 + pos_rt.x, pos_rt.y + 190); - std::vector rectsTo(7); - rectsTo[0] = Rect(pt2.x, pt2.y, 34, 34); // wood - rectsTo[1] = Rect(pt2.x + 37, pt2.y, 34, 34); // mercury - rectsTo[2] = Rect(pt2.x + 74, pt2.y, 34, 34); // ore - rectsTo[3] = Rect(pt2.x, pt2.y + 37, 34, 34); // sulfur - rectsTo[4] = Rect(pt2.x + 37, pt2.y + 37, 34, 34); // crystal - rectsTo[5] = Rect(pt2.x + 74, pt2.y + 37, 34, 34); // gems - rectsTo[6] = Rect(pt2.x + 37, pt2.y + 74, 34, 34); // gold - SpriteCursor cursorTo(spritecursor); - text.Set(header_to, Font::SMALL); - dst_pt.x = pt2.x + (108 - text.w()) / 2; - dst_pt.y = pt2.y - 15; - text.Blit(dst_pt); - RedrawToResource(pt2, false, fromTradingPost); - - u32 count_sell = 0; - u32 count_buy = 0; - - u32 max_sell = 0; - u32 max_buy = 0; - - Button & buttonTrade = gui.buttonTrade; - Button & buttonLeft = gui.buttonLeft; - Button & buttonRight = gui.buttonRight; - Splitter & splitter = gui.splitter; - - // button exit - const Sprite & sprite_exit = AGG::GetICN(tradpost, 17); - dst_pt.x = pos_rt.x + (pos_rt.w - sprite_exit.w()) / 2; - dst_pt.y = pos_rt.y + pos_rt.h - sprite_exit.h(); - Button buttonExit(dst_pt, tradpost, 17, 18); - - buttonExit.Draw(); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - - // message loop - while(le.HandleEvents()) - { - if(buttonTrade.isEnable()) le.MousePressLeft(buttonTrade) ? buttonTrade.PressDraw() : buttonTrade.ReleaseDraw(); - if(buttonLeft.isEnable()) le.MousePressLeft(buttonLeft) ? buttonLeft.PressDraw() : buttonLeft.ReleaseDraw(); - if(buttonRight.isEnable()) le.MousePressLeft(buttonRight) ? buttonRight.PressDraw() : buttonRight.ReleaseDraw(); - - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - - if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) break; - - // click from - for(u8 ii = 0; ii < rectsFrom.size(); ++ii) - { - const Rect & rect_from = rectsFrom[ii]; - - if(le.MouseClickLeft(rect_from)) - { - switch(ii) - { - case 0: - resourceFrom = Resource::WOOD; - max_sell = fundsFrom.wood; - break; - case 1: - resourceFrom = Resource::MERCURY; - max_sell = fundsFrom.mercury; - break; - case 2: - resourceFrom = Resource::ORE; - max_sell = fundsFrom.ore; - break; - case 3: - resourceFrom = Resource::SULFUR; - max_sell = fundsFrom.sulfur; - break; - case 4: - resourceFrom = Resource::CRYSTAL; - max_sell = fundsFrom.crystal; - break; - case 5: - resourceFrom = Resource::GEMS; - max_sell = fundsFrom.gems; - break; - case 6: - resourceFrom = Resource::GOLD; - max_sell = fundsFrom.gold; - break; - default: break; - } - - if(GetTradeCosts(resourceFrom, resourceTo, fromTradingPost)) - { - max_buy = Resource::GOLD == resourceTo ? - max_sell * GetTradeCosts(resourceFrom, resourceTo, fromTradingPost) : - max_sell / GetTradeCosts(resourceFrom, resourceTo, fromTradingPost); - } - - count_sell = 0; - count_buy = 0; - - cursor.Hide(); - cursorFrom.Move(rect_from.x - 2, rect_from.y - 2); - cursorFrom.Show(); - - if(resourceTo) cursorTo.Hide(); - RedrawToResource(pt2, true, fromTradingPost, resourceFrom); - if(resourceTo) cursorTo.Show(); - if(resourceTo) gui.ShowTradeArea(resourceFrom, resourceTo, max_buy, max_sell, count_buy, count_sell, fromTradingPost); - - cursor.Show(); - display.Flip(); - } - } - - // click to - for(u8 ii = 0; ii < rectsTo.size(); ++ii) - { - const Rect & rect_to = rectsTo[ii]; - - if(le.MouseClickLeft(rect_to)) - { - switch(ii) - { - case 0: resourceTo = Resource::WOOD; break; - case 1: resourceTo = Resource::MERCURY; break; - case 2: resourceTo = Resource::ORE; break; - case 3: resourceTo = Resource::SULFUR; break; - case 4: resourceTo = Resource::CRYSTAL; break; - case 5: resourceTo = Resource::GEMS; break; - case 6: resourceTo = Resource::GOLD; break; - default: break; - } - - if(GetTradeCosts(resourceFrom, resourceTo, fromTradingPost)) - { - max_buy = Resource::GOLD == resourceTo ? - max_sell * GetTradeCosts(resourceFrom, resourceTo, fromTradingPost) : - max_sell / GetTradeCosts(resourceFrom, resourceTo, fromTradingPost); - } - - count_sell = 0; - count_buy = 0; - - cursor.Hide(); - cursorTo.Move(rect_to.x - 2, rect_to.y - 2); - - if(resourceFrom) - { - cursorTo.Hide(); - RedrawToResource(pt2, true, fromTradingPost, resourceFrom); - cursorTo.Show(); - gui.ShowTradeArea(resourceFrom, resourceTo, max_buy, max_sell, count_buy, count_sell, fromTradingPost); - } - cursor.Show(); - display.Flip(); - } - } - - // move splitter - if(buttonLeft.isEnable() && buttonRight.isEnable() && max_buy && le.MousePressLeft(splitter.GetRect())) - { - u32 seek = (le.GetMouseCursor().x - splitter.GetRect().x) * 100 / splitter.GetStep(); - - if(seek < splitter.Min()) seek = splitter.Min(); - else - if(seek > splitter.Max()) seek = splitter.Max(); - - count_buy = seek * (Resource::GOLD == resourceTo ? GetTradeCosts(resourceFrom, resourceTo, fromTradingPost) : 1); - count_sell = seek * (Resource::GOLD == resourceTo ? 1: GetTradeCosts(resourceFrom, resourceTo, fromTradingPost)); - - cursor.Hide(); - splitter.Move(seek); - gui.RedrawInfoBuySell(count_sell, count_buy); - cursor.Show(); - display.Flip(); - } - - // trade - if(buttonTrade.isEnable() && le.MouseClickLeft(buttonTrade) && count_sell && count_buy) - { - kingdom.OddFundsResource(Resource::funds_t(static_cast(resourceFrom), count_sell)); - kingdom.AddFundsResource(Resource::funds_t(static_cast(resourceTo), count_buy)); -#ifdef WITH_NET - FH2LocalClient::SendMarketSellResource(kingdom, resourceFrom, count_sell, fromTradingPost); - FH2LocalClient::SendMarketBuyResource(kingdom, resourceTo, count_buy, fromTradingPost); -#endif - resourceTo = resourceFrom = Resource::UNKNOWN; - gui.ShowTradeArea(resourceFrom, resourceTo, 0, 0, 0, 0, fromTradingPost); - - fundsFrom = kingdom.GetFundsResource(); - cursorTo.Hide(); - cursorFrom.Hide(); - RedrawFromResource(pt1, fundsFrom); - RedrawToResource(pt2, false, fromTradingPost, resourceFrom); - display.Flip(); - } - - // decrease trade resource - if(count_buy && - ((buttonLeft.isEnable() && le.MouseClickLeft(gui.buttonLeft)) || - le.MouseWheelDn(splitter.GetRect()))) - { - count_buy -= Resource::GOLD == resourceTo ? GetTradeCosts(resourceFrom, resourceTo, fromTradingPost) : 1; - - count_sell -= Resource::GOLD == resourceTo ? 1: GetTradeCosts(resourceFrom, resourceTo, fromTradingPost); - - cursor.Hide(); - splitter.Backward(); - gui.RedrawInfoBuySell(count_sell, count_buy); - cursor.Show(); - display.Flip(); - } - - // increase trade resource - if( count_buy < max_buy && - ((buttonRight.isEnable() && le.MouseClickLeft(buttonRight)) || - le.MouseWheelUp(splitter.GetRect()))) - { - count_buy += Resource::GOLD == resourceTo ? GetTradeCosts(resourceFrom, resourceTo, fromTradingPost) : 1; - - count_sell += Resource::GOLD == resourceTo ? 1: GetTradeCosts(resourceFrom, resourceTo, fromTradingPost); - - cursor.Hide(); - splitter.Forward(); - gui.RedrawInfoBuySell(count_sell, count_buy); - cursor.Show(); - display.Flip(); - } - } -} - -void RedrawResourceSprite(const Surface & sf, s16 px, s16 py, s32 value) -{ - Display & display = Display::Get(); - std::string str; - Text text; - Point dst_pt(px, py); - - display.Blit(sf, dst_pt); - String::AddInt(str, value); - text.Set(str, Font::SMALL); - dst_pt.x += (34 - text.w()) / 2; - dst_pt.y += 21; - text.Blit(dst_pt); -} - -void RedrawFromResource(const Point & pt, const Resource::funds_t & rs) -{ - const ICN::icn_t tradpost = Settings::Get().EvilInterface() ? ICN::TRADPOSE : ICN::TRADPOST; - - // wood - RedrawResourceSprite(AGG::GetICN(tradpost, 7), 0, 0, rs.wood); - // mercury - RedrawResourceSprite(AGG::GetICN(tradpost, 8), 37, 0, rs.mercury); - // ore - RedrawResourceSprite(AGG::GetICN(tradpost, 9), 74, 0, rs.ore); - // sulfur - RedrawResourceSprite(AGG::GetICN(tradpost, 10), 0, 37, rs.sulfur); - // crystal - RedrawResourceSprite(AGG::GetICN(tradpost, 11), 37, 37, rs.crystal); - // gems - RedrawResourceSprite(AGG::GetICN(tradpost, 12), 74, 37, rs.gems); - // gold - RedrawResourceSprite(AGG::GetICN(tradpost, 13), 37, 74, rs.gold); -} - -void RedrawToResource(const Point & pt, bool showcost, bool tradingPost, u8 from_resource) -{ - Display & display = Display::Get(); - const ICN::icn_t tradpost = Settings::Get().EvilInterface() ? ICN::TRADPOSE : ICN::TRADPOST; - std::string str; - Point dst_pt; - Text text; - text.Set(Font::SMALL); - - // wood - dst_pt.x = pt.x; - dst_pt.y = pt.y; - display.Blit(AGG::GetICN(tradpost, 7), dst_pt); - if(showcost) - { - GetStringTradeCosts(str, from_resource, Resource::WOOD, tradingPost); - text.Set(str); - dst_pt.x += (34 - text.w()) / 2; - dst_pt.y += 21; - text.Blit(dst_pt); - } - - // mercury - dst_pt.x = pt.x + 37; - dst_pt.y = pt.y; - display.Blit(AGG::GetICN(tradpost, 8), dst_pt); - if(showcost) - { - GetStringTradeCosts(str, from_resource, Resource::MERCURY, tradingPost); - text.Set(str); - dst_pt.x += (34 - text.w()) / 2; - dst_pt.y += 21; - text.Blit(dst_pt); - } - - // ore - dst_pt.x = pt.x + 74; - dst_pt.y = pt.y; - display.Blit(AGG::GetICN(tradpost, 9), dst_pt); - if(showcost) - { - GetStringTradeCosts(str, from_resource, Resource::ORE, tradingPost); - text.Set(str); - dst_pt.x += (34 - text.w()) / 2; - dst_pt.y += 21; - text.Blit(dst_pt); - } - - // sulfur - dst_pt.x = pt.x; - dst_pt.y = pt.y + 37; - display.Blit(AGG::GetICN(tradpost, 10), dst_pt); - if(showcost) - { - GetStringTradeCosts(str, from_resource, Resource::SULFUR, tradingPost); - text.Set(str); - dst_pt.x += (34 - text.w()) / 2; - dst_pt.y += 21; - text.Blit(dst_pt); - } - - // crystal - dst_pt.x = pt.x + 37; - dst_pt.y = pt.y + 37; - display.Blit(AGG::GetICN(tradpost, 11), dst_pt); - if(showcost) - { - GetStringTradeCosts(str, from_resource, Resource::CRYSTAL, tradingPost); - text.Set(str); - dst_pt.x += (34 - text.w()) / 2; - dst_pt.y += 21; - text.Blit(dst_pt); - } - - // gems - dst_pt.x = pt.x + 74; - dst_pt.y = pt.y + 37; - display.Blit(AGG::GetICN(tradpost, 12), dst_pt); - if(showcost) - { - GetStringTradeCosts(str, from_resource, Resource::GEMS, tradingPost); - text.Set(str); - dst_pt.x += (34 - text.w()) / 2; - dst_pt.y += 21; - text.Blit(dst_pt); - } - - // gold - dst_pt.x = pt.x + 37; - dst_pt.y = pt.y + 74; - display.Blit(AGG::GetICN(tradpost, 13), dst_pt); - if(showcost) - { - GetStringTradeCosts(str, from_resource, Resource::GOLD, tradingPost); - text.Set(str); - dst_pt.x += (34 - text.w()) / 2; - dst_pt.y += 21; - text.Blit(dst_pt); - } -} - -void GetStringTradeCosts(std::string & str, u8 rs_from, u8 rs_to, bool tradingPost) -{ - if(str.size()) str.clear(); - - if(rs_from == rs_to) - { - str = _("n/a"); - - return; - } - - if(Resource::GOLD != rs_from && Resource::GOLD != rs_to) str = "1/"; - - String::AddInt(str, GetTradeCosts(rs_from, rs_to, tradingPost)); -} - -u16 GetTradeCosts(u8 rs_from, u8 rs_to, bool tradingPost) -{ - const u8 markets = tradingPost ? 3 : world.GetMyKingdom().GetCountMarketplace(); - - if(rs_from == rs_to) return 0; - - switch(rs_from) - { - // uncostly - case Resource::WOOD: - case Resource::ORE: - - switch(rs_to) - { - // sale uncostly - case Resource::GOLD: - if(1 == markets) return SALE_UNCOSTLY1; - else - if(2 == markets) return SALE_UNCOSTLY2; - else - if(3 == markets) return SALE_UNCOSTLY3; - else - if(4 == markets) return SALE_UNCOSTLY4; - else - if(5 == markets) return SALE_UNCOSTLY5; - else - if(6 == markets) return SALE_UNCOSTLY6; - else - if(7 == markets) return SALE_UNCOSTLY7; - else - if(8 == markets) return SALE_UNCOSTLY8; - else - if(8 < markets) return SALE_UNCOSTLY9; - break; - - // change uncostly to costly - case Resource::MERCURY: - case Resource::SULFUR: - case Resource::CRYSTAL: - case Resource::GEMS: - if(1 == markets) return UNCOSTLY_COSTLY1; - else - if(2 == markets) return UNCOSTLY_COSTLY2; - else - if(3 == markets) return UNCOSTLY_COSTLY3; - else - if(4 == markets) return UNCOSTLY_COSTLY4; - else - if(5 == markets) return UNCOSTLY_COSTLY5; - else - if(6 == markets) return UNCOSTLY_COSTLY6; - else - if(7 == markets) return UNCOSTLY_COSTLY7; - else - if(8 == markets) return UNCOSTLY_COSTLY8; - else - if(8 < markets) return UNCOSTLY_COSTLY9; - break; - - // change uncostly to uncostly - case Resource::WOOD: - case Resource::ORE: - if(1 == markets) return COSTLY_COSTLY1; - else - if(2 == markets) return COSTLY_COSTLY2; - else - if(3 == markets) return COSTLY_COSTLY3; - else - if(4 == markets) return COSTLY_COSTLY4; - else - if(5 == markets) return COSTLY_COSTLY5; - else - if(6 == markets) return COSTLY_COSTLY6; - else - if(7 == markets) return COSTLY_COSTLY7; - else - if(8 == markets) return COSTLY_COSTLY8; - else - if(8 < markets) return COSTLY_COSTLY9; - break; - } - break; - - // costly - case Resource::MERCURY: - case Resource::SULFUR: - case Resource::CRYSTAL: - case Resource::GEMS: - - switch(rs_to) - { - // sale costly - case Resource::GOLD: - if(1 == markets) return SALE_COSTLY1; - else - if(2 == markets) return SALE_COSTLY2; - else - if(3 == markets) return SALE_COSTLY3; - else - if(4 == markets) return SALE_COSTLY4; - else - if(5 == markets) return SALE_COSTLY5; - else - if(6 == markets) return SALE_COSTLY6; - else - if(7 == markets) return SALE_COSTLY7; - else - if(8 == markets) return SALE_COSTLY8; - else - if(8 < markets) return SALE_COSTLY9; - break; - - // change costly to costly - case Resource::MERCURY: - case Resource::SULFUR: - case Resource::CRYSTAL: - case Resource::GEMS: - if(1 == markets) return COSTLY_COSTLY1; - else - if(2 == markets) return COSTLY_COSTLY2; - else - if(3 == markets) return COSTLY_COSTLY3; - else - if(4 == markets) return COSTLY_COSTLY4; - else - if(5 == markets) return COSTLY_COSTLY5; - else - if(6 == markets) return COSTLY_COSTLY6; - else - if(7 == markets) return COSTLY_COSTLY7; - else - if(8 == markets) return COSTLY_COSTLY8; - else - if(8 < markets) return COSTLY_COSTLY9; - break; - - // change costly to uncostly - case Resource::WOOD: - case Resource::ORE: - if(1 == markets) return COSTLY_UNCOSTLY1; - else - if(2 == markets) return COSTLY_UNCOSTLY2; - else - if(3 == markets) return COSTLY_UNCOSTLY3; - else - if(4 == markets) return COSTLY_UNCOSTLY4; - else - if(5 == markets) return COSTLY_UNCOSTLY5; - else - if(6 == markets) return COSTLY_UNCOSTLY6; - else - if(7 == markets) return COSTLY_UNCOSTLY7; - else - if(8 == markets) return COSTLY_UNCOSTLY8; - else - if(8 < markets) return COSTLY_UNCOSTLY9; - break; - } - break; - - // gold - case Resource::GOLD: - - switch(rs_to) - { - default: break; - - // buy costly - case Resource::MERCURY: - case Resource::SULFUR: - case Resource::CRYSTAL: - case Resource::GEMS: - if(1 == markets) return BUY_COSTLY1; - else - if(2 == markets) return BUY_COSTLY2; - else - if(3 == markets) return BUY_COSTLY3; - else - if(4 == markets) return BUY_COSTLY4; - else - if(5 == markets) return BUY_COSTLY5; - else - if(6 == markets) return BUY_COSTLY6; - else - if(7 == markets) return BUY_COSTLY7; - else - if(8 == markets) return BUY_COSTLY8; - else - if(8 < markets) return BUY_COSTLY9; - break; - - // buy uncostly - case Resource::WOOD: - case Resource::ORE: - if(1 == markets) return BUY_UNCOSTLY1; - else - if(2 == markets) return BUY_UNCOSTLY2; - else - if(3 == markets) return BUY_UNCOSTLY3; - else - if(4 == markets) return BUY_UNCOSTLY4; - else - if(5 == markets) return BUY_UNCOSTLY5; - else - if(6 == markets) return BUY_UNCOSTLY6; - else - if(7 == markets) return BUY_UNCOSTLY7; - else - if(8 == markets) return BUY_UNCOSTLY8; - else - if(8 < markets) return BUY_UNCOSTLY9; - break; - } - break; - - // not select - default: break; - } - - return 0; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_message.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_message.cpp deleted file mode 100644 index c6e9ece50..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_message.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" - -u16 Dialog::Message(const std::string &header, const std::string &message, Font::type_t ft, u16 buttons) -{ - Display & display = Display::Get(); - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // preload - AGG::PreloadObject(system); - - // cursor - Cursor & cursor = Cursor::Get(); - Cursor::themes_t oldthemes = cursor.Themes(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - TextBox textbox1(header, Font::YELLOW_BIG, BOXAREA_WIDTH); - TextBox textbox2(message, ft, BOXAREA_WIDTH); - - Box box(10 + (header.size() ? textbox1.h() + 10 : 0) + textbox2.h(), buttons); - const Rect & pos = box.GetArea(); - - if(header.size()) textbox1.Blit(pos.x, pos.y + 10); - if(message.size()) textbox2.Blit(pos.x, pos.y + 10 + (header.size() ? textbox1.h() : 0) + 10); - - LocalEvent & le = LocalEvent::Get(); - - ButtonGroups btnGroups(box.GetArea(), buttons); - btnGroups.Draw(); - - cursor.Show(); - display.Flip(); - - // message loop - u16 result = Dialog::ZERO; - - while(result == Dialog::ZERO && le.HandleEvents()) - { - if(!buttons && !le.MousePressRight()) break; - - result = btnGroups.QueueEventProcessing(); - } - - cursor.Hide(); - cursor.SetThemes(oldthemes); - cursor.Show(); - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_quickinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_quickinfo.cpp deleted file mode 100644 index a4b077edf..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_quickinfo.cpp +++ /dev/null @@ -1,735 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "maps.h" -#include "army.h" -#include "heroes.h" -#include "castle.h" -#include "monster.h" -#include "interface_gamearea.h" -#include "cursor.h" -#include "game_focus.h" -#include "world.h" -#include "settings.h" -#include "kingdom.h" -#include "dialog.h" - -const char* ArmyGetSizeString(u32 count) -{ - switch(Army::GetSize(count)) - { - default: break; - case Army::SEVERAL: return _("Several\n%{monster}"); - case Army::PACK: return _("A pack of\n%{monster}"); - case Army::LOTS: return _("Lots of\n%{monster}"); - case Army::HORDE: return _("A horde of\n%{monster}"); - case Army::THRONG: return _("A throng of\n%{monster}"); - case Army::SWARM: return _("A swarm of\n%{monster}"); - case Army::ZOUNDS: return _("Zounds of\n%{monster}"); - case Army::LEGION: return _("A legion of\n%{monster}"); - } - return _("A few\n%{monster}"); -} - -void Dialog::QuickInfo(const Maps::Tiles & tile) -{ - // check - switch(tile.GetObject()) - { - case MP2::OBJN_MINES: - case MP2::OBJN_ABANDONEDMINE: - case MP2::OBJN_SAWMILL: - case MP2::OBJN_ALCHEMYLAB: - { - const Maps::Tiles & left = world.GetTiles(tile.GetIndex() - 1); - const Maps::Tiles & right = world.GetTiles(tile.GetIndex() + 1); - const Maps::Tiles* center = NULL; - - if(MP2::isGroundObject(left.GetObject())) center = &left; - else - if(MP2::isGroundObject(right.GetObject())) center = &right; - - if(center) - { - QuickInfo(*center); - return; - } - } - break; - - default: break; - } - - Display & display = Display::Get(); - - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - - // preload - const ICN::icn_t qwikinfo = ICN::QWIKINFO; - - AGG::PreloadObject(qwikinfo); - - // image box - const Sprite &box = AGG::GetICN(qwikinfo, 0); - const Interface::GameArea & gamearea = Interface::GameArea::Get(); - const Rect ar(BORDERWIDTH, BORDERWIDTH, gamearea.GetArea().w, gamearea.GetArea().h); - - LocalEvent & le = LocalEvent::Get(); - const Point & mp = le.GetMouseCursor(); - - Rect pos; - s16 mx = (mp.x - BORDERWIDTH) / TILEWIDTH; - mx *= TILEWIDTH; - s16 my = (mp.y - BORDERWIDTH) / TILEWIDTH; - my *= TILEWIDTH; - - // top left - if(mx <= ar.x + ar.w / 2 && my <= ar.y + ar.h / 2) - pos = Rect(mx + TILEWIDTH, my + TILEWIDTH, box.w(), box.h()); - else - // top right - if(mx > ar.x + ar.w / 2 && my <= ar.y + ar.h / 2) - pos = Rect(mx - box.w(), my + TILEWIDTH, box.w(), box.h()); - else - // bottom left - if(mx <= ar.x + ar.w / 2 && my > ar.y + ar.h / 2) - pos = Rect(mx + TILEWIDTH, my - box.h(), box.w(), box.h()); - else - // bottom right - pos = Rect(mx - box.w(), my - box.h(), box.w(), box.h()); - - Background back(pos); - back.Save(); - - display.Blit(box, pos.x, pos.y); - - std::string name_object; - const Settings & settings = Settings::Get(); - - const Heroes* hero = (Game::Focus::HEROES == Game::Focus::Get().Type() ? &Game::Focus::Get().GetHeroes() : NULL); - const Kingdom & kingdom = world.GetKingdom(settings.MyColor()); - - if(tile.isFog(settings.MyColor())) - name_object = _("Unchartered Territory"); - else - // check guardians mine - if(MP2::OBJ_ABANDONEDMINE == tile.GetObject() || tile.CheckEnemyGuardians()) - { - const Army::Troop troop(tile); - - if(MP2::OBJ_MINES == tile.GetObject()) - name_object = Maps::GetMinesName(tile.GetMinesType()); - else - name_object = MP2::StringObject(tile.GetObject()); - - name_object.append("\n"); - name_object.append(_("guarded by %{count} of %{monster}")); - std::string name = troop.GetMultiName(); - if(!settings.Unicode()) String::Lower(name); - String::Replace(name_object, "%{monster}", name); - - if((settings.MyColor() == world.ColorCapturedObject(tile.GetIndex())) || - (hero && hero->CanScouteTile(tile.GetIndex()))) - { - name.clear(); - String::AddInt(name, troop.GetCount()); - } - else - { - name = Army::String(troop.GetCount()); - if(!settings.Unicode()) String::Lower(name); - } - - String::Replace(name_object, "%{count}", name); - } - else - switch(tile.GetObject()) - { - case MP2::OBJ_MONSTER: - { - const Army::Troop troop(tile); - name_object = ArmyGetSizeString(troop.GetCount()); - std::string name = troop.GetMultiName(); - if(!settings.Unicode()) String::Lower(name); - String::Replace(name_object, "%{monster}", name); - - if(hero && hero->CanScouteTile(tile.GetIndex()) && - Skill::Level::EXPERT == hero->GetSecondaryValues(Skill::Secondary::SCOUTING)) - { - name_object.append("\n"); - name = _("scoute expert: (%{count})"); - String::Replace(name, "%{count}", troop.GetCount()); - name_object.append(name); - } - } - break; - - case MP2::OBJ_EVENT: - case MP2::OBJ_ZERO: - name_object = Maps::Ground::String(tile.GetGround()); - break; - - case MP2::OBJ_DERELICTSHIP: - case MP2::OBJ_SHIPWRECK: - case MP2::OBJ_GRAVEYARD: - case MP2::OBJ_DAEMONCAVE: - case MP2::OBJ_PYRAMID: - case MP2::OBJ_WAGON: - case MP2::OBJ_SKELETON: - case MP2::OBJ_WINDMILL: - case MP2::OBJ_WATERWHEEL: - case MP2::OBJ_LEANTO: - case MP2::OBJ_MAGICGARDEN: - name_object = MP2::StringObject(tile.GetObject()); - // check visited - if(settings.ExtShowVisitedContent() && kingdom.isVisited(tile)) - { - name_object.append("\n"); - name_object.append(_("(already visited)")); - } - break; - - case MP2::OBJ_RESOURCE: - name_object = MP2::StringObject(tile.GetObject()); - // check visited - if(settings.ExtShowVisitedContent()) - { - name_object.append("\n("); - name_object.append(Resource::String(tile.GetQuantity1())); - name_object.append(")"); - } - break; - - case MP2::OBJ_ARTIFACT: - name_object = MP2::StringObject(tile.GetObject()); - // check visited - if(settings.ExtShowVisitedContent()) - { - name_object.append("\n("); - name_object.append( Artifact::GetName(Artifact::FromInt(tile.GetQuantity1()))); - name_object.append(")"); - } - break; - - case MP2::OBJ_MINES: - name_object = Maps::GetMinesName(tile.GetMinesType()); - break; - - // join army - case MP2::OBJ_WATCHTOWER: - case MP2::OBJ_EXCAVATION: - case MP2::OBJ_CAVE: - case MP2::OBJ_TREEHOUSE: - case MP2::OBJ_ARCHERHOUSE: - case MP2::OBJ_GOBLINHUT: - case MP2::OBJ_DWARFCOTT: - case MP2::OBJ_HALFLINGHOLE: - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_THATCHEDHUT: - // recruit army - case MP2::OBJ_RUINS: - case MP2::OBJ_TREECITY: - case MP2::OBJ_WAGONCAMP: - case MP2::OBJ_DESERTTENT: - // battle and recruit army - case MP2::OBJ_DRAGONCITY: - case MP2::OBJ_CITYDEAD: - case MP2::OBJ_TROLLBRIDGE: - name_object = MP2::StringObject(tile.GetObject()); - if((settings.ExtShowVisitedContent() && kingdom.isVisited(tile)) || - (hero && hero->CanScouteTile(tile.GetIndex()))) - { - name_object.append("\n"); - if(tile.GetCountMonster()) - { - name_object.append(_("(available: %{count})")); - String::Replace(name_object, "%{count}", tile.GetCountMonster()); - } - else - { - name_object.append("(empty)"); - } - } - break; - - case MP2::OBJ_GAZEBO: - case MP2::OBJ_FORT: - case MP2::OBJ_XANADU: - case MP2::OBJ_MERCENARYCAMP: - case MP2::OBJ_DOCTORHUT: - case MP2::OBJ_STANDINGSTONES: - case MP2::OBJ_ARTESIANSPRING: - case MP2::OBJ_TREEKNOWLEDGE: - name_object = MP2::StringObject(tile.GetObject()); - // check visited - if(hero) - { - name_object.append("\n"); - name_object.append(hero->isVisited(tile) ? _("(already visited)") : _("(not visited)")); - } - break; - - case MP2::OBJ_MAGICWELL: - case MP2::OBJ_FOUNTAIN: - case MP2::OBJ_FAERIERING: - case MP2::OBJ_IDOL: - case MP2::OBJ_OASIS: - case MP2::OBJ_TEMPLE: - case MP2::OBJ_BUOY: - case MP2::OBJ_WATERINGHOLE: - case MP2::OBJ_ARENA: - case MP2::OBJ_STABLES: - name_object = MP2::StringObject(tile.GetObject()); - // check visited - if(hero) - { - name_object.append("\n"); - name_object.append(hero->isVisited(tile.GetObject()) ? _("(already visited)") : _("(not visited)")); - } - break; - - case MP2::OBJ_SHRINE1: - case MP2::OBJ_SHRINE2: - case MP2::OBJ_SHRINE3: - name_object = MP2::StringObject(tile.GetObject()); - // addons pack - if(settings.ExtShowVisitedContent() && kingdom.isVisited(tile)) - { - name_object.append("\n("); - name_object.append(Spell::GetName(Spell::FromInt(tile.GetQuantity1()))); - name_object.append(")"); - if(hero && hero->HaveSpell(Spell::FromInt(tile.GetQuantity1()))) - { - name_object.append("\n("); - name_object.append(_("already learned")); - name_object.append(")"); - } - } - break; - - case MP2::OBJ_WITCHSHUT: - name_object = MP2::StringObject(tile.GetObject()); - // addons pack - if(settings.ExtShowVisitedContent() && kingdom.isVisited(tile)) - { - const Skill::Secondary::skill_t skill = Skill::Secondary::Skill(tile.GetQuantity1()); - name_object.append("\n("); - name_object.append(Skill::Secondary::String(skill)); - name_object.append(")"); - - if(hero) - { - if(hero->HasSecondarySkill(skill)) - { - name_object.append("\n("); - name_object.append(_("already knows this skill")); - name_object.append(")"); - } - else - if(hero->HasMaxSecondarySkill()) - { - name_object.append("\n("); - name_object.append(_("already has max skills")); - name_object.append(")"); - } - } - } - break; - - case MP2::OBJ_OBELISK: - name_object = MP2::StringObject(tile.GetObject()); - // check visited - name_object.append("\n"); - name_object.append(kingdom.isVisited(tile) ? _("(already visited)") : _("(not visited)")); - break; - - case MP2::OBJ_BARRIER: - case MP2::OBJ_TRAVELLERTENT: - name_object = Barrier::Color(tile.GetQuantity1()); - name_object.append(" "); - name_object.append(MP2::StringObject(tile.GetObject())); - - if(MP2::OBJ_TRAVELLERTENT == tile.GetObject() && - kingdom.IsVisitTravelersTent(tile.GetQuantity1())) - { - name_object.append("\n"); - name_object.append(_("(already visited)")); - } - break; - - case MP2::OBJ_TREASURECHEST: - if(Maps::Ground::WATER == tile.GetGround()) - name_object = _("Sea Chest"); - else - name_object = MP2::StringObject(tile.GetObject()); - break; - - default: - name_object = MP2::StringObject(tile.GetObject()); - break; - } - - TextBox text(name_object, Font::SMALL, 118); - text.Blit(pos.x + BORDERWIDTH + (pos.w - BORDERWIDTH - text.w()) / 2, pos.y + (pos.h - BORDERWIDTH - text.h()) / 2); - - cursor.Show(); - display.Flip(); - - // quick info loop - while(le.HandleEvents() && le.MousePressRight()); - - // restore background - cursor.Hide(); - back.Restore(); - cursor.Show(); - display.Flip(); -} - -void Dialog::QuickInfo(const Castle & castle) -{ - Display & display = Display::Get(); - - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - - const ICN::icn_t qwiktown = ICN::QWIKTOWN; - AGG::PreloadObject(qwiktown); - - // image box - const Sprite &box = AGG::GetICN(qwiktown, 0); - const Interface::GameArea & gamearea = Interface::GameArea::Get(); - const Rect ar(BORDERWIDTH, BORDERWIDTH, gamearea.GetArea().w, gamearea.GetArea().h); - - LocalEvent & le = LocalEvent::Get(); - const Point & mp = le.GetMouseCursor(); - - Rect cur_rt; - s16 mx = (mp.x - BORDERWIDTH) / TILEWIDTH; - mx *= TILEWIDTH; - s16 my = (mp.y - BORDERWIDTH) / TILEWIDTH; - my *= TILEWIDTH; - - // top left - if(mx <= ar.x + ar.w / 2 && my <= ar.y + ar.h / 2) - cur_rt = Rect(mx + TILEWIDTH, my + TILEWIDTH, box.w(), box.h()); - else - // top right - if(mx > ar.x + ar.w / 2 && my <= ar.y + ar.h / 2) - cur_rt = Rect(mx - box.w(), my + TILEWIDTH, box.w(), box.h()); - else - // bottom left - if(mx <= ar.x + ar.w / 2 && my > ar.y + ar.h / 2) - cur_rt = Rect(mx + TILEWIDTH, my - box.h(), box.w(), box.h()); - else - // bottom right - cur_rt = Rect(mx - box.w(), my - box.h(), box.w(), box.h()); - - if(Settings::Get().QVGA()) - { - cur_rt = Rect((display.w() - box.w()) / 2, (display.h() - box.h()) / 2, box.w(), box.h()); - } - - Background back(cur_rt); - back.Save(); - display.Blit(box, cur_rt.x, cur_rt.y); - - cur_rt = Rect(back.GetRect().x + 28 , back.GetRect().y + 12, 178, 140); - Point dst_pt; - Text text; - - // castle name - text.Set(castle.GetName(), Font::SMALL); - dst_pt.x = cur_rt.x + (cur_rt.w - text.w()) / 2; - dst_pt.y = cur_rt.y + 5; - text.Blit(dst_pt); - - u8 index = 0; - - switch(castle.GetRace()) - { - case Race::KNGT: index = (castle.isCastle() ? 9 : 15); break; - case Race::BARB: index = (castle.isCastle() ? 10 : 16); break; - case Race::SORC: index = (castle.isCastle() ? 11 : 17); break; - case Race::WRLK: index = (castle.isCastle() ? 12 : 18); break; - case Race::WZRD: index = (castle.isCastle() ? 13 : 19); break; - case Race::NECR: index = (castle.isCastle() ? 14 : 20); break; - default: DEBUG(DBG_GAME , DBG_WARN, "Dialog::QuickInfo: unknown race."); return; - } - - // castle icon - const Sprite & sprite = AGG::GetICN(ICN::LOCATORS, index); - - dst_pt.x = cur_rt.x + (cur_rt.w - sprite.w()) / 2; - dst_pt.y += 18; - display.Blit(sprite, dst_pt); - - // color flags - switch(castle.GetColor()) - { - case Color::BLUE: index = 0; break; - case Color::GREEN: index = 2; break; - case Color::RED: index = 4; break; - case Color::YELLOW: index = 6; break; - case Color::ORANGE: index = 8; break; - case Color::PURPLE: index = 10; break; - case Color::GRAY: index = 12; break; - default: break; - } - - const Sprite & l_flag = AGG::GetICN(ICN::FLAG32, index); - dst_pt.x = cur_rt.x + (cur_rt.w - 60) / 2 - l_flag.w(); - display.Blit(l_flag, dst_pt); - - const Sprite & r_flag = AGG::GetICN(ICN::FLAG32, index + 1); - dst_pt.x = cur_rt.x + (cur_rt.w + 60) / 2; - display.Blit(r_flag, dst_pt); - - // info - text.Set(_("Defenders:")); - dst_pt.x = cur_rt.x + (cur_rt.w - text.w()) / 2; - dst_pt.y += sprite.h() + 5; - text.Blit(dst_pt); - - u8 count = castle.GetArmy().GetCount(); - const Settings & conf = Settings::Get(); - bool hide = Settings::Get().MyColor() != castle.GetColor() && !conf.IsUnions(conf.MyColor(), castle.GetColor()); - - if(hide) - { - const Heroes* hero = (Game::Focus::HEROES == Game::Focus::Get().Type() ? &Game::Focus::Get().GetHeroes() : NULL); - if(hero && Skill::Level::EXPERT == hero->GetSecondaryValues(Skill::Secondary::SCOUTING)) hide = false; - } - - if(! count) - { - text.Set(_("None")); - dst_pt.x = cur_rt.x + (cur_rt.w - text.w()) / 2; - dst_pt.y += 45; - text.Blit(dst_pt); - } - else - castle.GetArmy().DrawMons32Line(cur_rt.x - 5, cur_rt.y + 100, 192, 0, 0, hide); - - cursor.Show(); - display.Flip(); - - // quick info loop - while(le.HandleEvents() && le.MousePressRight()); - - // restore background - cursor.Hide(); - back.Restore(); - cursor.Show(); - display.Flip(); -} - -void Dialog::QuickInfo(const Heroes & hero) -{ - Display & display = Display::Get(); - - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - - const ICN::icn_t qwikhero = ICN::QWIKHERO; - AGG::PreloadObject(qwikhero); - - // image box - const Sprite &box = AGG::GetICN(qwikhero, 0); - const Interface::GameArea & gamearea = Interface::GameArea::Get(); - const Rect ar(BORDERWIDTH, BORDERWIDTH, gamearea.GetArea().w, gamearea.GetArea().h); - - LocalEvent & le = LocalEvent::Get(); - const Point & mp = le.GetMouseCursor(); - - Rect cur_rt; - s16 mx = (mp.x - BORDERWIDTH) / TILEWIDTH; - mx *= TILEWIDTH; - s16 my = (mp.y - BORDERWIDTH) / TILEWIDTH; - my *= TILEWIDTH; - - // top left - if(mx <= ar.x + ar.w / 2 && my <= ar.y + ar.h / 2) - cur_rt = Rect(mx + TILEWIDTH, my + TILEWIDTH, box.w(), box.h()); - else - // top right - if(mx > ar.x + ar.w / 2 && my <= ar.y + ar.h / 2) - cur_rt = Rect(mx - box.w(), my + TILEWIDTH, box.w(), box.h()); - else - // bottom left - if(mx <= ar.x + ar.w / 2 && my > ar.y + ar.h / 2) - cur_rt = Rect(mx + TILEWIDTH, my - box.h(), box.w(), box.h()); - else - // bottom right - cur_rt = Rect(mx - box.w(), my - box.h(), box.w(), box.h()); - - if(Settings::Get().QVGA()) - { - cur_rt = Rect((display.w() - box.w()) / 2, (display.h() - box.h()) / 2, box.w(), box.h()); - } - - Background back(cur_rt); - back.Save(); - - display.Blit(box, cur_rt.x, cur_rt.y); - - cur_rt = Rect(back.GetRect().x + 28 , back.GetRect().y + 10, 146, 144); - Point dst_pt; - Text text; - - // heroes name - text.Set(hero.GetName(), Font::SMALL); - dst_pt.x = cur_rt.x + (cur_rt.w - text.w()) / 2; - dst_pt.y = cur_rt.y + 2; - text.Blit(dst_pt); - - // mini port heroes - const Surface & port = hero.GetPortrait30x22(); - dst_pt.x = cur_rt.x + (cur_rt.w - port.w()) / 2; - dst_pt.y += 15; - display.Blit(port, dst_pt); - - // color flags - u8 index = 0; - - switch(hero.GetColor()) - { - case Color::BLUE: index = 0; break; - case Color::GREEN: index = 2; break; - case Color::RED: index = 4; break; - case Color::YELLOW: index = 6; break; - case Color::ORANGE: index = 8; break; - case Color::PURPLE: index = 10; break; - case Color::GRAY: index = 12; break; - default: break; - } - - const Sprite & l_flag = AGG::GetICN(ICN::FLAG32, index); - dst_pt.x = cur_rt.x + (cur_rt.w - 40) / 2 - l_flag.w(); - display.Blit(l_flag, dst_pt); - - const Sprite & r_flag = AGG::GetICN(ICN::FLAG32, index + 1); - dst_pt.x = cur_rt.x + (cur_rt.w + 40) / 2; - display.Blit(r_flag, dst_pt); - std::string message; - - // attack - message = _("Attack"); - message += ":"; - text.Set(message); - dst_pt.x = cur_rt.x + 35; - dst_pt.y += port.h() + 4; - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, hero.GetAttack()); - text.Set(message); - dst_pt.x += 75; - text.Blit(dst_pt); - - // defense - message = _("Defense"); - message += ":"; - text.Set(message); - dst_pt.x = cur_rt.x + 35; - dst_pt.y += 12; - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, hero.GetDefense()); - text.Set(message); - dst_pt.x += 75; - text.Blit(dst_pt); - - // power - message = _("Spell Power"); - message += ":"; - text.Set(message); - dst_pt.x = cur_rt.x + 35; - dst_pt.y += 12; - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, hero.GetPower()); - text.Set(message); - dst_pt.x += 75; - text.Blit(dst_pt); - - // knowledge - message = _("Knowledge"); - message += ":"; - text.Set(message); - dst_pt.x = cur_rt.x + 35; - dst_pt.y += 12; - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, hero.GetKnowledge()); - text.Set(message); - dst_pt.x += 75; - text.Blit(dst_pt); - - // spell point - message = _("Spell Points"); - message += ":"; - text.Set(message); - dst_pt.x = cur_rt.x + 35; - dst_pt.y += 12; - text.Blit(dst_pt); - - message.clear(); - String::AddInt(message, hero.GetSpellPoints()); - message += "/"; - String::AddInt(message, hero.GetMaxSpellPoints()); - text.Set(message); - dst_pt.x += 75; - text.Blit(dst_pt); - - // draw monster sprite in one string - const Settings & conf = Settings::Get(); - bool hide = conf.MyColor() != hero.GetColor() && !conf.IsUnions(conf.MyColor(), hero.GetColor()); - - // check spell identify hero - if(hide && world.GetKingdom(conf.MyColor()).Modes(Kingdom::IDENTIFYHERO)) hide = false; - - // check scouting expert - if(hide) - { - const Heroes* hero = (Game::Focus::HEROES == Game::Focus::Get().Type() ? &Game::Focus::Get().GetHeroes() : NULL); - if(hero && Skill::Level::EXPERT == hero->GetSecondaryValues(Skill::Secondary::SCOUTING)) hide = false; - } - - hero.GetArmy().DrawMons32Line(cur_rt.x - 5, cur_rt.y + 114, 160, 0, 0, hide); - - cursor.Show(); - display.Flip(); - - // quick info loop - while(le.HandleEvents() && le.MousePressRight()); - - // restore background - cursor.Hide(); - back.Restore(); - cursor.Show(); - display.Flip(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_recrut.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_recrut.cpp deleted file mode 100644 index d3320acf2..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_recrut.cpp +++ /dev/null @@ -1,491 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "payment.h" -#include "world.h" -#include "button.h" -#include "kingdom.h" -#include "dialog.h" - -void RedrawCurrentInfo(const Point & pos, u16 available, u32 result, - const payment_t & paymentMonster, const payment_t & paymentCosts) -{ - std::string str; - Text text; - - str = _("Available: %{count}"); - String::Replace(str, "%{count}", available); - text.Set(str, Font::SMALL); - text.Blit(pos.x + 70 - text.w() / 2, pos.y + 130); - str.clear(); - String::AddInt(str, result); - text.Set(str, Font::BIG); - text.Blit(pos.x + 167 - text.w() / 2, pos.y + 160); - if(paymentMonster.ore || - paymentMonster.wood || - paymentMonster.mercury || - paymentMonster.crystal || - paymentMonster.sulfur || - paymentMonster.gems) - { - str.clear(); - String::AddInt(str, paymentCosts.gold); - text.Set(str, Font::SMALL); - text.Blit(pos.x + 133 - text.w() / 2, pos.y + 228); - str.clear(); - if(paymentMonster.ore) String::AddInt(str, paymentCosts.ore); - else - if(paymentMonster.wood) String::AddInt(str, paymentCosts.wood); - else - if(paymentMonster.mercury) String::AddInt(str, paymentCosts.mercury); - else - if(paymentMonster.crystal) String::AddInt(str, paymentCosts.crystal); - else - if(paymentMonster.sulfur) String::AddInt(str, paymentCosts.sulfur); - else - if(paymentMonster.gems) String::AddInt(str, paymentCosts.gems); - text.Set(str, Font::SMALL); - text.Blit(pos.x + 195 - text.w() / 2, pos.y + 228); - } - else - { - str.clear(); - String::AddInt(str, paymentCosts.gold); - text.Set(str, Font::SMALL); - text.Blit(pos.x + 160 - text.w() / 2, pos.y + 228); - } -} - -void RedrawResourceInfo(const Surface & sres, const Point & pos, s32 value, - u8 px1, u8 py1, u8 px2, u8 py2) -{ - Display & display = Display::Get(); - Point dst_pt; - std::string str; - Text text; - - dst_pt.x = pos.x + px1; - dst_pt.y = pos.y + py1; - display.Blit(sres, dst_pt); - - String::AddInt(str, value); - text.Set(str, Font::SMALL); - - dst_pt.x = pos.x + px2 - text.w() / 2; - dst_pt.y = pos.y + py2; - text.Blit(dst_pt); -} - -u16 Dialog::RecruitMonster(const Monster & monster, u16 available) -{ - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - // cursor - Cursor & cursor = Cursor::Get(); - const Cursor::themes_t oldcursor = cursor.Themes(); - cursor.Hide(); - cursor.SetThemes(Cursor::POINTER); - - // calculate max count - u32 max = 0; - const PaymentConditions::BuyMonster paymentMonster(monster()); - const Resource::funds_t & kingdomResource = world.GetMyKingdom().GetFundsResource(); - while(Resource::funds_t(paymentMonster * max) <= kingdomResource && max <= available) ++max; - - u32 result = --max; - - payment_t paymentCosts(paymentMonster * result); - - const Sprite & box = AGG::GetICN(ICN::RECRBKG, 0); - const Rect pos((display.w() - box.w()) / 2, Settings::Get().QVGA() ? (display.h() - box.h()) / 2 - 15 : (display.h() - box.h()) / 2, box.w(), box.h()); - - Background back(pos); - back.Save(); - - display.Blit(box, pos.x, pos.y); - - Point dst_pt; - std::string str; - Text text; - - // smear hardcore text "Cost per troop:" - const Sprite & smear = AGG::GetICN(ICN::TOWNNAME, 0); - dst_pt.x = pos.x + 144; - dst_pt.y = pos.y + 55; - display.Blit(smear, Rect(8, 1, 120, 12), dst_pt); - - str = _("Cost per troop:"); - text.Set(str, Font::SMALL); - dst_pt.x = pos.x + 206 - text.w() / 2; - dst_pt.y = pos.y + 55; - text.Blit(dst_pt); - - // text recruit monster - str = _("Recruit %{name}"); - String::Replace(str, "%{name}", monster.GetMultiName()); - text.Set(str, Font::BIG); - dst_pt.x = pos.x + (pos.w - text.w()) / 2; - dst_pt.y = pos.y + 25; - text.Blit(dst_pt); - - // sprite monster - const Sprite & smon = AGG::GetICN(monster.ICNMonh(), 0); - dst_pt.x = pos.x + 70 - smon.w() / 2; - dst_pt.y = pos.y + 130 - smon.h(); - display.Blit(smon, dst_pt); - - // info resource - // gold - const Sprite & sgold = AGG::GetICN(ICN::RESOURCE, 6); - dst_pt.x = pos.x + (paymentMonster.ore || - paymentMonster.wood || - paymentMonster.mercury || - paymentMonster.crystal || - paymentMonster.sulfur || - paymentMonster.gems ? 150 : 175); - dst_pt.y = pos.y + 75; - display.Blit(sgold, dst_pt); - - dst_pt.x = pos.x + (paymentMonster.ore || - paymentMonster.wood || - paymentMonster.mercury || - paymentMonster.crystal || - paymentMonster.sulfur || - paymentMonster.gems ? 105 : 130); - dst_pt.y = pos.y + 200; - display.Blit(sgold, dst_pt); - - str.clear(); - String::AddInt(str, paymentMonster.gold); - text.Set(str, Font::SMALL); - dst_pt.x = pos.x + (paymentMonster.ore || - paymentMonster.wood || - paymentMonster.mercury || - paymentMonster.crystal || - paymentMonster.sulfur || - paymentMonster.gems ? 183 : 205) - text.w() / 2; - dst_pt.y = pos.y + 103; - text.Blit(dst_pt); - - // crystal - if(paymentMonster.crystal) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 4); - RedrawResourceInfo(sres, pos, paymentMonster.crystal, - 225, 75, 240, 103); - dst_pt.x = pos.x + 180; - dst_pt.y = pos.y + 200; - display.Blit(sres, dst_pt); - } - else - // mercury - if(paymentMonster.mercury) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 1); - RedrawResourceInfo(sres, pos, paymentMonster.mercury, - 225, 72, 240, 103); - dst_pt.x = pos.x + 180; - dst_pt.y = pos.y + 197; - display.Blit(sres, dst_pt); - } - else - // wood - if(paymentMonster.wood) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 0); - RedrawResourceInfo(sres, pos, paymentMonster.wood, - 225, 72, 240, 103); - dst_pt.x = pos.x + 180; - dst_pt.y = pos.y + 197; - display.Blit(sres, dst_pt); - } - else - // ore - if(paymentMonster.ore) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 2); - RedrawResourceInfo(sres, pos, paymentMonster.ore, - 225, 72, 240, 103); - dst_pt.x = pos.x + 180; - dst_pt.y = pos.y + 197; - display.Blit(sres, dst_pt); - } - else - // sulfur - if(paymentMonster.sulfur) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 3); - RedrawResourceInfo(sres, pos, paymentMonster.sulfur, - 225, 75, 240, 103); - dst_pt.x = pos.x + 180; - dst_pt.y = pos.y + 200; - display.Blit(sres, dst_pt); - } - else - // gems - if(paymentMonster.gems) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 5); - RedrawResourceInfo(sres, pos, paymentMonster.gems, - 225, 75, 240, 103); - dst_pt.x = pos.x + 180; - dst_pt.y = pos.y + 200; - display.Blit(sres, dst_pt); - } - - // text number buy - text.Set(_("Number to buy:")); - dst_pt.x = pos.x + 30; - dst_pt.y = pos.y + 163; - text.Blit(dst_pt); - - Background static_info(Rect(pos.x + 16, pos.y + 125, pos.w - 32, 122)); - static_info.Save(); - - RedrawCurrentInfo(pos, available, result, paymentMonster, paymentCosts); - - // buttons - dst_pt.x = pos.x + 34; - dst_pt.y = pos.y + 249; - Button buttonOk(dst_pt, ICN::RECRUIT, 8, 9); - - dst_pt.x = pos.x + 187; - dst_pt.y = pos.y + 249; - Button buttonCancel(dst_pt, ICN::RECRUIT, 6, 7); - - dst_pt.x = pos.x + 230; - dst_pt.y = pos.y + 155; - Button buttonMax(dst_pt, ICN::RECRUIT, 4, 5); - dst_pt.x = pos.x + 208; - dst_pt.y = pos.y + 156; - Button buttonUp(dst_pt, ICN::RECRUIT, 0, 1); - - dst_pt.x = pos.x + 208; - dst_pt.y = pos.y + 171; - Button buttonDn(dst_pt, ICN::RECRUIT, 2, 3); - - buttonOk.Draw(); - buttonCancel.Draw(); - buttonMax.Draw(); - buttonUp.Draw(); - buttonDn.Draw(); - - cursor.Show(); - display.Flip(); - - bool redraw = false; - - // str loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - le.MousePressLeft(buttonMax) ? buttonMax.PressDraw() : buttonMax.ReleaseDraw(); - le.MousePressLeft(buttonUp) ? buttonUp.PressDraw() : buttonUp.ReleaseDraw(); - le.MousePressLeft(buttonDn) ? buttonDn.PressDraw() : buttonDn.ReleaseDraw(); - - if(PressIntKey(0, max, result)) - { - paymentCosts = paymentMonster * result; - redraw = true; - } - - if(le.MouseClickLeft(buttonUp) && result < max) - { - ++result; - paymentCosts += paymentMonster; - redraw = true; - } - else - if(le.MouseClickLeft(buttonDn) && result) - { - --result; - paymentCosts -= paymentMonster; - redraw = true; - } - else - if(le.MouseClickLeft(buttonMax) && result != max) - { - result = max; - paymentCosts = paymentMonster * max; - redraw = true; - } - - if(redraw) - { - cursor.Hide(); - static_info.Restore(); - RedrawCurrentInfo(pos, available, result, paymentMonster, paymentCosts); - cursor.Show(); - display.Flip(); - redraw = false; - } - - if(le.MouseClickLeft(buttonOk) || Game::HotKeyPress(Game::EVENT_DEFAULT_READY)) break; - - if(le.MouseClickLeft(buttonCancel) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)){ result = 0; break; } - } - - cursor.Hide(); - - back.Restore(); - cursor.SetThemes(oldcursor); - - cursor.Show(); - display.Flip(); - - return result; -} - -void Dialog::DwellingInfo(const Monster & monster, u16 available) -{ - Display & display = Display::Get(); - - // cursor - Cursor & cursor = Cursor::Get(); - const Cursor::themes_t oldcursor = cursor.Themes(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const PaymentConditions::BuyMonster paymentMonster(monster()); - - const Sprite & box = AGG::GetICN(ICN::RECR2BKG, 0); - const Rect pos((display.w() - box.w()) / 2, (display.h() - box.h()) / 2, box.w(), box.h()); - - Background back(pos); - back.Save(); - - display.Blit(box, pos.x, pos.y); - - LocalEvent & le = LocalEvent::Get(); - - Point dst_pt; - Text text; - std::string str; - - // text recruit monster - str = _("Recruit %{name}"); - String::Replace(str, "%{name}", monster.GetMultiName()); - text.Set(str, Font::BIG); - text.Blit(pos.x + (pos.w - text.w()) / 2, pos.y + 25); - - // sprite monster - const Sprite & smon = AGG::GetICN(monster.ICNMonh(), 0); - dst_pt.x = pos.x + 70 - smon.w() / 2; - dst_pt.y = pos.y + 120 - smon.h(); - display.Blit(smon, dst_pt); - - // info resource - // gold - const Sprite & sgold = AGG::GetICN(ICN::RESOURCE, 6); - dst_pt.x = pos.x + (paymentMonster.ore || - paymentMonster.wood || - paymentMonster.mercury || - paymentMonster.crystal || - paymentMonster.sulfur || - paymentMonster.gems ? 150 : 175); - dst_pt.y = pos.y + 75; - display.Blit(sgold, dst_pt); - - str.clear(); - String::AddInt(str, paymentMonster.gold); - text.Set(str, Font::SMALL); - dst_pt.x = pos.x + (paymentMonster.ore || - paymentMonster.wood || - paymentMonster.mercury || - paymentMonster.crystal || - paymentMonster.sulfur || - paymentMonster.gems ? 183 : 205) - text.w() / 2; - dst_pt.y = pos.y + 103; - text.Blit(dst_pt); - // crystal - if(paymentMonster.crystal) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 4); - RedrawResourceInfo(sres, pos, paymentMonster.crystal, - 225, 75, 240, 103); - } - else - // mercury - if(paymentMonster.mercury) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 1); - RedrawResourceInfo(sres, pos, paymentMonster.mercury, - 225, 72, 240, 103); - } - else - // wood - if(paymentMonster.wood) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 0); - RedrawResourceInfo(sres, pos, paymentMonster.wood, - 225, 72, 240, 103); - } - else - // ore - if(paymentMonster.ore) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 2); - RedrawResourceInfo(sres, pos, paymentMonster.ore, - 225, 72, 240, 103); - } - else - // sulfur - if(paymentMonster.sulfur) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 3); - RedrawResourceInfo(sres, pos, paymentMonster.sulfur, - 225, 75, 240, 103); - } - else - // gems - if(paymentMonster.gems) - { - const Sprite & sres = AGG::GetICN(ICN::RESOURCE, 5); - RedrawResourceInfo(sres, pos, paymentMonster.gems, - 225, 75, 240, 103); - } - - // text available - str = _("Available: %{count}"); - String::Replace(str, "%{count}", available); - text.Set(str); - text.Blit(pos.x + 70 - text.w() / 2, pos.y + 130); - - cursor.Show(); - display.Flip(); - - // - while(le.HandleEvents() && le.MousePressRight()); - - cursor.Hide(); - - back.Restore(); - cursor.SetThemes(oldcursor); - - cursor.Show(); - display.Flip(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_resourceinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_resourceinfo.cpp deleted file mode 100644 index 964b0a59f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_resourceinfo.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" - -u16 Dialog::ResourceInfo(const std::string &header, const std::string &message, const Resource::funds_t & rs, u16 buttons) -{ - Display & display = Display::Get(); - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // preload - AGG::PreloadObject(system); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - TextBox box1(header, Font::YELLOW_BIG, BOXAREA_WIDTH); - TextBox box2(message, Font::BIG, BOXAREA_WIDTH); - Resource::BoxSprite rbs(rs, BOXAREA_WIDTH); - - const u8 spacer = Settings::Get().QVGA(); - - Box box(box1.h() + spacer + box2.h() + spacer + rbs.GetArea().h, true); - Point pos = box.GetArea(); - - if(header.size()) box1.Blit(pos); - pos.y += box1.h() + spacer; - - if(message.size()) box2.Blit(pos); - pos.y += box2.h() + spacer; - - rbs.SetPos(pos.x, pos.y); - rbs.Redraw(); - - LocalEvent & le = LocalEvent::Get(); - - ButtonGroups btnGroups(box.GetArea(), buttons); - btnGroups.Draw(); - - cursor.Show(); - display.Flip(); - - u16 result = Dialog::ZERO; - - while(result == Dialog::ZERO && le.HandleEvents()) - { - if(!buttons && !le.MousePressRight()) break; - result = btnGroups.QueueEventProcessing(); - } - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectcount.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectcount.cpp deleted file mode 100644 index a8cf41f8f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectcount.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "pocketpc.h" -#include "dialog.h" - -bool Dialog::SelectCount(const std::string &header, u32 min, u32 max, u32 & cur) -{ - Display & display = Display::Get(); - - if(min >= max) min = 0; - if(cur > max || cur < min) cur = min; - - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // preload - AGG::PreloadObject(system); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - - Text text(header, Font::BIG); - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - - Box box(text.h() + spacer + 30, true); - - const Rect & pos = box.GetArea(); - Point pt; - std::string message; - - // text - pt.x = pos.x + (pos.w - text.w()) / 2; - pt.y = pos.y; - text.Blit(pt); - - // sprite edit - const Surface & sprite_edit = AGG::GetICN(ICN::TOWNWIND, 4); - pt.x = pos.x + 80; - pt.y = pos.y + 35; - display.Blit(sprite_edit, pt); - - message.clear(); - String::AddInt(message, cur); - text.Set(message); - pt.x = pos.x + 80 + (sprite_edit.w() - text.w()) / 2; - pt.y = pos.y + 36; - text.Blit(pt); - - // buttons - pt.x = pos.x + 150; - pt.y = pos.y + 31; - Button buttonUp(pt, ICN::TOWNWIND, 5, 6); - - pt.x = pos.x + 150; - pt.y = pos.y + 47; - Button buttonDn(pt, ICN::TOWNWIND, 7, 8); - - pt.x = pos.x; - pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 1).h(); - Button buttonOk(pt, system, 1, 2); - - pt.x = pos.x + pos.w - AGG::GetICN(system, 3).w(); - pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 3).h(); - Button buttonCancel(pt, system, 3, 4); - - text.Set("MAX", Font::SMALL); - const Rect rectMax(pos.x + 173, pos.y + 38, text.w(), text.h()); - text.Blit(rectMax.x, rectMax.y); - - LocalEvent & le = LocalEvent::Get(); - - buttonUp.Draw(); - buttonDn.Draw(); - buttonOk.Draw(); - buttonCancel.Draw(); - - bool redraw_count = false; - cursor.Show(); - display.Flip(); - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - le.MousePressLeft(buttonUp) ? buttonUp.PressDraw() : buttonUp.ReleaseDraw(); - le.MousePressLeft(buttonDn) ? buttonDn.PressDraw() : buttonDn.ReleaseDraw(); - - if(PressIntKey(min, max, cur)) - redraw_count = true; - - // max - if(le.MouseClickLeft(rectMax)) - { - cur = max; - redraw_count = true; - } - else - // up - if((le.MouseWheelUp(pos) || - le.MouseClickLeft(buttonUp)) && cur < max) - { - ++cur; - redraw_count = true; - } - else - // down - if((le.MouseWheelDn(pos) || - le.MouseClickLeft(buttonDn)) && min < cur) - { - --cur; - redraw_count = true; - } - - if(redraw_count) - { - cursor.Hide(); - pt.x = pos.x + 80; - pt.y = pos.y + 35; - display.Blit(sprite_edit, pt); - - message.clear(); - String::AddInt(message, cur); - text.Set(message, Font::BIG); - pt.x = pos.x + 80 + (sprite_edit.w() - text.w()) / 2; - pt.y = pos.y + 36; - text.Blit(pt); - cursor.Show(); - display.Flip(); - - redraw_count = false; - } - - if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || le.MouseClickLeft(buttonOk)){ cursor.Hide(); return true; } - else - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancel)){ cur = 0; break; } - } - cursor.Hide(); - return false; -} - -bool Dialog::InputString(const std::string &header, std::string &res) -{ - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - Cursor::themes_t oldcursor = cursor.Themes(); - cursor.SetThemes(cursor.POINTER); - - //const bool pda = Settings::Get().PocketPC(); - if(res.size()) res.clear(); - res.reserve(48); - - TextBox textbox(header, Font::BIG, BOXAREA_WIDTH); - Point dst_pt; - const Surface & sprite = AGG::GetICN((Settings::Get().EvilInterface() ? ICN::BUYBUILD : ICN::BUYBUILE), 3); - - Box box(10 + textbox.h() + 10 + sprite.h(), OK|CANCEL); - const Rect & box_rt = box.GetArea(); - - // text - dst_pt.x = box_rt.x + (box_rt.w - textbox.w()) / 2; - dst_pt.y = box_rt.y + 10; - textbox.Blit(dst_pt); - - dst_pt.y = box_rt.y + 10 + textbox.h() + 10; - dst_pt.x = box_rt.x + (box_rt.w - sprite.w()) / 2; - display.Blit(sprite, dst_pt); - const Rect text_rt(dst_pt.x, dst_pt.y, sprite.w(), sprite.h()); - - Text text("_", Font::BIG); - display.Blit(sprite, text_rt); - text.Blit(dst_pt.x + (sprite.w() - text.w()) / 2, dst_pt.y - 1); - - dst_pt.x = box_rt.x; - dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 1).h(); - Button buttonOk(dst_pt, system, 1, 2); - - dst_pt.x = box_rt.x + box_rt.w - AGG::GetICN(system, 3).w(); - dst_pt.y = box_rt.y + box_rt.h - AGG::GetICN(system, 3).h(); - Button buttonCancel(dst_pt, system, 3, 4); - - buttonOk.SetDisable(res.empty()); - buttonOk.Draw(); - buttonCancel.Draw(); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - bool redraw = true; - - // message loop - while(le.HandleEvents()) - { - buttonOk.isEnable() && le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - - if(Settings::Get().PocketPC() && le.MousePressLeft(text_rt)) - { - PocketPC::KeyboardDialog(res); - redraw = true; - } - - if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || (buttonOk.isEnable() && le.MouseClickLeft(buttonOk))) break; - else - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancel)){ res.clear(); break; } - else - if(le.KeyPress()) - { - String::AppendKey(res, le.KeyValue(), le.KeyMod()); - redraw = true; - } - - if(redraw) - { - buttonOk.SetDisable(res.empty()); - buttonOk.Draw(); - - text.Set(res + "_"); - - if(text.w() < sprite.w() - 24) - { - cursor.Hide(); - display.Blit(sprite, text_rt); - text.Blit(text_rt.x + (text_rt.w - text.w()) / 2, text_rt.y - 1); - cursor.Show(); - display.Flip(); - } - redraw = false; - } - } - - cursor.SetThemes(oldcursor); - cursor.Hide(); - - return res.size(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectfile.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectfile.cpp deleted file mode 100644 index ce79c5812..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectfile.cpp +++ /dev/null @@ -1,338 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include "dir.h" -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "maps_fileinfo.h" -#include "interface_list.h" -#include "pocketpc.h" -#include "dialog.h" - -#ifdef __SYMBIAN32__ -#include -#endif - -bool SelectFileListSimple(const std::string &, MapsFileInfoList &, std::string &, bool); -void RedrawExtraInfo(const Point &, const std::string &, const std::string &); - -class FileInfoListBox : public Interface::ListBox -{ -public: - FileInfoListBox(const Point & pt, std::string & res, bool & edit) : Interface::ListBox(pt), result(res), edit_mode(edit) {}; - - void RedrawItem(const Maps::FileInfo &, s16, s16, bool); - void RedrawBackground(const Point &); - - void ActionCurrentUp(void); - void ActionCurrentDn(void); - void ActionListDoubleClick(Maps::FileInfo &); - void ActionListSingleClick(Maps::FileInfo &); - void ActionListPressRight(Maps::FileInfo &){}; - - std::string & result; - bool & edit_mode; -}; - -void FileInfoListBox::RedrawItem(const Maps::FileInfo & info, s16 dstx, s16 dsty, bool current) -{ - char short_date[20]; - - std::fill(short_date, short_date + sizeof(short_date), 0); - std::strftime(short_date, sizeof(short_date) - 1, "%b %d, %H:%M", std::localtime(&info.localtime)); - std::string savname(GetBasename(info.file)); - - if(savname.size()) - { - Text text; - const size_t dotpos = savname.size() - 4; - std::string ext = savname.substr(dotpos); - String::Lower(ext); - if(ext == ".sav") savname.erase(dotpos); - - text.Set(savname, (current ? Font::YELLOW_BIG : Font::BIG)); - text.Blit(dstx + 5, dsty, (Settings::Get().QVGA() ? 190 : 155)); - - text.Set(short_date, (current ? Font::YELLOW_BIG : Font::BIG)); - text.Blit(dstx + 265 - text.w(), dsty); - } -} - -void FileInfoListBox::RedrawBackground(const Point & dst) -{ - Display & display = Display::Get(); - const Sprite & panel = AGG::GetICN(ICN::REQBKG, 0); - - if(Settings::Get().QVGA()) - { - display.Blit(panel, Rect(0, 0, panel.w(), 120), dst.x, dst.y); - display.Blit(panel, Rect(0, panel.h() - 120, panel.w(), 120), dst.x, dst.y + 224 - 120); - } - else - display.Blit(panel, dst); -} - -void FileInfoListBox::ActionCurrentUp(void) -{ - edit_mode = false; -} - -void FileInfoListBox::ActionCurrentDn(void) -{ - edit_mode = false; -} - -void FileInfoListBox::ActionListDoubleClick(Maps::FileInfo &) -{ - result = (*cur).file; - edit_mode = false; -} - -void FileInfoListBox::ActionListSingleClick(Maps::FileInfo &) -{ - edit_mode = false; -} - -void ResizeToShortName(const std::string & str, std::string & res) -{ - res.assign(GetBasename(str)); - size_t it = res.find('.'); - if(std::string::npos != it) res.resize(it); -} - -bool Dialog::SelectFileSave(std::string & file) -{ - Dir dir; - const std::string store_dir(Settings::Get().LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "save"); - dir.Read(store_dir, ".sav", false); - - MapsFileInfoList lists(dir.size()); - MapsFileInfoList::const_iterator res; - int ii = 0; - for(Dir::const_iterator itd = dir.begin(); itd != dir.end(); ++itd, ++ii) if(!lists[ii].ReadSAV(*itd)) --ii; - if(static_cast(ii) != lists.size()) lists.resize(ii); - std::sort(lists.begin(), lists.end(), Maps::FileInfo::FileSorting); - - // set default - if(file.empty()) - { - const Settings & conf = Settings::Get(); - file = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "save" + SEPARATOR; - - if(conf.ExtRememberLastFilename() && Game::IO::last_name.size()) - file = Game::IO::last_name; - else - if(conf.PocketPC()) - { - std::ostringstream ss; - ss << std::time(0); - file += ss.str() + ".sav"; - } - else - file += "newgame.sav"; - } - - return SelectFileListSimple(_("File to Save:"), lists, file, true); -} - -bool Dialog::SelectFileLoad(std::string & file) -{ - Dir dir; - const std::string store_dir(Settings::Get().LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "save"); - dir.Read(store_dir, ".sav", false); - - MapsFileInfoList lists(dir.size()); - MapsFileInfoList::const_iterator res; - int ii = 0; - for(Dir::const_iterator itd = dir.begin(); itd != dir.end(); ++itd, ++ii) if(!lists[ii].ReadSAV(*itd)) --ii; - if(static_cast(ii) != lists.size()) lists.resize(ii); - std::sort(lists.begin(), lists.end(), Maps::FileInfo::FileSorting); - - // set default - if(file.empty() && Settings::Get().ExtRememberLastFilename() && Game::IO::last_name.size()) file = Game::IO::last_name; - - return SelectFileListSimple(_("File to Load:"), lists, file, false); -} - -bool SelectFileListSimple(const std::string & header, MapsFileInfoList & lists, std::string & result, bool editor) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite & sprite = AGG::GetICN(ICN::REQBKG, 0); - Size panel(sprite.w(), sprite.h()); - bool pocket = Settings::Get().QVGA(); - if(pocket) panel = Size(sprite.w(), 224); - - Background back((display.w() - panel.w) / 2, (display.h() - panel.h) / 2, panel.w, panel.h); - back.Save(); - - const Rect & rt = back.GetRect(); - const Rect enter_field(rt.x + 45, rt.y + (pocket ? 148 : 286), 260, 16); - - Button buttonOk(rt.x + 34, rt.y + (pocket ? 176 : 315), ICN::REQUEST, 1, 2); - Button buttonCancel(rt.x + 244, rt.y + (pocket ? 176 : 315), ICN::REQUEST, 3, 4); - - bool edit_mode = false; - - FileInfoListBox listbox(rt, result, edit_mode); - - listbox.RedrawBackground(rt); - listbox.SetScrollButtonUp(ICN::REQUESTS, 5, 6, Point(rt.x + 327, rt.y + 55)); - listbox.SetScrollButtonDn(ICN::REQUESTS, 7, 8, Point(rt.x + 327, rt.y + (pocket ? 117 : 257))); - listbox.SetScrollSplitter(AGG::GetICN(ICN::ESCROLL, 3), Rect(rt.x + 330, rt.y + 73, 12, (pocket ? 40 : 180))); - listbox.SetAreaMaxItems(pocket ? 5 : 11); - listbox.SetAreaItems(Rect(rt.x + 40, rt.y + 55, 265, (pocket ? 78 : 215))); - listbox.SetListContent(lists); - - std::string filename; - - if(result.size()) - { - ResizeToShortName(result, filename); - - MapsFileInfoList::iterator it = lists.begin(); - for(; it != lists.end(); ++it) if((*it).file == result) break; - - if(it != lists.end()) - listbox.SetCurrent(std::distance(lists.begin(), it)); - else - listbox.Unselect(); - - result.clear(); - } - - if(!editor && lists.empty()) - buttonOk.SetDisable(true); - - if(filename.empty() && listbox.isSelected()) - ResizeToShortName(listbox.GetCurrent().file, filename); - - listbox.Redraw(); - RedrawExtraInfo(rt, header, filename); - - buttonOk.Draw(); - buttonCancel.Draw(); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents() && result.empty()) - { - le.MousePressLeft(buttonOk) && buttonOk.isEnable() ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - - listbox.QueueEventProcessing(); - - if((buttonOk.isEnable() && le.MouseClickLeft(buttonOk)) || Game::HotKeyPress(Game::EVENT_DEFAULT_READY)) - { - if(filename.size()) - result = Settings::Get().LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "save" + SEPARATOR + filename + ".sav"; - else - if(listbox.isSelected()) - result = listbox.GetCurrent().file; - } - else - if(le.MouseClickLeft(buttonCancel) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) - { - break; - } - else - if(le.MouseClickLeft(enter_field) && editor) - { - edit_mode = true; - if(Settings::Get().PocketPC()) - PocketPC::KeyboardDialog(filename); - buttonOk.SetDisable(filename.empty()); - cursor.Hide(); - } - else - if(edit_mode && le.KeyPress()) - { - String::AppendKey(filename, le.KeyValue(), le.KeyMod()); - buttonOk.SetDisable(filename.empty()); - cursor.Hide(); - } - if((le.KeyPress(KEY_DELETE) || (pocket && le.MousePressRight())) && listbox.isSelected()) - { - std::string msg(_("Are you sure you want to delete file:")); - msg.append("\n \n"); - msg.append(GetBasename(listbox.GetCurrent().file)); - if(Dialog::YES == Dialog::Message(_("Warning!"), msg, Font::BIG, Dialog::YES | Dialog::NO)) - { - remove(listbox.GetCurrent().file.c_str()); - listbox.RemoveSelected(); - if(lists.empty() || filename.empty()) buttonOk.SetDisable(true); - listbox.SetListContent(lists); - } - cursor.Hide(); - } - - if(! cursor.isVisible()) - { - listbox.Redraw(); - - if(edit_mode && editor) - RedrawExtraInfo(rt, header, filename + "_"); - else - if(listbox.isSelected()) - { - ResizeToShortName(listbox.GetCurrent().file, filename); - RedrawExtraInfo(rt, header, filename); - } - else - RedrawExtraInfo(rt, header, filename); - - buttonOk.Draw(); - buttonCancel.Draw(); - cursor.Show(); - display.Flip(); - } - } - - cursor.Hide(); - back.Restore(); - - return result.size(); -} - -void RedrawExtraInfo(const Point & dst, const std::string & header, const std::string & filename) -{ - Text text(header, Font::BIG); - text.Blit(dst.x + 175 - text.w() / 2, dst.y + 30); - - if(filename.size()) - { - text.Set(filename, Font::BIG); - text.Blit(dst.x + 175 - text.w() / 2, Settings::Get().QVGA() ? dst.y + 148 : dst.y + 289); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectscenario.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectscenario.cpp deleted file mode 100644 index 1fce86316..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectscenario.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "dialog.h" -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "difficulty.h" -#include "settings.h" -#include "maps.h" -#include "text.h" -#include "tools.h" -#include "dialog_selectscenario.h" - -void LossConditionInfo(const Maps::FileInfo &); -void VictoryConditionInfo(const Maps::FileInfo &); - -void ScenarioListBox::RedrawItem(const Maps::FileInfo & info, s16 dstx, s16 dsty, bool current) -{ - Display & display = Display::Get(); - Text text; - u8 index = 19 + Color::Count(info.kingdom_colors); - - if(!Settings::Get().QVGA()) - { - dstx = dstx - 10; - dsty = dsty + 2; - } - - const Sprite & spriteCount = AGG::GetICN(ICN::REQUESTS, index); - display.Blit(spriteCount, dstx, dsty); - - switch(info.size_w) - { - case Maps::SMALL: index = 26; break; - case Maps::MEDIUM: index = 27; break; - case Maps::LARGE: index = 28; break; - case Maps::XLARGE: index = 29; break; - default: index = 30; break; - } - - const Sprite & spriteSize = AGG::GetICN(ICN::REQUESTS, index); - display.Blit(spriteSize, dstx + spriteCount.w() + 2, dsty); - - text.Set(info.name, (current ? Font::YELLOW_BIG : Font::BIG)); - text.Blit(dstx + 54, dsty + 2); - - index = 30 + info.conditions_wins; - const Sprite & spriteWins = AGG::GetICN(ICN::REQUESTS, index); - display.Blit(spriteWins, dstx + 224, dsty); - - index = 36 + info.conditions_loss; - const Sprite & spriteLoss = AGG::GetICN(ICN::REQUESTS, index); - display.Blit(spriteLoss, dstx + 224 + spriteWins.w() + 2, dsty); -} - -void ScenarioListBox::ActionListDoubleClick(Maps::FileInfo &) -{ - selectOk = true; -} - -void ScenarioListBox::RedrawBackground(const Point & dst) -{ - Display & display = Display::Get(); - - if(Settings::Get().QVGA()) - { - display.Blit(AGG::GetICN(ICN::STONEBAK, 0), Rect(17, 37, 266, 156), dst.x + 15, dst.y + 35); - display.Blit(AGG::GetICN(ICN::REQSBKG, 0), Rect(325, 70, 16, 100), dst.x + 283, dst.y + 55); - display.Blit(AGG::GetICN(ICN::REQSBKG, 0), Rect(325, 167, 16, 50), dst.x + 283, dst.y + 125); - } - else - { - display.Blit(AGG::GetICN(ICN::REQSBKG, 0), dst); - - if(content && cur != content->end()) - { - Text text; - const Maps::FileInfo & info = *cur; - u8 index = 19 + Color::Count(info.kingdom_colors); - - const Sprite & spriteCount = AGG::GetICN(ICN::REQUESTS, index); - display.Blit(spriteCount, dst.x + 65, dst.y + 265); - - switch(info.size_w) - { - case Maps::SMALL: index = 26; break; - case Maps::MEDIUM: index = 27; break; - case Maps::LARGE: index = 28; break; - case Maps::XLARGE: index = 29; break; - default: index = 30; break; - } - - const Sprite & spriteSize = AGG::GetICN(ICN::REQUESTS, index); - display.Blit(spriteSize, dst.x + 65 + spriteCount.w() + 2, dst.y + 265); - - text.Set(info.name, Font::BIG); - text.Blit(dst.x + 190 - text.w() / 2, dst.y + 265); - - index = 30 + info.conditions_wins; - const Sprite & spriteWins = AGG::GetICN(ICN::REQUESTS, index); - display.Blit(spriteWins, dst.x + 275, dst.y + 265); - - index = 36 + info.conditions_loss; - const Sprite & spriteLoss = AGG::GetICN(ICN::REQUESTS, index); - display.Blit(spriteLoss, dst.x + 275 + spriteWins.w() + 2, dst.y + 265); - - text.Set(_("Maps Difficulty:"), Font::BIG); - text.Blit(dst.x + 70, dst.y + 290); - - text.Set(Difficulty::String(info.difficulty)); - text.Blit(dst.x + 275 - text.w() / 2, dst.y + 290); - - TextBox box(info.description, Font::BIG, 290); - box.Blit(dst.x + 45, dst.y + 320); - } - } -} - -bool Dialog::SelectScenario(const MapsFileInfoList & all, std::string & filename) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - MapsFileInfoList small; - MapsFileInfoList medium; - MapsFileInfoList large; - MapsFileInfoList xlarge; - - small.reserve(all.size()); - medium.reserve(all.size()); - large.reserve(all.size()); - xlarge.reserve(all.size()); - - for(MapsFileInfoList::const_iterator cur = all.begin(); cur != all.end(); ++ cur) - { - switch((*cur).size_w) - { - case Maps::SMALL: small.push_back(*cur); break; - case Maps::MEDIUM: medium.push_back(*cur); break; - case Maps::LARGE: large.push_back(*cur); break; - case Maps::XLARGE: xlarge.push_back(*cur); break; - default: continue; - } - } - - const Sprite & panel = AGG::GetICN(ICN::REQSBKG, 0); - Background back((display.w() - panel.w()) / 2, (display.h() - panel.h()) / 2, panel.w(), panel.h()); - back.Save(); - - const Rect & rt = back.GetRect(); - - const Rect countPlayers(rt.x + 45, rt.y + 55, 20, 175); - const Rect sizeMaps(rt.x + 62, rt.y + 55, 20, 175); - const Rect victoryConds(rt.x + 267, rt.y + 55, 20, 175); - const Rect lossConds(rt.x + 287, rt.y + 55, 20, 175); - - const Rect curCountPlayer(rt.x + 66, rt.y + 264, 18, 18); - const Rect curMapSize(rt.x + 85, rt.y + 264, 18, 18); - const Rect curMapName(rt.x + 107, rt.y + 264, 166, 18); - const Rect curVictoryCond(rt.x + 277, rt.y + 264, 18, 18); - const Rect curLossCond(rt.x + 295, rt.y + 264, 18, 18); - const Rect curDifficulty(rt.x + 220, rt.y + 292, 114, 20); - const Rect curDescription(rt.x + 42, rt.y + 316, 292, 90); - - Button buttonOk(rt.x + 140, rt.y + 410, ICN::REQUESTS, 1, 2); - - Button buttonSelectSmall(rt.x + 37, rt.y + 22, ICN::REQUESTS, 9, 10); - Button buttonSelectMedium(rt.x + 99, rt.y + 22, ICN::REQUESTS, 11, 12); - Button buttonSelectLarge(rt.x + 161, rt.y + 22, ICN::REQUESTS, 13, 14); - Button buttonSelectXLarge(rt.x + 223, rt.y + 22, ICN::REQUESTS, 15, 16); - Button buttonSelectAll(rt.x + 285, rt.y + 22, ICN::REQUESTS, 17, 18); - - if(small.empty()) buttonSelectSmall.SetDisable(true); - if(medium.empty()) buttonSelectMedium.SetDisable(true); - if(large.empty()) buttonSelectLarge.SetDisable(true); - if(xlarge.empty()) buttonSelectXLarge.SetDisable(true); - - ScenarioListBox listbox(rt); - - listbox.RedrawBackground(rt); - listbox.SetScrollButtonUp(ICN::REQUESTS, 5, 6, Point(rt.x + 327, rt.y + 55)); - listbox.SetScrollButtonDn(ICN::REQUESTS, 7, 8, Point(rt.x + 327, rt.y + 217)); - listbox.SetScrollSplitter(AGG::GetICN(ICN::ESCROLL, 3), Rect(rt.x + 330, rt.y + 73, 12, 141)); - listbox.SetAreaMaxItems(9); - listbox.SetAreaItems(Rect(rt.x + 55, rt.y + 55, 270, 175)); - listbox.SetListContent(const_cast(all)); - listbox.Redraw(); - - buttonOk.Draw(); - buttonSelectSmall.Draw(); - buttonSelectMedium.Draw(); - buttonSelectLarge.Draw(); - buttonSelectXLarge.Draw(); - buttonSelectAll.Draw(); - - filename.clear(); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - if(buttonOk.isEnable()) le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - le.MousePressLeft(buttonSelectSmall) && buttonSelectSmall.isEnable() ? buttonSelectSmall.PressDraw() : buttonSelectSmall.ReleaseDraw(); - le.MousePressLeft(buttonSelectMedium) && buttonSelectMedium.isEnable() ? buttonSelectMedium.PressDraw() : buttonSelectMedium.ReleaseDraw(); - le.MousePressLeft(buttonSelectLarge) && buttonSelectLarge.isEnable() ? buttonSelectLarge.PressDraw() : buttonSelectLarge.ReleaseDraw(); - le.MousePressLeft(buttonSelectXLarge) && buttonSelectXLarge.isEnable() ? buttonSelectXLarge.PressDraw() : buttonSelectXLarge.ReleaseDraw(); - le.MousePressLeft(buttonSelectAll) ? buttonSelectAll.PressDraw() : buttonSelectAll.ReleaseDraw(); - - if((buttonOk.isEnable() && le.MouseClickLeft(buttonOk)) || - Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || - listbox.selectOk) - { - filename = listbox.GetCurrent().file; - break; - } - else - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) - { - filename.clear(); - break; - } - else - if(((le.MouseClickLeft(buttonSelectSmall) || le.KeyPress(KEY_s)) && buttonSelectSmall.isEnable()) && buttonSelectSmall.isEnable()) - { - listbox.SetListContent(small); - cursor.Hide(); - } - else - if(((le.MouseClickLeft(buttonSelectMedium) || le.KeyPress(KEY_m)) && buttonSelectMedium.isEnable()) && buttonSelectMedium.isEnable()) - { - listbox.SetListContent(medium); - cursor.Hide(); - } - else - if(((le.MouseClickLeft(buttonSelectLarge) || le.KeyPress(KEY_l)) && buttonSelectLarge.isEnable()) && buttonSelectLarge.isEnable()) - { - listbox.SetListContent(large); - cursor.Hide(); - } - else - if(((le.MouseClickLeft(buttonSelectXLarge) || le.KeyPress(KEY_x)) && buttonSelectXLarge.isEnable()) && buttonSelectXLarge.isEnable()) - { - listbox.SetListContent(xlarge); - cursor.Hide(); - } - else - if(le.MouseClickLeft(buttonSelectAll) || le.KeyPress(KEY_a)) - { - listbox.SetListContent(const_cast(all)); - cursor.Hide(); - } - - listbox.QueueEventProcessing(); - - // right info - if(le.MousePressRight(buttonSelectSmall)) Dialog::Message(_("Small Maps"), _("View only maps of size small (36x36)."), Font::BIG); - else - if(le.MousePressRight(buttonSelectMedium)) Dialog::Message(_("Medium Maps"), _("View only maps of size medium (72x72)."), Font::BIG); - else - if(le.MousePressRight(buttonSelectLarge)) Dialog::Message(_("Large Maps"), _("View only maps of size large (108x108)."), Font::BIG); - else - if(le.MousePressRight(buttonSelectXLarge)) Dialog::Message(_("Extra Large Maps"), _("View only maps of size extra large (144x144)."), Font::BIG); - else - if(le.MousePressRight(buttonSelectAll)) Dialog::Message(_("All Maps"), _("View all maps, regardless of size."), Font::BIG); - else - if(le.MousePressRight(countPlayers) || le.MousePressRight(curCountPlayer)) Dialog::Message(_("Players Icon"), _("Indicates how many players total are in the EditScenario. Any positions not occupied by humans will be occupied by computer players."), Font::BIG); - else - if(le.MousePressRight(sizeMaps) || le.MousePressRight(curMapSize)) Dialog::Message(_("Size Icon"), _("Indicates whether the maps is small (36x36), medium (72x72), large (108x108), or extra large (144x144)."), Font::BIG); - else - if(le.MousePressRight(curMapName)) Dialog::Message(_("Selected Name"), _("The name of the currently selected map."), Font::BIG); - else - if(le.MousePressRight(victoryConds)) - { - const Maps::FileInfo* item = listbox.GetFromPosition(le.GetMouseCursor()); - if(item) VictoryConditionInfo(*item); - } - else - if(le.MousePressRight(lossConds)) - { - const Maps::FileInfo* item = listbox.GetFromPosition(le.GetMouseCursor()); - if(item) LossConditionInfo(*item); - } - else - if(le.MousePressRight(curVictoryCond)) VictoryConditionInfo(listbox.GetCurrent()); - else - if(le.MousePressRight(curLossCond)) LossConditionInfo(listbox.GetCurrent()); - else - if(le.MousePressRight(curDifficulty)) Dialog::Message(_("Selected Map Difficulty"), _("The map difficulty of the currently selected map. The map difficulty is determined by the EditScenario designer. More difficult maps might include more or stronger enemies, fewer resources, or other special conditions making things tougher for the human player."), Font::BIG); - else - if(le.MousePressRight(curDescription)) Dialog::Message(_("Selected Description"), _("The description of the currently selected map."), Font::BIG); - else - if(le.MousePressRight(buttonOk)) Dialog::Message(_("OK"), _("Accept the choice made."), Font::BIG); - - if(!cursor.isVisible()) - { - listbox.Redraw(); - buttonOk.Draw(); - buttonSelectSmall.Draw(); - buttonSelectMedium.Draw(); - buttonSelectLarge.Draw(); - buttonSelectXLarge.Draw(); - buttonSelectAll.Draw(); - cursor.Show(); - display.Flip(); - } - } - - cursor.Hide(); - back.Restore(); - - return filename.size(); -} - -void LossConditionInfo(const Maps::FileInfo & info) -{ - std::string msg; - - switch(info.conditions_loss) - { - case 0: msg = _("Lose all your heroes and towns."); break; - case 1: msg = _("Lose a specific town."); break; - case 2: msg = _("Lose a specific hero."); break; - case 3: msg = _("Run out of time. Fail to win by a certain point."); break; - default: return; - } - Dialog::Message(_("Loss Condition"), msg, Font::BIG); -} - -void VictoryConditionInfo(const Maps::FileInfo & info) -{ - std::string msg; - - switch(info.conditions_wins) - { - case 0: msg = _("Defeat all enemy heroes and towns."); break; - case 1: msg = _("Capture a specific town."); break; - case 2: msg = _("Defeat a specific hero."); break; - case 3: msg = _("Find a specific artifact."); break; - case 4: msg = _("Your side defeats the opposing side."); break; - case 5: msg = _("Accumulate a large amount of gold."); break; - default: return; - } - Dialog::Message(_("Victory Condition"), msg, Font::BIG); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectscenario.h b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectscenario.h deleted file mode 100644 index f580b82e1..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_selectscenario.h +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2SELECT_SCENARIO_H -#define H2SELECT_SCENARIO_H - -#include "maps_fileinfo.h" -#include "interface_list.h" - -class ScenarioListBox : public Interface::ListBox -{ -public: - ScenarioListBox(const Point & pt) : Interface::ListBox(pt), selectOk(false) {}; - - void RedrawItem(const Maps::FileInfo &, s16, s16, bool); - void RedrawBackground(const Point &); - - void ActionCurrentUp(void){}; - void ActionCurrentDn(void){}; - void ActionListDoubleClick(Maps::FileInfo &); - void ActionListSingleClick(Maps::FileInfo &){}; - void ActionListPressRight(Maps::FileInfo &){}; - - bool selectOk; -}; - -namespace Dialog -{ - bool SelectScenario(const MapsFileInfoList &, std::string &); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_settings.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_settings.cpp deleted file mode 100644 index 9f1837867..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_settings.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" -#include "interface_list.h" - -class SettingsListBox : public Interface::ListBox -{ -public: - SettingsListBox(const Point & pt) : Interface::ListBox(pt) {}; - - void RedrawItem(const u32 &, s16, s16, bool); - void RedrawBackground(const Point &); - - void ActionCurrentUp(void){}; - void ActionCurrentDn(void){}; - void ActionListDoubleClick(u32 &); - void ActionListSingleClick(u32 &); - void ActionListPressRight(u32 &){}; -}; - -void SettingsListBox::RedrawItem(const u32 & item, s16 ox, s16 oy, bool current) -{ - Display & display = Display::Get(); - const Settings & conf = Settings::Get(); - - const Sprite & cell = AGG::GetICN(ICN::CELLWIN, 1); - const Sprite & mark = AGG::GetICN(ICN::CELLWIN, 2); - - display.Blit(cell, ox, oy); - if(conf.ExtModes(item)) display.Blit(mark, ox + 3, oy + 2); - - TextBox msg(conf.ExtName(item), Font::SMALL, 250); - msg.SetAlign(ALIGN_LEFT); - - if(1 < msg.row()) - msg.Blit(ox + cell.w() + 5, oy - 1); - else - msg.Blit(ox + cell.w() + 5, oy + 4); -} - -void SettingsListBox::RedrawBackground(const Point & top) -{ - Display & display = Display::Get(); - const Settings & conf = Settings::Get(); - - const u16 window_h = conf.QVGA() ? 224 : 400; - const u16 ah = window_h - 54; - - display.Blit(AGG::GetICN(ICN::STONEBAK, 0), Rect(15, 25, 280, ah), top.x + 15, top.y + 25); - - for(u8 ii = 1; ii < (window_h / 25); ++ii) - display.Blit(AGG::GetICN(ICN::DROPLISL, 11), top.x + 295, top.y + 35 + (19 * ii)); - - display.Blit(AGG::GetICN(ICN::DROPLISL, 10), top.x + 295, top.y + 46); - display.Blit(AGG::GetICN(ICN::DROPLISL, 12), top.x + 295, top.y + ah - 14); -} - -void SettingsListBox::ActionListDoubleClick(u32 & item) -{ - ActionListSingleClick(item); -} - -void SettingsListBox::ActionListSingleClick(u32 & item) -{ - Settings & conf = Settings::Get(); - conf.ExtModes(item) ? conf.ExtResetModes(item) : conf.ExtSetModes(item); -} - -void Dialog::ExtSettings(void) -{ - Display & display = Display::Get(); - const Settings & conf = Settings::Get(); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = conf.QVGA() ? 224 : 400; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & area = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), area); - - Text text("FHeroes2 Settings", Font::YELLOW_BIG); - text.Blit(area.x + (area.w - text.w()) / 2, area.y + 6); - - std::vector states; - - states.push_back(Settings::GAME_SAVE_REWRITE_CONFIRM); - states.push_back(Settings::GAME_ALSO_CONFIRM_AUTOSAVE); - states.push_back(Settings::GAME_REMEMBER_LAST_FOCUS); - states.push_back(Settings::GAME_REMEMBER_LAST_FILENAME); - states.push_back(Settings::GAME_SHOW_SYSTEM_INFO); - states.push_back(Settings::GAME_EVIL_INTERFACE); - if(!conf.PocketPC()) - states.push_back(Settings::GAME_DYNAMIC_INTERFACE); - if(conf.VideoMode().w >= 640 && conf.VideoMode().w >= 480) - states.push_back(Settings::GAME_HIDE_INTERFACE); - states.push_back(Settings::GAME_AUTOSAVE_ON); - if(conf.VideoMode().w == 640 && conf.VideoMode().w == 480) - states.push_back(Settings::GAME_USE_FADE); -#ifdef BUILD_RELEASE - states.push_back(Settings::GAME_SHOW_SDL_LOGO); -#endif - states.push_back(Settings::WORLD_SHOW_VISITED_CONTENT); - states.push_back(Settings::WORLD_ABANDONED_MINE_RANDOM); - states.push_back(Settings::WORLD_SAVE_MONSTER_BATTLE); - states.push_back(Settings::WORLD_ALLOW_SET_GUARDIAN); - states.push_back(Settings::WORLD_NOREQ_FOR_ARTIFACTS); - states.push_back(Settings::WORLD_SCOUTING_EXTENDED); - states.push_back(Settings::WORLD_ARTIFACT_CRYSTAL_BALL); - states.push_back(Settings::WORLD_ONLY_FIRST_MONSTER_ATTACK); - states.push_back(Settings::WORLD_EYE_EAGLE_AS_SCHOLAR); - states.push_back(Settings::WORLD_BUY_BOOK_FROM_SHRINES); - states.push_back(Settings::HEROES_FORCE_RACE_FROM_TYPE); - states.push_back(Settings::HEROES_LEARN_SPELLS_WITH_DAY); - states.push_back(Settings::HEROES_COST_DEPENDED_FROM_LEVEL); - states.push_back(Settings::HEROES_REMEMBER_POINTS_RETREAT); - states.push_back(Settings::HEROES_SURRENDERING_GIVE_EXP); - states.push_back(Settings::HEROES_RECALCULATE_MOVEMENT); - - if(conf.VideoMode().w >= 640 && conf.VideoMode().w >= 480) - states.push_back(Settings::CASTLE_ALLOW_BUY_FROM_WELL); - - states.push_back(Settings::UNIONS_ALLOW_HERO_MEETINGS); - states.push_back(Settings::UNIONS_ALLOW_CASTLE_VISITING); - states.push_back(Settings::UNIONS_ALLOW_VIEW_MAPS); - - states.push_back(Settings::BATTLE_SHOW_DAMAGE); - states.push_back(Settings::BATTLE_SOFT_WAITING); - states.push_back(Settings::BATTLE_TROOP_DIRECTION); - states.push_back(Settings::BATTLE_SHOW_GRID); - states.push_back(Settings::BATTLE_SHOW_MOUSE_SHADOW); - states.push_back(Settings::BATTLE_SHOW_MOVE_SHADOW); - states.push_back(Settings::BATTLE_OBJECTS_ARCHERS_PENALTY); - states.push_back(Settings::BATTLE_MERGE_ARMIES); - states.push_back(Settings::BATTLE_ARCHMAGE_RESIST_BAD_SPELL); - states.push_back(Settings::BATTLE_MAGIC_TROOP_RESIST); - states.push_back(Settings::BATTLE_SKIP_INCREASE_DEFENSE); - - if(conf.PocketPC()) - { - states.push_back(Settings::POCKETPC_HIDE_CURSOR); - states.push_back(Settings::POCKETPC_TAP_MODE); - states.push_back(Settings::POCKETPC_LOW_MEMORY); - } - - SettingsListBox listbox(area); - - const u16 ah = window_h - 54; - - listbox.RedrawBackground(area); - listbox.SetScrollButtonUp(ICN::DROPLISL, 6, 7, Point(area.x + 295, area.y + 25)); - listbox.SetScrollButtonDn(ICN::DROPLISL, 8, 9, Point(area.x + 295, area.y + ah + 5)); - listbox.SetScrollSplitter(AGG::GetICN(ICN::DROPLISL, 13), Rect(area.x + 300, area.y + 49, 12, ah - 48)); - listbox.SetAreaMaxItems(ah / 36); - listbox.SetAreaItems(Rect(area.x + 10, area.y + 30, 290, ah)); - listbox.SetListContent(states); - listbox.Redraw(); - - LocalEvent & le = LocalEvent::Get(); - - ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL); - btnGroups.Draw(); - - cursor.Show(); - display.Flip(); - - // message loop - u16 result = Dialog::ZERO; - - while(result == Dialog::ZERO && le.HandleEvents()) - { - result = btnGroups.QueueEventProcessing(); - - listbox.QueueEventProcessing(); - - if(!cursor.isVisible()) - { - listbox.Redraw(); - cursor.Show(); - display.Flip(); - } - } - - // store - if(result == Dialog::OK) - { - le.SetTapMode(conf.ExtTapMode()); - Settings::Get().BinarySave(); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_skillinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_skillinfo.cpp deleted file mode 100644 index 49e9308d4..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_skillinfo.cpp +++ /dev/null @@ -1,218 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "profit.h" -#include "button.h" -#include "dialog.h" - -void Dialog::SecondarySkillInfo(const Skill::Secondary::skill_t skill, const Skill::Level::type_t level, const bool ok_button) -{ - std::string header(Skill::Level::String(level)); - header.append(" "); - header.append(Skill::Secondary::String(skill)); - - std::string description(Skill::Secondary::Description(skill, level)); - String::Replace(description, "%{count}", Skill::Secondary::GetValues(skill, level)); - - SecondarySkillInfo(header, description, skill, level, ok_button); -} - -void Dialog::SecondarySkillInfo(const std::string &header, const std::string &message, const Skill::Secondary::skill_t skill, const Skill::Level::type_t level, const bool ok_button) -{ - Display & display = Display::Get(); - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // preload - AGG::PreloadObject(system); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - TextBox box1(header, Font::YELLOW_BIG, BOXAREA_WIDTH); - TextBox box2(message, Font::BIG, BOXAREA_WIDTH); - const Sprite & border = AGG::GetICN(ICN::SECSKILL, 15); - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - - Box box(box1.h() + spacer + box2.h() + spacer + border.h(), ok_button); - Rect pos = box.GetArea(); - - if(header.size()) box1.Blit(pos); - pos.y += box1.h() + spacer; - - if(message.size()) box2.Blit(pos); - pos.y += box2.h() + spacer; - - // blit sprite - pos.x = box.GetArea().x + (pos.w - border.w()) / 2; - display.Blit(border, pos.x, pos.y); - const Sprite & sprite = AGG::GetICN(ICN::SECSKILL, Skill::Secondary::GetIndexSprite1(skill)); - pos.x = box.GetArea().x + (pos.w - sprite.w()) / 2; - display.Blit(sprite, pos.x, pos.y + 3); - - Text text; - - // small text - text.Set(Skill::Secondary::String(skill), Font::SMALL); - pos.x = box.GetArea().x + (pos.w - text.w()) / 2; - text.Blit(pos.x, pos.y + 3); - - text.Set(Skill::Level::String(level)); - pos.x = box.GetArea().x + (pos.w - text.w()) / 2; - text.Blit(pos.x, pos.y + 55); - - LocalEvent & le = LocalEvent::Get(); - - Button *button = NULL; - Point pt; - - if(ok_button) - { - pt.x = box.GetArea().x + (box.GetArea().w - AGG::GetICN(system, 1).w()) / 2; - pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 1).h(); - button = new Button(pt, system, 1, 2); - } - - if(button) (*button).Draw(); - - cursor.Show(); - display.Flip(); - - // message loop - while(le.HandleEvents()) - { - if(!ok_button && !le.MousePressRight()) break; - - if(button) le.MousePressLeft(*button) ? button->PressDraw() : button->ReleaseDraw(); - - if(button && le.MouseClickLeft(*button)){ break; } - - if(HotKeyCloseWindow){ break; } - } - - cursor.Hide(); - if(button) delete button; -} - -void Dialog::PrimarySkillInfo(const std::string &header, const std::string &message, const Skill::Primary::skill_t skill) -{ - Display & display = Display::Get(); - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // preload - AGG::PreloadObject(system); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - u8 index = 0; - std::string skill_name; - - switch(skill) - { - case Skill::Primary::ATTACK: - index = 0; - skill_name = _("Attack Skill"); - break; - - case Skill::Primary::DEFENSE: - index = 1; - skill_name = _("Defense Skill"); - break; - - case Skill::Primary::POWER: - index = 2; - skill_name = _("Spell Power"); - break; - - case Skill::Primary::KNOWLEDGE: - index = 3; - skill_name = _("Knowledge"); - break; - - default: break; - } - - TextBox box1(header, Font::BIG, BOXAREA_WIDTH); - TextBox box2(message, Font::BIG, BOXAREA_WIDTH); - const Sprite & border = AGG::GetICN(ICN::PRIMSKIL, 4); - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - - Box box(box1.h() + spacer + box2.h() + spacer + border.h(), Dialog::OK); - Rect pos = box.GetArea(); - - if(header.size()) box1.Blit(pos); - pos.y += box1.h() + spacer; - - if(message.size()) box2.Blit(pos); - pos.y += box2.h() + spacer; - - // blit sprite - pos.x = box.GetArea().x + (pos.w - border.w()) / 2; - display.Blit(border, pos.x, pos.y); - const Sprite & sprite = AGG::GetICN(ICN::PRIMSKIL, index); - pos.x = box.GetArea().x + (pos.w - sprite.w()) / 2; - display.Blit(sprite, pos.x, pos.y + 6); - - Text text; - - text.Set(skill_name, Font::SMALL); - pos.x = box.GetArea().x + (pos.w - text.w()) / 2; - text.Blit(pos.x, pos.y + 8); - - text.Set("+1", Font::BIG); - pos.x = box.GetArea().x + (pos.w - text.w()) / 2; - text.Blit(pos.x, pos.y + 80); - - LocalEvent & le = LocalEvent::Get(); - - Point pt; - - pt.x = box.GetArea().x + (box.GetArea().w - AGG::GetICN(system, 1).w()) / 2; - pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 1).h(); - Button button(pt, system, 1, 2); - - button.Draw(); - - cursor.Show(); - display.Flip(); - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(button) ? button.PressDraw() : button.ReleaseDraw(); - - if(le.MouseClickLeft(button)){ break; } - - if(HotKeyCloseWindow){ break; } - } - - cursor.Hide(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_spellinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_spellinfo.cpp deleted file mode 100644 index de2888486..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_spellinfo.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" - -void Dialog::SpellInfo(const Spell::spell_t spell, const bool ok_button) -{ - std::string msg = Spell::GetDescription(spell); - - const u8 extra = Spell::GetExtraValue(spell); - - if(1 == extra) - String::Replace(msg, "%{count}", _("one")); - else - if(2 == extra) - String::Replace(msg, "%{count}", _("two")); - else - String::Replace(msg, "%{count}", extra); - - Dialog::SpellInfo(Spell::GetName(spell), msg, spell, ok_button); -} - -void Dialog::SpellInfo(const std::string &header, const std::string &message, const Spell::spell_t spell, const bool ok_button) -{ - Display & display = Display::Get(); - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // preload - AGG::PreloadObject(system); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - TextBox box1(header, Font::YELLOW_BIG, BOXAREA_WIDTH); - TextBox box2(message, Font::BIG, BOXAREA_WIDTH); - Text text(Spell::GetName(spell), Font::SMALL); - - const Sprite & sprite = AGG::GetICN(ICN::SPELLS, Spell::IndexSprite(spell)); - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - - Box box(box1.h() + spacer + box2.h() + spacer + sprite.h() + 2 + text.h(), ok_button); - - Rect pos = box.GetArea(); - - if(header.size()) box1.Blit(pos); - pos.y += box1.h() + spacer; - - if(message.size()) box2.Blit(pos); - pos.y += box2.h() + spacer; - - // blit sprite - pos.x = box.GetArea().x + (pos.w - sprite.w()) / 2; - display.Blit(sprite, pos.x, pos.y); - - // small text - pos.x = box.GetArea().x + (pos.w - text.w()) / 2; - pos.y = pos.y + sprite.h() + 2; - text.Blit(pos); - - LocalEvent & le = LocalEvent::Get(); - - Button *button = NULL; - Point pt; - - if(ok_button) - { - pt.x = box.GetArea().x + (box.GetArea().w - AGG::GetICN(system, 1).w()) / 2; - pt.y = box.GetArea().y + box.GetArea().h - AGG::GetICN(system, 1).h(); - button = new Button(pt, system, 1, 2); - } - - if(button) (*button).Draw(); - - cursor.Show(); - display.Flip(); - - // message loop - while(le.HandleEvents()) - { - if(!ok_button && !le.MousePressRight()) break; - - if(button) le.MousePressLeft(*button) ? button->PressDraw() : button->ReleaseDraw(); - - if(button && le.MouseClickLeft(*button)){ break; } - - if(HotKeyCloseWindow){ break; } - } - - cursor.Hide(); - if(button) delete button; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_spriteinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_spriteinfo.cpp deleted file mode 100644 index f5e074243..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_spriteinfo.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" - -u16 Dialog::SpriteInfo(const std::string &header, const std::string &message, const Surface & sprite, u16 buttons) -{ - Display & display = Display::Get(); - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - // preload - AGG::PreloadObject(system); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - TextBox box1(header, Font::YELLOW_BIG, BOXAREA_WIDTH); - TextBox box2(message, Font::BIG, BOXAREA_WIDTH); - const u8 spacer = Settings::Get().QVGA() ? 5 : 10; - - Box box(box1.h() + spacer + box2.h() + spacer + sprite.h(), buttons); - Rect pos = box.GetArea(); - - if(header.size()) box1.Blit(pos); - pos.y += box1.h() + spacer; - - if(message.size()) box2.Blit(pos); - pos.y += box2.h() + spacer; - - // blit sprite - pos.x = box.GetArea().x + (pos.w - sprite.w()) / 2; - display.Blit(sprite, pos.x, pos.y); - - LocalEvent & le = LocalEvent::Get(); - - ButtonGroups btnGroups(box.GetArea(), buttons); - btnGroups.Draw(); - - cursor.Show(); - display.Flip(); - - // message loop - u16 result = Dialog::ZERO; - - while(result == Dialog::ZERO && le.HandleEvents()) - { - if(!buttons && !le.MousePressRight()) break; - - result = btnGroups.QueueEventProcessing(); - } - - cursor.Hide(); - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_system.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_system.cpp deleted file mode 100644 index e9f19a61a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_system.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "background.h" -#include "dialog.h" - -namespace Dialog -{ - void DrawSystemInfo(const Point & dst); -} - -/* return 0x01 - change speed, 0x02 - change sound, 0x04 - change music, 0x08 - change interface, 0x10 - change scroll */ -u8 Dialog::SystemOptions(void) -{ - // FIXME: QVGA version - if(Settings::Get().QVGA()) - { - Dialog::Message("", _("For the QVGA version is not available."), Font::SMALL, Dialog::OK); - return 0; - } - - Display & display = Display::Get(); - Settings & conf = Settings::Get(); - - // preload - const ICN::icn_t spanbkg = conf.EvilInterface() ? ICN::SPANBKGE : ICN::SPANBKG; - const ICN::icn_t spanbtn = conf.EvilInterface() ? ICN::SPANBTNE : ICN::SPANBTN; - - AGG::PreloadObject(spanbkg); - AGG::PreloadObject(spanbtn); - AGG::PreloadObject(ICN::SPANEL); - - // cursor - Cursor & cursor = Cursor::Get(); - const Cursor::themes_t oldcursor = cursor.Themes(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - // image box - const Sprite &box = AGG::GetICN(spanbkg, 0); - - Rect rb((display.w() - box.w()) / 2, (display.h() - box.h()) / 2, box.w(), box.h()); - Background back(rb); - back.Save(); - display.Blit(box, rb.x, rb.y); - - const Rect rect1(rb.x + 36, rb.y + 47, 64, 64); - const Rect rect2(rb.x + 128, rb.y + 47, 64, 64); - //const Rect rect3(rb.x + 220, rb.y + 47, 64, 64); - const Rect rect4(rb.x + 36, rb.y + 157, 64, 64); - const Rect rect5(rb.x + 128, rb.y + 157, 64, 64); - const Rect rect6(rb.x + 220, rb.y + 157, 64, 64); - const Rect rect7(rb.x + 36, rb.y + 267, 64, 64); - //const Rect rect8(rb.x + 128, rb.y + 267, 64, 64); - //const Rect rect9(rb.x + 220, rb.y + 267, 64, 64); - - Surface back2(rb.w, rb.h); - back2.Blit(display, rb, 0, 0); - - DrawSystemInfo(rb); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonOk(rb.x + 113, rb.y + 362, spanbtn, 0, 1); - - buttonOk.Draw(); - - cursor.Show(); - display.Flip(); - - u8 result = 0; - - // dialog menu loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - - if(le.MouseClickLeft(buttonOk) || Game::HotKeyPress(Game::EVENT_DEFAULT_READY)){ break; } - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)){ result = false; break; } - - // set sound volume - if(conf.Sound() && le.MouseClickLeft(rect1)) - { - conf.SetSoundVolume(10 > conf.SoundVolume() ? conf.SoundVolume() + 1 : 0); - cursor.Hide(); - display.Blit(back2, rb); - DrawSystemInfo(rb); - cursor.Show(); - display.Flip(); - Game::EnvironmentSoundMixer(); - } - - // set music volume - if(conf.Music() && le.MouseClickLeft(rect2)) - { - conf.SetMusicVolume(10 > conf.MusicVolume() ? conf.MusicVolume() + 1 : 0); - cursor.Hide(); - display.Blit(back2, rb); - DrawSystemInfo(rb); - cursor.Show(); - display.Flip(); - Music::Volume(Mixer::MaxVolume() * conf.MusicVolume() / 10); - } - - // set hero speed - if(le.MouseClickLeft(rect4)) - { - conf.SetHeroesMoveSpeed(10 > conf.HeroesMoveSpeed() ? conf.HeroesMoveSpeed() + 1 : 0); - result |= 0x01; - cursor.Hide(); - display.Blit(back2, rb); - DrawSystemInfo(rb); - cursor.Show(); - display.Flip(); - Game::UpdateHeroesMoveSpeed(); - } - - // set ai speed - if(le.MouseClickLeft(rect5)) - { - conf.SetAIMoveSpeed(10 > conf.AIMoveSpeed() ? conf.AIMoveSpeed() + 1 : 0); - result |= 0x01; - cursor.Hide(); - display.Blit(back2, rb); - DrawSystemInfo(rb); - cursor.Show(); - display.Flip(); - Game::UpdateHeroesMoveSpeed(); - } - - // set scroll speed - if(le.MouseClickLeft(rect6)) - { - conf.SetScrollSpeed(SCROLL_FAST2 > conf.ScrollSpeed() ? conf.ScrollSpeed() << 1 : SCROLL_SLOW); - result |= 0x10; - cursor.Hide(); - display.Blit(back2, rb); - DrawSystemInfo(rb); - cursor.Show(); - display.Flip(); - } - - // set interface - if(le.MouseClickLeft(rect7)) - { - conf.SetEvilInterface(!conf.EvilInterface()); - result |= 0x08; - cursor.Hide(); - display.Blit(back2, rb); - DrawSystemInfo(rb); - cursor.Show(); - display.Flip(); - } - } - - // restore background - cursor.Hide(); - back.Restore(); - cursor.SetThemes(oldcursor); - cursor.Show(); - display.Flip(); - - return result; -} - -void Dialog::DrawSystemInfo(const Point & dst) -{ - Display & display = Display::Get(); - Settings & conf = Settings::Get(); - - std::string str; - Text text; - - Surface black(65, 65); - black.Fill(0, 0, 0); - - // sound - const Sprite & sprite1 = AGG::GetICN(ICN::SPANEL, conf.Sound() ? 1 : 0); - const Rect rect1(dst.x + 36, dst.y + 47, sprite1.w(), sprite1.h()); - display.Blit(sprite1, rect1); - str.clear(); - str = _("sound"); - str += " "; - if(conf.Sound() && conf.SoundVolume()) - String::AddInt(str, conf.SoundVolume()); - else - str += _("off"); - text.Set(str, Font::SMALL); - text.Blit(rect1.x + (rect1.w - text.w()) / 2, rect1.y + rect1.h + 5); - - // music - const Sprite & sprite2 = AGG::GetICN(ICN::SPANEL, conf.Music() ? 3 : 2); - const Rect rect2(dst.x + 128, dst.y + 47, sprite2.w(), sprite2.h()); - display.Blit(sprite2, rect2); - str.clear(); - str = _("music"); - str += " "; - if(conf.Music() && conf.MusicVolume()) - String::AddInt(str, conf.MusicVolume()); - else - str += _("off"); - text.Set(str); - text.Blit(rect2.x + (rect2.w - text.w()) / 2, rect2.y + rect2.h + 5); - - // unused - const Sprite & sprite3 = AGG::GetICN(ICN::SPANEL, 17); - const Rect rect3(dst.x + 220, dst.y + 47, sprite3.w(), sprite3.h()); - display.Blit(black, rect3); - str.clear(); - str = "unused"; - text.Set(str); - text.Blit(rect3.x + (rect3.w - text.w()) / 2, rect3.y + rect3.h + 5); - - // hero move speed - const u8 is4 = conf.HeroesMoveSpeed() ? (conf.HeroesMoveSpeed() < 9 ? (conf.HeroesMoveSpeed() < 7 ? (conf.HeroesMoveSpeed() < 4 ? 4 : 5) : 6) : 7) : 9; - const Sprite & sprite4 = AGG::GetICN(ICN::SPANEL, is4); - const Rect rect4(dst.x + 36, dst.y + 157, sprite4.w(), sprite4.h()); - display.Blit(sprite4, rect4); - str.clear(); - str = _("hero speed"); - str += " "; - if(conf.HeroesMoveSpeed()) - String::AddInt(str, conf.HeroesMoveSpeed()); - else - str += _("off"); - text.Set(str); - text.Blit(rect4.x + (rect4.w - text.w()) / 2, rect4.y + rect4.h + 5); - - // ai move speed - const u8 is5 = conf.AIMoveSpeed() ? (conf.AIMoveSpeed() < 9 ? (conf.AIMoveSpeed() < 7 ? (conf.AIMoveSpeed() < 4 ? 4 : 5) : 6) : 7) : 9; - const Sprite & sprite5 = AGG::GetICN(ICN::SPANEL, is5); - const Rect rect5(dst.x + 128, dst.y + 157, sprite5.w(), sprite5.h()); - display.Blit(sprite5, rect5); - str.clear(); - str = _("ai speed"); - str += " "; - if(conf.AIMoveSpeed()) - String::AddInt(str, conf.AIMoveSpeed()); - else - str += _("off"); - text.Set(str); - text.Blit(rect5.x + (rect5.w - text.w()) / 2, rect5.y + rect5.h + 5); - - // scroll speed - const u8 is6 = (conf.ScrollSpeed() < SCROLL_FAST2 ? (conf.ScrollSpeed() < SCROLL_FAST1 ? (conf.ScrollSpeed() < SCROLL_NORMAL ? 4 : 5) : 6) : 7); - const Sprite & sprite6 = AGG::GetICN(ICN::SPANEL, is6); - const Rect rect6(dst.x + 220, dst.y + 157, sprite6.w(), sprite6.h()); - display.Blit(sprite6, rect6); - str.clear(); - str = _("scroll speed"); - str += " "; - String::AddInt(str, conf.ScrollSpeed()); - text.Set(str); - text.Blit(rect6.x + (rect6.w - text.w()) / 2, rect6.y + rect6.h + 5); - - // interface - const Sprite & sprite7 = AGG::GetICN(ICN::SPANEL, (conf.EvilInterface() ? 17 : 16)); - const Rect rect7(dst.x + 36, dst.y + 267, sprite7.w(), sprite7.h()); - display.Blit(sprite7, rect7); - str.clear(); - str = _("Interface"); - str += ": "; - if(conf.EvilInterface()) - str += _("Evil"); - else - str += _("Good"); - text.Set(str); - text.Blit(rect7.x + (rect7.w - text.w()) / 2, rect7.y + rect7.h + 5); - - // unused - const Sprite & sprite8 = AGG::GetICN(ICN::SPANEL, 17); - const Rect rect8(dst.x + 128, dst.y + 267, sprite8.w(), sprite8.h()); - display.Blit(black, rect8); - str.clear(); - str = "unused"; - text.Set(str); - text.Blit(rect8.x + (rect8.w - text.w()) / 2, rect8.y + rect8.h + 5); - - // unused - const Sprite & sprite9 = AGG::GetICN(ICN::SPANEL, 17); - const Rect rect9(dst.x + 220, dst.y + 267, sprite9.w(), sprite9.h()); - display.Blit(black, rect9); - str.clear(); - str = "unused"; - text.Set(str); - text.Blit(rect9.x + (rect9.w - text.w()) / 2, rect9.y + rect9.h + 5); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_thievesguild.cpp b/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_thievesguild.cpp deleted file mode 100644 index 484b80d89..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/dialog/dialog_thievesguild.cpp +++ /dev/null @@ -1,514 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "text.h" -#include "world.h" -#include "kingdom.h" -#include "castle.h" -#include "pocketpc.h" -#include "dialog.h" - -struct ValueColors : std::pair -{ - ValueColors() : std::pair(0, 0){}; - ValueColors(int v, int c) : std::pair(v, c){}; - - bool IsValue(int v) const { return v == first; }; - bool IsColor(Color::color_t c) const { return (c & second); }; - - static bool SortValueGreat(const ValueColors & v1, const ValueColors & v2) { return v1.first > v2.first; }; -}; - -void GetTownsInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors(color)) - { - int value = world.GetKingdom(color).GetCountTown(); - - std::vector::iterator it = - std::find_if(v.begin(), v.end(), std::bind2nd(std::mem_fun_ref(&ValueColors::IsValue), value)); - - if(it == v.end()) - v.push_back(ValueColors(value, color)); - else - (*it).second |= color; - } - - std::sort(v.begin(), v.end(), ValueColors::SortValueGreat); -} - -void GetCastlesInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors(color)) - { - int value = world.GetKingdom(color).GetCountCastle(); - - std::vector::iterator it = - std::find_if(v.begin(), v.end(), std::bind2nd(std::mem_fun_ref(&ValueColors::IsValue), value)); - - if(it == v.end()) - v.push_back(ValueColors(value, color)); - else - (*it).second |= color; - } - - std::sort(v.begin(), v.end(), ValueColors::SortValueGreat); -} - -void GetHeroesInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors(color)) - { - int value = world.GetKingdom(color).GetHeroes().size(); - - std::vector::iterator it = - std::find_if(v.begin(), v.end(), std::bind2nd(std::mem_fun_ref(&ValueColors::IsValue), value)); - - if(it == v.end()) - v.push_back(ValueColors(value, color)); - else - (*it).second |= color; - } - - std::sort(v.begin(), v.end(), ValueColors::SortValueGreat); -} - -void GetGoldsInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors(color)) - { - int value = world.GetKingdom(color).GetFundsGold(); - - std::vector::iterator it = - std::find_if(v.begin(), v.end(), std::bind2nd(std::mem_fun_ref(&ValueColors::IsValue), value)); - - if(it == v.end()) - v.push_back(ValueColors(value, color)); - else - (*it).second |= color; - } - - std::sort(v.begin(), v.end(), ValueColors::SortValueGreat); -} - -void GetWoodOreInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors(color)) - { - int value = world.GetKingdom(color).GetFundsWood() + world.GetKingdom(color).GetFundsOre(); - - std::vector::iterator it = - std::find_if(v.begin(), v.end(), std::bind2nd(std::mem_fun_ref(&ValueColors::IsValue), value)); - - if(it == v.end()) - v.push_back(ValueColors(value, color)); - else - (*it).second |= color; - } - - std::sort(v.begin(), v.end(), ValueColors::SortValueGreat); -} - -void GetGemsCrSlfMerInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors(color)) - { - int value = world.GetKingdom(color).GetFundsGems() + - world.GetKingdom(color).GetFundsCrystal() + - world.GetKingdom(color).GetFundsSulfur() + - world.GetKingdom(color).GetFundsMercury(); - - std::vector::iterator it = - std::find_if(v.begin(), v.end(), std::bind2nd(std::mem_fun_ref(&ValueColors::IsValue), value)); - - if(it == v.end()) - v.push_back(ValueColors(value, color)); - else - (*it).second |= color; - } - - std::sort(v.begin(), v.end(), ValueColors::SortValueGreat); -} - -void GetObelisksInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors(color)) - { - int value = world.GetKingdom(color).CountVisitedObjects(MP2::OBJ_OBELISK); - - std::vector::iterator it = - std::find_if(v.begin(), v.end(), std::bind2nd(std::mem_fun_ref(&ValueColors::IsValue), value)); - - if(it == v.end()) - v.push_back(ValueColors(value, color)); - else - (*it).second |= color; - } - - std::sort(v.begin(), v.end(), ValueColors::SortValueGreat); -} - -void GetArmyInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors(color)) - { - int value = world.GetKingdom(color).GetArmiesStrength(); - - std::vector::iterator it = - std::find_if(v.begin(), v.end(), std::bind2nd(std::mem_fun_ref(&ValueColors::IsValue), value)); - - if(it == v.end()) - v.push_back(ValueColors(value, color)); - else - (*it).second |= color; - } - - std::sort(v.begin(), v.end(), ValueColors::SortValueGreat); -} - -void GetIncomesInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors(color)) - { - int value = world.GetKingdom(color).GetIncome(); - - std::vector::iterator it = - std::find_if(v.begin(), v.end(), std::bind2nd(std::mem_fun_ref(&ValueColors::IsValue), value)); - - if(it == v.end()) - v.push_back(ValueColors(value, color)); - else - (*it).second |= color; - } - - std::sort(v.begin(), v.end(), ValueColors::SortValueGreat); -} - -void GetBestHeroArmyInfo(std::vector & v) -{ - v.clear(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors() & color) - { - const Heroes* hero = world.GetKingdom(color).GetBestHero(); - v.push_back(ValueColors(hero ? hero->GetID() : Heroes::UNKNOWN, color)); - } -} - -void DrawFlags(const std::vector & v, const Point & pos, const u16 width, const u8 count) -{ - Display & display = Display::Get(); - const u16 chunk = width / count; - bool qvga = Settings::Get().QVGA(); - - for(u8 ii = 0; ii < count; ++ii) - { - if(ii < v.size()) - { - const u8 colors = v[ii].second; - const u8 items = Color::Count(colors); - const u8 sw = qvga ? AGG::GetICN(ICN::MISC6, 7).w() : AGG::GetICN(ICN::FLAG32, 1).w(); - u16 px = pos.x + chunk / 2 + ii * chunk - (items * sw) / 2; - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) if(colors & color) - { - const Sprite & flag = qvga ? - AGG::GetICN(ICN::MISC6, Color::GetIndex(color) + 7) : - AGG::GetICN(ICN::FLAG32, Color::GetIndex(color) * 2 + 1); - display.Blit(flag, px, (qvga ? pos.y + 2 : pos.y)); - px = px + sw; - } - } - } -} - -void DrawHeroIcons(const std::vector & v, const Point & pos, const u16 width) -{ - if(v.size()) - { - Display & display = Display::Get(); - const u16 chunk = width / v.size(); - - for(u8 ii = 0; ii < v.size(); ++ii) - { - Heroes::heroes_t id = Heroes::ConvertID(v[ii].first); - u16 px = pos.x + chunk / 2 + ii * chunk; - - if(Heroes::UNKNOWN != id) - { - const Sprite & window = AGG::GetICN(ICN::LOCATORS, 22); - const Surface & icons = world.GetHeroes(id)->GetPortrait30x22(); - display.Blit(window, px - window.w() / 2, pos.y - 4); - display.Blit(icons, px - icons.w() / 2, pos.y); - } - } - } -} - -void Dialog::ThievesGuild(bool oracle) -{ - if(Settings::Get().QVGA()) - { - PocketPC::ThievesGuild(oracle); - return; - } - - Display & display = Display::Get(); - - // cursor - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - 640 - BORDERWIDTH * 2) / 2, (display.h() - 480 - BORDERWIDTH * 2) / 2, 640, 480); - frameborder.Redraw(); - - const Point cur_pt(frameborder.GetArea().x, frameborder.GetArea().y); - Point dst_pt(cur_pt); - - display.Blit(AGG::GetICN(ICN::STONEBAK, 0), dst_pt); - - const u8 count = oracle ? 0xFF : world.GetMyKingdom().GetCountBuilding(BUILD_THIEVESGUILD); - - std::vector v; - v.reserve(KINGDOMMAX); - const u8 colors = Color::Count(Settings::Get().KingdomColors()); - const u16 textx = 185; - const u16 startx = 210; - const u16 maxw = 430; - Text text; - - // head 1 - u8 ii = 0; - for(ii = 0; ii < colors; ++ii) - { - switch(ii+1) - { - case 1: text.Set(_("1st")); break; - case 2: text.Set(_("2nd")); break; - case 3: text.Set(_("3rd")); break; - case 4: text.Set(_("4th")); break; - case 5: text.Set(_("5th")); break; - case 6: text.Set(_("6th")); break; - default: break; - } - - dst_pt.x = cur_pt.x + startx + maxw / (colors * 2) + ii * maxw / colors - text.w() / 2; - dst_pt.y = cur_pt.y + 5; - text.Blit(dst_pt); - } - - // bar - dst_pt.x = cur_pt.x; - dst_pt.y = cur_pt.y + 461; - display.Blit(AGG::GetICN(ICN::WELLXTRA, 2), dst_pt); - - // text bar - text.Set(_("Thieves' Guild: Player RanKings"), Font::BIG); - dst_pt.x = cur_pt.x + 280 - text.w() / 2; - dst_pt.y = cur_pt.y + 461; - text.Blit(dst_pt); - - // button exit - dst_pt.x = cur_pt.x + 578; - dst_pt.y = cur_pt.y + 461; - Button buttonExit(dst_pt, ICN::WELLXTRA, 0, 1); - - text.Set(_("Number of Towns:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 28; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetTownsInfo(v); - DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Number of Castles:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 54; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetCastlesInfo(v); - DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Number of Heroes:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 80; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetHeroesInfo(v); - DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Gold in Treasury:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 106; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetGoldsInfo(v); - if(1 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Wood & Ore:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 132; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetWoodOreInfo(v); - if(1 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Gems, Cr, Slf & Mer:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 158; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetGemsCrSlfMerInfo(v); - if(1 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Obelisks Found:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 184; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetObelisksInfo(v); - if(2 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Total Army Strength:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 210; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetArmyInfo(v); - if(3 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Income:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 238; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetIncomesInfo(v); - if(4 < count) DrawFlags(v, dst_pt, maxw, colors); - - // head 2 - ii = 0; - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors() & color) - { - text.Set(Color::String(color)); - dst_pt.x = cur_pt.x + startx + maxw / (colors * 2) + ii * maxw / colors - text.w() / 2; - dst_pt.y = cur_pt.y + 270; - text.Blit(dst_pt); - ++ii; - } - - text.Set(_("Best Hero:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 306; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetBestHeroArmyInfo(v); - DrawHeroIcons(v, dst_pt, maxw); - - text.Set(_("Best Hero Stats:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 347; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - //GetBestHeroStatsInfo(v); - //if(1 < count) DrawHeroIcons(v, dst_pt, maxw); - - text.Set(_("Personality:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 388; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - //GetPersonalityInfo(v); - //if(2 < count) DrawHeroIcons(v, dst_pt, maxw); - - text.Set(_("Best Monster:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 429; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - //GetBestMonsterInfo(v); - //if(3 < count) DrawHeroIcons(v, dst_pt, maxw); - - buttonExit.Draw(); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - - if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) break; - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/editor/editor_interface.cpp b/project/jni/application/fheroes2/src/fheroes2/editor/editor_interface.cpp deleted file mode 100644 index 98dadd6ee..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/editor/editor_interface.cpp +++ /dev/null @@ -1,405 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_EDITOR - -#include "agg.h" -#include "settings.h" -#include "interface_gamearea.h" -#include "world.h" -#include "editor_interface.h" - -EditorInterface::EditorInterface() -{ - btnLeftTopScroll.SetSprite(ICN::ESCROLL, 12, 13); - btnRightTopScroll.SetSprite(ICN::ESCROLL, 14, 15); - btnTopScroll.SetSprite(ICN::ESCROLL, 4, 5); - btnLeftBottomScroll.SetSprite(ICN::ESCROLL, 18, 19); - btnLeftScroll.SetSprite(ICN::ESCROLL, 8, 9); - btnRightScroll.SetSprite(ICN::ESCROLL, 10, 11); - btnRightBottomScroll.SetSprite(ICN::ESCROLL, 16, 17); - btnBottomScroll.SetSprite(ICN::ESCROLL, 6, 7); - btnSelectGround.SetSprite(ICN::EDITBTNS, 0, 1); - btnSelectObject.SetSprite(ICN::EDITBTNS, 2, 3); - btnSelectInfo.SetSprite(ICN::EDITBTNS, 4, 5); - btnSelectRiver.SetSprite(ICN::EDITBTNS, 6, 7); - btnSelectRoad.SetSprite(ICN::EDITBTNS, 8, 9); - btnSelectClear.SetSprite(ICN::EDITBTNS, 10, 11); - btnSizeSmall.SetSprite(ICN::EDITBTNS, 24, 25); - btnSizeMedium.SetSprite(ICN::EDITBTNS, 26, 27); - btnSizeLarge.SetSprite(ICN::EDITBTNS, 28, 29); - btnSizeManual.SetSprite(ICN::EDITBTNS, 30, 31); - btnZoom.SetSprite(ICN::EDITBTNS, 12, 13); - btnUndo.SetSprite(ICN::EDITBTNS, 14, 15); - btnNew.SetSprite(ICN::EDITBTNS, 16, 17); - btnSpec.SetSprite(ICN::EDITBTNS, 18, 19); - btnFile.SetSprite(ICN::EDITBTNS, 20, 21); - btnSystem.SetSprite(ICN::EDITBTNS, 22, 23); - - split_h.SetSprite(AGG::GetICN(ICN::ESCROLL, 2)); - split_v.SetSprite(AGG::GetICN(ICN::ESCROLL, 3)); -} - -EditorInterface & EditorInterface::Get(void) -{ - static EditorInterface einterface; - - return einterface; -} - -void EditorInterface::Draw(void) -{ - Display & display = Display::Get(); - Interface::GameArea & areaMaps = Interface::GameArea::Get(); - const Rect & areaPos = areaMaps.GetArea(); - - display.Fill(0x00, 0x00, 0x00); - - Rect src_rt; - Point dst_pt; - - const Sprite & spritePanelGround = AGG::GetICN(ICN::EDITPANL, 0); - const Sprite & spriteBac = AGG::GetICN(ICN::STONBACK, 0); - - // bottom scroll bar indicator - const Sprite & spriteBottomBar(AGG::GetICN(ICN::ESCROLL, 0)); - dst_pt.x = BORDERWIDTH * 2; - dst_pt.y = BORDERWIDTH + areaPos.h; - src_rt.x = 0; - src_rt.y = 0; - src_rt.w = TILEWIDTH; - src_rt.h = BORDERWIDTH; - display.Blit(spriteBottomBar, src_rt, dst_pt); - src_rt.x = TILEWIDTH; - for(u16 ii = 0; ii < (areaMaps.GetRectMaps().w - 4); ++ii) - { - dst_pt.x += TILEWIDTH; - display.Blit(spriteBottomBar, src_rt, dst_pt); - } - dst_pt.x += TILEWIDTH; - src_rt.x = spriteBottomBar.w() - TILEWIDTH; - display.Blit(spriteBottomBar, src_rt, dst_pt); - // left scroll bar indicator - const Sprite & spriteLeftBar(AGG::GetICN(ICN::ESCROLL, 1)); - dst_pt.x = BORDERWIDTH + areaPos.w; - dst_pt.y = BORDERWIDTH * 2; - src_rt.x = 0; - src_rt.y = 0; - src_rt.w = BORDERWIDTH; - src_rt.h = TILEWIDTH; - display.Blit(spriteLeftBar, src_rt, dst_pt); - src_rt.y = TILEWIDTH; - for(u16 ii = 0; ii < (areaMaps.GetRectMaps().h - 4); ++ii) - { - dst_pt.y += TILEWIDTH; - display.Blit(spriteLeftBar, src_rt, dst_pt); - } - dst_pt.y += TILEWIDTH; - src_rt.y = spriteLeftBar.h() - TILEWIDTH; - display.Blit(spriteLeftBar,src_rt, dst_pt); - - // draw EditorInterface - const Sprite & spriteAdv = AGG::GetICN(ICN::ADVBORD, 0); - - // left top static border - src_rt.x = spriteAdv.w() - BORDERWIDTH - RADARWIDTH; - src_rt.y = 0; - src_rt.w = BORDERWIDTH + RADARWIDTH; - src_rt.h = BORDERWIDTH; - dst_pt.x = 2 * BORDERWIDTH + areaPos.w; - dst_pt.y = 0; - display.Blit(spriteAdv, src_rt, dst_pt); - // left bottom static border - src_rt.x = spriteAdv.w() - BORDERWIDTH - RADARWIDTH; - src_rt.y = spriteAdv.h() - BORDERWIDTH; - src_rt.w = BORDERWIDTH + RADARWIDTH; - src_rt.h = BORDERWIDTH; - dst_pt.x = 2 * BORDERWIDTH + areaPos.w; - dst_pt.y = BORDERWIDTH + areaPos.h; - display.Blit(spriteAdv, src_rt, dst_pt); - // left static border - src_rt.x = spriteAdv.w() - BORDERWIDTH; - src_rt.y = 0; - src_rt.w = BORDERWIDTH; - src_rt.h = 250; - dst_pt.x = display.w() - BORDERWIDTH; - dst_pt.y = 0; - display.Blit(spriteAdv, src_rt, dst_pt); - // - src_rt.y = 250; - src_rt.h = TILEWIDTH; - dst_pt.y = 250; - // - u8 var1 = 4 + (display.h() - 480) / TILEWIDTH; - - for(u8 ii = 0; ii < var1; ++ii) - { - display.Blit(spriteAdv, src_rt, dst_pt); - dst_pt.y += TILEWIDTH; - } - // - src_rt.y = spriteAdv.h() - 102; - src_rt.h = 102; - dst_pt.y = display.h() - 102; - display.Blit(spriteAdv, src_rt, dst_pt); - - - Point pt_rts, pt_tsc, pt_lbs, pt_lsc, pt_rsc, pt_rbs, pt_bsc, pt_sgr, pt_sob, pt_sin, pt_sri, pt_sro, pt_scl; - Point pt_ssm, pt_sme, pt_sla, pt_smn, pt_zoo, pt_und, pt_new, pt_spe, pt_fil, pt_sys; - - // btn right top scroll - pt_rts.x = BORDERWIDTH + areaPos.w; - pt_rts.y = 0; - // btn top scroll - pt_tsc.x = pt_rts.x; - pt_tsc.y = BORDERWIDTH; - // btn left bottom scroll - pt_lbs.x = 0; - pt_lbs.y = BORDERWIDTH + areaPos.h; - // btn left scroll - pt_lsc.x = BORDERWIDTH; - pt_lsc.y = pt_lbs.y; - // btn right scroll - pt_rsc.x = 2 * BORDERWIDTH + (areaMaps.GetRectMaps().w - 2) * TILEWIDTH; - pt_rsc.y = pt_lbs.y; - // btn right bottom scroll - pt_rbs.x = BORDERWIDTH + areaPos.w; - pt_rbs.y = pt_lbs.y; - // btn bottom scroll - pt_bsc.x = pt_rbs.x; - pt_bsc.y = areaPos.h; - // btn select ground - pt_sgr.x = display.w() - BORDERWIDTH - RADARWIDTH; - pt_sgr.y = BORDERWIDTH + RADARWIDTH; - // btn select object - pt_sob.x = pt_sgr.x + btnSelectGround.w; - pt_sob.y = pt_sgr.y; - // btn select info - pt_sin.x = pt_sob.x + btnSelectObject.w; - pt_sin.y = pt_sgr.y; - // btn select river - pt_sri.x = pt_sgr.x; - pt_sri.y = pt_sgr.y + btnSelectGround.h; - // btn select road - pt_sro.x = pt_sgr.x + btnSelectRiver.w; - pt_sro.y = pt_sri.y; - // btn select clear - pt_scl.x = pt_sro.x + btnSelectRoad.w; - pt_scl.y = pt_sri.y; - // btn size small - pt_ssm.x = pt_sgr.x + 14; - pt_ssm.y = pt_sri.y + btnSelectRiver.h + 127; - // btn size medium - pt_sme.x = pt_sgr.x + 44; - pt_sme.y = pt_ssm.y; - // btn size large - pt_sla.x = pt_sgr.x + 74; - pt_sla.y = pt_ssm.y; - // btn size manual - pt_smn.x = pt_sgr.x + 104; - pt_smn.y = pt_ssm.y; - // btn zoom - pt_zoo.x = pt_sgr.x; - pt_zoo.y = pt_sri.y + btnSelectRiver.h + spritePanelGround.h(); - // btn undo - pt_und.x = pt_zoo.x + btnZoom.w; - pt_und.y = pt_zoo.y; - // btn new - pt_new.x = pt_und.x + btnUndo.w; - pt_new.y = pt_zoo.y; - // btn spec - pt_spe.x = pt_zoo.x; - pt_spe.y = pt_zoo.y + btnZoom.h; - // btn file - pt_fil.x = pt_spe.x + btnSpec.w; - pt_fil.y = pt_spe.y; - // btn system - pt_sys.x = pt_fil.x + btnFile.w; - pt_sys.y = pt_spe.y; - - btnLeftTopScroll.SetPos(0, 0); - btnRightTopScroll.SetPos(pt_rts); - btnTopScroll.SetPos(pt_tsc); - btnLeftBottomScroll.SetPos(pt_lbs); - btnLeftScroll.SetPos(pt_lsc); - btnRightScroll.SetPos(pt_rsc); - btnRightBottomScroll.SetPos(pt_rbs); - btnBottomScroll.SetPos(pt_bsc); - btnSelectGround.SetPos(pt_sgr); - btnSelectObject.SetPos(pt_sob); - btnSelectInfo.SetPos(pt_sin); - btnSelectRiver.SetPos(pt_sri); - btnSelectRoad.SetPos(pt_sro); - btnSelectClear.SetPos(pt_scl); - btnSizeSmall.SetPos(pt_ssm); - btnSizeMedium.SetPos(pt_sme); - btnSizeLarge.SetPos(pt_sla); - btnSizeManual.SetPos(pt_smn); - btnZoom.SetPos(pt_zoo); - btnUndo.SetPos(pt_und); - btnNew.SetPos(pt_new); - btnSpec.SetPos(pt_spe); - btnFile.SetPos(pt_fil); - btnSystem.SetPos(pt_sys); - - // bottom static - var1 = (display.h() - 480) / TILEWIDTH - 2; - - src_rt.x = 0; - src_rt.y = 0; - src_rt.w = spriteBac.w(); - src_rt.h = TILEWIDTH; - dst_pt.x = btnSpec.x; - dst_pt.y = btnSpec.y + btnSpec.h; - if(var1) display.Blit(spriteBac, src_rt, dst_pt); - src_rt.y = TILEWIDTH; - dst_pt.y += TILEWIDTH; - for(u8 ii = 0; ii < var1; ++ii) - { - display.Blit(spriteBac, src_rt, dst_pt); - dst_pt.y += TILEWIDTH; - } - src_rt.y = spriteBac.h() - TILEWIDTH; - if(var1) display.Blit(spriteBac, src_rt, dst_pt); - -/* - const Point dstPanel(btnSelectRiver.x, btnSelectRiver.y + btnSelectRiver.h); - const Sprite & spritePanelGround = AGG::GetICN(ICN::EDITPANL, 0); - const Sprite & spritePanelObject = AGG::GetICN(ICN::EDITPANL, 1); - const Sprite & spritePanelInfo = AGG::GetICN(ICN::EDITPANL, 2); - const Sprite & spritePanelRiver = AGG::GetICN(ICN::EDITPANL, 3); - const Sprite & spritePanelRoad = AGG::GetICN(ICN::EDITPANL, 4); - const Sprite & spritePanelClear = AGG::GetICN(ICN::EDITPANL, 5); -*/ - - btnLeftTopScroll.Draw(); - btnRightTopScroll.Draw(); - btnTopScroll.Draw(); - btnLeftBottomScroll.Draw(); - btnLeftScroll.Draw(); - btnRightScroll.Draw(); - btnRightBottomScroll.Draw(); - btnBottomScroll.Draw(); - btnZoom.Draw(); - btnUndo.Draw(); - btnNew.Draw(); - btnSpec.Draw(); - btnFile.Draw(); - btnSystem.Draw(); - btnSelectObject.Draw(); - btnSelectInfo.Draw(); - btnSelectRiver.Draw(); - btnSelectRoad.Draw(); - btnSelectClear.Draw(); - btnSelectGround.Draw(); - btnSizeSmall.Draw(); - btnSizeLarge.Draw(); - btnSizeManual.Draw(); - btnSizeMedium.Press(); - btnSizeMedium.Draw(); - - DrawTopNumberCell(); - DrawLeftNumberCell(); - - split_h.SetArea(Rect(2 * BORDERWIDTH + 3, display.h() - BORDERWIDTH + 4, (areaMaps.GetRectMaps().w - 2) * TILEWIDTH - 6, BORDERWIDTH - 8)); - split_h.SetOrientation(Splitter::HORIZONTAL); - - split_v.SetArea(Rect(BORDERWIDTH + areaPos.w + 4, 2 * BORDERWIDTH + 3, BORDERWIDTH - 8, (areaMaps.GetRectMaps().h - 2) * TILEWIDTH - 6)); - split_v.SetOrientation(Splitter::VERTICAL); - - split_h.SetRange(0, world.w() - areaMaps.GetRectMaps().w); - split_v.SetRange(0, world.h() - areaMaps.GetRectMaps().h); - - split_h.Move(areaMaps.GetRectMaps().x); - split_v.Move(areaMaps.GetRectMaps().y); -} - -void EditorInterface::Scroll(const u8 scroll) -{ - if(scroll & SCROLL_LEFT) - { - split_h.Backward(); - DrawTopNumberCell(); - } - else - if(scroll & SCROLL_RIGHT) - { - split_h.Forward(); - DrawTopNumberCell(); - } - - if(scroll & SCROLL_TOP) - { - split_v.Backward(); - DrawLeftNumberCell(); - } - else - if(scroll & SCROLL_BOTTOM) - { - split_v.Forward(); - DrawLeftNumberCell(); - } -} - -void EditorInterface::DrawTopNumberCell(void) -{ - const Rect & area = Interface::GameArea::Get().GetRectMaps(); - Point dst_pt; - - // top number cell - for(u16 ii = 0; ii < area.w - 1; ++ii) - { - dst_pt.x = BORDERWIDTH + ii * TILEWIDTH; - dst_pt.y = 0; - - Display::Get().Blit(AGG::GetICN(ICN::EDITBTNS, 34), dst_pt); - - std::string number; - String::AddInt(number, area.x + ii); - - Text text(number, Font::SMALL); - text.Blit(2 * BORDERWIDTH + ii * TILEWIDTH - text.w() / 2, 2); - } -} - -void EditorInterface::DrawLeftNumberCell(void) -{ - const Rect & area = Interface::GameArea::Get().GetRectMaps(); - Point dst_pt; - - // left number cell - for(u16 ii = 0; ii < area.h - 1; ++ii) - { - dst_pt.x = 0; - dst_pt.y = BORDERWIDTH + ii * TILEWIDTH; - - Display::Get().Blit(AGG::GetICN(ICN::EDITBTNS, 33), dst_pt); - - std::string number; - String::AddInt(number, area.y + ii); - - Text text(number, Font::SMALL); - text.Blit(BORDERWIDTH / 2 - text.w() / 2 - 1, BORDERWIDTH + ii * TILEWIDTH + BORDERWIDTH - 5); - } -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/editor/editor_interface.h b/project/jni/application/fheroes2/src/fheroes2/editor/editor_interface.h deleted file mode 100644 index 8622e1fed..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/editor/editor_interface.h +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2EDITORINTERFACE_H -#define H2EDITORINTERFACE_H - -#ifdef WITH_EDITOR - -#include "gamedefs.h" -#include "button.h" -#include "splitter.h" -#include "interface_radar.h" - -class EditorInterface -{ -public: - static EditorInterface & Get(void); - - static void DrawTopNumberCell(void); - static void DrawLeftNumberCell(void); - - void Draw(void); - void Scroll(const u8 scroll); - - Button btnLeftTopScroll; - Button btnRightTopScroll; - Button btnTopScroll; - Button btnLeftBottomScroll; - Button btnLeftScroll; - Button btnRightScroll; - Button btnRightBottomScroll; - Button btnBottomScroll; - Button btnSelectGround; - Button btnSelectObject; - Button btnSelectInfo; - Button btnSelectRiver; - Button btnSelectRoad; - Button btnSelectClear; - Button btnSizeSmall; - Button btnSizeMedium; - Button btnSizeLarge; - Button btnSizeManual; - Button btnZoom; - Button btnUndo; - Button btnNew; - Button btnSpec; - Button btnFile; - Button btnSystem; - - Splitter split_h; - Splitter split_v; - -private: - EditorInterface(); -}; -#endif -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/editor/editor_loadmaps.cpp b/project/jni/application/fheroes2/src/fheroes2/editor/editor_loadmaps.cpp deleted file mode 100644 index 166d9a135..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/editor/editor_loadmaps.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_EDITOR - -#include "gamedefs.h" -#include "settings.h" -#include "world.h" -#include "dialog.h" -#include "dialog_selectscenario.h" - -Game::menu_t Game::Editor::LoadMaps(void) -{ - Settings & conf = Settings::Get(); - - std::string filemaps; - MapsFileInfoList lists; - - if(! PrepareMapsFileInfoList(lists, true)) - { - Dialog::Message(_("Warning"), _("No maps available!"), Font::BIG, Dialog::OK); - return MAINMENU; - } - - if(Dialog::SelectScenario(lists, filemaps) && conf.LoadFileMapsMP2(filemaps)) - { - Game::ShowLoadMapsText(); - // - world.LoadMaps(filemaps); - - return EDITSTART; - } - - return MAINMENU; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/editor/editor_mainmenu.cpp b/project/jni/application/fheroes2/src/fheroes2/editor/editor_mainmenu.cpp deleted file mode 100644 index 26af94301..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/editor/editor_mainmenu.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_EDITOR - -#include "gamedefs.h" -#include "agg.h" -#include "dialog.h" -#include "cursor.h" -#include "button.h" -#include "settings.h" -#include "game.h" - -Game::menu_t Game::Editor::MainMenu(void) -{ - Display & display = Display::Get(); - - // preload - AGG::PreloadObject(ICN::EDITOR); - AGG::PreloadObject(ICN::BTNEMAIN); - AGG::PreloadObject(ICN::REDBACK); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display::SetVideoMode(640, 480, Settings::Get().DisplayFlags()); - - // image background - const Sprite &back = AGG::GetICN(ICN::EDITOR, 0); - display.Blit(back); - - const Sprite &panel = AGG::GetICN(ICN::REDBACK, 0); - display.Blit(panel, 405, 5); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonNewMap(455, 45, ICN::BTNEMAIN, 0, 1); - Button buttonLoadMap(455, 110, ICN::BTNEMAIN, 2, 3); - Button buttonCancelGame(455, 375, ICN::BTNEMAIN, 4, 5); - - buttonNewMap.Draw(); - buttonLoadMap.Draw(); - buttonCancelGame.Draw(); - - cursor.Show(); - display.Flip(); - - // NewMap loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonNewMap) ? buttonNewMap.PressDraw() : buttonNewMap.ReleaseDraw(); - le.MousePressLeft(buttonLoadMap) ? buttonLoadMap.PressDraw() : buttonLoadMap.ReleaseDraw(); - le.MousePressLeft(buttonCancelGame) ? buttonCancelGame.PressDraw() : buttonCancelGame.ReleaseDraw(); - - if(le.MouseClickLeft(buttonNewMap) || HotKeyPress(EVENT_BUTTON_NEWGAME)) return EDITNEWMAP; - if(le.MouseClickLeft(buttonLoadMap) || HotKeyPress(EVENT_BUTTON_LOADGAME)) return EDITLOADMAP; - if(le.MouseClickLeft(buttonCancelGame) || HotKeyPress(EVENT_DEFAULT_EXIT)) return QUITGAME; - - // right info - if(le.MousePressRight(buttonNewMap)) Dialog::Message(_("New Map"), _("Create a new map, either from scratch or using the random map generator."), Font::BIG); - if(le.MousePressRight(buttonLoadMap)) Dialog::Message(_("Load Map"), _("Load an existing map."), Font::BIG); - if(le.MousePressRight(buttonCancelGame)) Dialog::Message(_("Quit"), _("Quit out of the map editor."), Font::BIG); - } - - return QUITGAME; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/editor/editor_newmaps.cpp b/project/jni/application/fheroes2/src/fheroes2/editor/editor_newmaps.cpp deleted file mode 100644 index f999bbedf..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/editor/editor_newmaps.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_EDITOR - -#include "gamedefs.h" -#include "agg.h" -#include "dialog.h" -#include "cursor.h" -#include "button.h" -#include "settings.h" -#include "maps.h" -#include "game.h" -#include "world.h" - -#include "error.h" - -Game::menu_t Game::Editor::NewMaps(void) -{ - Display & display = Display::Get(); - - // preload - AGG::PreloadObject(ICN::BTNESIZE); - AGG::PreloadObject(ICN::REDBACK); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display::SetVideoMode(640, 480, Settings::Get().DisplayFlags()); - - // image background - const Sprite &back = AGG::GetICN(ICN::EDITOR, 0); - display.Blit(back); - - const Sprite &panel = AGG::GetICN(ICN::REDBACK, 0); - display.Blit(panel, 405, 5); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonSmall(455, 45, ICN::BTNESIZE, 0, 1); - Button buttonMedium(455, 110, ICN::BTNESIZE, 2, 3); - Button buttonLarge(455, 175, ICN::BTNESIZE, 4, 5); - Button buttonXLarge(455, 240, ICN::BTNESIZE, 6, 7); - Button buttonCancel(455, 375, ICN::BTNESIZE, 8, 9); - - buttonSmall.Draw(); - buttonMedium.Draw(); - buttonLarge.Draw(); - buttonXLarge.Draw(); - buttonCancel.Draw(); - - cursor.Show(); - display.Flip(); - - // NewMap loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonSmall) ? buttonSmall.PressDraw() : buttonSmall.ReleaseDraw(); - le.MousePressLeft(buttonMedium) ? buttonMedium.PressDraw() : buttonMedium.ReleaseDraw(); - le.MousePressLeft(buttonLarge) ? buttonLarge.PressDraw() : buttonLarge.ReleaseDraw(); - le.MousePressLeft(buttonXLarge) ? buttonXLarge.PressDraw() : buttonXLarge.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - - if(le.MouseClickLeft(buttonSmall)) - { - Game::ShowLoadMapsText(); - world.NewMaps(Maps::SMALL, Maps::SMALL); - return EDITSTART; - } - else - if(le.MouseClickLeft(buttonMedium)) - { - Game::ShowLoadMapsText(); - world.NewMaps(Maps::MEDIUM, Maps::MEDIUM); - return EDITSTART; - } - else - if(le.MouseClickLeft(buttonLarge)) - { - Game::ShowLoadMapsText(); - world.NewMaps(Maps::LARGE, Maps::LARGE); - return EDITSTART; - } - else - if(le.MouseClickLeft(buttonXLarge)) - { - Game::ShowLoadMapsText(); - world.NewMaps(Maps::XLARGE, Maps::XLARGE); - return EDITSTART; - } - if(le.MouseClickLeft(buttonCancel) || HotKeyPress(EVENT_DEFAULT_EXIT)) return EDITMAINMENU; - - // right info - if(le.MousePressRight(buttonSmall)) Dialog::Message("", _("Create a map that is 36 squares wide by 36 squares high. (For reference, all the maps in Heroes where 72 x 72)"), Font::BIG); - else - if(le.MousePressRight(buttonMedium)) Dialog::Message("", _("Create a map that is 72 squares wide by 72 squares high. (For reference, all the maps in Heroes where 72 x 72)"), Font::BIG); - else - if(le.MousePressRight(buttonLarge)) Dialog::Message("", _("Create a map that is 108 squares wide by 108 squares high. (For reference, all the maps in Heroes where 72 x 72)"), Font::BIG); - else - if(le.MousePressRight(buttonXLarge)) Dialog::Message("", _("Create a map that is 144 squares wide by 144 squares high. (For reference, all the maps in Heroes where 72 x 72)"), Font::BIG); - else - if(le.MousePressRight(buttonCancel)) Dialog::Message("", _("Cancel back to the main menu."), Font::BIG); - } - - return EDITMAINMENU; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/editor/editor_startgame.cpp b/project/jni/application/fheroes2/src/fheroes2/editor/editor_startgame.cpp deleted file mode 100644 index 7d9eb81f1..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/editor/editor_startgame.cpp +++ /dev/null @@ -1,1130 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_EDITOR - -#include - -#include "gamedefs.h" -#include "agg.h" -#include "settings.h" -#include "button.h" -#include "dialog.h" -#include "world.h" -#include "interface_gamearea.h" -#include "cursor.h" -#include "splitter.h" -#include "sizecursor.h" -#include "direction.h" -#include "maps_tiles.h" -#include "ground.h" -#include "editor_interface.h" -#include "game.h" - -struct GroundIndexAndRotate : std::pair -{ - GroundIndexAndRotate() {}; -}; - -namespace Game -{ - namespace Editor - { - void ModifySingleTile(Maps::Tiles & center); - void ModifyTileAbroad(Maps::Tiles & center); - void SetGroundToTile(Maps::Tiles & tile, const Maps::Ground::ground_t ground); - GroundIndexAndRotate GetTileWithCorner(u16 around, const Maps::Ground::ground_t ground); - } -} - -Game::menu_t Game::Editor::StartGame() -{ - Game::SetFixVideoMode(); - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - EditorInterface & I = EditorInterface::Get(); - - Interface::GameArea & areaMaps = Interface::GameArea::Get(); - Interface::Radar & radar = Interface::Radar::Get(); - - Settings::Get().SetScrollSpeed(SCROLL_FAST2); - areaMaps.Build(); - - radar.SetPos(display.w() - BORDERWIDTH - RADARWIDTH, BORDERWIDTH); - radar.Build(); - - const Rect & areaPos = areaMaps.GetArea(); - - // cursor - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - I.Draw(); - - const Rect area_pos(BORDERWIDTH, BORDERWIDTH, areaPos.w, areaPos.h); - const Rect areaScrollLeft(0, BORDERWIDTH, BORDERWIDTH / 2, display.h() - 2 * BORDERWIDTH); - const Rect areaScrollRight(display.w() - BORDERWIDTH / 2, BORDERWIDTH, BORDERWIDTH / 2, display.h() - 2 * BORDERWIDTH); - const Rect areaScrollTop(BORDERWIDTH, 0, areaPos.w, BORDERWIDTH / 2); - const Rect areaScrollBottom(2 * BORDERWIDTH, display.h() - BORDERWIDTH / 2, (areaMaps.GetRectMaps().w - 1) * TILEWIDTH, BORDERWIDTH / 2); - const Rect areaLeftPanel(display.w() - 2 * BORDERWIDTH - RADARWIDTH, 0, BORDERWIDTH + RADARWIDTH, display.h()); - - const Sprite & spritePanelGround = AGG::GetICN(ICN::EDITPANL, 0); - const Sprite & spritePanelObject = AGG::GetICN(ICN::EDITPANL, 1); - const Sprite & spritePanelInfo = AGG::GetICN(ICN::EDITPANL, 2); - const Sprite & spritePanelRiver = AGG::GetICN(ICN::EDITPANL, 3); - const Sprite & spritePanelRoad = AGG::GetICN(ICN::EDITPANL, 4); - const Sprite & spritePanelClear = AGG::GetICN(ICN::EDITPANL, 5); - - - LocalEvent & le = LocalEvent::Get(); - - Button &btnLeftTopScroll = I.btnLeftTopScroll; - Button &btnRightTopScroll = I.btnRightTopScroll; - Button &btnTopScroll = I.btnTopScroll; - Button &btnLeftBottomScroll = I.btnLeftBottomScroll; - Button &btnLeftScroll = I.btnLeftScroll; - Button &btnRightScroll = I.btnRightScroll; - Button &btnRightBottomScroll = I.btnRightBottomScroll; - Button &btnBottomScroll = I.btnBottomScroll; - Button &btnSelectGround = I.btnSelectGround; - Button &btnSelectObject = I.btnSelectObject; - Button &btnSelectInfo = I.btnSelectInfo; - Button &btnSelectRiver = I.btnSelectRiver; - Button &btnSelectRoad = I.btnSelectRoad; - Button &btnSelectClear = I.btnSelectClear; - Button &btnSizeSmall = I.btnSizeSmall; - Button &btnSizeMedium = I.btnSizeMedium; - Button &btnSizeLarge = I.btnSizeLarge; - Button &btnSizeManual = I.btnSizeManual; - Button &btnZoom = I.btnZoom; - Button &btnUndo = I.btnUndo; - Button &btnNew = I.btnNew; - Button &btnSpec = I.btnSpec; - Button &btnFile = I.btnFile; - Button &btnSystem = I.btnSystem; - - btnSelectGround.Press(); - btnSizeMedium.Press(); - - btnSelectGround.Draw(); - btnSizeMedium.Draw(); - - const Point dstPanel(btnSelectRiver.x, btnSelectRiver.y + btnSelectRiver.h); - - SizeCursor sizeCursor; - - sizeCursor.ModifySize(2, 2); - sizeCursor.Hide(); - - const Rect rectTerrainWater(dstPanel.x + 29, dstPanel.y + 10, 28, 28); - const Rect rectTerrainGrass(dstPanel.x + 58, dstPanel.y + 10, 28, 28); - const Rect rectTerrainSnow(dstPanel.x + 87, dstPanel.y + 10, 28, 28); - const Rect rectTerrainSwamp(dstPanel.x + 29, dstPanel.y + 39, 28, 28); - const Rect rectTerrainLava(dstPanel.x + 58, dstPanel.y + 39, 28, 28); - const Rect rectTerrainBeach(dstPanel.x + 87, dstPanel.y + 39, 28, 28); - const Rect rectTerrainDirt(dstPanel.x + 29, dstPanel.y + 68, 28, 28); - const Rect rectTerrainWasteland(dstPanel.x + 58, dstPanel.y + 68, 28, 28); - const Rect rectTerrainDesert(dstPanel.x + 87, dstPanel.y + 68, 28, 28); - - const Rect rectObjectWater(dstPanel.x + 14, dstPanel.y + 11, 28, 28); - const Rect rectObjectGrass(dstPanel.x + 43, dstPanel.y + 11, 28, 28); - const Rect rectObjectSnow(dstPanel.x + 72, dstPanel.y + 11, 28, 28); - const Rect rectObjectSwamp(dstPanel.x + 101, dstPanel.y + 11, 28, 28); - const Rect rectObjectLava(dstPanel.x + 14, dstPanel.y + 39, 28, 28); - const Rect rectObjectDesert(dstPanel.x + 43, dstPanel.y + 39, 28, 28); - const Rect rectObjectDirt(dstPanel.x + 72, dstPanel.y + 39, 28, 28); - const Rect rectObjectWasteland(dstPanel.x + 101, dstPanel.y + 39, 28, 28); - const Rect rectObjectBeach(dstPanel.x + 14, dstPanel.y + 67, 28, 28); - const Rect rectObjectTown(dstPanel.x + 43, dstPanel.y + 67, 28, 28); - const Rect rectObjectMonster(dstPanel.x + 72, dstPanel.y + 67, 28, 28); - const Rect rectObjectHero(dstPanel.x + 101, dstPanel.y + 67, 28, 28); - const Rect rectObjectArtifact(dstPanel.x + 14, dstPanel.y + 95, 28, 28); - const Rect rectObjectResource(dstPanel.x + 101, dstPanel.y + 95, 28, 28); - - SpriteCursor selectTerrainCursor(AGG::GetICN(ICN::TERRAINS, 9), rectTerrainWater.x - 1, rectTerrainWater.y - 1); - selectTerrainCursor.Hide(); - - SpriteCursor selectObjectCursor(AGG::GetICN(ICN::TERRAINS, 9), rectObjectWater.x - 1, rectObjectWater.y - 1); - selectTerrainCursor.Hide(); - - u8 selectTerrain = 0; - u8 selectObject = 0; - - // redraw - areaMaps.Redraw(display, LEVEL_ALL); - radar.RedrawArea(); - radar.RedrawCursor(); - display.Blit(spritePanelGround, dstPanel); - selectTerrainCursor.Show(); - - cursor.Show(); - display.Flip(); - - //u32 ticket = 0; - // startgame loop - while(le.HandleEvents()) - { - // ESC - if(HotKeyPress(EVENT_DEFAULT_EXIT) && (Dialog::YES & Dialog::Message("", _("Are you sure you want to quit?"), Font::BIG, Dialog::YES|Dialog::NO))) return QUITGAME; - - // scroll area maps left - if(le.MouseCursor(areaScrollLeft)) areaMaps.SetScroll(SCROLL_LEFT); - else - // scroll area maps right - if(le.MouseCursor(areaScrollRight)) areaMaps.SetScroll(SCROLL_RIGHT); - - // scroll area maps top - if(le.MouseCursor(areaScrollTop)) areaMaps.SetScroll(SCROLL_TOP); - else - // scroll area maps bottom - if(le.MouseCursor(areaScrollBottom)) areaMaps.SetScroll(SCROLL_BOTTOM); - - // point radar - if(le.MouseCursor(radar.GetArea()) && - (le.MouseClickLeft(radar.GetArea()) || - le.MousePressLeft(radar.GetArea()))) - { - const Point prev(areaMaps.GetRectMaps()); - const Point & pt = le.GetMouseCursor(); - areaMaps.Center((pt.x - radar.GetArea().x) * world.w() / RADARWIDTH, (pt.y - radar.GetArea().y) * world.h() / RADARWIDTH); - if(prev != areaMaps.GetRectMaps()) - { - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - sizeCursor.Hide(); - I.split_h.Move(areaMaps.GetRectMaps().x); - I.split_v.Move(areaMaps.GetRectMaps().y); - radar.RedrawCursor(); - EditorInterface::DrawTopNumberCell(); - EditorInterface::DrawLeftNumberCell(); - areaMaps.Redraw(display, LEVEL_ALL); - cursor.Show(); - display.Flip(); - } - } - else - // pointer cursor on left panel - if(le.MouseCursor(areaLeftPanel)) - { - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - sizeCursor.Hide(); - cursor.Show(); - display.Flip(); - } - else - // cursor over game area - if(le.MouseCursor(area_pos) && - Maps::isValidAbsIndex(areaMaps.GetIndexFromMousePoint(le.GetMouseCursor()))) - { - const Point & mouse_coord = le.GetMouseCursor(); - const s32 index_maps = areaMaps.GetIndexFromMousePoint(mouse_coord); - Maps::Tiles & tile = world.GetTiles(index_maps); - const Rect tile_pos(BORDERWIDTH + ((u16) (mouse_coord.x - BORDERWIDTH) / TILEWIDTH) * TILEWIDTH, BORDERWIDTH + ((u16) (mouse_coord.y - BORDERWIDTH) / TILEWIDTH) * TILEWIDTH, TILEWIDTH, TILEWIDTH); - //u8 object = tile.GetObject(); - - cursor.SetThemes(cursor.POINTER); - - const u16 div_x = mouse_coord.x < BORDERWIDTH + TILEWIDTH * (areaMaps.GetRectMaps().w - sizeCursor.w()) ? - (u16) ((mouse_coord.x - BORDERWIDTH) / TILEWIDTH) * TILEWIDTH + BORDERWIDTH : - BORDERWIDTH + (areaMaps.GetRectMaps().w - sizeCursor.w()) * TILEWIDTH; - const u16 div_y = mouse_coord.y < BORDERWIDTH + TILEWIDTH * (areaMaps.GetRectMaps().h - sizeCursor.h()) ? - (u16) ((mouse_coord.y - BORDERWIDTH) / TILEWIDTH) * TILEWIDTH + BORDERWIDTH : - BORDERWIDTH + (areaMaps.GetRectMaps().h - sizeCursor.h()) * TILEWIDTH; - - if(! sizeCursor.isVisible() || sizeCursor.GetPos().x != div_x || sizeCursor.GetPos().y != div_y) - { - cursor.Hide(); - sizeCursor.Hide(); - sizeCursor.Show(div_x, div_y); - cursor.Show(); - display.Flip(); - } - - if(le.MousePressLeft()) - { - cursor.Hide(); - sizeCursor.Hide(); - - - const Point topleft(areaMaps.GetRectMaps().x + (div_x - BORDERWIDTH) / 32, - areaMaps.GetRectMaps().y + (div_y - BORDERWIDTH) / 32); - - - for(u8 iy = 0; iy < sizeCursor.h(); ++iy) - { - for(u8 ix = 0; ix < sizeCursor.w(); ++ix) - { - Maps::Tiles & newtile = world.GetTiles(topleft.x + ix, topleft.y + iy); - - switch(selectTerrain) - { - case 0: SetGroundToTile(newtile, Maps::Ground::WATER); break; - case 1: SetGroundToTile(newtile, Maps::Ground::GRASS); break; - case 2: SetGroundToTile(newtile, Maps::Ground::SNOW); break; - case 3: SetGroundToTile(newtile, Maps::Ground::SWAMP); break; - case 4: SetGroundToTile(newtile, Maps::Ground::LAVA); break; - case 5: SetGroundToTile(newtile, Maps::Ground::DESERT); break; - case 6: SetGroundToTile(newtile, Maps::Ground::DIRT); break; - case 7: SetGroundToTile(newtile, Maps::Ground::WASTELAND); break; - case 8: SetGroundToTile(newtile, Maps::Ground::BEACH); break; - - default: break; - } - - newtile.RedrawTile(display); - newtile.RedrawBottom(display); - newtile.RedrawTop(display); - } - } - - // modify single tiles - for(int ii = 0; ii < world.w() * world.h(); ++ii) ModifySingleTile(world.GetTiles(ii)); - - // modify all tiles abroad - for(int ii = 0; ii < world.w() * world.h(); ++ii) ModifyTileAbroad(world.GetTiles(ii)); - - sizeCursor.Show(); - cursor.Show(); - - display.Flip(); - - // wait - while(le.HandleEvents() && le.MousePressLeft()); - - radar.Generate(); - radar.RedrawArea(); - radar.RedrawCursor(); - display.Flip(); - } - else - if(le.MousePressRight()) - { - if(btnSelectInfo.isPressed()) - { - if(IS_DEVEL()) - { - tile.DebugInfo(); - - const u16 around = Maps::GetDirectionAroundGround(tile.GetIndex(), tile.GetGround()); - if(Direction::TOP_LEFT & around) VERBOSE("TOP_LEFT"); - if(Direction::TOP & around) VERBOSE("TOP"); - if(Direction::TOP_RIGHT & around) VERBOSE("TOP_RIGHT"); - if(Direction::RIGHT & around) VERBOSE("RIGHT"); - if(Direction::BOTTOM_RIGHT & around) VERBOSE("BOTTOM_RIGHT"); - if(Direction::BOTTOM & around) VERBOSE("BOTTOM"); - if(Direction::BOTTOM_LEFT & around) VERBOSE("BOTTOM_LEFT"); - if(Direction::LEFT & around) VERBOSE("LEFT"); - - // wait - while(le.HandleEvents() && le.MousePressRight()); - } - else - { - //const std::string & info = (MP2::OBJ_ZERO == object || MP2::OBJ_EVENT == object ? - //Maps::Ground::String(tile.GetGround()) : MP2::StringObject(object)); - - //Dialog::QuickInfo(info); - } - } - } - // end cursor over game area - } - - - // draw push buttons - le.MousePressLeft(btnLeftTopScroll) ? btnLeftTopScroll.PressDraw() : btnLeftTopScroll.ReleaseDraw(); - le.MousePressLeft(btnRightTopScroll) ? btnRightTopScroll.PressDraw() : btnRightTopScroll.ReleaseDraw(); - le.MousePressLeft(btnTopScroll) ? btnTopScroll.PressDraw() : btnTopScroll.ReleaseDraw(); - le.MousePressLeft(btnLeftBottomScroll) ? btnLeftBottomScroll.PressDraw() : btnLeftBottomScroll.ReleaseDraw(); - le.MousePressLeft(btnLeftScroll) ? btnLeftScroll.PressDraw() : btnLeftScroll.ReleaseDraw(); - le.MousePressLeft(btnRightScroll) ? btnRightScroll.PressDraw() : btnRightScroll.ReleaseDraw(); - le.MousePressLeft(btnRightBottomScroll) ? btnRightBottomScroll.PressDraw() : btnRightBottomScroll.ReleaseDraw(); - le.MousePressLeft(btnBottomScroll) ? btnBottomScroll.PressDraw() : btnBottomScroll.ReleaseDraw(); - - le.MousePressLeft(btnZoom) ? btnZoom.PressDraw() : btnZoom.ReleaseDraw(); - le.MousePressLeft(btnUndo) ? btnUndo.PressDraw() : btnUndo.ReleaseDraw(); - le.MousePressLeft(btnNew) ? btnNew.PressDraw() : btnNew.ReleaseDraw(); - le.MousePressLeft(btnSpec) ? btnSpec.PressDraw() : btnSpec.ReleaseDraw(); - le.MousePressLeft(btnFile) ? btnFile.PressDraw() : btnFile.ReleaseDraw(); - le.MousePressLeft(btnSystem) ? btnSystem.PressDraw() : btnSystem.ReleaseDraw(); - - - // click control button - if(le.MouseClickLeft(btnSelectGround) || - le.MouseClickLeft(btnSelectObject) || - le.MouseClickLeft(btnSelectInfo) || - le.MouseClickLeft(btnSelectRiver) || - le.MouseClickLeft(btnSelectRoad) || - le.MouseClickLeft(btnSelectClear)) - { - cursor.Hide(); - - if(btnSelectGround.isPressed()){ btnSelectGround.Release(); btnSelectGround.Draw(); } - else - if(btnSelectObject.isPressed()){ btnSelectObject.Release(); btnSelectObject.Draw(); } - else - if(btnSelectInfo.isPressed()){ btnSelectInfo.Release(); btnSelectInfo.Draw(); } - else - if(btnSelectRiver.isPressed()){ btnSelectRiver.Release(); btnSelectRiver.Draw(); } - else - if(btnSelectRoad.isPressed()){ btnSelectRoad.Release(); btnSelectRoad.Draw(); } - else - if(btnSelectClear.isPressed()){ btnSelectClear.Release(); btnSelectClear.Draw(); } - - if(le.MouseCursor(btnSelectGround)) - { - selectTerrain = 0; - - btnSizeSmall.SetDisable(false); - btnSizeMedium.SetDisable(false); - btnSizeLarge.SetDisable(false); - btnSizeManual.SetDisable(false); - - btnSelectGround.Press(); - btnSelectGround.Draw(); - - display.Blit(spritePanelGround, dstPanel); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select Terrain Mode"); - selectTerrainCursor.Move(rectTerrainWater.x - 1, rectTerrainWater.y - 1); - } - else - if(le.MouseCursor(btnSelectObject)) - { - selectObject = 0; - - btnSizeSmall.SetDisable(true); - btnSizeMedium.SetDisable(true); - btnSizeLarge.SetDisable(true); - btnSizeManual.SetDisable(true); - - btnSelectObject.Press(); - btnSelectObject.Draw(); - - display.Blit(spritePanelObject, dstPanel); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select Object Mode"); - selectObjectCursor.Move(rectObjectWater.x - 1, rectObjectWater.y - 1); - } - else - if(le.MouseCursor(btnSelectInfo)) - { - btnSizeSmall.Release(); - btnSizeMedium.Release(); - btnSizeLarge.Release(); - btnSizeManual.Release(); - - btnSizeSmall.Press(); - sizeCursor.ModifySize(1, 1); - - btnSizeSmall.SetDisable(true); - btnSizeMedium.SetDisable(true); - btnSizeLarge.SetDisable(true); - btnSizeManual.SetDisable(true); - - btnSelectInfo.Press(); - btnSelectInfo.Draw(); - - display.Blit(spritePanelInfo, dstPanel); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select Detail Mode"); - } - else - if(le.MouseCursor(btnSelectRiver)) - { - btnSizeSmall.SetDisable(true); - btnSizeMedium.SetDisable(true); - btnSizeLarge.SetDisable(true); - btnSizeManual.SetDisable(true); - - btnSelectRiver.Press(); - btnSelectRiver.Draw(); - - display.Blit(spritePanelRiver, dstPanel); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select Stream Mode"); - } - else - if(le.MouseCursor(btnSelectRoad)) - { - btnSizeSmall.SetDisable(true); - btnSizeMedium.SetDisable(true); - btnSizeLarge.SetDisable(true); - btnSizeManual.SetDisable(true); - - btnSelectRoad.Press(); - btnSelectRoad.Draw(); - - display.Blit(spritePanelRoad, dstPanel); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select Road Mode"); - } - else - if(le.MouseCursor(btnSelectClear)) - { - btnSizeSmall.SetDisable(false); - btnSizeMedium.SetDisable(false); - btnSizeLarge.SetDisable(false); - btnSizeManual.SetDisable(false); - - btnSelectClear.Press(); - btnSelectClear.Draw(); - - display.Blit(spritePanelClear, dstPanel); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select Erase Mode"); - } - - - if(btnSizeSmall.isEnable()) btnSizeSmall.isPressed() ? btnSizeSmall.Press() : btnSizeSmall.Release(); - if(btnSizeMedium.isEnable()) btnSizeMedium.isPressed() ? btnSizeMedium.Press() : btnSizeMedium.Release(); - if(btnSizeLarge.isEnable()) btnSizeLarge.isPressed() ? btnSizeLarge.Press() : btnSizeLarge.Release(); - if(btnSizeManual.isEnable()) btnSizeManual.isPressed() ? btnSizeManual.Press() : btnSizeManual.Release(); - - if(btnSizeSmall.isEnable()) btnSizeSmall.Draw(); - if(btnSizeMedium.isEnable()) btnSizeMedium.Draw(); - if(btnSizeLarge.isEnable()) btnSizeLarge.Draw(); - if(btnSizeManual.isEnable()) btnSizeManual.Draw(); - - cursor.Show(); - display.Flip(); - } - - // click select size button - if((btnSizeSmall.isEnable() && le.MouseClickLeft(btnSizeSmall)) || - (btnSizeMedium.isEnable() && le.MouseClickLeft(btnSizeMedium)) || - (btnSizeLarge.isEnable() && le.MouseClickLeft(btnSizeLarge)) || - (btnSizeManual.isEnable() && le.MouseClickLeft(btnSizeManual))) - { - cursor.Hide(); - - btnSizeSmall.Release(); - btnSizeMedium.Release(); - btnSizeLarge.Release(); - btnSizeManual.Release(); - - if(le.MouseCursor(btnSizeSmall)){ btnSizeSmall.Press(); sizeCursor.ModifySize(1, 1); } - else - if(le.MouseCursor(btnSizeMedium)){ btnSizeMedium.Press(); sizeCursor.ModifySize(2, 2); } - else - if(le.MouseCursor(btnSizeLarge)){ btnSizeLarge.Press(); sizeCursor.ModifySize(4, 4); } - else - if(le.MouseCursor(btnSizeManual)){ btnSizeManual.Press(); sizeCursor.ModifySize(2, 2); } - - btnSizeSmall.Draw(); - btnSizeMedium.Draw(); - btnSizeLarge.Draw(); - btnSizeManual.Draw(); - - cursor.Show(); - display.Flip(); - } - - // click select terrain - if(btnSelectGround.isPressed() && le.MouseClickLeft(rectTerrainWater)) - { - selectTerrain = 0; - cursor.Hide(); - selectTerrainCursor.Move(rectTerrainWater.x - 1, rectTerrainWater.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select terrain: water"); - } - else - if(btnSelectGround.isPressed() && le.MouseClickLeft(rectTerrainGrass)) - { - selectTerrain = 1; - cursor.Hide(); - selectTerrainCursor.Move(rectTerrainGrass.x - 1, rectTerrainGrass.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select terrain: grass"); - } - else - if(btnSelectGround.isPressed() && le.MouseClickLeft(rectTerrainSnow)) - { - selectTerrain = 2; - cursor.Hide(); - selectTerrainCursor.Move(rectTerrainSnow.x - 1, rectTerrainSnow.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select terrain: snow"); - } - else - if(btnSelectGround.isPressed() && le.MouseClickLeft(rectTerrainSwamp)) - { - selectTerrain = 3; - cursor.Hide(); - selectTerrainCursor.Move(rectTerrainSwamp.x - 1, rectTerrainSwamp.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select terrain: swamp"); - } - else - if(btnSelectGround.isPressed() && le.MouseClickLeft(rectTerrainLava)) - { - selectTerrain = 4; - cursor.Hide(); - selectTerrainCursor.Move(rectTerrainLava.x - 1, rectTerrainLava.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select terrain: lava"); - } - else - if(btnSelectGround.isPressed() && le.MouseClickLeft(rectTerrainBeach)) - { - selectTerrain = 5; - cursor.Hide(); - selectTerrainCursor.Move(rectTerrainBeach.x - 1, rectTerrainBeach.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select terrain: beach"); - } - else - if(btnSelectGround.isPressed() && le.MouseClickLeft(rectTerrainDirt)) - { - selectTerrain = 6; - cursor.Hide(); - selectTerrainCursor.Move(rectTerrainDirt.x - 1, rectTerrainDirt.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select terrain: dirt"); - } - else - if(btnSelectGround.isPressed() && le.MouseClickLeft(rectTerrainWasteland)) - { - selectTerrain = 7; - cursor.Hide(); - selectTerrainCursor.Move(rectTerrainWasteland.x - 1, rectTerrainWasteland.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select terrain: wasteland"); - } - else - if(btnSelectGround.isPressed() && le.MouseClickLeft(rectTerrainDesert)) - { - selectTerrain = 8; - cursor.Hide(); - selectTerrainCursor.Move(rectTerrainDesert.x - 1, rectTerrainDesert.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select terrain: desert"); - } - - // click select object - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectWater)) - { - selectObject = 0; - cursor.Hide(); - selectObjectCursor.Move(rectObjectWater.x - 1, rectObjectWater.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: water"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectGrass)) - { - selectObject = 1; - cursor.Hide(); - selectObjectCursor.Move(rectObjectGrass.x - 1, rectObjectGrass.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: grass"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectSnow)) - { - selectObject = 2; - cursor.Hide(); - selectObjectCursor.Move(rectObjectSnow.x - 1, rectObjectSnow.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: snow"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectSwamp)) - { - selectObject = 3; - cursor.Hide(); - selectObjectCursor.Move(rectObjectSwamp.x - 1, rectObjectSwamp.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: swamp"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectLava)) - { - selectObject = 4; - cursor.Hide(); - selectObjectCursor.Move(rectObjectLava.x - 1, rectObjectLava.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: lava"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectDesert)) - { - selectObject = 5; - cursor.Hide(); - selectObjectCursor.Move(rectObjectDesert.x - 1, rectObjectDesert.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: desert"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectDirt)) - { - selectObject = 6; - cursor.Hide(); - selectObjectCursor.Move(rectObjectDirt.x - 1, rectObjectDirt.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: dirt"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectWasteland)) - { - selectObject = 7; - cursor.Hide(); - selectObjectCursor.Move(rectObjectWasteland.x - 1, rectObjectWasteland.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: wasteland"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectBeach)) - { - selectObject = 8; - cursor.Hide(); - selectObjectCursor.Move(rectObjectBeach.x - 1, rectObjectBeach.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: beach"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectTown)) - { - selectObject = 9; - cursor.Hide(); - selectObjectCursor.Move(rectObjectTown.x - 1, rectObjectTown.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: town"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectMonster)) - { - selectObject = 10; - cursor.Hide(); - selectObjectCursor.Move(rectObjectMonster.x - 1, rectObjectMonster.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: monster"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectHero)) - { - selectObject = 11; - cursor.Hide(); - selectObjectCursor.Move(rectObjectHero.x - 1, rectObjectHero.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: hero"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectArtifact)) - { - selectObject = 12; - cursor.Hide(); - selectObjectCursor.Move(rectObjectArtifact.x - 1, rectObjectArtifact.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: artifact"); - } - else - if(btnSelectObject.isPressed() && le.MouseClickLeft(rectObjectResource)) - { - selectObject = 13; - cursor.Hide(); - selectObjectCursor.Move(rectObjectResource.x - 1, rectObjectResource.y - 1); - cursor.Show(); - display.Flip(); - DEBUG(DBG_GAME , DBG_INFO, "Game::Editor::StartGame: select object: resource"); - } - - // button click - if(le.MouseClickLeft(btnZoom)) - { - VERBOSE("Game::Editor::StartGame: FIXME: click button Zoom"); - } - if(le.MouseClickLeft(btnUndo)) - { - VERBOSE("Game::Editor::StartGame: FIXME: click button Undo"); - } - if(le.MouseClickLeft(btnNew)) - { - return EDITNEWMAP; - } - if(le.MouseClickLeft(btnSpec)) - { - VERBOSE("Game::Editor::StartGame: FIXME: click button Spec"); - } - if(le.MouseClickLeft(btnFile)) - { - switch(Dialog::FileOptions()) - { - case Game::NEWGAME: return EDITNEWMAP; - case Game::LOADGAME: return EDITLOADMAP; - case Game::SAVEGAME: return EDITSAVEMAP; - case Game::QUITGAME: return QUITGAME; - - default: break; - } - } - if(le.MouseClickLeft(btnSystem)) - { - VERBOSE("Game::Editor::StartGame: FIXME: click button Options"); - } - - // press right info - if(le.MousePressRight(btnZoom)) - Dialog::Message(_("Magnify"), _("Change between zoom and normal view."), Font::BIG); - else - if(le.MousePressRight(btnUndo)) - Dialog::Message(_("Undo"), _("Undo your last action. Press againt to redo the action."), Font::BIG); - else - if(le.MousePressRight(btnNew)) - Dialog::Message(_("New"), _("Start a new map from scratch."), Font::BIG); - else - if(le.MousePressRight(btnSpec)) - Dialog::Message(_("Specifications"), _("Edit maps title, description, and other general information."), Font::BIG); - else - if(le.MousePressRight(btnFile)) - Dialog::Message(_("File Options"), _("Open the file options menu, where you can save or load maps, or quit out of the editor."), Font::BIG); - else - if(le.MousePressRight(btnSystem)) - Dialog::Message(_("System Options"), _("View the editor system options, which let you customize the editor."), Font::BIG); - else - if(le.MousePressRight(btnSelectGround)) - Dialog::Message(_("Terrain Mode"), _("Used to draw the underlying grass, dirt, water, etc. on the map."), Font::BIG); - else - if(le.MousePressRight(btnSelectObject)) - Dialog::Message(_("Object Mode"), _("Used to place objects (mountains, trees, treasure, etc.) on the map."), Font::BIG); - else - if(le.MousePressRight(btnSelectInfo)) - Dialog::Message(_("Detail Mode"), _("Used for special editing of monsters, heroes and towns."), Font::BIG); - else - if(le.MousePressRight(btnSelectRiver)) - Dialog::Message(_("Stream Mode"), _("Allows you to draw streams by clicking and dragging."), Font::BIG); - else - if(le.MousePressRight(btnSelectRoad)) - Dialog::Message(_("Road Mode"), _("Allows you to draw roads by clicking and dragging."), Font::BIG); - else - if(le.MousePressRight(btnSelectClear)) - Dialog::Message(_("Erase Mode"), _("Used to erase objects of the map."), Font::BIG); - else - if(btnSelectGround.isPressed() && le.MousePressRight(rectTerrainWater)) - Dialog::Message(_("Water"), _("Traversable only by boat."), Font::BIG); - else - if(btnSelectGround.isPressed() && le.MousePressRight(rectTerrainGrass)) - Dialog::Message(_("Grass"), _("No special modifiers."), Font::BIG); - else - if(btnSelectGround.isPressed() && le.MousePressRight(rectTerrainSnow)) - Dialog::Message(_("Snow"), _("Cost 1.5 times normal movement for all heroes. (Pathfinding reduces or eliminates the penalty.)"), Font::BIG); - else - if(btnSelectGround.isPressed() && le.MousePressRight(rectTerrainSwamp)) - Dialog::Message(_("Swamp"), _("Cost 1.75 times normal movement for all heroes. (Pathfinding reduces or eliminates the penalty.)"), Font::BIG); - else - if(btnSelectGround.isPressed() && le.MousePressRight(rectTerrainLava)) - Dialog::Message(_("Lava"), _("No special modifiers."), Font::BIG); - else - if(btnSelectGround.isPressed() && le.MousePressRight(rectTerrainBeach)) - Dialog::Message(_("Beach"), _("Cost 1.25 times normal movement for all heroes. (Pathfinding reduces or eliminates the penalty.)"), Font::BIG); - else - if(btnSelectGround.isPressed() && le.MousePressRight(rectTerrainDirt)) - Dialog::Message(_("Dirt"), _("No special modifiers."), Font::BIG); - else - if(btnSelectGround.isPressed() && le.MousePressRight(rectTerrainWasteland)) - Dialog::Message(_("Wasteland"), _("Cost 1.25 times normal movement for all heroes. (Pathfinding reduces or eliminates the penalty.)"), Font::BIG); - else - if(btnSelectGround.isPressed() && le.MousePressRight(rectTerrainDesert)) - Dialog::Message(_("Desert"), _("Cost 2 times normal movement for all heroes. (Pathfinding reduces or eliminates the penalty.)"), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectWater)) - Dialog::Message(_("Water Objects"), _("Used to select objects most appropriate for use on water."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectGrass)) - Dialog::Message(_("Grass Objects"), _("Used to select objects most appropriate for use on grass."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectSnow)) - Dialog::Message(_("Snow Objects"), _("Used to select objects most appropriate for use on snow."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectSwamp)) - Dialog::Message(_("Swamp Objects"), _("Used to select objects most appropriate for use on swamp."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectLava)) - Dialog::Message(_("Lava Objects"), _("Used to select objects most appropriate for use on lava."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectDesert)) - Dialog::Message(_("Desert Objects"), _("Used to select objects most appropriate for use on desert."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectDirt)) - Dialog::Message(_("Dirt Objects"), _("Used to select objects most appropriate for use on dirt."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectWasteland)) - Dialog::Message(_("Wasteland Objects"), _("Used to select objects most appropriate for use on wasteland."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectBeach)) - Dialog::Message(_("Beach Objects"), _("Used to select objects most appropriate for use on beach."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectTown)) - Dialog::Message(_("Towns"), _("Used to place a town or castle."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectMonster)) - Dialog::Message(_("Monsters"), _("Used to place a monster group."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectHero)) - Dialog::Message(_("Heroes"), _("Used to place a hero."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectArtifact)) - Dialog::Message(_("Artifact"), _("Used to place an artifact."), Font::BIG); - else - if(btnSelectObject.isPressed() && le.MousePressRight(rectObjectResource)) - Dialog::Message(_("Treasures"), _("Used to place a resource or treasure."), Font::BIG); - - if(areaMaps.NeedScroll()) - { - cursor.Hide(); - sizeCursor.Hide(); - cursor.SetThemes(areaMaps.GetScrollCursor()); - areaMaps.Scroll(); - //I.Scroll(scrollDir); - areaMaps.Redraw(display, LEVEL_ALL); - radar.RedrawCursor(); - cursor.Show(); - display.Flip(); - } - } - - return QUITGAME; -} - -void Game::Editor::ModifySingleTile(Maps::Tiles & tile) -{ - //u8 count = Maps::GetCountAroundGround(tile.GetIndex(), tile.GetGround()); - const u16 center = tile.GetIndex(); - const Maps::Ground::ground_t ground = tile.GetGround(); - const u16 max = Maps::GetMaxGroundAround(center); - Display & display = Display::Get(); - - if(max & ground) return; - - if((ground == world.GetTiles(Maps::GetDirectionIndex(center, Direction::TOP)).GetGround() && - ground == world.GetTiles(Maps::GetDirectionIndex(center, Direction::LEFT)).GetGround()) || - (ground == world.GetTiles(Maps::GetDirectionIndex(center, Direction::TOP)).GetGround() && - ground == world.GetTiles(Maps::GetDirectionIndex(center, Direction::RIGHT)).GetGround()) || - (ground == world.GetTiles(Maps::GetDirectionIndex(center, Direction::BOTTOM)).GetGround() && - ground == world.GetTiles(Maps::GetDirectionIndex(center, Direction::LEFT)).GetGround()) || - (ground == world.GetTiles(Maps::GetDirectionIndex(center, Direction::BOTTOM)).GetGround() && - ground == world.GetTiles(Maps::GetDirectionIndex(center, Direction::RIGHT)).GetGround())) return; - - u16 index = 0; - - if(max & Maps::Ground::DESERT) index = 300; - else - if(max & Maps::Ground::SNOW) index = 130; - else - if(max & Maps::Ground::SWAMP) index = 184; - else - if(max & Maps::Ground::WASTELAND) index = 399; - else - if(max & Maps::Ground::BEACH) index = 415; - else - if(max & Maps::Ground::LAVA) index = 246; - else - if(max & Maps::Ground::DIRT) index = 337; - else - if(max & Maps::Ground::GRASS) index = 68; - else - if(max & Maps::Ground::WATER) index = 16; - - if(index) - { - tile.SetTile(Rand::Get(index, index + 7), 0); - tile.RedrawTile(display); - tile.RedrawBottom(display); - tile.RedrawTop(display); - } -} - -void Game::Editor::ModifyTileAbroad(Maps::Tiles & tile) -{ - const u16 center = tile.GetIndex(); - Display & display = Display::Get(); - - // fix - if(Maps::Ground::WATER != tile.GetGround()) return; - - for(Direction::vector_t direct = Direction::TOP_LEFT; direct != Direction::CENTER; ++direct) - { - if(Maps::isValidDirection(center, direct)) - { - const Maps::Tiles & opposition = world.GetTiles(Maps::GetDirectionIndex(center, direct)); - u16 index = 0; - - // start index sprite - switch(opposition.GetGround()) - { - case Maps::Ground::DESERT: - case Maps::Ground::SNOW: - case Maps::Ground::SWAMP: - case Maps::Ground::WASTELAND: - case Maps::Ground::BEACH: - case Maps::Ground::LAVA: - case Maps::Ground::DIRT: - case Maps::Ground::GRASS: index = 0; break; - - case Maps::Ground::WATER: - default: continue; - } - - const u16 around = Maps::GetDirectionAroundGround(center, tile.GetGround()); - - // normal: 0, vertical: 1, horizontal: 2, any: 3 - bool fix = false; - u8 revert = 0; - - // sprite small corner - if(around == (DIRECTION_ALL & (~(Direction::TOP_RIGHT | Direction::CENTER)))) - { fix = true; index += 12; revert = 0; } - else - if(around == (DIRECTION_ALL & (~(Direction::TOP_LEFT | Direction::CENTER)))) - { fix = true; index += 12; revert = 2; } - else - if(around == (DIRECTION_ALL & (~(Direction::BOTTOM_RIGHT | Direction::CENTER)))) - { fix = true; index += 12; revert = 1; } - else - if(around == (DIRECTION_ALL & (~(Direction::BOTTOM_LEFT | Direction::CENTER)))) - { fix = true; index += 12; revert = 3; } - else - // sprite row - if(around & (DIRECTION_CENTER_ROW | DIRECTION_BOTTOM_ROW) && - !(around & (Direction::TOP))) - { fix = true; index += 0; revert = 0; } - else - if(around & (DIRECTION_CENTER_ROW | DIRECTION_TOP_ROW) && - !(around & (Direction::BOTTOM))) - { fix = true; index += 0; revert = 1; } - else - // sprite col - if(around & (DIRECTION_CENTER_COL | DIRECTION_LEFT_COL) && - !(around & (Direction::RIGHT))) - { fix = true; index += 8; revert = 0; } - else - if(around & (DIRECTION_CENTER_COL | DIRECTION_RIGHT_COL) && - !(around & (Direction::LEFT))) - { fix = true; index += 8; revert = 2; } - // sprite small corner - if(around & (Direction::CENTER | Direction::LEFT | Direction::BOTTOM_LEFT | Direction::BOTTOM) && - !(around & (Direction::TOP | Direction::TOP_RIGHT | Direction::RIGHT))) - { fix = true; index += 4; revert = 0; } - else - if(around & (Direction::CENTER | Direction::RIGHT | Direction::BOTTOM_RIGHT | Direction::BOTTOM) && - !(around & (Direction::TOP | Direction::TOP_LEFT | Direction::LEFT))) - { fix = true; index += 4; revert = 2; } - else - if(around & (Direction::CENTER | Direction::LEFT | Direction::TOP_LEFT | Direction::TOP) && - !(around & (Direction::BOTTOM | Direction::BOTTOM_RIGHT | Direction::RIGHT))) - { fix = true; index += 4; revert = 1; } - else - if(around & (Direction::CENTER | Direction::RIGHT | Direction::TOP_RIGHT | Direction::TOP) && - !(around & (Direction::BOTTOM | Direction::BOTTOM_LEFT | Direction::LEFT))) - { fix = true; index += 4; revert = 3; } - - // fix random - if(fix) - { - tile.SetTile(Rand::Get(index, index + 3), revert); - tile.RedrawTile(display); - tile.RedrawBottom(display); - tile.RedrawTop(display); - } - } - } -} - -/* set ground to tile */ -void Game::Editor::SetGroundToTile(Maps::Tiles & tile, const Maps::Ground::ground_t ground) -{ - const u16 around = Maps::GetDirectionAroundGround(tile.GetIndex(), ground); - - // simply set - if(ground == around) - { - u16 index_ground = 0; - - switch(ground) - { - case Maps::Ground::WATER: tile.SetTile(Rand::Get(16, 19), 0); return; - case Maps::Ground::GRASS: index_ground = 68; break; - case Maps::Ground::SNOW: index_ground = 130; break; - case Maps::Ground::SWAMP: index_ground = 184; break; - case Maps::Ground::LAVA: index_ground = 246; break; - case Maps::Ground::DESERT: index_ground = 300; break; - case Maps::Ground::DIRT: index_ground = 337; break; - case Maps::Ground::WASTELAND: index_ground = 399; break; - case Maps::Ground::BEACH: index_ground = 415; break; - default: break; - } - - switch(Rand::Get(1, 7)) - { - // 85% simple ground - case 1: - case 2: - case 3: - case 4: - case 5: - case 6: - tile.SetTile(Rand::Get(index_ground, index_ground + 7), 0); - break; - - // 15% extended ground - default: - tile.SetTile(Rand::Get(index_ground + 8, index_ground + 15), 0); - break; - } - } - else - { - } -} - -GroundIndexAndRotate Game::Editor::GetTileWithCorner(u16 around, const Maps::Ground::ground_t ground) -{ - GroundIndexAndRotate result; - - switch(ground) - { - case Maps::Ground::WATER: - default: break; - } - - return result; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/game/difficulty.cpp b/project/jni/application/fheroes2/src/fheroes2/game/difficulty.cpp deleted file mode 100644 index 8f8c3ae2e..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/difficulty.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "gamedefs.h" -#include "difficulty.h" - -// operator ++difficulty_t -Difficulty::difficulty_t& Difficulty::operator++ (Difficulty::difficulty_t& difficulty) -{ return difficulty = ( Difficulty::IMPOSSIBLE == difficulty ? Difficulty::EASY : Difficulty::difficulty_t(difficulty + 1)); } - -// operator --difficulty_t -Difficulty::difficulty_t& Difficulty::operator-- (Difficulty::difficulty_t& difficulty) -{ return difficulty = ( Difficulty::EASY == difficulty ? Difficulty::IMPOSSIBLE : Difficulty::difficulty_t(difficulty - 1)); } - - -const char* Difficulty::String(u8 difficulty) -{ - const char* str_difficulty[] = { _("difficulty|Easy"), _("difficulty|Normal"), _("difficulty|Hard"), _("difficulty|Expert"), _("difficulty|Impossible"), "Unknown" }; - - switch(difficulty) - { - case Difficulty::EASY: return str_difficulty[0]; - case Difficulty::NORMAL: return str_difficulty[1]; - case Difficulty::HARD: return str_difficulty[2]; - case Difficulty::EXPERT: return str_difficulty[3]; - case Difficulty::IMPOSSIBLE: return str_difficulty[4]; - default: break; - } - - return str_difficulty[5]; -} - -Difficulty::difficulty_t Difficulty::Get(u8 index) -{ - return IMPOSSIBLE < index ? IMPOSSIBLE : static_cast(index); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/difficulty.h b/project/jni/application/fheroes2/src/fheroes2/game/difficulty.h deleted file mode 100644 index 4bf4b0350..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/difficulty.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2DIFFICULTY_H -#define H2DIFFICULTY_H - -#include -#include "gamedefs.h" - -namespace Difficulty -{ - enum difficulty_t - { - EASY, - NORMAL, - HARD, - EXPERT, - IMPOSSIBLE - }; - - difficulty_t& operator++ (difficulty_t& difficulty); - difficulty_t& operator-- (difficulty_t& difficulty); - - const char* String(u8); - difficulty_t Get(u8); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/game/fheroes2.cpp b/project/jni/application/fheroes2/src/fheroes2/game/fheroes2.cpp deleted file mode 100644 index 8a246fa83..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/fheroes2.cpp +++ /dev/null @@ -1,397 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include - -#include "gamedefs.h" -#include "engine.h" -#include "settings.h" -#include "dir.h" -#include "agg.h" -#include "cursor.h" -#include "game.h" -#include "test.h" -#include "sdlnet.h" -#include "images_pack.h" -#include "localclient.h" - -#include "zzlib.h" - -void LoadZLogo(void); -void SetVideoDriver(const std::string &); -void SetTimidityEnvPath(const Settings &); -void SetLangEnvPath(const Settings &); -void ReadConfigFile(Settings &); -void LoadConfigFiles(Settings &, const std::string &); - -int PrintHelp(const char *basename) -{ - std::cout << "Usage: " << basename << " [OPTIONS]" << std::endl; -#ifdef WITH_EDITOR - std::cout << " -e\teditors mode" << std::endl; -#endif -#ifndef BUILD_RELEASE - std::cout << " -d\tdebug mode" << std::endl; -#endif -#ifdef WITH_NET - std::cout << " -s\tdedicated server" << std::endl; -#endif - std::cout << " -h\tprint this help and exit" << std::endl; - - return EXIT_SUCCESS; -} - -std::string GetCaption(void) -{ - return std::string("Free Heroes II, " + Settings::Get().BuildVersion()); -} - -int main(int argc, char **argv) -{ - VERBOSE("000 - entered SDL_main()"); - Settings & conf = Settings::Get(); - int test = 0; - - std::cout << "Free Heroes II, " + conf.BuildVersion() << std::endl; - VERBOSE("Free Heroes II, " + conf.BuildVersion()); - - LoadConfigFiles(conf, GetDirname(argv[0])); - - VERBOSE("001"); - -#ifndef ANDROID // Crashes for some reason - // getopt - { - int opt; - while((opt = getopt(argc, argv, "hest:d:")) != -1) - switch(opt) - { -#ifdef WITH_EDITOR - case 'e': - conf.SetEditor(); - conf.SetDebug(DBG_DEVEL | DBG_GAME | DBG_INFO); - std::cout << "start: editor mode." << std::endl; - break; -#endif -#ifndef BUILD_RELEASE - case 't': - test = String::ToInt(optarg); - break; - - case 'd': - conf.SetDebug(optarg ? String::ToInt(optarg) : 0); - break; -#endif - -#ifdef WITH_NET - case 's': - return Network::RunDedicatedServer(); -#endif - case '?': - case 'h': return PrintHelp(argv[0]); - - default: break; - } - } -#endif - - VERBOSE("002"); - - if(conf.SelectVideoDriver().size()) SetVideoDriver(conf.SelectVideoDriver()); - - VERBOSE("003"); - - // random init - Rand::Init(); - if(conf.Music()) SetTimidityEnvPath(conf); - - VERBOSE("004"); - - u32 subsystem = INIT_VIDEO | INIT_TIMER; - - if(conf.Sound() || conf.Music()) - subsystem |= INIT_AUDIO; -#ifdef WITH_AUDIOCD - if(conf.CDMusic()) - subsystem |= INIT_CDROM | INIT_AUDIO; -#endif -#ifdef WITH_NET - Network::SetProtocolVersion(static_cast((conf.MajorVersion() << 8)) | conf.MinorVersion()); -#endif - - VERBOSE("005"); - - if(SDL::Init(subsystem)) - try - { - VERBOSE("006"); - std::atexit(SDL::Quit); - - if(conf.Unicode()) SetLangEnvPath(conf); - - if(Mixer::isValid()) - { - Mixer::SetChannels(8); - Mixer::Volume(-1, Mixer::MaxVolume() * conf.SoundVolume() / 10); - Music::Volume(Mixer::MaxVolume() * conf.MusicVolume() / 10); - if(conf.Music()) - { - Music::SetFadeIn(3000); - } - } - else - if(conf.Sound() || conf.Music()) - { - conf.ResetSound(); - conf.ResetMusic(); - } - - if(0 == conf.VideoMode().w || 0 == conf.VideoMode().h) - conf.SetAutoVideoMode(); - - Display::SetVideoMode(conf.VideoMode().w, conf.VideoMode().h, conf.DisplayFlags()); - - Display::HideCursor(); - Display::SetCaption(GetCaption()); - - //Ensure the mouse position is updated to prevent bad initial values. - LocalEvent::Get().GetMouseCursor(); - - VERBOSE("007"); - -#ifdef WITH_ZLIB - ZSurface zicons; - if(zicons.Load(FH2_ICONS_WIDTH, FH2_ICONS_HEIGHT, FH2_ICONS_BPP, fh2_icons_pack, FH2_ICONS_SIZE, true)) Display::SetIcons(zicons); -#endif - AGG::Cache & cache = AGG::Cache::Get(); - - VERBOSE("008"); - - // read data dir - if(! cache.ReadDataDir()) Error::Except("FHeroes2: ", "AGG data files not found."); - - if(IS_DEBUG(DBG_GAME, DBG_INFO)) conf.Dump(); - - VERBOSE("009"); - - // load palette - cache.LoadPAL(); - - // load font - cache.LoadFNT(); - -#ifdef WITH_ZLIB - LoadZLogo(); -#endif - - // init cursor - Cursor::Get().SetThemes(Cursor::POINTER); - AGG::ICNRegistryEnable(true); - - // init game data - Game::Init(); - - // goto main menu -#ifdef WITH_EDITOR - Game::menu_t rs = (test ? Game::TESTING : (conf.Editor() ? Game::EDITMAINMENU : Game::MAINMENU)); -#else - Game::menu_t rs = (test ? Game::TESTING : Game::MAINMENU); -#endif - - while(rs != Game::QUITGAME) - { - switch(rs) - { -#ifdef WITH_EDITOR - case Game::EDITMAINMENU: rs = Game::Editor::MainMenu(); break; - case Game::EDITNEWMAP: rs = Game::Editor::NewMaps(); break; - case Game::EDITLOADMAP: rs = Game::Editor::LoadMaps(); break; - case Game::EDITSTART: rs = Game::Editor::StartGame(); break; -#endif - case Game::MAINMENU: rs = Game::MainMenu(); break; - case Game::NEWGAME: rs = Game::NewGame(); break; - case Game::LOADGAME: rs = Game::LoadGame(); break; - case Game::HIGHSCORES: rs = Game::HighScores(); break; - case Game::CREDITS: rs = Game::Credits(); break; - case Game::NEWSTANDARD: rs = Game::NewStandard(); break; - case Game::NEWCAMPAIN: rs = Game::NewCampain(); break; - case Game::NEWMULTI: rs = Game::NewMulti(); break; - case Game::NEWHOTSEAT: rs = Game::NewHotSeat(); break; - case Game::NEWNETWORK: rs = Game::NewNetwork(); break; - case Game::LOADSTANDARD: rs = Game::LoadStandard(); break; - case Game::LOADCAMPAIN: rs = Game::LoadCampain(); break; - case Game::LOADMULTI: rs = Game::LoadMulti(); break; - case Game::SCENARIOINFO: rs = Game::ScenarioInfo(); break; - case Game::SELECTSCENARIO: rs = Game::SelectScenario(); break; - case Game::STARTGAME: rs = Game::StartGame(); break; - case Game::TESTING: rs = Game::Testing(test); break; - - default: break; - } - } - - //Display::ShowCursor(); - if(Settings::Get().ExtUseFade()) Display::Fade(); - - } catch(std::bad_alloc) - { - DEBUG(DBG_GAME, DBG_WARN, "std::bad_alloc"); - AGG::Cache::Get().Dump(); - } catch(Error::Exception) - { - DEBUG(DBG_GAME, DBG_WARN, "Error::Exception"); -#ifdef WITH_NET - if(Game::NETWORK == conf.GameType()) FH2LocalClient::Get().Logout(); -#endif - AGG::Cache::Get().Dump(); - conf.Dump(); - } - - return EXIT_SUCCESS; -} - -void LoadZLogo(void) -{ -#ifdef BUILD_RELEASE - // SDL logo - if(Settings::Get().ExtShowSDL()) - { - Display & display = Display::Get(); - - ZSurface* zlogo = new ZSurface(); - if(zlogo->Load(SDL_LOGO_WIDTH, SDL_LOGO_HEIGHT, SDL_LOGO_BPP, sdl_logo_data, SDL_LOGO_SIZE, false)) - { - Surface* logo = zlogo; - - // scale logo - if(Settings::Get().QVGA()) - { - Surface* small = new Surface(); - Surface::ScaleMinifyByTwo(*small, *zlogo); - delete zlogo; - zlogo = NULL; - logo = small; - } - - logo->SetDisplayFormat(); - - const u32 black = logo->MapRGB(0, 0, 0); - const Point offset((display.w() - logo->w()) / 2, (display.h() - logo->h()) / 2); - - u8 ii = 0; - - while(ii < 250) - { - logo->SetAlpha(ii); - display.Blit(*logo, offset); - display.Flip(); - display.Fill(black); - ii += 10; - } - - DELAY(500); - - while(ii > 0) - { - logo->SetAlpha(ii); - display.Blit(*logo, offset); - display.Flip(); - display.Fill(black); - ii -= 10; - } - } - if(zlogo) delete zlogo; - } -#endif -} - -void SetVideoDriver(const std::string & driver) -{ - std::string strtmp = "SDL_VIDEODRIVER=" + driver; - putenv(const_cast(strtmp.c_str())); -} - -void SetTimidityEnvPath(const Settings & conf) -{ - std::string strtmp = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "timidity" + SEPARATOR + "timidity.cfg"; - if(FilePresent(strtmp)) - { - strtmp = "TIMIDITY_PATH=" + conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "timidity"; - putenv(const_cast(strtmp.c_str())); - } -} - -void SetLangEnvPath(const Settings & conf) -{ -#ifdef WITH_TTF - if(conf.ForceLang().size()) - { - static std::string language("LANGUAGE=" + conf.ForceLang()); - static std::string lang("LANG=" + conf.ForceLang()); - putenv(const_cast(language.c_str())); - putenv(const_cast(lang.c_str())); - } - - const std::string strtmp = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "lang"; - setlocale(LC_ALL, ""); - bindtextdomain(GETTEXT_PACKAGE, strtmp.c_str()); - bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8"); - textdomain(GETTEXT_PACKAGE); -#endif -} - -void ReadConfigFile(Settings & conf) -{ - std::string strtmp = conf.LocalPrefix() + SEPARATOR + "fheroes2.cfg"; - if(FilePresent(strtmp)) - { - std::cout << "config: " << strtmp << " load." << std::endl; - VERBOSE("config: " << strtmp << " load."); - conf.Read(strtmp); - } -} - -void LoadConfigFiles(Settings & conf, const std::string & dirname) -{ - // prefix from build -#ifdef CONFIGURE_FHEROES2_DATA - conf.SetLocalPrefix(CONFIGURE_FHEROES2_DATA); - if(conf.LocalPrefix().size()) ReadConfigFile(conf); -#endif - - // prefix from env - if(getenv("FHEROES2_DATA")) - { - conf.SetLocalPrefix(getenv("FHEROES2_DATA")); - ReadConfigFile(conf); - } - - // prefix from dirname - if(conf.LocalPrefix().empty() && dirname.size()) - { - conf.SetLocalPrefix(dirname.c_str()); - ReadConfigFile(conf); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game.cpp deleted file mode 100644 index def99ae87..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game.cpp +++ /dev/null @@ -1,449 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include - -#include "gamedefs.h" -#include "tinyconfig.h" -#include "settings.h" -#include "game_focus.h" -#include "maps_tiles.h" -#include "ground.h" -#include "world.h" -#include "kingdom.h" -#include "castle.h" -#include "mp2.h" -#include "agg.h" -#include "test.h" -#include "cursor.h" -#include "monster.h" -#include "spell.h" -#include "payment.h" -#include "profit.h" -#include "buildinginfo.h" -#include "skill.h" -#include "battle2.h" -#include "game.h" - -#ifdef WITH_XML -#include "xmlccwrap.h" -#endif - -namespace Game -{ - u8 GetMixerChannelFromObject(const Maps::Tiles &); - void AnimateDelaysInitialize(void); - void KeyboardGlobalFilter(int, u16); - void UpdateGlobalDefines(const std::string &); - void LoadExternalResource(const Settings &); - - void HotKeysDefaults(void); - void HotKeysLoad(const std::string &); - - static u8 lost_town_days(7); - static u16 reserved_vols[LOOPXX_COUNT]; - - // town, castle, heroes, artifact_telescope, object_observation_tower, object_magi_eyes - static u8 view_distance[] = { 4, 5, 4, 1, 10, 9 }; - static u8 whirlpool_percent = 50; - static u8 heroes_restore_spell_points_day = 1; -} - -Game::menu_t Game::Testing(u8 t) -{ -#ifndef BUILD_RELEASE - Test::Run(t); - return Game::QUITGAME; -#else - return Game::MAINMENU; -#endif -} - -Game::menu_t Game::Credits(void) -{ - const Settings & conf = Settings::Get(); - - std::string str = conf.BuildVersion(); - - str.append("\n \n"); - str.append("Site project: https://sf.net/projects/fheroes2"); - - Dialog::Message("Free Heroes II Engine", str, Font::SMALL, Dialog::OK); - - //VERBOSE("Credits: under construction."); - - return Game::MAINMENU; -} - -void Game::Init(void) -{ - Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - - // update all global defines - if(conf.UseAltResource()) LoadExternalResource(conf); - - // default events - le.SetStateDefaults(); - - // set global events - le.SetGlobalFilterMouseEvents(Cursor::Redraw); - le.SetGlobalFilterKeysEvents(Game::KeyboardGlobalFilter); - le.SetGlobalFilter(true); - - le.SetTapMode(conf.ExtTapMode()); - - Game::AnimateDelaysInitialize(); - - HotKeysDefaults(); - - const std::string hotkeys = conf.LocalPrefix() + SEPARATOR + "fheroes2.key"; - - if(FilePresent(hotkeys)) - Game::HotKeysLoad(hotkeys); -} - -void Game::SetFixVideoMode(void) -{ - const Settings & conf = Settings::Get(); - - Size fixsize(conf.VideoMode()); - u32 max = (6 + conf.MapsWidth()) * TILEWIDTH; - - if(conf.VideoMode().w > max) fixsize.w = max; - if(conf.VideoMode().h > max) fixsize.h = max; - - Display::Get().SetVideoMode(fixsize.w, fixsize.h, conf.DisplayFlags()); -} - -/* play all sound from focus area game */ -void Game::EnvironmentSoundMixer(void) -{ - const Focus & focus = Focus::Get(); - const Point & abs_pt = focus.Center(); - const Settings & conf = Settings::Get(); - - if(conf.Sound()) - { - std::fill(reserved_vols, reserved_vols + LOOPXX_COUNT, 0); - - // scan 4x4 square from focus - for(s16 yy = abs_pt.y - 3; yy <= abs_pt.y + 3; ++yy) - { - for(s16 xx = abs_pt.x - 3; xx <= abs_pt.x + 3; ++xx) - { - if(Maps::isValidAbsPoint(xx, yy)) - { - const u8 channel = GetMixerChannelFromObject(world.GetTiles(xx, yy)); - if(channel < LOOPXX_COUNT) - { - // calculation volume - const u8 length = std::max(std::abs(xx - abs_pt.x), std::abs(yy - abs_pt.y)); - const u16 volume = (2 < length ? 4 : (1 < length ? 8 : (0 < length ? 12 : 16))) * Mixer::MaxVolume() / 16; - - if(volume > reserved_vols[channel]) reserved_vols[channel] = volume; - } - } - } - } - - AGG::Cache::Get().LoadLOOPXXSounds(reserved_vols); - } -} - -u8 Game::GetMixerChannelFromObject(const Maps::Tiles & tile) -{ - // force: check stream - if(tile.isStream()) return 13; - - MP2::object_t object = tile.GetObject(); - if(MP2::OBJ_HEROES == object) - { - const Heroes* hero = world.GetHeroes(tile.GetIndex()); - object = hero->GetUnderObject(); - } - - return M82::GetIndexLOOP00XXFromObject(object); -} - -Game::control_t Game::GetControl(u8 index) -{ - switch(index) - { - case LOCAL: return LOCAL; - case REMOTE: return REMOTE; - case AI: return AI; - default: break; - } - return NONE; -} - -Game::type_t Game::GetType(u8 index) -{ - switch(index) - { - case STANDARD: return STANDARD; - case CAMPAIGN: return CAMPAIGN; - case HOTSEAT: return HOTSEAT; - case NETWORK: return NETWORK; - default: break; - } - return UNKNOWN; -} - -u8 Game::GetRating(void) -{ - Settings & conf = Settings::Get(); - u8 rating = 50; - - switch(conf.MapsDifficulty()) - { - case Difficulty::NORMAL: rating += 20; break; - case Difficulty::HARD: rating += 40; break; - case Difficulty::EXPERT: - case Difficulty::IMPOSSIBLE: rating += 80; break; - default: break; - } - - switch(conf.GameDifficulty()) - { - case Difficulty::NORMAL: rating += 30; break; - case Difficulty::HARD: rating += 50; break; - case Difficulty::EXPERT: rating += 70; break; - case Difficulty::IMPOSSIBLE: rating += 90; break; - default: break; - } - - return rating; -} - -u16 Game::GetGameOverScores(void) -{ - Settings & conf = Settings::Get(); - - u8 k_size = 0; - - switch(conf.MapsWidth()) - { - case Maps::SMALL: k_size = 140; break; - case Maps::MEDIUM: k_size = 100; break; - case Maps::LARGE: k_size = 80; break; - case Maps::XLARGE: k_size = 60; break; - default: break; - } - - u8 flag = 0; - u8 nk = 0; - u16 end_days = world.CountDay(); - - for(u16 ii = 1; ii <= end_days; ++ii) - { - nk = ii * k_size / 100; - - if(0 == flag && nk > 60){ end_days = ii + (world.CountDay() - ii) / 2; flag = 1; } - else - if(1 == flag && nk > 120) end_days = ii + (world.CountDay() - ii) / 2; - else - if(nk > 180) break; - } - - return GetRating() * (200 - nk) / 100; -} - -void Game::ShowLoadMapsText(void) -{ - Display & display = Display::Get(); - const Rect pos(0, display.h() / 2, display.w(), display.h() / 2); - TextBox text(_("Maps Loading..."), Font::BIG, pos.w); - - // blit test - display.Fill(0, 0, 0); - text.Blit(pos, display); - display.Flip(); -} - -u8 Game::GetLostTownDays(void) -{ - return lost_town_days; -} - -u8 Game::GetViewDistance(distance_t d) -{ - return view_distance[d]; -} - -void Game::UpdateGlobalDefines(const std::string & spec) -{ -#ifdef WITH_XML - // parse profits.xml - TiXmlDocument doc; - const TiXmlElement* xml_globals = NULL; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_globals = doc.FirstChildElement("globals"))) - { - const TiXmlElement* xml_element; - - // starting_resource - xml_element = xml_globals->FirstChildElement("starting_resource"); - if(xml_element) - Kingdom::UpdateStartingResource(xml_element); - - // view_distance - xml_element = xml_globals->FirstChildElement("view_distance"); - if(xml_element) - { - int value; - xml_element->Attribute("town", &value); - if(value) view_distance[0] = value; - - xml_element->Attribute("castle", &value); - if(value) view_distance[1] = value; - - xml_element->Attribute("heroes", &value); - if(value) view_distance[2] = value; - - xml_element->Attribute("artifact_telescope", &value); - if(value) view_distance[3] = value; - - xml_element->Attribute("object_observation_tower", &value); - if(value) view_distance[4] = value; - - xml_element->Attribute("object_magi_eyes", &value); - if(value) view_distance[5] = value; - } - - // kingdom - xml_element = xml_globals->FirstChildElement("kingdom"); - if(xml_element) - { - int value; - xml_element->Attribute("max_heroes", &value); - Kingdom::SetMaxHeroes(value); - } - - // game_over - xml_element = xml_globals->FirstChildElement("game_over"); - if(xml_element) - { - int value; - xml_element->Attribute("lost_towns_days", &value); - lost_town_days = value; - } - - // whirlpool - xml_element = xml_globals->FirstChildElement("whirlpool"); - if(xml_element) - { - int value; - xml_element->Attribute("percent", &value); - if(value && value < 90) whirlpool_percent = value; - } - - // heroes - xml_element = xml_globals->FirstChildElement("heroes"); - if(xml_element) - { - int value; - xml_element->Attribute("spell_points_per_day", &value); - if(value < 11) heroes_restore_spell_points_day = value; - } - - // castle_extra_growth - xml_element = xml_globals->FirstChildElement("castle_extra_growth "); - if(xml_element) Castle::UpdateExtraGrowth(xml_element); - } - else - VERBOSE(spec << ": " << doc.ErrorDesc()); -#endif -} - -u8 Game::GetWhirlpoolPercent(void) -{ - return whirlpool_percent; -} - -u8 Game::GetHeroRestoreSpellPointsPerDay(void) -{ - return heroes_restore_spell_points_day; -} - -void Game::LoadExternalResource(const Settings & conf) -{ - std::string spec; - - // globals.xml - spec = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "stats" + SEPARATOR + "globals.xml"; - - if(FilePresent(spec)) - Game::UpdateGlobalDefines(spec); - - // animations.xml - spec = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "stats" + SEPARATOR + "animations.xml"; - - if(FilePresent(spec)) - Battle2::UpdateMonsterInfoAnimation(spec); - - // battle.xml - spec = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "stats" + SEPARATOR + "battle.xml"; - - if(FilePresent(spec)) - Battle2::UpdateMonsterAttributes(spec); - - // monsters.xml - spec = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "stats" + SEPARATOR + "monsters.xml"; - - if(FilePresent(spec)) - Monster::UpdateStats(spec); - - // spells.xml - spec = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "stats" + SEPARATOR + "spells.xml"; - - if(FilePresent(spec)) - Spell::UpdateStats(spec); - - // buildings.xml - spec = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "stats" + SEPARATOR + "buildings.xml"; - - if(FilePresent(spec)) - BuildingInfo::UpdateCosts(spec); - - // payments.xml - spec = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "stats" + SEPARATOR + "payments.xml"; - - if(FilePresent(spec)) - PaymentConditions::UpdateCosts(spec); - - // profits.xml - spec = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "stats" + SEPARATOR + "profits.xml"; - - if(FilePresent(spec)) - ProfitConditions::UpdateCosts(spec); - - // skills.xml - spec = conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "stats" + SEPARATOR + "skills.xml"; - - if(FilePresent(spec)) - Skill::UpdateStats(spec); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game.h b/project/jni/application/fheroes2/src/fheroes2/game/game.h deleted file mode 100644 index 774fddf37..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game.h +++ /dev/null @@ -1,267 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2GAME_H -#define H2GAME_H - -#include -#include "rect.h" -#include "types.h" - -class Heroes; -class Castle; -class Surface; -class Kingdom; -class Player; - -namespace Game -{ - enum menu_t - { - CANCEL = 0, - QUITGAME, - MAINMENU, - NEWGAME, - LOADGAME, - HIGHSCORES, - CREDITS, - NEWSTANDARD, - NEWCAMPAIN, - NEWMULTI, - NEWHOTSEAT, - NEWNETWORK, - LOADSTANDARD, - LOADCAMPAIN, - LOADMULTI, - SCENARIOINFO, - SELECTSCENARIO, - STARTGAME, - SAVEGAME, - EDITMAINMENU, - EDITNEWMAP, - EDITLOADMAP, - EDITSAVEMAP, - EDITSTART, - ENDTURN, - TESTING - }; - - void Init(void); - - enum type_t { UNKNOWN = 0, STANDARD = 1, CAMPAIGN = 2, HOTSEAT = 4, NETWORK = 8, MULTI = HOTSEAT | NETWORK }; - enum control_t { NONE = 0, LOCAL = 1, REMOTE = 2, AI = 4 }; - enum distance_t { VIEW_TOWN = 0, VIEW_CASTLE = 1, VIEW_HEROES = 2, VIEW_TELESCOPE = 3, VIEW_OBSERVATION_TOWER = 4, VIEW_MAGI_EYES = 5 }; - - enum events_t - { - EVENT_NONE, - EVENT_BUTTON_NEWGAME, - EVENT_BUTTON_LOADGAME, - EVENT_BUTTON_HIGHSCORES, - EVENT_BUTTON_CREDITS, - EVENT_BUTTON_STANDARD, - EVENT_BUTTON_CAMPAIN, - EVENT_BUTTON_MULTI, - EVENT_BUTTON_SETTINGS, - EVENT_BUTTON_SELECT, - EVENT_BUTTON_HOTSEAT, - EVENT_BUTTON_NETWORK, - EVENT_BUTTON_HOST, - EVENT_BUTTON_GUEST, - EVENT_DEFAULT_READY, - EVENT_DEFAULT_EXIT, - EVENT_DEFAULT_LEFT, - EVENT_DEFAULT_RIGHT, - EVENT_SYSTEM_FULLSCREEN, - EVENT_SYSTEM_SCREENSHOT, - EVENT_SYSTEM_DEBUG1, - EVENT_SYSTEM_DEBUG2, - EVENT_ENDTURN, - EVENT_NEXTHERO, - EVENT_NEXTTOWN, - EVENT_CONTINUE, - EVENT_SAVEGAME, - EVENT_LOADGAME, - EVENT_FILEOPTIONS, - EVENT_PUZZLEMAPS, - EVENT_INFOGAME, - EVENT_DIGARTIFACT, - EVENT_CASTSPELL, - EVENT_DEFAULTACTION, - EVENT_OPENFOCUS, - EVENT_SYSTEMOPTIONS, - EVENT_BATTLE_CASTSPELL, - EVENT_BATTLE_RETREAT, - EVENT_BATTLE_SURRENDER, - EVENT_BATTLE_AUTOSWITCH, - EVENT_BATTLE_OPTIONS, - EVENT_BATTLE_HARDSKIP, - EVENT_BATTLE_SOFTSKIP, - EVENT_MOVELEFT, - EVENT_MOVERIGHT, - EVENT_MOVETOP, - EVENT_MOVEBOTTOM, - EVENT_MOVETOPLEFT, - EVENT_MOVETOPRIGHT, - EVENT_MOVEBOTTOMLEFT, - EVENT_MOVEBOTTOMRIGHT, - EVENT_SCROLLLEFT, - EVENT_SCROLLRIGHT, - EVENT_SCROLLUP, - EVENT_SCROLLDOWN, - EVENT_CTRLPANEL, - EVENT_SHOWRADAR, - EVENT_SHOWBUTTONS, - EVENT_SHOWSTATUS, - EVENT_SHOWICONS, - EVENT_SWITCHGROUP, - EVENT_EMULATETOGGLE, - EVENT_LAST - }; - - events_t & operator++ (events_t &); - - bool HotKeyPress(events_t); - - enum delay_t - { - SCROLL_DELAY, - MAIN_MENU_DELAY, - MAPS_DELAY, - CASTLE_TAVERN_DELAY, - CASTLE_AROUND_DELAY, - CASTLE_BUYHERO_DELAY, - CASTLE_BUILD_DELAY, - HEROES_MOVE_DELAY, - HEROES_FADE_DELAY, - HEROES_PICKUP_DELAY, - PUZZLE_FADE_DELAY, - BATTLE_DIALOG_DELAY, - BATTLE_FRAME_DELAY, - BATTLE_MISSILE_DELAY, - BATTLE_SPELL_DELAY, - BATTLE_DISRUPTING_DELAY, - BATTLE_CATAPULT_DELAY, - BATTLE_CATAPULT2_DELAY, - BATTLE_CATAPULT3_DELAY, - BATTLE_BRIDGE_DELAY, - BATTLE_IDLE_DELAY, - BATTLE_IDLE2_DELAY, - BATTLE_OPPONENTS_DELAY, - BATTLE_FLAGS_DELAY, - AUTOHIDE_STATUS_DELAY, - // - CURRENT_HERO_DELAY, - CURRENT_AI_DELAY, - // - LAST_DELAY - }; - - bool AnimateInfrequent(delay_t); - void AnimateDelayReset(delay_t); - void UpdateHeroesMoveSpeed(void); - - control_t GetControl(u8); - type_t GetType(u8); - - menu_t MainMenu(void); - menu_t NewGame(void); - menu_t LoadGame(void); - menu_t HighScores(void); - menu_t Credits(void); - menu_t NewStandard(void); - menu_t NewCampain(void); - menu_t NewMulti(void); - menu_t NewHotSeat(void); - menu_t NewNetwork(void); - menu_t LoadStandard(void); - menu_t LoadCampain(void); - menu_t LoadMulti(void); - menu_t ScenarioInfo(void); - menu_t SelectScenario(void); - menu_t StartGame(void); - - menu_t NetworkHost(void); - menu_t NetworkGuest(void); - - menu_t Testing(u8); - - void DrawInterface(void); - - void SetFixVideoMode(void); - - void EnvironmentSoundMixer(void); - - u8 GetRating(void); - u16 GetGameOverScores(void); - u8 GetLostTownDays(void); - u8 GetViewDistance(distance_t); - u8 GetWhirlpoolPercent(void); - u8 GetHeroRestoreSpellPointsPerDay(void); - - void ShowLoadMapsText(void); - - void EventEndTurn(menu_t &); - void EventExit(menu_t &); - void EventNextHero(void); - void EventNextTown(void); - void EventDefaultAction(void); - void EventOpenFocus(void); - void EventSaveGame(void); - void EventLoadGame(menu_t &); - void EventContinueMovement(void); - void EventKingdomInfo(void); - void EventCastSpell(void); - void EventPuzzleMaps(void); - void EventGameInfo(void); - void EventDigArtifact(menu_t &); - void EventAdventureDialog(menu_t &); - void EventFileDialog(menu_t &); - void EventSystemDialog(void); - void EventSwitchShowRadar(void); - void EventSwitchShowStatus(void); - void EventSwitchShowButtons(void); - void EventSwitchShowIcons(void); - void EventSwitchShowControlPanel(void); - void EventSwitchGroup(void); - - namespace Scenario - { - void RedrawStaticInfo(const Point &); - void RedrawDifficultyInfo(const Point & dst, bool label = true); - void RedrawOpponentsInfo(const Point &, const std::vector *players = NULL); - void RedrawClassInfo(const Point &, bool label = true); - } - - namespace Editor - { - Game::menu_t MainMenu(void); - Game::menu_t NewMaps(void); - Game::menu_t LoadMaps(void); - Game::menu_t StartGame(void); - Game::menu_t StartGame(void); - } -} - -#define HotKeyCloseWindow (Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || Game::HotKeyPress(Game::EVENT_DEFAULT_READY)) - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_delays.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_delays.cpp deleted file mode 100644 index 456aa7cd4..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_delays.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include - -#include "gamedefs.h" -#include "settings.h" -#include "game.h" - -struct TimeDelay : std::pair -{ - TimeDelay(int dl) - { - second = dl; - } - - int operator() (void) const - { - return second; - } - - void operator= (int dl) - { - second = dl; - } - - void Reset(void) - { - first.Start(); - } - - bool Trigger(void) - { - first.Stop(); - if(first.Get() < static_cast(second)) return false; - - first.Start(); - return true; - } -}; - -namespace Game -{ - void AnimateDelaysInitialize(void); - void UpdateBattleSpeed(); - - TimeDelay delays[] = { - 20, // SCROLL_DELAY - 400, // MAIN_MENU_DELAY - 700, // MAPS_DELAY - 200, // CASTLE_TAVERN_DELAY - 400, // CASTLE_AROUND_DELAY - 130, // CASTLE_BUYHERO_DELAY - 130, // CASTLE_BUILD_DELAY - 60, // HEROES_MOVE_DELAY - 40, // HEROES_FADE_DELAY - 40, // HEROES_PICKUP_DELAY - 50, // PUZZLE_FADE_DELAY - 300, // BATTLE_DIALOG_DELAY - 80, // BATTLE_FRAME_DELAY - 40, // BATTLE_MISSILE_DELAY - 90, // BATTLE_SPELL_DELAY - 20, // BATTLE_DISRUPTING_DELAY - 90, // BATTLE_CATAPULT_DELAY // catapult - 40, // BATTLE_CATAPULT2_DELAY // boulder - 40, // BATTLE_CATAPULT3_DELAY // cloud - 90, // BATTLE_BRIDGE_DELAY - 3000, // BATTLE_IDLE_DELAY - 200, // BATTLE_IDLE2_DELAY - 500, // BATTLE_OPPONENTS_DELAY - 300, // BATTLE_FLAGS_DELAY - 300, // AUTOHIDE_STATUS_DELAY - 0, // CURRENT_HERO_DELAY - 0, // CURRENT_AI_DELAY - 0 - }; -} - -void Game::AnimateDelaysInitialize(void) -{ - std::for_each(&delays[0], &delays[LAST_DELAY], std::mem_fun_ref(&TimeDelay::Reset)); - UpdateHeroesMoveSpeed(); - UpdateBattleSpeed(); -} - -void Game::AnimateDelayReset(delay_t dl) -{ - delays[dl].Reset(); -} - -bool Game::AnimateInfrequent(delay_t dl) -{ - return delays[dl].Trigger(); -} - -void Game::UpdateHeroesMoveSpeed(void) -{ - const Settings & conf = Settings::Get(); - - const TimeDelay & td_etalon = delays[HEROES_MOVE_DELAY]; - TimeDelay & td_hero = delays[CURRENT_HERO_DELAY]; - TimeDelay & td_ai = delays[CURRENT_AI_DELAY]; - - const int hr_value = conf.HeroesMoveSpeed() ? - ((conf.HeroesMoveSpeed() - DEFAULT_SPEED_DELAY) * td_etalon()) / DEFAULT_SPEED_DELAY : - td_etalon(); - - const int ai_value = conf.AIMoveSpeed() ? - ((conf.AIMoveSpeed() - DEFAULT_SPEED_DELAY) * td_etalon()) / DEFAULT_SPEED_DELAY : - td_etalon(); - - if(conf.HeroesMoveSpeed() == DEFAULT_SPEED_DELAY) - td_hero = td_etalon(); - else - td_hero = td_etalon() - hr_value; - - if(conf.AIMoveSpeed() == DEFAULT_SPEED_DELAY) - td_ai = td_etalon(); - else - td_ai = td_etalon() - ai_value; -} - -void Game::UpdateBattleSpeed(void) -{ - const Settings & conf = Settings::Get(); - - delays[BATTLE_FRAME_DELAY] = 80 - (conf.BattleSpeed() - DEFAULT_SPEED_DELAY) * 15; - delays[BATTLE_MISSILE_DELAY] = 40 - (conf.BattleSpeed() - DEFAULT_SPEED_DELAY) * 7; - delays[BATTLE_SPELL_DELAY] = 90 - (conf.BattleSpeed() - DEFAULT_SPEED_DELAY) * 17; - delays[BATTLE_DISRUPTING_DELAY] = 20 - (conf.BattleSpeed() - DEFAULT_SPEED_DELAY) * 3; - delays[BATTLE_CATAPULT_DELAY] = 90 - (conf.BattleSpeed() - DEFAULT_SPEED_DELAY) * 17; - delays[BATTLE_CATAPULT2_DELAY] = 40 - (conf.BattleSpeed() - DEFAULT_SPEED_DELAY) * 7; - delays[BATTLE_CATAPULT3_DELAY] = 40 - (conf.BattleSpeed() - DEFAULT_SPEED_DELAY) * 7; - delays[BATTLE_BRIDGE_DELAY] = 90 - (conf.BattleSpeed() - DEFAULT_SPEED_DELAY) * 17; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_focus.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_focus.cpp deleted file mode 100644 index 1dbd8052d..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_focus.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "castle.h" -#include "heroes.h" -#include "cursor.h" -#include "settings.h" -#include "game_interface.h" -#include "agg.h" -#include "world.h" -#include "kingdom.h" -#include "game_focus.h" - -Game::Focus::Focus() : castle(NULL), heroes(NULL) -{ -} - -Game::Focus & Game::Focus::Get(void) -{ - static Game::Focus gfocus; - - return gfocus; -} - -void Game::Focus::Set(Heroes *hero2) -{ - if(NULL == hero2) return; - - if(castle) - castle = NULL; - - if(heroes && hero2 != heroes) - { - heroes->SetMove(false); - heroes->ShowPath(false); - } - - heroes = hero2; - heroes->RescanPath(); - heroes->ShowPath(true); - - Interface::Basic & I = Interface::Basic::Get(); - - I.iconsPanel.Select(*heroes); - I.gameArea.Center(heroes->GetCenter()); - I.statusWindow.SetState(STATUS_ARMY); - - AGG::PlayMusic(MUS::FromGround(world.GetTiles(heroes->GetCenter()).GetGround())); - Game::EnvironmentSoundMixer(); -} - -void Game::Focus::Set(Castle *castle2) -{ - if(NULL == castle2) return; - - if(heroes) - { - heroes->SetMove(false); - heroes->ShowPath(false); - heroes = NULL; - } - - castle = castle2; - - Interface::Basic & I = Interface::Basic::Get(); - - I.iconsPanel.Select(*castle); - I.gameArea.Center(castle->GetCenter()); - I.statusWindow.SetState(STATUS_FUNDS); - - AGG::PlayMusic(MUS::FromGround(world.GetTiles(castle->GetCenter()).GetGround())); - Game::EnvironmentSoundMixer(); -} - -void Game::Focus::Reset(const focus_t priority) -{ - Kingdom & myKingdom = world.GetMyKingdom(); - - Interface::Basic & I = Interface::Basic::Get(); - - I.iconsPanel.ResetIcons(); - - switch(priority) - { - case HEROES: - if(heroes && heroes->GetColor() == Settings::Get().MyColor()) - Set(heroes); - else - if(myKingdom.GetHeroes().size()) - Set(myKingdom.GetHeroes().front()); - else - if(myKingdom.GetCastles().size()) - { - I.SetRedraw(REDRAW_HEROES); - Set(myKingdom.GetCastles().front()); - } - else - { - castle = NULL; - heroes = NULL; - } - break; - - case CASTLE: - if(castle && castle->GetColor() == Settings::Get().MyColor()) - Set(castle); - else - if(myKingdom.GetCastles().size()) - Set(myKingdom.GetCastles().front()); - else - if(myKingdom.GetHeroes().size()) - { - I.SetRedraw(REDRAW_CASTLES); - Set(myKingdom.GetHeroes().front()); - } - else - { - castle = NULL; - heroes = NULL; - } - break; - - default: - castle = NULL; - heroes = NULL; - break; - } -} - -Game::Focus::focus_t Game::Focus::Type(void) const -{ - if(heroes) return HEROES; - else - if(castle) return CASTLE; - - return UNSEL; -} - -const Castle & Game::Focus::GetCastle(void) const -{ - if(NULL == castle) DEBUG(DBG_GAME , DBG_WARN, "Game::Focus::GetCastle: is NULL"); - - return *castle; -} - -Castle & Game::Focus::GetCastle(void) -{ - if(NULL == castle) DEBUG(DBG_GAME , DBG_WARN, "Game::Focus::GetCastle: is NULL"); - - return *castle; -} - -const Heroes & Game::Focus::GetHeroes(void) const -{ - if(NULL == heroes) DEBUG(DBG_GAME , DBG_WARN, "Game::Focus::GetHeroes: is NULL"); - - return *heroes; -} - -Heroes & Game::Focus::GetHeroes(void) -{ - if(NULL == heroes) DEBUG(DBG_GAME , DBG_WARN, "Game::Focus::GetHeroes: is NULL"); - - return *heroes; -} - -const Point & Game::Focus::Center(void) const -{ - if(heroes) return heroes->GetCenter(); - else - if(castle) return castle->GetCenter(); - - return center; -} - -void Game::Focus::CheckIconsPanel(void) -{ - Interface::Basic & I = Interface::Basic::Get(); - - if(!heroes && I.iconsPanel.IsSelected(ICON_HEROES)) - { - I.iconsPanel.ResetIcons(ICON_HEROES); - I.SetRedraw(REDRAW_ICONS); - } - else - if(heroes && !I.iconsPanel.IsSelected(ICON_HEROES)) - { - I.iconsPanel.Select(*heroes); - I.SetRedraw(REDRAW_ICONS); - } - - if(!castle && I.iconsPanel.IsSelected(ICON_CASTLES)) - { - I.iconsPanel.ResetIcons(ICON_CASTLES); - I.SetRedraw(REDRAW_ICONS); - } - else - if(castle && !I.iconsPanel.IsSelected(ICON_CASTLES)) - { - I.iconsPanel.Select(*castle); - I.SetRedraw(REDRAW_ICONS); - } -} - -void Game::Focus::SetRedraw(void) -{ - Interface::Basic & I = Interface::Basic::Get(); - - CheckIconsPanel(); - - I.SetRedraw(REDRAW_GAMEAREA | REDRAW_RADAR); - - if(heroes) I.SetRedraw(REDRAW_HEROES); - else - if(castle) I.SetRedraw(REDRAW_CASTLES); - - I.SetRedraw(REDRAW_STATUS); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_focus.h b/project/jni/application/fheroes2/src/fheroes2/game/game_focus.h deleted file mode 100644 index 90acda928..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_focus.h +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2GAMEFOCUS_H -#define H2GAMEFOCUS_H - -#include "gamedefs.h" -#include "game.h" - -class Castle; -class Heroes; - -namespace Game -{ - class Focus - { - public: - enum focus_t { UNSEL, HEROES, CASTLE }; - - static Focus & Get(void); - - void Set(Heroes *hr); - void Set(Castle *cs); - void SetRedraw(void); - void Reset(const focus_t priority = UNSEL); - - void CheckIconsPanel(void); - - const Point & Center(void) const; - - focus_t Type(void) const; - - const Castle & GetCastle(void) const; - const Heroes & GetHeroes(void) const; - - Heroes & GetHeroes(void); - Castle & GetCastle(void); - - private: - Focus(); - - Castle * castle; - Heroes * heroes; - Point center; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_highscores.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_highscores.cpp deleted file mode 100644 index ee3f3fd03..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_highscores.cpp +++ /dev/null @@ -1,306 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include "gamedefs.h" -#include "agg.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" -#include "settings.h" -#include "world.h" -#include "sdlnet.h" -#include "zzlib.h" -#include "game.h" - -#define HGS_ID 0xF1F2 -#define HGS_MAX 10 - -struct hgs_t -{ - hgs_t() : days(0), rating(0) {}; - - bool operator== (const hgs_t &) const; - - std::string player; - std::string land; - u32 localtime; - u16 days; - u16 rating; -}; - -bool hgs_t::operator== (const hgs_t & h) const -{ - return player == h.player && land == h.land && days == h.days; -} - -bool RatingSort(const hgs_t & h1, const hgs_t & h2) -{ - return h1.rating < h2.rating; -} - -class HGSData : public QueueMessage -{ -public: - HGSData(){}; - - bool Load(const char*); - bool Save(const char*); - void ScoreRegistry(const std::string &, const std::string &, u16, u16); - void RedrawList(s16, s16); -private: - std::vector list; -}; - -bool HGSData::Load(const char* fn) -{ - std::ifstream fs(fn, std::ios::binary); - - if(!fs.is_open()) return false; - - fs.seekg(0, std::ios_base::end); - dtsz = fs.tellg(); - fs.seekg(0, std::ios_base::beg); - - if(data) delete [] data; - data = new char [dtsz]; - fs.read(data, dtsz); - fs.close(); - -#ifdef WITH_ZLIB - std::vector v; - if(ZLib::UnCompress(v, data, dtsz)) - { - dtsz = v.size(); - delete [] data; - data = new char [dtsz]; - std::memcpy(data, &v[0], dtsz); - v.clear(); - } -#endif - - itd1 = data; - itd2 = data + dtsz; - - u16 byte16; - - // check id - Pop(byte16); - if(byte16 != HGS_ID) return false; - - // size - Pop(byte16); - list.resize(byte16); - - std::vector::iterator it1 = list.begin(); - std::vector::const_iterator it2 = list.end(); - - for(; it1 != it2; ++it1) - { - hgs_t & hgs = *it1; - - Pop(hgs.player); - Pop(hgs.land); - Pop(hgs.localtime); - Pop(hgs.days); - Pop(hgs.rating); - } - - return true; -} - -bool HGSData::Save(const char* fn) -{ - std::ofstream fs(fn, std::ios::binary); - - if(!fs.is_open()) return false; - - Reset(); - - // set id - Push(static_cast(HGS_ID)); - // set size - Push(static_cast(list.size())); - - std::vector::const_iterator it1 = list.begin(); - std::vector::const_iterator it2 = list.end(); - - for(; it1 != it2; ++it1) - { - const hgs_t & hgs = *it1; - - Push(hgs.player); - Push(hgs.land); - Push(hgs.localtime); - Push(hgs.days); - Push(hgs.rating); - } - -#ifdef WITH_ZLIB - std::vector v; - if(!ZLib::Compress(v, data, DtSz())) return false; - fs.write(&v[0], v.size()); -#else - fs.write(data, DtSz()); -#endif - fs.close(); - - return true; -} - -void HGSData::ScoreRegistry(const std::string & p, const std::string & m, u16 r, u16 s) -{ - hgs_t h; - - h.player = p; - h.land = m; - h.localtime = std::time(NULL); - h.days = r; - h.rating = s; - - if(IS_DEVEL()) h.player+= " (+)"; - - if(list.end() == std::find(list.begin(), list.end(), h)) list.push_back(h); - if(list.size() > HGS_MAX) list.resize(HGS_MAX); -} - -void HGSData::RedrawList(s16 ox, s16 oy) -{ - const Settings & conf = Settings::Get(); - Display & display = Display::Get(); - - // image background - const Sprite &back = AGG::GetICN(ICN::HSBKG, 0); - display.Blit(back, ox, oy); - - std::sort(list.begin(), list.end(), RatingSort); - - std::vector::const_iterator it1 = list.begin(); - std::vector::const_iterator it2 = list.end(); - - Text text; - text.Set(conf.QVGA() ? Font::SMALL : Font::BIG); - std::string str; - - for(; it1 != it2 && (it1 - list.begin() < HGS_MAX); ++it1) - { - const hgs_t & hgs = *it1; - - text.Set(hgs.player); - text.Blit(ox + (conf.QVGA() ? 45 : 88), oy + (conf.QVGA() ? 33 : 70)); - - text.Set(hgs.land); - text.Blit(ox + (conf.QVGA() ? 170 : 260), oy + (conf.QVGA() ? 33 : 70)); - - str.clear(); - String::AddInt(str, hgs.days); - text.Set(str); - text.Blit(ox + (conf.QVGA() ? 250 : 420), oy + (conf.QVGA() ? 33 : 70)); - - str.clear(); - String::AddInt(str, hgs.rating); - text.Set(str); - text.Blit(ox + (conf.QVGA() ? 270 : 480), oy + (conf.QVGA() ? 33 : 70)); - - oy += conf.QVGA() ? 20 : 40; - } -} - -Game::menu_t Game::HighScores(void) -{ - const Settings & conf = Settings::Get(); - HGSData hgs; - - std::ostringstream stream; - stream << conf.LocalPrefix() << SEPARATOR << "files" << SEPARATOR << "save" << SEPARATOR << "fheroes2.hgs"; - - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - - cursor.SetThemes(cursor.POINTER); - Mixer::Pause(); - AGG::PlayMusic(MUS::MAINMENU); - hgs.Load(stream.str().c_str()); - - const Sprite &back = AGG::GetICN(ICN::HSBKG, 0); - - cursor.Hide(); - display.Fill(0, 0, 0); - const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2); - - hgs.RedrawList(top.x, top.y); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonCampain(top.x + (conf.QVGA() ? 0 : 9), top.y + (conf.QVGA() ? 100 : 315), ICN::HISCORE, 0, 1); - Button buttonExit(top.x + back.w() - (conf.QVGA() ? 27 : 36), top.y + (conf.QVGA() ? 100 : 315), ICN::HISCORE, 4, 5); - - buttonCampain.Draw(); - buttonExit.Draw(); - - cursor.Show(); - display.Flip(); - - const u16 rating = GetGameOverScores(); - const u16 days = world.CountDay(); - GameOver::Result & gameResult = GameOver::Result::Get(); - - if(rating && (gameResult.GetResult() & GameOver::WINS)) - { - std::string player("Unknown Hero"); - Dialog::InputString("Your Name", player); - cursor.Hide(); - if(player.empty()) player = "Unknown Hero"; - hgs.ScoreRegistry(player, Settings::Get().CurrentFileInfo().name, days, rating); - hgs.Save(stream.str().c_str()); - hgs.RedrawList(top.x, top.y); - buttonCampain.Draw(); - buttonExit.Draw(); - cursor.Show(); - display.Flip(); - gameResult.Reset(); - } - - // highscores loop - while(le.HandleEvents()) - { - // key code info - if(IS_DEBUG(DBG_ENGINE, DBG_INFO) && le.KeyPress()) - { - std::string str; - String::AddInt(str, le.KeyValue()); - Dialog::Message("Key Press:", str, Font::SMALL, Dialog::OK); - } - le.MousePressLeft(buttonCampain) ? buttonCampain.PressDraw() : buttonCampain.ReleaseDraw(); - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - - if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) return MAINMENU; - } - - return QUITGAME; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_hotkeys.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_hotkeys.cpp deleted file mode 100644 index 2729765eb..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_hotkeys.cpp +++ /dev/null @@ -1,309 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include - -#include "gamedefs.h" -#include "tinyconfig.h" -#include "agg.h" -#include "settings.h" -#include "game.h" - -namespace Game -{ - void HotKeysDefaults(void); - void HotKeysLoad(const std::string &); - const char* EventsName(events_t); - void KeyboardGlobalFilter(int, u16); - - events_t & operator++ (events_t & evnt) - { - return evnt = (EVENT_LAST == evnt ? EVENT_NONE : events_t(evnt + 1)); - } - - KeySym key_events[EVENT_LAST]; - static int key_groups = 0; -} - -const char* Game::EventsName(events_t evnt) -{ - switch(evnt) - { - case EVENT_BUTTON_NEWGAME: return "button newgame"; - case EVENT_BUTTON_LOADGAME: return "button loadgame"; - case EVENT_BUTTON_HIGHSCORES: return "button highscores"; - case EVENT_BUTTON_CREDITS: return "button credits"; - case EVENT_BUTTON_STANDARD: return "button standard"; - case EVENT_BUTTON_CAMPAIN: return "button campain"; - case EVENT_BUTTON_MULTI: return "button multigame"; - case EVENT_BUTTON_SETTINGS: return "button settings"; - case EVENT_BUTTON_SELECT: return "button select"; - case EVENT_BUTTON_HOTSEAT: return "button hotseat"; - case EVENT_BUTTON_NETWORK: return "button network"; - case EVENT_BUTTON_HOST: return "button host"; - case EVENT_BUTTON_GUEST: return "button guest"; - - case EVENT_DEFAULT_READY: return "default ready"; - case EVENT_DEFAULT_EXIT: return "default exit"; - case EVENT_DEFAULT_LEFT: return "default left"; - case EVENT_DEFAULT_RIGHT: return "default right"; - - case EVENT_SYSTEM_FULLSCREEN: return "system fullscreen"; - case EVENT_SYSTEM_SCREENSHOT: return "system screenshot"; - case EVENT_SYSTEM_DEBUG1: return "system debug1"; - case EVENT_SYSTEM_DEBUG2: return "system debug2"; - - case EVENT_ENDTURN: return "end turn"; - case EVENT_NEXTHERO: return "next hero"; - case EVENT_NEXTTOWN: return "next town"; - case EVENT_CONTINUE: return "continue move"; - case EVENT_SAVEGAME: return "save game"; - case EVENT_LOADGAME: return "load game"; - case EVENT_FILEOPTIONS: return "show file dialog"; - case EVENT_SYSTEMOPTIONS: return "show system options"; - case EVENT_PUZZLEMAPS: return "show puzzle maps"; - case EVENT_INFOGAME: return "show game info"; - case EVENT_DIGARTIFACT: return "dig artifact"; - case EVENT_CASTSPELL: return "cast spell"; - case EVENT_DEFAULTACTION: return "default action"; - - case EVENT_BATTLE_CASTSPELL: return "battle cast spell"; - case EVENT_BATTLE_RETREAT: return "battle retreat"; - case EVENT_BATTLE_SURRENDER: return "battle surrender"; - case EVENT_BATTLE_AUTOSWITCH: return "battle auto switch"; - case EVENT_BATTLE_OPTIONS: return "battle options"; - case EVENT_BATTLE_HARDSKIP: return "battle hard skip"; - case EVENT_BATTLE_SOFTSKIP: return "battle soft skip"; - - case EVENT_MOVELEFT: return "move left"; - case EVENT_MOVERIGHT: return "move right"; - case EVENT_MOVETOP: return "move top"; - case EVENT_MOVEBOTTOM: return "move bottom"; - case EVENT_MOVETOPLEFT: return "move top left"; - case EVENT_MOVETOPRIGHT: return "move top right"; - case EVENT_MOVEBOTTOMLEFT: return "move bottom left"; - case EVENT_MOVEBOTTOMRIGHT: return "move bottom right"; - case EVENT_OPENFOCUS: return "open focus"; - case EVENT_SCROLLLEFT: return "scroll left"; - case EVENT_SCROLLRIGHT: return "scroll right"; - case EVENT_SCROLLUP: return "scroll up"; - case EVENT_SCROLLDOWN: return "scroll down"; - case EVENT_CTRLPANEL: return "control panel"; - case EVENT_SHOWRADAR: return "show radar"; - case EVENT_SHOWBUTTONS: return "show buttons"; - case EVENT_SHOWSTATUS: return "show status"; - case EVENT_SHOWICONS: return "show icons"; - case EVENT_EMULATETOGGLE: return "emulate mouse toggle"; - case EVENT_SWITCHGROUP: return "switch group"; - default: break; - } - return NULL; -} - -void Game::HotKeysDefaults(void) -{ - std::fill(&key_events[0], &key_events[EVENT_LAST], KEY_NONE); - - // main menu - key_events[EVENT_BUTTON_NEWGAME] = KEY_n; - key_events[EVENT_BUTTON_LOADGAME] = KEY_l; - key_events[EVENT_BUTTON_HIGHSCORES] = KEY_h; - key_events[EVENT_BUTTON_CREDITS] = KEY_c; - key_events[EVENT_BUTTON_STANDARD] = KEY_s; - key_events[EVENT_BUTTON_CAMPAIN] = KEY_c; - key_events[EVENT_BUTTON_MULTI] = KEY_m; - key_events[EVENT_BUTTON_SETTINGS] = KEY_t; - key_events[EVENT_BUTTON_SELECT] = KEY_s; - key_events[EVENT_BUTTON_HOTSEAT] = KEY_h; - key_events[EVENT_BUTTON_NETWORK] = KEY_n; - key_events[EVENT_BUTTON_HOST] = KEY_h; - key_events[EVENT_BUTTON_GUEST] = KEY_g; - - // default - key_events[EVENT_DEFAULT_READY] = KEY_RETURN; - key_events[EVENT_DEFAULT_EXIT] = KEY_ESCAPE; - key_events[EVENT_DEFAULT_LEFT] = KEY_NONE; - key_events[EVENT_DEFAULT_RIGHT] = KEY_NONE; - - // system - key_events[EVENT_SYSTEM_FULLSCREEN] = KEY_F4; - key_events[EVENT_SYSTEM_SCREENSHOT] = KEY_PRINT; - key_events[EVENT_SYSTEM_DEBUG1] = KEY_NONE; - key_events[EVENT_SYSTEM_DEBUG2] = KEY_NONE; - - // battle - key_events[EVENT_BATTLE_CASTSPELL] = KEY_c; - key_events[EVENT_BATTLE_RETREAT] = KEY_ESCAPE; - key_events[EVENT_BATTLE_SURRENDER] = KEY_s; - key_events[EVENT_BATTLE_AUTOSWITCH] = KEY_a; - key_events[EVENT_BATTLE_OPTIONS] = KEY_o; - key_events[EVENT_BATTLE_HARDSKIP] = KEY_h; - key_events[EVENT_BATTLE_SOFTSKIP] = KEY_SPACE; - - // end turn - key_events[EVENT_ENDTURN] = KEY_e; - // next hero - key_events[EVENT_NEXTHERO] = KEY_h; - // next town - key_events[EVENT_NEXTTOWN] = KEY_t; - // continue (move hero) - key_events[EVENT_CONTINUE] = KEY_m; - // save game - key_events[EVENT_SAVEGAME] = KEY_s; - // load game - key_events[EVENT_LOADGAME] = KEY_l; - // show file dialog - key_events[EVENT_FILEOPTIONS] = KEY_f; - // show system options - key_events[EVENT_SYSTEMOPTIONS] = KEY_o; - // show puzzle maps - key_events[EVENT_PUZZLEMAPS] = KEY_p; - // show game info - key_events[EVENT_INFOGAME] = KEY_i; - // dig artifact - key_events[EVENT_DIGARTIFACT] = KEY_d; - // cast spell - key_events[EVENT_CASTSPELL] = KEY_c; - // default action - key_events[EVENT_DEFAULTACTION] = KEY_RETURN; - // move hero - key_events[EVENT_MOVELEFT] = KEY_LEFT; - key_events[EVENT_MOVERIGHT] = KEY_RIGHT; - key_events[EVENT_MOVETOP] = KEY_UP; - key_events[EVENT_MOVEBOTTOM] = KEY_DOWN; - //key_events[EVENT_MOVEBOTTOM] = KEVENT_MOVETOPLEFT] = KEY_NONE; - //key_events[EVENT_MOVEBOTTOM] = KEVENT_MOVETOPRIGHT] = KEY_NONE; - //key_events[EVENT_MOVEBOTTOM] = KEVENT_MOVEBOTTOMLEFT] = KEY_NONE; - //key_events[EVENT_MOVEBOTTOM] = KEVENT_MOVEBOTTOMRIGHT] = KEY_NONE; - // open focus - // key_events[EVENT_OPENFOCUS] = KEY_NONE; - // scroll - // key_events[EVENT_SCROLLLEFT] = KEY_NONE; - // key_events[EVENT_SCROLLRIGHT] = KEY_NONE; - // key_events[EVENT_SCROLLUP] = KEY_NONE; - // key_events[EVENT_SCROLLDOWN] = KEY_NONE; - // control panel - key_events[EVENT_CTRLPANEL] = KEY_1; - key_events[EVENT_SHOWRADAR] = KEY_2; - key_events[EVENT_SHOWBUTTONS] = KEY_3; - key_events[EVENT_SHOWSTATUS] = KEY_4; - key_events[EVENT_SHOWICONS] = KEY_5; - // system: - // emulate mouse - // key_events[EVENT_EMULATETOGGLE] = KEY_NONE; - // switch group - // key_events[EVENT_SWITCHGROUP] = KEY_NONE; -} - -void Game::EventSwitchGroup(void) -{ - ++key_groups; -} - -bool Game::HotKeyPress(events_t evnt) -{ - LocalEvent & le = LocalEvent::Get(); - return le.KeyPress() && le.KeyValue() == key_events[evnt]; -} - -void Game::HotKeysLoad(const std::string & hotkeys) -{ - Tiny::Config config; - const Tiny::Entry* entry = NULL; - - config.SetSeparator('='); - config.SetComment('#'); - - if(config.Load(hotkeys.c_str())) - { - for(events_t evnt = EVENT_NONE; evnt < EVENT_LAST; ++evnt) - { - const char* name = EventsName(evnt); - if(name) - { - entry = config.Find(name); - if(entry) - { - const KeySym sym = GetKeySym(entry->IntParams()); - key_events[evnt] = sym; - DEBUG(DBG_GAME, DBG_INFO, "Game::HotKeysLoad: events: " << EventsName(evnt) << ", key: " << KeySymGetName(sym)); - } - } - } - -#ifdef WITHOUT_MOUSE - LocalEvent & le = LocalEvent::Get(); - - entry = config.Find("emulate mouse up"); - if(entry) le.SetEmulateMouseUpKey(GetKeySym(entry->IntParams())); - - entry = config.Find("emulate mouse down"); - if(entry) le.SetEmulateMouseDownKey(GetKeySym(entry->IntParams())); - - entry = config.Find("emulate mouse left"); - if(entry) le.SetEmulateMouseLeftKey(GetKeySym(entry->IntParams())); - - entry = config.Find("emulate mouse right"); - if(entry) le.SetEmulateMouseRightKey(GetKeySym(entry->IntParams())); - - entry = config.Find("emulate press left"); - if(entry) le.SetEmulatePressLeftKey(GetKeySym(entry->IntParams())); - - entry = config.Find("emulate press right"); - if(entry) le.SetEmulatePressRightKey(GetKeySym(entry->IntParams())); -#endif - } -} - -void Game::KeyboardGlobalFilter(int sym, u16 mod) -{ - Display & display = Display::Get(); - - // system hotkeys - if(sym == key_events[EVENT_SYSTEM_FULLSCREEN]) - display.FullScreen(); - else - if(sym == key_events[EVENT_SYSTEM_SCREENSHOT]) - { - std::ostringstream stream; - stream << Settings::Get().LocalPrefix() << SEPARATOR << "files" << SEPARATOR << "save" << SEPARATOR << "screenshot_" << std::time(0); - -#ifndef WITH_IMAGE - stream << ".bmp"; -#else - stream << ".png"; -#endif - if(display.Save(stream.str().c_str())) DEBUG(DBG_GAME , DBG_INFO, "Game::KeyboardGlobalFilter: save: " << stream.str()); - } - else - if(sym == key_events[EVENT_SYSTEM_DEBUG1]) - { - AGG::Cache::Get().Dump(); - } - else - if(sym == key_events[EVENT_SYSTEM_DEBUG2]) - { - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_interface.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_interface.cpp deleted file mode 100644 index a0fa20ed0..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_interface.cpp +++ /dev/null @@ -1,286 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "settings.h" -#include "maps.h" -#include "mp2.h" -#include "world.h" -#include "dialog.h" -#include "game_focus.h" -#include "game_interface.h" - -bool Interface::NoGUI(void) -{ - const Settings & conf = Settings::Get(); - - return conf.NetworkDedicatedServer(); -} - -Interface::Basic::Basic() : gameArea(GameArea::Get()), radar(Radar::Get()), - iconsPanel(IconsPanel::Get()), buttonsArea(ButtonsArea::Get()), - statusWindow(StatusWindow::Get()), borderWindow(BorderWindow::Get()), - controlPanel(ControlPanel::Get()), redraw(0) -{ - Settings & conf = Settings::Get().Get(); - const Display & display = Display::Get(); - const u16 & px = display.w() - BORDERWIDTH - RADARWIDTH; - const u8 scroll_width = conf.QVGA() ? 12 : BORDERWIDTH; - - if(conf.HideInterface()) - { - iconsPanel.SetCount(2); - conf.SetShowPanel(true); - - Point pos_radr = conf.PosRadar(); - Point pos_bttn = conf.PosButtons(); - Point pos_icon = conf.PosIcons(); - Point pos_stat = conf.PosStatus(); - - if(0 == pos_radr.x && 0 == pos_radr.y) - pos_radr = Point(BORDERWIDTH, conf.QVGA() ? TILEWIDTH : BORDERWIDTH); - if(0 == pos_icon.x && 0 == pos_icon.y) - pos_icon = Point(conf.QVGA() ? BORDERWIDTH : px - BORDERWIDTH, conf.QVGA() ? TILEWIDTH : radar.GetArea().y + radar.GetArea().h); - if(0 == pos_bttn.x && 0 == pos_bttn.y) - pos_bttn = Point(conf.QVGA() ? BORDERWIDTH : px - BORDERWIDTH, conf.QVGA() ? TILEWIDTH : iconsPanel.GetArea().y + iconsPanel.GetArea().h); - if(0 == pos_stat.x && 0 == pos_stat.y) - pos_stat = Point(conf.QVGA() ? BORDERWIDTH : px - BORDERWIDTH, conf.QVGA() ? TILEWIDTH : buttonsArea.GetArea().y + buttonsArea.GetArea().h); - - controlPanel.SetPos(display.w() - controlPanel.GetArea().w - scroll_width, 0); - radar.SetPos(pos_radr.x, pos_radr.y); - iconsPanel.SetPos(pos_icon.x, pos_icon.y); - buttonsArea.SetPos(pos_bttn.x, pos_bttn.y); - statusWindow.SetPos(pos_stat.x, pos_stat.y); - } - else - { - radar.SetPos(px, BORDERWIDTH); - iconsPanel.SetPos(px, radar.GetArea().y + radar.GetArea().h + BORDERWIDTH); - - const u8 count_h = (display.h() - 480) / TILEWIDTH; - iconsPanel.SetCount(count_h > 3 ? 8 : ( count_h < 3 ? 4 : 7)); - - buttonsArea.SetPos(px, iconsPanel.GetArea().y + iconsPanel.GetArea().h + BORDERWIDTH); - statusWindow.SetPos(px, buttonsArea.GetArea().y + buttonsArea.GetArea().h); - } - - scrollLeft = Rect(0, 0, scroll_width, display.h()); - scrollRight = Rect(display.w() - scroll_width, 0, scroll_width, display.h()); - scrollTop = conf.QVGA() ? Rect(0, 0, controlPanel.GetArea().x, scroll_width) : Rect(0, 0, display.w() - radar.GetArea().w, scroll_width); - scrollBottom = Rect(0, display.h() - scroll_width, display.w(), scroll_width); - - system_info.Set(Font::YELLOW_SMALL); -} - -Interface::Basic & Interface::Basic::Get(void) -{ - static Basic basic; - return basic; -} - -const Rect & Interface::Basic::GetAreaScrollLeft(void) const -{ - return scrollLeft; -} - -const Rect & Interface::Basic::GetAreaScrollRight(void) const -{ - return scrollRight; -} - -const Rect & Interface::Basic::GetAreaScrollTop(void) const -{ - return scrollTop; -} - -const Rect & Interface::Basic::GetAreaScrollBottom(void) const -{ - return scrollBottom; -} - - -bool Interface::Basic::NeedRedraw(void) const -{ - return redraw; -} - -void Interface::Basic::SetRedraw(u8 f) -{ - redraw |= f; -} - -void Interface::Basic::Redraw(u8 force) -{ - Settings & conf = Settings::Get(); - - if((redraw | force) & REDRAW_GAMEAREA) gameArea.Redraw(Display::Get(), LEVEL_ALL); - - if((conf.HideInterface() && conf.ShowRadar()) || ((redraw | force) & REDRAW_RADAR)) radar.Redraw(); - - if((conf.HideInterface() && conf.ShowIcons()) || ((redraw | force) & REDRAW_ICONS)) iconsPanel.Redraw(); - else - if((redraw | force) & REDRAW_HEROES) iconsPanel.RedrawIcons(ICON_HEROES); - else - if((redraw | force) & REDRAW_CASTLES) iconsPanel.RedrawIcons(ICON_CASTLES); - - if((conf.HideInterface() && conf.ShowButtons()) || ((redraw | force) & REDRAW_BUTTONS)) buttonsArea.Redraw(); - - if((conf.HideInterface() && conf.ShowStatus()) || ((redraw | force) & REDRAW_STATUS)) statusWindow.Redraw(); - - if(conf.HideInterface() && conf.ShowControlPanel() && (redraw & REDRAW_GAMEAREA)) controlPanel.Redraw(); - - u32 usage = GetMemoryUsage(); - - // show system info - if(conf.ExtShowSystemInfo() && usage) - RedrawSystemInfo((conf.HideInterface() ? 10 : 26), Display::Get().h() - (conf.HideInterface() ? 14 : 30), usage); - - // memory limit trigger - if(conf.ExtLowMemory() && conf.MemoryLimit() && usage) - { - if(conf.MemoryLimit() < usage) - { - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - - cursor.Hide(); - Mixer::Reset(); - - Rect rect((display.w() - 90) / 2, (display.h() - 30) / 2, 90, 45); - TextBox text("memory limit\nclear cache\nwaiting...", Font::SMALL, rect.w); - - display.FillRect(0, 0, 0, rect); - text.Blit(rect.x, rect.y); - - display.Flip(); - - AGG::Cache & cache = AGG::Cache::Get(); - - VERBOSE("MemoryLimit: " << "settings: " << conf.MemoryLimit() << ", game usage: " << usage); - cache.ClearAllICN(); - VERBOSE("MemoryLimit: " << "free all " << "ICN" << ", game usage: " << GetMemoryUsage()); - cache.ClearAllWAV(); - VERBOSE("MemoryLimit: " << "free all " << "WAV" << ", game usage: " << GetMemoryUsage()); - cache.ClearAllMID(); - VERBOSE("MemoryLimit: " << "free all " << "MID" << ", game usage: " << GetMemoryUsage()); - - redraw = 0xFF; - if(conf.HideInterface()) redraw &= ~REDRAW_BORDER; - - cursor.SetThemes(cursor.Themes(), true); - cursor.Show(); - - AGG::PlayMusic(MUS::FromGround(world.GetTiles(Game::Focus::Get().Center()).GetGround())); - Game::EnvironmentSoundMixer(); - } - - usage = GetMemoryUsage(); - - if(conf.MemoryLimit() < usage + (300 * 1024)) - { - VERBOSE("MemoryLimit: " << "settings: " << conf.MemoryLimit() << ", too small"); - - // increase + 300Kb - conf.SetMemoryLimit(usage + (300 * 1024)); - - VERBOSE("MemoryLimit: " << "settings: " << "increase limit on 300kb, current value: " << conf.MemoryLimit()); - } - } - - if((redraw | force) & REDRAW_BORDER) borderWindow.Redraw(); - - redraw = 0; -} - -void Interface::Basic::RedrawSystemInfo(s16 cx, s16 cy, u32 usage) -{ - std::ostringstream os; - - os << "mem. usage: " << usage / 1024 << "Kb" << ", cur. time: "; - - time_t rawtime; - std::time(&rawtime); - // strtime format: Www Mmm dd hh:mm:ss yyyy - const char* strtime = std::ctime(&rawtime); - - // draw info - os << std::string(&strtime[11], 8); - - system_info.Set(os.str()); - system_info.Blit(cx, cy); -} - -s32 Interface::Basic::GetDimensionDoorDestination(const s32 from, const u8 distance) const -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - s32 dst = -1; - - while(le.HandleEvents()) - { - const Point & mp = le.GetMouseCursor(); - dst = gameArea.GetIndexFromMousePoint(mp); - if(0 > dst) break; - - const Maps::Tiles & tile = world.GetTiles(dst); - - const bool valid = ((gameArea.GetArea() & mp) && - dst >= 0 && - (! tile.isFog(conf.MyColor())) && - MP2::isClearGroundObject(tile.GetObject()) && - Maps::Ground::WATER != world.GetTiles(dst).GetGround() && - distance >= Maps::GetApproximateDistance(from, dst)); - - cursor.SetThemes(valid ? Cursor::MOVE : Cursor::WAR_NONE); - - // exit - if(le.MousePressRight()) break; - else - if(Cursor::MOVE == cursor.Themes() && le.MouseClickLeft()) return dst; - - // redraw cursor - if(!cursor.isVisible()) - { - cursor.Show(); - display.Flip(); - } - } - - return -1; -} - -void Interface::FixOutOfDisplay(const Rect & rt, s16 & ox, s16 & oy) -{ - Display & display = Display::Get(); - - if(ox + rt.w < 0) ox = 0; - else - if(ox > display.w() - rt.w + BORDERWIDTH) ox = display.w() - rt.w; - - if(oy + rt.h < 0) oy = 0; - else - if(oy > display.h() - rt.h + BORDERWIDTH) oy = display.h() - rt.h; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_interface.h b/project/jni/application/fheroes2/src/fheroes2/game/game_interface.h deleted file mode 100644 index 2f4a70a59..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_interface.h +++ /dev/null @@ -1,95 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2GAMEINTERFACE_H -#define H2GAMEINTERFACE_H - -#include "gamedefs.h" -#include "interface_border.h" -#include "interface_radar.h" -#include "interface_buttons.h" -#include "interface_icons.h" -#include "interface_status.h" -#include "interface_gamearea.h" -#include "interface_cpanel.h" - -enum redraw_t -{ - REDRAW_RADAR = 0x01, - REDRAW_HEROES = 0x02, - REDRAW_CASTLES = 0x04, - REDRAW_BUTTONS = 0x08, - REDRAW_STATUS = 0x10, - REDRAW_BORDER = 0x20, - REDRAW_GAMEAREA = 0x40, - REDRAW_CURSOR = 0x80, - - REDRAW_ICONS = REDRAW_HEROES | REDRAW_CASTLES, - REDRAW_ALL = 0xFF -}; - -namespace Interface -{ - bool NoGUI(void); - - void FixOutOfDisplay(const Rect &, s16 & , s16 &); - - class Basic - { - public: - static Basic & Get(void); - - bool NeedRedraw(void) const; - void SetRedraw(u8); - void Redraw(u8 f = 0); - - const Rect & GetAreaScrollLeft(void) const; - const Rect & GetAreaScrollRight(void) const; - const Rect & GetAreaScrollTop(void) const; - const Rect & GetAreaScrollBottom(void) const; - - s32 GetDimensionDoorDestination(const s32, const u8) const; - - GameArea & gameArea; - Radar & radar; - IconsPanel & iconsPanel; - ButtonsArea & buttonsArea; - StatusWindow & statusWindow; - BorderWindow & borderWindow; - ControlPanel & controlPanel; - - private: - Basic(); - void RedrawSystemInfo(s16, s16, u32); - - u8 redraw; - - Rect scrollLeft; - Rect scrollRight; - Rect scrollBottom; - Rect scrollTop; - - Text system_info; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_io.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_io.cpp deleted file mode 100644 index 04d5a0a02..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_io.cpp +++ /dev/null @@ -1,1291 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include "zzlib.h" -#include "settings.h" -#include "kingdom.h" -#include "heroes.h" -#include "castle.h" -#include "army.h" -#include "world.h" -#include "gameevent.h" -#include "interface_gamearea.h" -#include "settings.h" -#include "tools.h" - -std::string Game::IO::last_name; - -bool Game::Save(const std::string &fn) -{ - DEBUG(DBG_GAME , DBG_INFO, "Game::Save: " << fn); - const bool autosave = std::string::npos != fn.find("autosave.sav"); - - if(Settings::Get().ExtRewriteConfirm() && FilePresent(fn) && - (!autosave || Settings::Get().ExtAutosaveConfirm()) && - Dialog::NO == Dialog::Message("", _("Are you sure you want to overwrite the save with this name?"), Font::BIG, Dialog::YES|Dialog::NO)) - { - return false; - } - - Game::IO msg; - - if(! Game::IO::SaveBIN(msg)) return false; - -#ifdef WITH_ZLIB - std::ofstream fs(fn.c_str(), std::ios::binary); - if(!fs.is_open()) return false; - std::vector v; - if(!ZLib::Compress(v, msg.DtPt(), msg.DtSz())) return false; - fs.write(&v[0], v.size()); - fs.close(); -#else - msg.Save(fn.c_str()); -#endif - - if(! autosave) Game::IO::last_name = fn; - - return true; -} - -bool Game::IO::LoadSAV(const std::string & fn) -{ - if(fn.empty()) return false; - - Load(fn.c_str()); - -#ifdef WITH_ZLIB - std::vector v; - if(ZLib::UnCompress(v, data, dtsz)) - { - dtsz = v.size(); - delete [] data; - data = new char [dtsz + 1]; - itd1 = data; - itd2 = data + dtsz; - - std::memcpy(data, &v[0], dtsz); - v.clear(); - } -#endif - - return true; -} - -bool Game::Load(const std::string & fn) -{ - DEBUG(DBG_GAME , DBG_INFO, "Game::Load: " << fn); - - // loading info - Game::ShowLoadMapsText(); - - Game::IO msg; - if(!msg.LoadSAV(fn) || !Game::IO::LoadBIN(msg)) return false; - - Game::IO::last_name = fn; - Settings::Get().SetLoadedGameVersion(true); - - return true; -} - -bool Game::LoadSAV2FileInfo(const std::string & fn, Maps::FileInfo & maps_file) -{ - Game::IO msg; - - if(!msg.LoadSAV(fn)) return false; - - u8 byte8; - u16 byte16, version; - u32 byte32; - std::string str; - - maps_file.file = fn; - - msg.Pop(byte16); - if(byte16 != 0xFF01) return false; - // format version - msg.Pop(version); - // major version - msg.Pop(byte8); - // minor version - msg.Pop(byte8); - // svn - msg.Pop(str); - // time - msg.Pop(byte32); - maps_file.localtime = byte32; - - // maps - msg.Pop(byte16); - if(FORMAT_VERSION_2031 <= version) - { - msg.Pop(maps_file.size_w); - msg.Pop(maps_file.size_h); - } - else - { - msg.Pop(byte8); maps_file.size_w = byte8; - msg.Pop(byte8); maps_file.size_h = byte8; - } - msg.Pop(str); - msg.Pop(maps_file.difficulty); - msg.Pop(maps_file.kingdom_colors); - msg.Pop(maps_file.human_colors); - msg.Pop(maps_file.computer_colors); - msg.Pop(maps_file.rnd_races); - msg.Pop(maps_file.conditions_wins); - msg.Pop(maps_file.wins1); - msg.Pop(maps_file.wins2); - msg.Pop(maps_file.wins3); - msg.Pop(maps_file.wins4); - msg.Pop(maps_file.conditions_loss); - msg.Pop(maps_file.loss1); - msg.Pop(maps_file.loss2); - // races - msg.Pop(byte16); - msg.Pop(byte8); maps_file.races[0] = byte8; - msg.Pop(byte8); maps_file.races[1] = byte8; - msg.Pop(byte8); maps_file.races[2] = byte8; - msg.Pop(byte8); maps_file.races[3] = byte8; - msg.Pop(byte8); maps_file.races[4] = byte8; - msg.Pop(byte8); maps_file.races[5] = byte8; - // maps name - msg.Pop(maps_file.name); - // maps description - msg.Pop(maps_file.description); - - return true; -} - -bool Game::IO::SaveBIN(QueueMessage & msg) -{ - const Settings & conf = Settings::Get(); - - msg.Reserve(world.w() > Maps::MEDIUM ? 600 * 1024 : 200 * 1024); - - msg.Push(static_cast(0xFF01)); - // format version - msg.Push(static_cast(CURRENT_FORMAT_VERSION)); - // version - msg.Push(conf.major_version); - msg.Push(conf.minor_version); - // svn - msg.Push(conf.svn_version); - // time - msg.Push(static_cast(std::time(NULL))); - // lang - msg.Push(conf.force_lang); - - // maps - msg.Push(static_cast(0xFF02)); - msg.Push(conf.current_maps_file.size_w); - msg.Push(conf.current_maps_file.size_h); - msg.Push(GetBasename(conf.current_maps_file.file)); - msg.Push(conf.current_maps_file.difficulty); - msg.Push(conf.current_maps_file.kingdom_colors); - msg.Push(conf.current_maps_file.human_colors); - msg.Push(conf.current_maps_file.computer_colors); - msg.Push(conf.current_maps_file.rnd_races); - msg.Push(conf.current_maps_file.conditions_wins); - msg.Push(conf.current_maps_file.wins1); - msg.Push(conf.current_maps_file.wins2); - msg.Push(conf.current_maps_file.wins3); - msg.Push(conf.current_maps_file.wins4); - msg.Push(conf.current_maps_file.conditions_loss); - msg.Push(conf.current_maps_file.loss1); - msg.Push(conf.current_maps_file.loss2); - // races - msg.Push(static_cast(0xFF03)); - msg.Push(static_cast(KINGDOMMAX)); - for(u32 ii = 0; ii < KINGDOMMAX; ++ii) - msg.Push(conf.current_maps_file.races[ii]); - // unions - msg.Push(static_cast(KINGDOMMAX)); - for(u32 ii = 0; ii < KINGDOMMAX; ++ii) - msg.Push(conf.current_maps_file.unions[ii]); - // maps name - msg.Push(conf.current_maps_file.name); - // maps description - msg.Push(conf.current_maps_file.description); - // game - msg.Push(static_cast(0xFF04)); - msg.Push(static_cast(conf.game_difficulty)); - msg.Push(static_cast(conf.my_color)); - msg.Push(static_cast(conf.cur_color)); - msg.Push(conf.game_type); - msg.Push(conf.players_colors); - msg.Push(conf.preferably_count_players); - msg.Push(conf.debug); - - msg.Push(conf.opt_game()); - msg.Push(conf.opt_world()); - msg.Push(conf.opt_battle()); - - // world - msg.Push(static_cast(0xFF05)); - msg.Push(world.width); - msg.Push(world.height); - msg.Push(world.ultimate_artifact); - msg.Push(world.uniq0); - msg.Push(static_cast(world.week_name)); - msg.Push(static_cast(world.heroes_cond_wins)); - msg.Push(static_cast(world.heroes_cond_loss)); - msg.Push(world.month); - msg.Push(world.week); - msg.Push(world.day); - - // tiles - msg.Push(static_cast(0xFF06)); - msg.Push(static_cast(world.vec_tiles.size())); - for(u32 ii = 0; ii < world.vec_tiles.size(); ++ii) - { - if(NULL == world.vec_tiles[ii]){ DEBUG(DBG_GAME , DBG_WARN, "Game::IO::SaveBIN: tiles is NULL"); return false; } - PackTile(msg, *world.vec_tiles[ii]); - } - - // heroes - msg.Push(static_cast(0xFF07)); - msg.Push(static_cast(world.vec_heroes.size())); - for(u32 ii = 0; ii < world.vec_heroes.size(); ++ii) - { - if(NULL == world.vec_heroes[ii]){ DEBUG(DBG_GAME , DBG_WARN, "Game::IO::SaveBIN: heroes is NULL"); return false; } - PackHeroes(msg, *world.vec_heroes[ii]); - } - - // castles - msg.Push(static_cast(0xFF08)); - msg.Push(static_cast(world.vec_castles.size())); - for(u32 ii = 0; ii < world.vec_castles.size(); ++ii) - { - if(NULL == world.vec_castles[ii]){ DEBUG(DBG_GAME , DBG_WARN, "Game::IO::SaveBIN: castles is NULL"); return false; } - PackCastle(msg, *world.vec_castles[ii]); - } - - // kingdoms - msg.Push(static_cast(0xFF09)); - msg.Push(static_cast(world.vec_kingdoms.size())); - for(u32 ii = 0; ii < world.vec_kingdoms.size(); ++ii) - { - if(NULL == world.vec_kingdoms[ii]){ DEBUG(DBG_GAME , DBG_WARN, "Game::IO::SaveBIN: kingdoms is NULL"); return false; } - PackKingdom(msg, *world.vec_kingdoms[ii]); - } - - // signs - msg.Push(static_cast(0xFF0A)); - msg.Push(static_cast(world.map_sign.size())); - { - std::map::const_iterator it1 = world.map_sign.begin(); - std::map::const_iterator it2 = world.map_sign.end(); - for(; it1 != it2; ++it1) - { - msg.Push((*it1).first); - msg.Push((*it1).second); - } - } - - // captured object - msg.Push(static_cast(0xFF0B)); - msg.Push(static_cast(world.map_captureobj.size())); - { - std::map::const_iterator it1 = world.map_captureobj.begin(); - std::map::const_iterator it2 = world.map_captureobj.end(); - for(; it1 != it2; ++it1) - { - msg.Push((*it1).first); - msg.Push(static_cast((*it1).second.first)); - msg.Push(static_cast((*it1).second.second)); - } - } - - // rumors - msg.Push(static_cast(0xFF0C)); - msg.Push(static_cast(world.vec_rumors.size())); - { - std::vector::const_iterator it1 = world.vec_rumors.begin(); - std::vector::const_iterator it2 = world.vec_rumors.end(); - for(; it1 != it2; ++it1) msg.Push(*it1); - } - - // day events - msg.Push(static_cast(0xFF0D)); - msg.Push(static_cast(world.vec_eventsday.size())); - { - std::vector::const_iterator it1 = world.vec_eventsday.begin(); - std::vector::const_iterator it2 = world.vec_eventsday.end(); - for(; it1 != it2; ++it1) - { - if(NULL == *it1){ DEBUG(DBG_GAME , DBG_WARN, "Game::IO::SaveBIN: eventday is NULL"); return false; } - - msg.Push((*it1)->resource.wood); - msg.Push((*it1)->resource.mercury); - msg.Push((*it1)->resource.ore); - msg.Push((*it1)->resource.sulfur); - msg.Push((*it1)->resource.crystal); - msg.Push((*it1)->resource.gems); - msg.Push((*it1)->resource.gold); - msg.Push(static_cast((*it1)->computer)); - msg.Push((*it1)->first); - msg.Push((*it1)->subsequent); - msg.Push((*it1)->colors); - msg.Push((*it1)->message); - } - } - - // coord events - msg.Push(static_cast(0xFF0E)); - msg.Push(static_cast(world.vec_eventsmap.size())); - { - std::vector::const_iterator it1 = world.vec_eventsmap.begin(); - std::vector::const_iterator it2 = world.vec_eventsmap.end(); - for(; it1 != it2; ++it1) - { - if(NULL == *it1){ DEBUG(DBG_GAME , DBG_WARN, "Game::IO::SaveBIN: eventmaps is NULL"); return false; } - - msg.Push((*it1)->index_map); - msg.Push((*it1)->resource.wood); - msg.Push((*it1)->resource.mercury); - msg.Push((*it1)->resource.ore); - msg.Push((*it1)->resource.sulfur); - msg.Push((*it1)->resource.crystal); - msg.Push((*it1)->resource.gems); - msg.Push((*it1)->resource.gold); - msg.Push(static_cast((*it1)->artifact)); - msg.Push(static_cast((*it1)->computer)); - msg.Push(static_cast((*it1)->cancel)); - msg.Push((*it1)->colors); - msg.Push((*it1)->message); - } - } - - // sphinx riddles - msg.Push(static_cast(0xFF0F)); - msg.Push(static_cast(world.vec_riddles.size())); - { - std::vector::const_iterator it1 = world.vec_riddles.begin(); - std::vector::const_iterator it2 = world.vec_riddles.end(); - for(; it1 != it2; ++it1) - { - if(NULL == *it1){ DEBUG(DBG_GAME , DBG_WARN, "Game::IO::SaveBIN: riddles is NULL"); return false; } - - msg.Push((*it1)->index_map); - msg.Push((*it1)->resource.wood); - msg.Push((*it1)->resource.mercury); - msg.Push((*it1)->resource.ore); - msg.Push((*it1)->resource.sulfur); - msg.Push((*it1)->resource.crystal); - msg.Push((*it1)->resource.gems); - msg.Push((*it1)->resource.gold); - msg.Push(static_cast((*it1)->artifact)); - msg.Push(static_cast((*it1)->quiet)); - - msg.Push(static_cast((*it1)->answers.size())); - std::vector::const_iterator ita1 = (*it1)->answers.begin(); - std::vector::const_iterator ita2 = (*it1)->answers.end(); - for(; ita1 != ita2; ++ita1) msg.Push(*ita1); - - msg.Push((*it1)->message); - } - } - - msg.Push(static_cast(0xFFFF)); - return true; -} - -void Game::IO::PackTile(QueueMessage & msg, const Maps::Tiles & tile) -{ - msg.Push(tile.tile_sprite_index); - msg.Push(tile.tile_sprite_shape); - msg.Push(tile.mp2_object); - msg.Push(tile.quantity1); - msg.Push(tile.quantity2); - msg.Push(tile.quantity3); - msg.Push(tile.quantity4); - msg.Push(tile.fogs); - msg.Push(tile.unused1); - msg.Push(tile.unused2); - msg.Push(tile.unused3); - - // addons 1 - msg.Push(static_cast(tile.addons_level1.size())); - std::list::const_iterator it1 = tile.addons_level1.begin(); - std::list::const_iterator it2 = tile.addons_level1.end(); - for(; it1 != it2; ++it1) - { - const Maps::TilesAddon & addon = *it1; - msg.Push(addon.level); - msg.Push(addon.uniq); - msg.Push(addon.object); - msg.Push(addon.index); - } - - // addons 2 - msg.Push(static_cast(tile.addons_level2.size())); - it1 = tile.addons_level2.begin(); - it2 = tile.addons_level2.end(); - for(; it1 != it2; ++it1) - { - const Maps::TilesAddon & addon = *it1; - msg.Push(addon.level); - msg.Push(addon.uniq); - msg.Push(addon.object); - msg.Push(addon.index); - } -} - -void Game::IO::PackKingdom(QueueMessage & msg, const Kingdom & kingdom) -{ - msg.Push(static_cast(kingdom.color)); - msg.Push(static_cast(kingdom.control)); - - msg.Push(kingdom.flags); - msg.Push(kingdom.lost_town_days); - msg.Push(static_cast(kingdom.ai_capital ? kingdom.ai_capital->GetIndex() : 0)); - - // funds - msg.Push(kingdom.resource.wood); - msg.Push(kingdom.resource.mercury); - msg.Push(kingdom.resource.ore); - msg.Push(kingdom.resource.sulfur); - msg.Push(kingdom.resource.crystal); - msg.Push(kingdom.resource.gems); - msg.Push(kingdom.resource.gold); - - // visit objects - msg.Push(static_cast(kingdom.visit_object.size())); - std::list::const_iterator it1 = kingdom.visit_object.begin(); - std::list::const_iterator it2 = kingdom.visit_object.end(); - for(; it1 != it2; ++it1) - { - msg.Push((*it1).first); - msg.Push(static_cast((*it1).second)); - } - - // recruits - msg.Push(static_cast(kingdom.recruits.GetID1())); - msg.Push(static_cast(kingdom.recruits.GetID2())); - - // puzzle - msg.Push(kingdom.puzzle_maps.to_string,std::allocator >()); - - // tents colors - msg.Push(kingdom.visited_tents_colors); -} - -void Game::IO::PackCastle(QueueMessage & msg, const Castle & castle) -{ - msg.Push(castle.GetCenter().x); - msg.Push(castle.GetCenter().y); - msg.Push(static_cast(castle.race)); - - msg.Push(castle.modes); - msg.Push(static_cast(castle.color)); - msg.Push(castle.name); - msg.Push(castle.building); - - // mageguild - { - std::vector::const_iterator it1, it2; - - msg.Push(static_cast(castle.mageguild.general.spells.size())); - - it1 = castle.mageguild.general.spells.begin(); - it2 = castle.mageguild.general.spells.end(); - for(; it1 != it2; ++it1) msg.Push(static_cast(*it1)); - - msg.Push(static_cast(castle.mageguild.library.spells.size())); - - it1 = castle.mageguild.library.spells.begin(); - it2 = castle.mageguild.library.spells.end(); - for(; it1 != it2; ++it1) msg.Push(static_cast(*it1)); - } - - // armies - msg.Push(static_cast(castle.army.Size())); - for(u32 jj = 0; jj < castle.army.Size(); ++jj) - { - const Army::Troop & troop = castle.army.At(jj); - msg.Push(static_cast(troop())); - msg.Push(troop.GetCount()); - } - - // dwelling - msg.Push(static_cast(CASTLEMAXMONSTER)); - for(u32 jj = 0; jj < CASTLEMAXMONSTER; ++jj) msg.Push(castle.dwelling[jj]); -} - -void Game::IO::PackHeroes(QueueMessage & msg, const Heroes & hero) -{ - msg.Push(static_cast(hero.portrait)); - msg.Push(static_cast(hero.race)); - - msg.Push(hero.modes); - msg.Push(static_cast(hero.color)); - msg.Push(hero.name); - msg.Push(hero.attack); - msg.Push(hero.defense); - msg.Push(hero.knowledge); - msg.Push(hero.power); - msg.Push(hero.experience); - msg.Push(hero.magic_point); - msg.Push(hero.move_point); - msg.Push(static_cast(hero.direction)); - msg.Push(hero.sprite_index); - msg.Push(static_cast(hero.save_maps_object)); - msg.Push(hero.center.x); - msg.Push(hero.center.y); - - // sec skills - msg.Push(static_cast(hero.secondary_skills.size())); - for(u32 jj = 0; jj < hero.secondary_skills.size(); ++jj) - { - const Skill::Secondary & sec = hero.secondary_skills[jj]; - msg.Push(static_cast(sec.Skill())); - msg.Push(static_cast(sec.Level())); - } - - // artifacts - msg.Push(static_cast(hero.bag_artifacts.size())); - for(u32 jj = 0; jj < hero.bag_artifacts.size(); ++jj) - { - msg.Push(static_cast(hero.bag_artifacts[jj].GetID())); - msg.Push(hero.bag_artifacts[jj].GetExt()); - } - - // armies - msg.Push(static_cast(hero.army.Size())); - for(u32 jj = 0; jj < hero.army.Size(); ++jj) - { - const Army::Troop & troop = hero.army.At(jj); - msg.Push(static_cast(troop())); - msg.Push(troop.GetCount()); - } - - // spell book - msg.Push(static_cast(hero.spell_book.active)); - { - std::vector::const_iterator it1, it2; - - msg.Push(static_cast(hero.spell_book.spells.size())); - - it1 = hero.spell_book.spells.begin(); - it2 = hero.spell_book.spells.end(); - for(; it1 != it2; ++it1) msg.Push(static_cast(*it1)); - } - - // visit objects - msg.Push(static_cast(hero.visit_object.size())); - std::list::const_iterator it1 = hero.visit_object.begin(); - std::list::const_iterator it2 = hero.visit_object.end(); - for(; it1 != it2; ++it1) - { - msg.Push((*it1).first); - msg.Push(static_cast((*it1).second)); - } - - // route path - msg.Push(hero.path.dst); - msg.Push(static_cast(hero.path.hide)); - msg.Push(static_cast(hero.path.size())); - Route::Path::const_iterator ip1 = hero.path.begin(); - Route::Path::const_iterator ip2 = hero.path.end(); - for(; ip1 != ip2; ++ip1) - { - msg.Push(static_cast((*ip1).Direction())); - msg.Push((*ip1).Penalty()); - } -} - -bool Game::IO::LoadBIN(QueueMessage & msg) -{ - Settings & conf = Settings::Get(); - - u8 byte8; - u16 byte16; - u32 byte32; - u16 format; - std::string str; - - // prepare World - world.Reset(); - - msg.Pop(byte16); - if(byte16 != 0xFF01){ DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF01"); return false; } - - // format version - msg.Pop(format); - if(format > CURRENT_FORMAT_VERSION || format < LAST_FORMAT_VERSION) - { - DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: unknown format: 0x" << std::hex << format); - return false; - } - else - { - DEBUG(DBG_GAME , DBG_INFO, "Game::IO::LoadBIN: format: " << format); - } - - - // major version - msg.Pop(byte8); - // minor version - msg.Pop(byte8); - - // svn - msg.Pop(conf.svn_version); - // time - msg.Pop(byte32); - // lang - msg.Pop(str); - if(str != "en" && str != conf.force_lang && !conf.Unicode()) - { - std::string msg("This is an saved game is localized for lang = "); - msg.append(str); - msg.append(", and most of the messages will be displayed incorrectly.\n \n"); - msg.append("(tip: set unicode = on)"); - Dialog::Message("Warning!", msg, Font::BIG, Dialog::OK); - } - - // maps - msg.Pop(byte16); - if(byte16 != 0xFF02) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF02"); - - if(FORMAT_VERSION_2031 <= format) - { - msg.Pop(conf.current_maps_file.size_w); - msg.Pop(conf.current_maps_file.size_h); - } - else - { - msg.Pop(byte8); conf.current_maps_file.size_w = byte8; - msg.Pop(byte8); conf.current_maps_file.size_h = byte8; - } - msg.Pop(conf.current_maps_file.file); - msg.Pop(conf.current_maps_file.difficulty); - msg.Pop(conf.current_maps_file.kingdom_colors); - msg.Pop(conf.current_maps_file.human_colors); - msg.Pop(conf.current_maps_file.computer_colors); - msg.Pop(conf.current_maps_file.rnd_races); - msg.Pop(conf.current_maps_file.conditions_wins); - msg.Pop(conf.current_maps_file.wins1); - msg.Pop(conf.current_maps_file.wins2); - msg.Pop(conf.current_maps_file.wins3); - msg.Pop(conf.current_maps_file.wins4); - msg.Pop(conf.current_maps_file.conditions_loss); - msg.Pop(conf.current_maps_file.loss1); - msg.Pop(conf.current_maps_file.loss2); - - msg.Pop(byte16); - if(byte16 != 0xFF03) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF03"); - // races - msg.Pop(byte32); - for(u8 ii = 0; ii < byte32; ++ii) - { - msg.Pop(byte8); - conf.current_maps_file.races[ii] = byte8; - } - // unions - msg.Pop(byte32); - for(u16 ii = 0; ii < byte32; ++ii) - { - msg.Pop(byte8); - conf.current_maps_file.unions[ii] = byte8; - } - // maps name - msg.Pop(conf.current_maps_file.name); - // maps description - msg.Pop(conf.current_maps_file.description); - // game - msg.Pop(byte16); - if(byte16 != 0xFF04) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF04"); - msg.Pop(byte8); conf.game_difficulty = Difficulty::Get(byte8); - msg.Pop(byte8); conf.my_color = Color::Get(byte8); - msg.Pop(byte8); conf.cur_color = Color::Get(byte8); - msg.Pop(conf.game_type); - msg.Pop(conf.players_colors); - msg.Pop(conf.preferably_count_players); -#ifdef WITH_DEBUG - msg.Pop(byte16); -#else - msg.Pop(conf.debug); -#endif - msg.Pop(byte32); - // skip load interface options - //conf.opt_game.ResetModes(MODES_ALL); - //conf.opt_game.SetModes(byte32); - msg.Pop(byte32); - conf.opt_world.ResetModes(MODES_ALL); - conf.opt_world.SetModes(byte32); - msg.Pop(byte32); - conf.opt_battle.ResetModes(MODES_ALL); - conf.opt_battle.SetModes(byte32); - - // world - msg.Pop(byte16); - if(byte16 != 0xFF05) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF05"); - msg.Pop(world.width); - msg.Pop(world.height); - - if(FORMAT_VERSION_2031 <= format) - { - msg.Pop(world.ultimate_artifact); - } - else - { - msg.Pop(byte16); world.ultimate_artifact = byte16; - } - msg.Pop(world.uniq0); - msg.Pop(byte8); world.week_name = Week::Get(byte8); - msg.Pop(byte8); world.heroes_cond_wins = Heroes::ConvertID(byte8); - msg.Pop(byte8); world.heroes_cond_loss = Heroes::ConvertID(byte8); - msg.Pop(world.month); - msg.Pop(world.week); - msg.Pop(world.day); - - // tiles - msg.Pop(byte16); - if(byte16 != 0xFF06) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF06"); - msg.Pop(byte32); - world.vec_tiles.reserve(byte32); - for(u32 maps_index = 0; maps_index < byte32; ++maps_index) - { - Maps::Tiles *tile = new Maps::Tiles(maps_index); - UnpackTile(msg, *tile, format); - world.vec_tiles.push_back(tile); - } - - // heroes - msg.Pop(byte16); - if(byte16 != 0xFF07) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF07"); - msg.Pop(byte32); - world.vec_heroes.reserve(byte32); - for(u32 ii = 0; ii < byte32; ++ii) - { - Heroes* hero = new Heroes(); - UnpackHeroes(msg, *hero, format); - world.vec_heroes.push_back(hero); - } - - // castles - msg.Pop(byte16); - if(byte16 != 0xFF08) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF08"); - msg.Pop(byte32); - world.vec_castles.reserve(byte32); - for(u32 ii = 0; ii < byte32; ++ii) - { - Castle* castle = new Castle(); - UnpackCastle(msg, *castle, format); - world.vec_castles.push_back(castle); - } - - // kingdoms - msg.Pop(byte16); - if(byte16 != 0xFF09) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF09"); - msg.Pop(byte32); - world.vec_kingdoms.reserve(byte32); - for(u32 ii = 0; ii < byte32; ++ii) - { - Kingdom* kingdom = new Kingdom(); - UnpackKingdom(msg, *kingdom, format); - world.vec_kingdoms.push_back(kingdom); - } - - // signs - msg.Pop(byte16); - if(byte16 != 0xFF0A) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF0A"); - if(FORMAT_VERSION_2031 <= format) - { - msg.Pop(byte32); - byte16 = byte32; - world.map_sign.clear(); - for(u16 ii = 0; ii < byte16; ++ii) - { - msg.Pop(byte32); - msg.Pop(str); - world.map_sign[byte32] = str; - } - } - else - { - msg.Pop(byte32); - world.map_sign.clear(); - for(u32 ii = 0; ii < byte32; ++ii) - { - msg.Pop(byte16); - msg.Pop(str); - world.map_sign[byte16] = str; - } - } - - // captured object - msg.Pop(byte16); - if(byte16 != 0xFF0B) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF0B"); - if(FORMAT_VERSION_2031 <= format) - { - msg.Pop(byte32); - byte16 = byte32; - world.map_captureobj.clear(); - for(u16 ii = 0; ii < byte16; ++ii) - { - msg.Pop(byte32); - ObjectColor & value = world.map_captureobj[byte32]; - msg.Pop(byte8); value.first = static_cast(byte8); - msg.Pop(byte8); value.second = Color::Get(byte8); - } - } - else - { - msg.Pop(byte32); - world.map_captureobj.clear(); - for(u32 ii = 0; ii < byte32; ++ii) - { - msg.Pop(byte16); - ObjectColor & value = world.map_captureobj[byte16]; - msg.Pop(byte8); value.first = static_cast(byte8); - msg.Pop(byte8); value.second = Color::Get(byte8); - } - } - - // rumors - msg.Pop(byte16); - if(byte16 != 0xFF0C) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF0C"); - msg.Pop(byte32); - world.vec_rumors.clear(); - world.vec_rumors.reserve(byte32); - for(u32 ii = 0; ii < byte32; ++ii) - { - msg.Pop(str); - world.vec_rumors.push_back(str); - } - - // day events - msg.Pop(byte16); - if(byte16 != 0xFF0D) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF0D"); - msg.Pop(byte32); - world.vec_eventsday.clear(); - world.vec_eventsday.reserve(byte32); - for(u32 ii = 0; ii < byte32; ++ii) - { - GameEvent::Day *event = new GameEvent::Day(); - u32 size; - - msg.Pop(size); event->resource.wood = size; - msg.Pop(size); event->resource.mercury = size; - msg.Pop(size); event->resource.ore = size; - msg.Pop(size); event->resource.sulfur = size; - msg.Pop(size); event->resource.crystal = size; - msg.Pop(size); event->resource.gems = size; - msg.Pop(size); event->resource.gold = size; - msg.Pop(byte8);event->computer = byte8; - msg.Pop(event->first); - msg.Pop(event->subsequent); - msg.Pop(event->colors); - msg.Pop(event->message); - - world.vec_eventsday.push_back(event); - } - - // coord events - msg.Pop(byte16); - if(byte16 != 0xFF0E) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF0E"); - msg.Pop(byte32); - world.vec_eventsmap.clear(); - world.vec_eventsmap.reserve(byte32); - for(u32 ii = 0; ii < byte32; ++ii) - { - GameEvent::Coord *event = new GameEvent::Coord(); - u32 size; - - if(FORMAT_VERSION_2031 <= format) - { - msg.Pop(size); event->index_map = size; - } - else - { - msg.Pop(byte16); event->index_map = byte16; - } - msg.Pop(size); event->resource.wood = size; - msg.Pop(size); event->resource.mercury = size; - msg.Pop(size); event->resource.ore = size; - msg.Pop(size); event->resource.sulfur = size; - msg.Pop(size); event->resource.crystal = size; - msg.Pop(size); event->resource.gems = size; - msg.Pop(size); event->resource.gold = size; - - msg.Pop(byte8);event->artifact = Artifact::FromInt(byte8); - msg.Pop(byte8);event->computer = byte8; - msg.Pop(byte8);event->cancel = byte8; - msg.Pop(event->colors); - msg.Pop(event->message); - - world.vec_eventsmap.push_back(event); - } - - // sphinx riddles - msg.Pop(byte16); - if(byte16 != 0xFF0F) DEBUG(DBG_GAME , DBG_WARN, "Game::IO::LoadBIN: 0xFF0F"); - msg.Pop(byte32); - world.vec_riddles.clear(); - world.vec_riddles.reserve(byte32); - for(u32 ii = 0; ii < byte32; ++ii) - { - GameEvent::Riddle *riddle = new GameEvent::Riddle(); - u32 size; - - if(FORMAT_VERSION_2031 <= format) - { - msg.Pop(size); riddle->index_map = size; - } - else - { - msg.Pop(byte16); riddle->index_map = byte16; - } - msg.Pop(size); riddle->resource.wood = size; - msg.Pop(size); riddle->resource.mercury = size; - msg.Pop(size); riddle->resource.ore = size; - msg.Pop(size); riddle->resource.sulfur = size; - msg.Pop(size); riddle->resource.crystal = size; - msg.Pop(size); riddle->resource.gems = size; - msg.Pop(size); riddle->resource.gold = size; - msg.Pop(byte8);riddle->artifact = Artifact::FromInt(byte8); - msg.Pop(byte8);riddle->quiet = byte8; - - msg.Pop(size); - riddle->answers.reserve(size); - for(u32 jj = 0; jj < size; ++jj) - { - msg.Pop(str); - riddle->answers.push_back(str); - } - msg.Pop(riddle->message); - - world.vec_riddles.push_back(riddle); - } - - msg.Pop(byte16); - - // sort castles to kingdoms - std::vector::const_iterator itc1 = world.vec_castles.begin(); - std::vector::const_iterator itc2 = world.vec_castles.end(); - for(; itc1 != itc2; ++itc1) - if(*itc1) world.GetKingdom((*itc1)->GetColor()).AddCastle(*itc1); - - // sort heroes to kingdoms - std::vector::const_iterator ith1 = world.vec_heroes.begin(); - std::vector::const_iterator ith2 = world.vec_heroes.end(); - for(; ith1 != ith2; ++ith1) - if(*ith1) world.GetKingdom((*ith1)->GetColor()).AddHeroes(*ith1); - - // regenerate puzzle surface - Interface::GameArea::GenerateUltimateArtifactAreaSurface(world.ultimate_artifact, world.puzzle_surface); - - return byte16 == 0xFFFF; -} - -void Game::IO::UnpackTile(QueueMessage & msg, Maps::Tiles & tile, u16 check_version) -{ - msg.Pop(tile.tile_sprite_index); - msg.Pop(tile.tile_sprite_shape); - msg.Pop(tile.mp2_object); - msg.Pop(tile.quantity1); - msg.Pop(tile.quantity2); - msg.Pop(tile.quantity3); - msg.Pop(tile.quantity4); - msg.Pop(tile.fogs); - msg.Pop(tile.unused1); - if(FORMAT_VERSION_2031 <= check_version) - { - msg.Pop(tile.unused2); - msg.Pop(tile.unused3); - } - -#ifdef WITH_DEBUG - if(IS_DEVEL()) tile.fogs &= ~Settings::Get().MyColor(); -#endif - - // addons 1 - u8 size; - tile.addons_level1.clear(); - msg.Pop(size); - for(u8 ii = 0; ii < size; ++ii) - { - Maps::TilesAddon addon; - msg.Pop(addon.level); - msg.Pop(addon.uniq); - msg.Pop(addon.object); - msg.Pop(addon.index); - tile.addons_level1.push_back(addon); - } - - // addons 2 - tile.addons_level2.clear(); - msg.Pop(size); - for(u8 ii = 0; ii < size; ++ii) - { - Maps::TilesAddon addon; - msg.Pop(addon.level); - msg.Pop(addon.uniq); - msg.Pop(addon.object); - msg.Pop(addon.index); - tile.addons_level2.push_back(addon); - } -} - -void Game::IO::UnpackKingdom(QueueMessage & msg, Kingdom & kingdom, u16 check_version) -{ - u8 byte8; - u16 byte16; - u32 byte32; - - msg.Pop(byte8); - kingdom.color =Color::Get(byte8); - - msg.Pop(byte8); - kingdom.control = Game::GetControl(byte8); - - msg.Pop(kingdom.flags); - msg.Pop(kingdom.lost_town_days); - msg.Pop(byte16); - kingdom.ai_capital = byte16 ? world.GetCastle(byte16) : NULL; - - // funds - msg.Pop(byte32); kingdom.resource.wood = byte32; - msg.Pop(byte32); kingdom.resource.mercury = byte32; - msg.Pop(byte32); kingdom.resource.ore = byte32; - msg.Pop(byte32); kingdom.resource.sulfur = byte32; - msg.Pop(byte32); kingdom.resource.crystal = byte32; - msg.Pop(byte32); kingdom.resource.gems = byte32; - msg.Pop(byte32); kingdom.resource.gold = byte32; - - // visit objects - msg.Pop(byte32); - kingdom.visit_object.clear(); - for(u32 jj = 0; jj < byte32; ++jj) - { - IndexObject io; - if(FORMAT_VERSION_2031 <= check_version) - { - msg.Pop(io.first); - } - else - { - msg.Pop(byte16); io.first = byte16; - } - msg.Pop(byte8); - io.second = static_cast(byte8); - kingdom.visit_object.push_back(io); - } - - // recruits - msg.Pop(byte8); kingdom.recruits.SetID1(byte8); - msg.Pop(byte8); kingdom.recruits.SetID2(byte8); - - std::string str; - - // puzzle - msg.Pop(str); - kingdom.puzzle_maps = str.c_str(); - - // visited tents - msg.Pop(kingdom.visited_tents_colors); -} - -void Game::IO::UnpackCastle(QueueMessage & msg, Castle & castle, u16 check_version) -{ - u8 byte8; - u16 byte16; - u32 byte32; - - if(FORMAT_VERSION_2031 <= check_version) - { - msg.Pop(castle.center.x); - msg.Pop(castle.center.y); - } - else - { - msg.Pop(byte16); castle.center.x = byte16; - msg.Pop(byte16); castle.center.y = byte16; - } - - msg.Pop(byte8); castle.race = Race::Get(byte8); - - msg.Pop(castle.modes); - msg.Pop(byte8); castle.color = Color::Get(byte8); - msg.Pop(castle.name); - msg.Pop(castle.building); - - // general - msg.Pop(byte32); - castle.mageguild.general.spells.clear(); - castle.mageguild.general.spells.reserve(byte32); - for(u32 jj = 0; jj < byte32; ++jj) - { - msg.Pop(byte8); - castle.mageguild.general.spells.push_back(Spell::FromInt(byte8)); - } - // library - msg.Pop(byte32); - castle.mageguild.library.spells.clear(); - castle.mageguild.library.spells.reserve(byte32); - for(u32 jj = 0; jj < byte32; ++jj) - { - msg.Pop(byte8); - castle.mageguild.library.spells.push_back(Spell::FromInt(byte8)); - } - - // armies - msg.Pop(byte32); - for(u32 jj = 0; jj < castle.army.Size(); ++jj) - { - msg.Pop(byte8); - castle.army.At(jj).SetMonster(Monster::FromInt(byte8)); - msg.Pop(byte32); - castle.army.At(jj).SetCount(byte32); - } - // dwelling - msg.Pop(byte32); - for(u32 jj = 0; jj < CASTLEMAXMONSTER; ++jj) msg.Pop(castle.dwelling[jj]); -} - -void Game::IO::UnpackHeroes(QueueMessage & msg, Heroes & hero, u16 check_version) -{ - u8 byte8; - u16 byte16; - u32 byte32; - - msg.Pop(byte8); hero.portrait = Heroes::ConvertID(byte8); - msg.Pop(byte8); hero.race = Race::Get(byte8); - - msg.Pop(hero.modes); - msg.Pop(byte8); hero.color = Color::Get(byte8); - msg.Pop(hero.name); - msg.Pop(hero.attack); - msg.Pop(hero.defense); - msg.Pop(hero.knowledge); - msg.Pop(hero.power); - msg.Pop(hero.experience); - msg.Pop(hero.magic_point); - msg.Pop(hero.move_point); - msg.Pop(byte16); hero.direction = Direction::FromInt(byte16); - msg.Pop(hero.sprite_index); - msg.Pop(byte8); hero.save_maps_object = static_cast(byte8); - if(FORMAT_VERSION_2031 <= check_version) - { - msg.Pop(hero.center.x); - msg.Pop(hero.center.y); - } - else - { - msg.Pop(byte16); hero.center.x = byte16; - msg.Pop(byte16); hero.center.y = byte16; - } - - // sec skills - hero.secondary_skills.clear(); - hero.secondary_skills.reserve(HEROESMAXSKILL); - msg.Pop(byte32); - for(u32 jj = 0; jj < byte32; ++jj) - { - Skill::Secondary skill; - msg.Pop(byte8); skill.SetSkill(Skill::Secondary::Skill(byte8)); - msg.Pop(byte8); skill.SetLevel(byte8); - hero.secondary_skills.push_back(skill); - } - - // artifacts - std::fill(hero.bag_artifacts.begin(), hero.bag_artifacts.end(), Artifact::UNKNOWN); - msg.Pop(byte32); - for(u32 jj = 0; jj < hero.bag_artifacts.size(); ++jj) - { - msg.Pop(byte8); - hero.bag_artifacts[jj].Set(Artifact::FromInt(byte8)); - - msg.Pop(byte8); - hero.bag_artifacts[jj].SetExt(byte8); - } - - // armies - msg.Pop(byte32); - for(u32 jj = 0; jj < hero.army.Size(); ++jj) - { - msg.Pop(byte8); - hero.army.At(jj).SetMonster(Monster::FromInt(byte8)); - msg.Pop(byte32); - hero.army.At(jj).SetCount(byte32); - } - - // spell book - hero.spell_book.spells.clear(); - msg.Pop(byte8); - hero.spell_book.active = byte8; - - msg.Pop(byte32); - hero.spell_book.spells.reserve(byte32); - for(u32 jj = 0; jj < byte32; ++jj) - { - msg.Pop(byte8); - hero.spell_book.spells.push_back(Spell::FromInt(byte8)); - } - - // visit objects - msg.Pop(byte32); - hero.visit_object.clear(); - for(u32 jj = 0; jj < byte32; ++jj) - { - IndexObject io; - if(FORMAT_VERSION_2031 <= check_version) - { - msg.Pop(io.first); - } - else - { - msg.Pop(byte16); io.first = byte16; - } - msg.Pop(byte8); - io.second = static_cast(byte8); - hero.visit_object.push_back(io); - } - - // route path - if(FORMAT_VERSION_2031 <= check_version) - { - msg.Pop(hero.path.dst); - } - else - { - msg.Pop(byte16); - hero.path.dst = byte16; - } - msg.Pop(byte8); - hero.path.hide = byte8; - msg.Pop(byte32); - hero.path.clear(); - for(u32 jj = 0; jj < byte32; ++jj) - { - Route::Step step; - msg.Pop(byte16); - step.first = Direction::FromInt(byte16); - msg.Pop(step.second); - hero.path.push_back(step); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_io.h b/project/jni/application/fheroes2/src/fheroes2/game/game_io.h deleted file mode 100644 index c884959b1..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_io.h +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2GAMEIO_H -#define H2GAMEIO_H - -#include "game.h" -#include "sdlnet.h" -#include "maps_fileinfo.h" - -namespace Maps {class Tiles; } -class Kingdom; -class Castle; -class Heroes; - -namespace Game -{ - class IO : public QueueMessage - { - public: - IO(){}; - - bool LoadSAV(const std::string &); - - static bool SaveBIN(QueueMessage &); - static bool LoadBIN(QueueMessage &); - - static void PackTile(QueueMessage &, const Maps::Tiles &); - static void PackKingdom(QueueMessage &, const Kingdom &); - static void PackCastle(QueueMessage &, const Castle &); - static void PackHeroes(QueueMessage &, const Heroes &); - - static void UnpackTile(QueueMessage &, Maps::Tiles &, u16 = 0); - static void UnpackKingdom(QueueMessage &, Kingdom &, u16 = 0); - static void UnpackCastle(QueueMessage &, Castle &, u16 = 0); - static void UnpackHeroes(QueueMessage &, Heroes &, u16 = 0); - - static std::string last_name; - }; - - bool Save(const std::string &); - bool Load(const std::string &); - bool LoadSAV2FileInfo(const std::string &, Maps::FileInfo &); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_loadgame.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_loadgame.cpp deleted file mode 100644 index baeb04477..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_loadgame.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "gamedefs.h" -#include "agg.h" -#include "cursor.h" -#include "button.h" -#include "dialog.h" -#include "settings.h" -#include "pocketpc.h" -#include "game.h" - -Game::menu_t Game::LoadCampain(void) -{ - Settings::Get().SetGameType(Game::CAMPAIGN); - VERBOSE("Load Campain Game: under construction."); - return Game::LOADGAME; -} - -Game::menu_t Game::LoadMulti(void) -{ - VERBOSE("Load Multi Game: under construction."); - return Game::LOADGAME; -} - -Game::menu_t Game::LoadGame(void) -{ - Mixer::Pause(); - AGG::PlayMusic(MUS::MAINMENU); - - if(Settings::Get().QVGA()) return PocketPC::LoadGame(); - - // preload - AGG::PreloadObject(ICN::HEROES); - AGG::PreloadObject(ICN::BTNNEWGM); - AGG::PreloadObject(ICN::REDBACK); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display & display = Display::Get(); - - // image background - const Sprite &back = AGG::GetICN(ICN::HEROES, 0); - const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2); - display.Blit(back, top); - - const Sprite &panel = AGG::GetICN(ICN::REDBACK, 0); - display.Blit(panel, top.x + 405, top.y + 5); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonStandartGame(top.x + 455, top.y + 45, ICN::BTNNEWGM, 0, 1); - Button buttonCampainGame(top.x + 455, top.y + 110, ICN::BTNNEWGM, 2, 3); - Button buttonMultiGame(top.x + 455, top.y + 175, ICN::BTNNEWGM, 4, 5); - Button buttonCancelGame(top.x + 455, top.y + 375, ICN::BTNNEWGM, 6, 7); - - buttonStandartGame.Draw(); - buttonCampainGame.Draw(); - buttonMultiGame.Draw(); - buttonCancelGame.Draw(); - - cursor.Show(); - display.Flip(); - - // loadgame loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonStandartGame) ? buttonStandartGame.PressDraw() : buttonStandartGame.ReleaseDraw(); - le.MousePressLeft(buttonCampainGame) ? buttonCampainGame.PressDraw() : buttonCampainGame.ReleaseDraw(); - le.MousePressLeft(buttonMultiGame) ? buttonMultiGame.PressDraw() : buttonMultiGame.ReleaseDraw(); - le.MousePressLeft(buttonCancelGame) ? buttonCancelGame.PressDraw() : buttonCancelGame.ReleaseDraw(); - - if(HotKeyPress(EVENT_BUTTON_STANDARD) || le.MouseClickLeft(buttonStandartGame)) return LOADSTANDARD; - if(HotKeyPress(EVENT_BUTTON_CAMPAIN) || le.MouseClickLeft(buttonCampainGame)) return LOADCAMPAIN; - if(HotKeyPress(EVENT_BUTTON_MULTI) || le.MouseClickLeft(buttonMultiGame)) return LOADMULTI; - if(HotKeyPress(EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancelGame)) return MAINMENU; - } - - return QUITGAME; -} - -Game::menu_t Game::LoadStandard(void) -{ - Settings::Get().SetGameType(Game::STANDARD); - - // preload - AGG::PreloadObject(ICN::HEROES); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display & display = Display::Get(); - - // image background - const Sprite &back = AGG::GetICN(ICN::HEROES, 0); - const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2); - display.Blit(back, top); - - cursor.Show(); - display.Flip(); - - std::string file; - - if(!Dialog::SelectFileLoad(file) || file.empty() || !Game::Load(file)) return MAINMENU; - - return STARTGAME; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_mainmenu.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_mainmenu.cpp deleted file mode 100644 index a5fe151a7..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_mainmenu.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "gamedefs.h" -#include "agg.h" -#include "cursor.h" -#include "dialog.h" -#include "button.h" -#include "settings.h" -#include "pocketpc.h" -#include "game.h" - -#define NEWGAME_DEFAULT 1 -#define LOADGAME_DEFAULT 5 -#define HIGHSCORES_DEFAULT 9 -#define CREDITS_DEFAULT 13 -#define QUIT_DEFAULT 17 - -Game::menu_t Game::MainMenu(void) -{ - Mixer::Pause(); - AGG::PlayMusic(MUS::MAINMENU); - - if(Settings::Get().QVGA()) return PocketPC::MainMenu(); - - // preload - AGG::PreloadObject(ICN::HEROES); - AGG::PreloadObject(ICN::BTNSHNGL); - AGG::PreloadObject(ICN::SHNGANIM); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display & display = Display::Get(); - - display.Fill(0, 0, 0); - - // image background - const Sprite &sprite = AGG::GetICN(ICN::HEROES, 0); - const Point top((display.w() - sprite.w()) / 2, (display.h() - sprite.h()) / 2); - display.Blit(sprite, top); - - LocalEvent & le = LocalEvent::Get(); - - const Sprite & s1 = AGG::GetICN(ICN::BTNSHNGL, NEWGAME_DEFAULT); - const Sprite & s2 = AGG::GetICN(ICN::BTNSHNGL, LOADGAME_DEFAULT); - const Sprite & s3 = AGG::GetICN(ICN::BTNSHNGL, HIGHSCORES_DEFAULT); - const Sprite & s4 = AGG::GetICN(ICN::BTNSHNGL, CREDITS_DEFAULT); - const Sprite & s5 = AGG::GetICN(ICN::BTNSHNGL, QUIT_DEFAULT); - - Button buttonNewGame(top.x + s1.x(), top.y + s1.y(), ICN::BTNSHNGL, NEWGAME_DEFAULT, NEWGAME_DEFAULT + 2); - Button buttonLoadGame(top.x + s2.x(), top.y + s2.y(), ICN::BTNSHNGL, LOADGAME_DEFAULT, LOADGAME_DEFAULT + 2); - Button buttonHighScores(top.x + s3.x(), top.y + s3.y(), ICN::BTNSHNGL, HIGHSCORES_DEFAULT, HIGHSCORES_DEFAULT + 2); - Button buttonCredits(top.x + s4.x(), top.y + s4.y(), ICN::BTNSHNGL, CREDITS_DEFAULT, CREDITS_DEFAULT + 2); - Button buttonQuit(top.x + s5.x(), top.y + s5.y(), ICN::BTNSHNGL, QUIT_DEFAULT, QUIT_DEFAULT + 2); - - const Point lt_pt(0, 0); - - const Sprite & lantern10 = AGG::GetICN(ICN::SHNGANIM, 0); - display.Blit(lantern10, top.x + lantern10.x(), top.y + lantern10.y()); - - const Sprite & lantern11 = AGG::GetICN(ICN::SHNGANIM, ICN::AnimationFrame(ICN::SHNGANIM, 0)); - display.Blit(lantern11, top.x + lantern11.x(), top.y + lantern11.y()); - - buttonNewGame.Draw(); - buttonLoadGame.Draw(); - buttonHighScores.Draw(); - buttonCredits.Draw(); - buttonQuit.Draw(); - - cursor.Show(); - display.Flip(); - - u32 lantern_frame = 0; - - struct ButtonInfo - { - u8 frame; - Button &button; - bool isOver; - bool wasOver; - } buttons[] = { - { NEWGAME_DEFAULT, buttonNewGame, false, false }, - { LOADGAME_DEFAULT, buttonLoadGame, false, false }, - { HIGHSCORES_DEFAULT, buttonHighScores, false, false }, - { CREDITS_DEFAULT, buttonCredits, false, false }, - { QUIT_DEFAULT, buttonQuit, false, false } - }; - - for(u16 i = 0; le.MouseMotion() && i < sizeof(buttons) / sizeof(buttons[0]); i++) - { - cursor.Hide(); - const Sprite & sprite = AGG::GetICN(ICN::BTNSHNGL, buttons[i].frame); - display.Blit(sprite, top.x + sprite.x(), top.y + sprite.y()); - cursor.Show(); - } - - // mainmenu loop - while(le.HandleEvents()) - { - for(u16 i = 0; i < sizeof(buttons) / sizeof(buttons[0]); i++) - { - buttons[i].wasOver = buttons[i].isOver; - - if(le.MousePressLeft(buttons[i].button)) - buttons[i].button.PressDraw(); - else buttons[i].button.ReleaseDraw(); - - buttons[i].isOver = le.MouseCursor(buttons[i].button); - - if((!buttons[i].isOver && buttons[i].wasOver) || - (buttons[i].isOver && !buttons[i].wasOver)) - { - u16 frame = buttons[i].frame; - - if(buttons[i].isOver && !buttons[i].wasOver) - frame++; - - cursor.Hide(); - const Sprite & sprite = AGG::GetICN(ICN::BTNSHNGL, frame); - display.Blit(sprite, top.x + sprite.x(), top.y + sprite.y()); - cursor.Show(); - } - } - - if(HotKeyPress(EVENT_BUTTON_NEWGAME) || le.MouseClickLeft(buttonNewGame)) return NEWGAME; - else - if(HotKeyPress(EVENT_BUTTON_LOADGAME) || le.MouseClickLeft(buttonLoadGame)) return LOADGAME; - else - if(HotKeyPress(EVENT_BUTTON_HIGHSCORES) || le.MouseClickLeft(buttonHighScores)) return HIGHSCORES; - else - if(HotKeyPress(EVENT_BUTTON_CREDITS) || le.MouseClickLeft(buttonCredits)) return CREDITS; - else - if(HotKeyPress(EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonQuit)) return QUITGAME; - - // right info - if(le.MousePressRight(buttonQuit)) Dialog::Message(_("Quit"), _("Quit Heroes of Might and Magic and return to the operating system."), Font::BIG); - else - if(le.MousePressRight(buttonLoadGame)) Dialog::Message(_("Load Game"), _("Load a previously saved game."), Font::BIG); - else - if(le.MousePressRight(buttonCredits)) Dialog::Message(_("Credits"), _("View the credits screen."), Font::BIG); - else - if(le.MousePressRight(buttonHighScores)) Dialog::Message(_("High Scores"), _("View the high score screen."), Font::BIG); - else - if(le.MousePressRight(buttonNewGame)) Dialog::Message(_("New Game"), _("Start a single or multi-player game."), Font::BIG); - - if(AnimateInfrequent(MAIN_MENU_DELAY)) - { - cursor.Hide(); - const Sprite & lantern12 = AGG::GetICN(ICN::SHNGANIM, ICN::AnimationFrame(ICN::SHNGANIM, 0, lantern_frame++)); - display.Blit(lantern12, top.x + lantern12.x(), top.y + lantern12.y()); - cursor.Show(); - display.Flip(); - } - } - - return QUITGAME; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_newgame.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_newgame.cpp deleted file mode 100644 index 984528dd8..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_newgame.cpp +++ /dev/null @@ -1,326 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "gamedefs.h" -#include "agg.h" -#include "dialog.h" -#include "cursor.h" -#include "settings.h" -#include "button.h" -#include "network.h" -#include "pocketpc.h" -#include "game.h" - -u8 SelectCountPlayers(void); - -Game::menu_t Game::NewStandard(void) -{ - Settings & conf = Settings::Get(); - conf.SetGameType(Game::STANDARD); - conf.SetPreferablyCountPlayers(0); - return Game::SELECTSCENARIO; -} - -Game::menu_t Game::NewHotSeat(void) -{ - Settings & conf = Settings::Get(); - conf.SetGameType(Game::HOTSEAT); - const u8 select = conf.QVGA() ? 2 : SelectCountPlayers(); - if(select) - { - conf.SetPreferablyCountPlayers(select); - return Game::SELECTSCENARIO; - } - return Game::MAINMENU; -} - -Game::menu_t Game::NewCampain(void) -{ - Settings::Get().SetGameType(Game::CAMPAIGN); - VERBOSE("New Campain Game: under construction."); - return Game::NEWGAME; -} - -Game::menu_t Game::NewNetwork(void) -{ - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display & display = Display::Get(); - Settings & conf = Settings::Get(); - - conf.SetGameType(Game::NETWORK); - - // image background - const Sprite &back = AGG::GetICN(ICN::HEROES, 0); - const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2); - display.Blit(back, top); - - const Sprite &panel = AGG::GetICN(ICN::REDBACK, 0); - display.Blit(panel, top.x + 405, top.y + 5); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonHost(top.x + 455, top.y + 45, ICN::BTNNET, 0, 1); - Button buttonGuest(top.x + 455, top.y + 110, ICN::BTNNET, 2, 3); - Button buttonCancelGame(top.x + 455, top.y + 375, ICN::BTNMP, 8, 9); - - buttonHost.Draw(); - buttonGuest.Draw(); - buttonCancelGame.Draw(); - - cursor.Show(); - display.Flip(); - - // newgame loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonHost) ? buttonHost.PressDraw() : buttonHost.ReleaseDraw(); - le.MousePressLeft(buttonGuest) ? buttonGuest.PressDraw() : buttonGuest.ReleaseDraw(); - le.MousePressLeft(buttonCancelGame) ? buttonCancelGame.PressDraw() : buttonCancelGame.ReleaseDraw(); - - if(le.MouseClickLeft(buttonHost) || HotKeyPress(EVENT_BUTTON_HOST)) return NetworkHost(); - if(le.MouseClickLeft(buttonGuest) || HotKeyPress(EVENT_BUTTON_GUEST)) return NetworkGuest(); - if(HotKeyPress(EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancelGame)) return MAINMENU; - - // right info - if(le.MousePressRight(buttonHost)) Dialog::Message(_("Host"), _("The host sets up the game options. There can only be one host per network game."), Font::BIG); - if(le.MousePressRight(buttonGuest)) Dialog::Message(_("Guest"), _("The guest waits for the host to set up the game, then is automatically added in. There can be multiple guests for TCP/IP games."), Font::BIG); - if(le.MousePressRight(buttonCancelGame)) Dialog::Message(_("Cancel"), _("Cancel back to the main menu."), Font::BIG); - } - - return Game::MAINMENU; -} - -Game::menu_t Game::NewGame(void) -{ - Mixer::Pause(); - AGG::PlayMusic(MUS::MAINMENU); - Settings & conf = Settings::Get(); - - Game::IO::last_name.clear(); - conf.SetLoadedGameVersion(false); - - if(Settings::Get().QVGA()) return PocketPC::NewGame(); - - // preload - AGG::PreloadObject(ICN::HEROES); - AGG::PreloadObject(ICN::BTNNEWGM); - AGG::PreloadObject(ICN::REDBACK); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display & display = Display::Get(); - - // load game settings - conf.BinaryLoad(); - - // image background - const Sprite &back = AGG::GetICN(ICN::HEROES, 0); - const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2); - display.Blit(back, top); - - const Sprite &panel = AGG::GetICN(ICN::REDBACK, 0); - display.Blit(panel, top.x + 405, top.y + 5); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonStandartGame(top.x + 455, top.y + 45, ICN::BTNNEWGM, 0, 1); - Button buttonCampainGame(top.x + 455, top.y + 110, ICN::BTNNEWGM, 2, 3); - Button buttonMultiGame(top.x + 455, top.y + 175, ICN::BTNNEWGM, 4, 5); - Button buttonCancelGame(top.x + 455, top.y + 375, ICN::BTNNEWGM, 6, 7); - Button buttonSettings(top.x + 455, top.y + 240, ICN::BTNDCCFG, 4, 5); - - buttonStandartGame.Draw(); - buttonCampainGame.Draw(); - buttonMultiGame.Draw(); - buttonCancelGame.Draw(); - buttonSettings.Draw(); - - cursor.Show(); - display.Flip(); - - // newgame loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonStandartGame) ? buttonStandartGame.PressDraw() : buttonStandartGame.ReleaseDraw(); - le.MousePressLeft(buttonCampainGame) ? buttonCampainGame.PressDraw() : buttonCampainGame.ReleaseDraw(); - le.MousePressLeft(buttonMultiGame) ? buttonMultiGame.PressDraw() : buttonMultiGame.ReleaseDraw(); - le.MousePressLeft(buttonCancelGame) ? buttonCancelGame.PressDraw() : buttonCancelGame.ReleaseDraw(); - le.MousePressLeft(buttonSettings) ? buttonSettings.PressDraw() : buttonSettings.ReleaseDraw(); - - if(HotKeyPress(EVENT_BUTTON_STANDARD) || le.MouseClickLeft(buttonStandartGame)) return NEWSTANDARD; - if(HotKeyPress(EVENT_BUTTON_CAMPAIN) || le.MouseClickLeft(buttonCampainGame)) return NEWCAMPAIN; - if(HotKeyPress(EVENT_BUTTON_MULTI) || le.MouseClickLeft(buttonMultiGame)) return NEWMULTI; - if(HotKeyPress(EVENT_BUTTON_SETTINGS) || le.MouseClickLeft(buttonSettings)){ Dialog::ExtSettings(); cursor.Show(); display.Flip(); } - if(HotKeyPress(EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancelGame)) return MAINMENU; - - // right info - if(le.MousePressRight(buttonStandartGame)) Dialog::Message(_("Standard Game"), _("A single player game playing out a single map."), Font::BIG); - if(le.MousePressRight(buttonCampainGame)) Dialog::Message(_("Campaign Game"), _("A single player game playing through a series of maps."), Font::BIG); - if(le.MousePressRight(buttonMultiGame)) Dialog::Message(_("Multi-Player Game"), _("A multi-player game, with several human players completing against each other on a single map."), Font::BIG); - if(le.MousePressRight(buttonSettings)) Dialog::Message(_("Settings"), _("FHeroes2 game settings."), Font::BIG); - if(le.MousePressRight(buttonCancelGame)) Dialog::Message(_("Cancel"), _("Cancel back to the main menu."), Font::BIG); - } - - return QUITGAME; -} - -Game::menu_t Game::NewMulti(void) -{ - // reset prev. scenario info - Settings::Get().SetMyColor(Color::GRAY); - - if(Settings::Get().QVGA()) return PocketPC::NewMulti(); - - // preload - AGG::PreloadObject(ICN::HEROES); - AGG::PreloadObject(ICN::BTNHOTST); - AGG::PreloadObject(ICN::REDBACK); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display & display = Display::Get(); - - // image background - const Sprite &back = AGG::GetICN(ICN::HEROES, 0); - const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2); - display.Blit(back, top); - - const Sprite &panel = AGG::GetICN(ICN::REDBACK, 0); - display.Blit(panel, top.x + 405, top.y + 5); - - LocalEvent & le = LocalEvent::Get(); - - Button buttonHotSeat(top.x + 455, top.y + 45, ICN::BTNMP, 0, 1); - Button buttonNetwork(top.x + 455, top.y + 110, ICN::BTNMP, 2, 3); - Button buttonCancelGame(top.x + 455, top.y + 375, ICN::BTNMP, 8, 9); - - buttonHotSeat.Draw(); - buttonCancelGame.Draw(); -#ifdef WITH_NET - buttonNetwork.Draw(); -#else - buttonNetwork.SetDisable(true); -#endif - - cursor.Show(); - display.Flip(); - - // newgame loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonHotSeat) ? buttonHotSeat.PressDraw() : buttonHotSeat.ReleaseDraw(); - le.MousePressLeft(buttonCancelGame) ? buttonCancelGame.PressDraw() : buttonCancelGame.ReleaseDraw(); - - if(le.MouseClickLeft(buttonHotSeat) || HotKeyPress(EVENT_BUTTON_HOTSEAT)) return NEWHOTSEAT; - if(HotKeyPress(EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancelGame)) return MAINMENU; - - // right info - if(le.MousePressRight(buttonHotSeat)) Dialog::Message(_("Hot Seat"), _("Play a Hot Seat game, where 2 to 4 players play around the same computer, switching into the 'Hot Seat' when it is their turn."), Font::BIG); - if(le.MousePressRight(buttonCancelGame)) Dialog::Message(_("Cancel"), _("Cancel back to the main menu."), Font::BIG); - - if(buttonNetwork.isEnable()) - { - le.MousePressLeft(buttonNetwork) ? buttonNetwork.PressDraw() : buttonNetwork.ReleaseDraw(); - if(le.MouseClickLeft(buttonNetwork) || HotKeyPress(EVENT_BUTTON_NETWORK)) return NEWNETWORK; - if(le.MousePressRight(buttonNetwork)) Dialog::Message(_("Network"), _("Play a network game, where 2 players use their own computers connected through a LAN (Local Area Network)."), Font::BIG); - } - } - - return QUITGAME; -} - -u8 SelectCountPlayers(void) -{ - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display & display = Display::Get(); - - // image background - const Sprite &back = AGG::GetICN(ICN::HEROES, 0); - const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2); - display.Blit(back, top); - - const Sprite &panel = AGG::GetICN(ICN::REDBACK, 0); - display.Blit(panel, top.x + 405, top.y + 5); - - LocalEvent & le = LocalEvent::Get(); - - Button button2Players(top.x + 455, top.y + 45, ICN::BTNHOTST, 0, 1); - Button button3Players(top.x + 455, top.y + 110, ICN::BTNHOTST, 2, 3); - Button button4Players(top.x + 455, top.y + 175, ICN::BTNHOTST, 4, 5); - Button button5Players(top.x + 455, top.y + 240, ICN::BTNHOTST, 6, 7); - Button button6Players(top.x + 455, top.y + 305, ICN::BTNHOTST, 8, 9); - Button buttonCancel(top.x + 455, top.y + 375, ICN::BTNNEWGM, 6, 7); - - button2Players.Draw(); - button3Players.Draw(); - button4Players.Draw(); - button5Players.Draw(); - button6Players.Draw(); - buttonCancel.Draw(); - - cursor.Show(); - display.Flip(); - - // newgame loop - while(le.HandleEvents()) - { - le.MousePressLeft(button2Players) ? button2Players.PressDraw() : button2Players.ReleaseDraw(); - le.MousePressLeft(button3Players) ? button3Players.PressDraw() : button3Players.ReleaseDraw(); - le.MousePressLeft(button4Players) ? button4Players.PressDraw() : button4Players.ReleaseDraw(); - le.MousePressLeft(button5Players) ? button5Players.PressDraw() : button5Players.ReleaseDraw(); - le.MousePressLeft(button6Players) ? button6Players.PressDraw() : button6Players.ReleaseDraw(); - - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - - if(le.MouseClickLeft(button2Players) || le.KeyPress(KEY_2)) return 2; - if(le.MouseClickLeft(button3Players) || le.KeyPress(KEY_3)) return 3; - if(le.MouseClickLeft(button4Players) || le.KeyPress(KEY_4)) return 4; - if(le.MouseClickLeft(button5Players) || le.KeyPress(KEY_5)) return 5; - if(le.MouseClickLeft(button6Players) || le.KeyPress(KEY_6)) return 6; - - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancel)) return 0; - - // right info - if(le.MousePressRight(button2Players)) Dialog::Message(_("2 Players"), _("Play with 2 human players, and optionally, up, to 4 additional computer players."), Font::BIG); - if(le.MousePressRight(button3Players)) Dialog::Message(_("3 Players"), _("Play with 3 human players, and optionally, up, to 3 additional computer players."), Font::BIG); - if(le.MousePressRight(button4Players)) Dialog::Message(_("4 Players"), _("Play with 4 human players, and optionally, up, to 2 additional computer players."), Font::BIG); - if(le.MousePressRight(button5Players)) Dialog::Message(_("5 Players"), _("Play with 5 human players, and optionally, up, to 1 additional computer players."), Font::BIG); - if(le.MousePressRight(button6Players)) Dialog::Message(_("6 Players"), _("Play with 6 human players."), Font::BIG); - if(le.MousePressRight(buttonCancel)) Dialog::Message(_("Cancel"), _("Cancel back to the main menu."), Font::BIG); - } - - return 0; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_over.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_over.cpp deleted file mode 100644 index 440ead157..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_over.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "gamedefs.h" -#include "dialog.h" -#include "world.h" -#include "kingdom.h" -#include "castle.h" -#include "settings.h" -#include "game_over.h" - -const char* GameOver::GetString(conditions_t cond) -{ - const char* cond_str[] = { "None", - _("Defeat all enemy heroes and towns."), _("Capture a specific town."), _("Defeat a specific hero."), _("Find a specific artifact."), _("Your side defeats the opposing side."), _("Accumulate a large amount of gold."), - _("Lose all your heroes and towns."), _("Lose a specific town."), _("Lose a specific hero."), _("Run out of time. (Fail to win by a certain point.)") }; - - switch(cond) - { - case WINS_ALL: return cond_str[1]; - case WINS_TOWN: return cond_str[2]; - case WINS_HERO: return cond_str[3]; - case WINS_ARTIFACT: return cond_str[4]; - case WINS_SIDE: return cond_str[5]; - case WINS_GOLD: return cond_str[6]; - - case LOSS_ALL: return cond_str[7]; - case LOSS_TOWN: return cond_str[8]; - case LOSS_HERO: return cond_str[9]; - case LOSS_TIME: return cond_str[10]; - - default: break; - } - - return cond_str[0]; -} - -void GameOver::GetActualDescription(u16 cond, std::string & msg) -{ - const Settings & conf = Settings::Get(); - - if(WINS_ALL == cond || WINS_SIDE == cond) - msg = GetString(WINS_ALL); - else - if(WINS_TOWN & cond) - { - const Castle *town = world.GetCastle(conf.WinsMapsIndexObject()); - if(town) - { - msg = town->isCastle() ? _("Capture the castle '%{name}'") : _("Capture the town '%{name}'");; - String::Replace(msg, "%{name}", town->GetName()); - } - } - else - if(WINS_HERO & cond) - { - const Heroes *hero = world.GetHeroesCondWins(); - if(hero) - { - msg = _("Defeat the hero '%{name}'"); - String::Replace(msg, "%{name}", hero->GetName()); - } - } - else - if(WINS_ARTIFACT & cond) - { - if(conf.WinsFindUltimateArtifact()) - msg = _("Find the ultimate artifact"); - else - { - msg = _("Find the '%{name}' artifact"); - String::Replace(msg, "%{name}", Artifact::GetName(conf.WinsFindArtifact())); - } - } - else - if(WINS_GOLD & cond) - { - msg = _("Accumulate %{count} gold"); - String::Replace(msg, "%{count}", conf.WinsAccumulateGold()); - } - - if(WINS_ALL != cond && (WINS_ALL & cond)) msg.append(_(", or you may win by defeating all enemy heroes and capturing all enemy towns and castles.")); - - if(LOSS_ALL == cond) - msg = GetString(WINS_ALL); - else - if(LOSS_TOWN & cond) - { - const Castle *town = world.GetCastle(conf.WinsMapsIndexObject()); - if(town) - { - msg = town->isCastle() ? _("Lose the castle '%{name}'.") : _("Lose the town '%{name}'."); - String::Replace(msg, "%{name}", town->GetName()); - } - } - else - if(LOSS_HERO & cond) - { - const Heroes *hero = world.GetHeroesCondWins(); - if(hero) - { - msg = _("Lose the hero '%{name}'."); - String::Replace(msg, "%{name}", hero->GetName()); - } - } - else - if(LOSS_TIME & cond) - { - msg = _("Fail to win by the end of month %{month}, week %{week}, day %{day}."); - String::Replace(msg, "%{day}", (conf.LossCountDays() % DAYOFWEEK)); - String::Replace(msg, "%{week}", (conf.LossCountDays() / DAYOFWEEK) + 1); - String::Replace(msg, "%{month}", (conf.LossCountDays() / (DAYOFWEEK * WEEKOFMONTH)) + 1); - } -} - -void GameOver::DialogWins(u16 cond) -{ - const Settings & conf = Settings::Get(); - std::string body; - - switch(cond) - { - case WINS_ALL: - break; - - case WINS_TOWN: - { - body = _("You captured %{name}!\nYou are victorious."); - const Castle *town = world.GetCastle(conf.WinsMapsIndexObject()); - if(town) String::Replace(body, "%{name}", town->GetName()); - } - break; - - case WINS_HERO: - { - body = _("You have captured the enemy hero %{name}!\nYour quest is complete."); - const Heroes *hero = world.GetHeroesCondWins(); - if(hero) String::Replace(body, "%{name}", hero->GetName()); - break; - } - - case WINS_ARTIFACT: - { - body = _("You have found the %{name}.\nYour quest is complete."); - const Artifact::artifact_t art = conf.WinsFindUltimateArtifact() ? world.GetUltimateArtifact() : conf.WinsFindArtifact(); - String::Replace(body, "%{name}", (conf.WinsFindUltimateArtifact() ? "Ultimate Artifact" : Artifact::GetName(art))); - break; - } - - case WINS_SIDE: - body = _("The enemy is beaten.\nYour side has triumphed!"); - break; - - case WINS_GOLD: - { - body = _("You have built up over %{count} gold in your treasury.\nAll enemies bow before your wealth and power."); - String::Replace(body, "%{count}", conf.WinsAccumulateGold()); - break; - } - - default: break; - } - - if(body.size()) Dialog::Message("", body, Font::BIG, Dialog::OK); -} - -void GameOver::DialogLoss(u16 cond) -{ - const Settings & conf = Settings::Get(); - std::string body; - - switch(cond) - { - case WINS_ARTIFACT: - { - body = _("The enemy has found the %{name}.\nYour quest is a failure."); - const Artifact::artifact_t art = conf.WinsFindArtifact(); - String::Replace(body, "%{name}", Artifact::GetName(art)); - break; - } - - case WINS_SIDE: - { - body = _("%{color} has fallen!\nAll is lost."); - String::Replace(body, "%{color}", Color::String(conf.MyColor())); - break; - } - - case WINS_GOLD: - { - body = _("The enemy has built up over %{count} gold in his treasury.\nYou must bow done in defeat before his wealth and power."); - String::Replace(body, "%{count}", conf.WinsAccumulateGold()); - break; - } - - case LOSS_ALL: - body = _("You have been eliminated from the game!!!"); - break; - - case LOSS_TOWN: - { - body = _("The enemy has captured %{name}!\nThey are triumphant."); - const Castle *town = world.GetCastle(conf.WinsMapsIndexObject()); - if(town) String::Replace(body, "%{name}", town->GetName()); - } - - case LOSS_HERO: - { - body = _("You have lost the hero %{name}.\nYour quest is over."); - const Heroes *hero = world.GetHeroesCondLoss(); - if(hero) String::Replace(body, "%{name}", hero->GetName()); - break; - } - - case LOSS_TIME: - body = _("You have failed to complete your quest in time.\nAll is lost."); - break; - - default: break; - } - - if(body.size()) Dialog::Message("", body, Font::BIG, Dialog::OK); -} - -GameOver::Result & GameOver::Result::Get(void) -{ - static Result gresult; - return gresult; -} - -GameOver::Result::Result() : colors(0), result(0) -{ -} - -void GameOver::Result::Reset(void) -{ - colors = Settings::Get().KingdomColors(); - result = GameOver::COND_NONE; -} - -void GameOver::Result::SetResult(u16 r) -{ - result = r; -} - -u16 GameOver::Result::GetResult(void) const -{ - return result; -} - -namespace Game -{ - void DialogPlayers(const Color::color_t, const std::string &); -} - -bool GameOver::Result::CheckGameOver(Game::menu_t & res) -{ - for(Color::color_t c = Color::BLUE; c != Color::GRAY; ++c) - if(!world.GetKingdom(c).isPlay() && (colors & c)) - { - std::string message(_("%{color} has been vanquished!")); - String::Replace(message, "%{color}", Color::String(c)); - Game::DialogPlayers(c, message); - colors &= (~c); - } - - const Kingdom & myKingdom = world.GetMyKingdom(); - - if(GameOver::COND_NONE != (result = world.CheckKingdomLoss(myKingdom))) - { - GameOver::DialogLoss(result); - res = Game::MAINMENU; - return true; - } - else - if(GameOver::COND_NONE != (result = world.CheckKingdomWins(myKingdom))) - { - GameOver::DialogWins(result); - res = Game::HIGHSCORES; - return true; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_over.h b/project/jni/application/fheroes2/src/fheroes2/game/game_over.h deleted file mode 100644 index 7bbd57a1f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_over.h +++ /dev/null @@ -1,74 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2GAMEOVER_H -#define H2GAMEOVER_H - -#include -#include "game.h" - -namespace GameOver -{ - enum conditions_t - { - COND_NONE = 0x0000, - - WINS_ALL = 0x0001, - WINS_TOWN = 0x0002, - WINS_HERO = 0x0004, - WINS_ARTIFACT = 0x0008, - WINS_SIDE = 0x0010, - WINS_GOLD = 0x0020, - WINS = WINS_ALL | WINS_TOWN | WINS_HERO | WINS_ARTIFACT | WINS_SIDE | WINS_GOLD, - - LOSS_ALL = 0x0100, - LOSS_TOWN = 0x0200, - LOSS_HERO = 0x0400, - LOSS_TIME = 0x0800, - LOSS = LOSS_ALL | LOSS_TOWN | LOSS_HERO | LOSS_TIME - }; - - const char* GetString(conditions_t); - void GetActualDescription(u16, std::string &); - - void DialogWins(u16); - void DialogLoss(u16); - - class Result - { - public: - static Result & Get(void); - - void Reset(void); - void SetResult(u16); - u16 GetResult(void) const; - bool CheckGameOver(Game::menu_t &); - - private: - Result(); - - u8 colors; - u16 result; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_scenarioinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_scenarioinfo.cpp deleted file mode 100644 index e0bc4c910..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_scenarioinfo.cpp +++ /dev/null @@ -1,543 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "agg.h" -#include "gamedefs.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "maps_fileinfo.h" -#include "dialog_selectscenario.h" -#include "difficulty.h" -#include "dialog.h" -#include "text.h" -#include "kingdom.h" -#include "splitter.h" -#include "world.h" -#include "player.h" -#include "pocketpc.h" -#include "game.h" - -u16 GetStepFor(u16, u16, u16); -void RedrawRatingInfo(TextSprite &); -void UpdateCoordOpponentsInfo(const Point &, std::vector &); -void UpdateCoordClassInfo(const Point &, std::vector &); - -Game::menu_t Game::SelectScenario(void) -{ - if(Settings::Get().QVGA()) return PocketPC::SelectScenario(); - return SCENARIOINFO; -} - -Game::menu_t Game::ScenarioInfo(void) -{ - Settings & conf = Settings::Get(); - if(conf.QVGA()) return PocketPC::ScenarioInfo(); - - AGG::PlayMusic(MUS::MAINMENU); - - MapsFileInfoList lists; - if(!PrepareMapsFileInfoList(lists, (conf.GameType() & Game::MULTI))) - { - Dialog::Message(_("Warning"), _("No maps available!"), Font::BIG, Dialog::OK); - return MAINMENU; - } - - // preload - AGG::PreloadObject(ICN::HEROES); - AGG::PreloadObject(ICN::NGEXTRA); - AGG::PreloadObject(ICN::NGHSBKG); - - menu_t result = QUITGAME; - LocalEvent & le = LocalEvent::Get(); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Display & display = Display::Get(); - - // image background - const Sprite &back = AGG::GetICN(ICN::HEROES, 0); - const Point top((display.w() - back.w()) / 2, (display.h() - back.h()) / 2); - display.Blit(back, top); - - const bool reset_starting_settings = (Color::GRAY == conf.MyColor() || !FilePresent(conf.MapsFile())); - - // set first maps settings - if(reset_starting_settings) - conf.LoadFileMapsMP2(lists.front().file); - - const Point pointPanel(top.x + 204, top.y + 32); - const Point pointDifficultyInfo(pointPanel.x + 24, pointPanel.y + 93); - const Point pointOpponentInfo(pointPanel.x + 24, pointPanel.y + 202); - const Point pointClassInfo(pointPanel.x + 24, pointPanel.y + 282); - - const Sprite &panel = AGG::GetICN(ICN::NGHSBKG, 0); - const Rect box(pointPanel, panel.w(), panel.h()); - - Button buttonSelectMaps(pointPanel.x + 309, pointPanel.y + 45, ICN::NGEXTRA, 64, 65); - Button buttonOk(pointPanel.x + 31, pointPanel.y + 380, ICN::NGEXTRA, 66, 67); - Button buttonCancel(pointPanel.x + 287, pointPanel.y + 380, ICN::NGEXTRA, 68, 69); - - std::vector::iterator itr; - - // vector coord difficulty - std::vector coordDifficulty(5); - - // vector coord colors opponent - std::vector coordColors(KINGDOMMAX); - - // vector coord class - std::vector coordClass(KINGDOMMAX); - - // first allow color - if(reset_starting_settings) - { - const Maps::FileInfo & info = conf.CurrentFileInfo(); - - if(info.HumanOnlyColors()) - conf.SetPlayersColors(info.HumanOnlyColors()); - else - conf.SetPlayersColors(conf.MyColor()); - - conf.SetMyColor(conf.FirstAllowColor()); - } - - Scenario::RedrawStaticInfo(pointPanel); - Scenario::RedrawDifficultyInfo(pointDifficultyInfo); - - UpdateCoordOpponentsInfo(pointOpponentInfo, coordColors); - Scenario::RedrawOpponentsInfo(pointOpponentInfo); - - UpdateCoordClassInfo(pointClassInfo, coordClass); - Scenario::RedrawClassInfo(pointClassInfo); - - const Sprite & ngextra = AGG::GetICN(ICN::NGEXTRA, 62); - - coordDifficulty[0] = Rect(pointPanel.x + 21, pointPanel.y + 91, ngextra.w(), ngextra.h()); - coordDifficulty[1] = Rect(pointPanel.x + 98, pointPanel.y + 91, ngextra.w(), ngextra.h()); - coordDifficulty[2] = Rect(pointPanel.x + 174, pointPanel.y + 91, ngextra.w(), ngextra.h()); - coordDifficulty[3] = Rect(pointPanel.x + 251, pointPanel.y + 91, ngextra.w(), ngextra.h()); - coordDifficulty[4] = Rect(pointPanel.x + 328, pointPanel.y + 91, ngextra.w(), ngextra.h()); - - SpriteCursor levelCursor(ngextra); - - switch(conf.GameDifficulty()) - { - case Difficulty::EASY: levelCursor.Move(coordDifficulty[0]); break; - case Difficulty::NORMAL: levelCursor.Move(coordDifficulty[1]); break; - case Difficulty::HARD: levelCursor.Move(coordDifficulty[2]); break; - case Difficulty::EXPERT: levelCursor.Move(coordDifficulty[3]); break; - case Difficulty::IMPOSSIBLE: levelCursor.Move(coordDifficulty[4]); break; - } - - levelCursor.Show(); - - - TextSprite rating; - rating.SetFont(Font::BIG); - rating.SetPos(pointPanel.x + 166, pointPanel.y + 383); - RedrawRatingInfo(rating); - - buttonSelectMaps.Draw(); - buttonOk.Draw(); - buttonCancel.Draw(); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - // press button - le.MousePressLeft(buttonSelectMaps) ? buttonSelectMaps.PressDraw() : buttonSelectMaps.ReleaseDraw(); - le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - - // click select - if(Game::HotKeyPress(Game::EVENT_BUTTON_SELECT) || le.MouseClickLeft(buttonSelectMaps)) - { - std::string filemaps; - if(Dialog::SelectScenario(lists, filemaps) && conf.LoadFileMapsMP2(filemaps)) - { - cursor.Hide(); - levelCursor.Hide(); - const Maps::FileInfo & info = conf.CurrentFileInfo(); - if(info.HumanOnlyColors()) - conf.SetPlayersColors(info.HumanOnlyColors()); - else - conf.SetPlayersColors(conf.MyColor()); - conf.SetMyColor(conf.FirstAllowColor()); - Scenario::RedrawStaticInfo(pointPanel); - Scenario::RedrawDifficultyInfo(pointDifficultyInfo); - UpdateCoordOpponentsInfo(pointOpponentInfo, coordColors); - Scenario::RedrawOpponentsInfo(pointOpponentInfo); - UpdateCoordClassInfo(pointClassInfo, coordClass); - Scenario::RedrawClassInfo(pointClassInfo); - RedrawRatingInfo(rating); - // default difficulty normal - levelCursor.Move(coordDifficulty[1]); - levelCursor.Show(); - conf.SetGameDifficulty(Difficulty::NORMAL); - } - cursor.Show(); - display.Flip(); - } - else - // click cancel - if(HotKeyPress(EVENT_DEFAULT_EXIT) || le.MouseClickLeft(buttonCancel)) - { - Settings::Get().SetGameType(Game::UNKNOWN); - result = MAINMENU; - break; - } - else - // click ok - if(HotKeyPress(EVENT_DEFAULT_READY) || le.MouseClickLeft(buttonOk)) - { - DEBUG(DBG_GAME , DBG_INFO, "Game::ScenarioInfo: select maps: " << conf.MapsFile() << \ - ", difficulty: " << Difficulty::String(conf.GameDifficulty())); - conf.FixKingdomRandomRace(); - if(Game::HOTSEAT == conf.GameType()) - conf.SetMyColor(Color::GRAY); - else - DEBUG(DBG_GAME , DBG_INFO, "Game::ScenarioInfo: select color: " << Color::String(conf.MyColor())); - result = STARTGAME; - break; - } - else - if(le.MouseClickLeft(box)) - { - // select difficulty - if(coordDifficulty.end() != (itr = std::find_if(coordDifficulty.begin(), coordDifficulty.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - { - cursor.Hide(); - levelCursor.Move((*itr).x, (*itr).y); - conf.SetGameDifficulty(Difficulty::Get(itr - coordDifficulty.begin())); - RedrawRatingInfo(rating); - cursor.Show(); - display.Flip(); - } - else - // select color - if(coordColors.end() != (itr = std::find_if(coordColors.begin(), coordColors.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - { - Color::color_t color = Color::GetFromIndex(itr - coordColors.begin()); - const Maps::FileInfo & info = conf.CurrentFileInfo(); - if(info.HumanOnlyColors() & color) - { - // change human only color to other player - } - else - if(conf.AllowColors(color)) - { - cursor.Hide(); - switch(conf.GameType()) - { - case Game::NETWORK: - case Game::HOTSEAT: - conf.SetPlayersColors(conf.PlayersColors() & color ? conf.PlayersColors() & ~color : conf.PlayersColors() | color); - break; - default: - conf.SetMyColor(color); - conf.SetPlayersColors(conf.MyColor()); - break; - } - Scenario::RedrawOpponentsInfo(pointOpponentInfo); - cursor.Show(); - display.Flip(); - } - } - else - // select class - if(coordClass.end() != (itr = std::find_if(coordClass.begin(), coordClass.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - { - Color::color_t color = Color::GetFromIndex(itr - coordClass.begin()); - if(conf.AllowChangeRace(color)) - { - cursor.Hide(); - Race::race_t race = conf.KingdomRace(color); - switch(race) - { - case Race::KNGT: race = Race::BARB; break; - case Race::BARB: race = Race::SORC; break; - case Race::SORC: race = Race::WRLK; break; - case Race::WRLK: race = Race::WZRD; break; - case Race::WZRD: race = Race::NECR; break; - case Race::NECR: race = Race::RAND; break; - case Race::RAND: race = Race::KNGT; break; - default: break; - } - conf.SetKingdomRace(color, race); - Scenario::RedrawStaticInfo(pointPanel); - levelCursor.Redraw(); - Scenario::RedrawDifficultyInfo(pointDifficultyInfo); - Scenario::RedrawOpponentsInfo(pointOpponentInfo); - Scenario::RedrawClassInfo(pointClassInfo); - RedrawRatingInfo(rating); - cursor.Show(); - display.Flip(); - } - } - } - - if(le.MousePressRight(box)) - { - // right info - if(le.MousePressRight(buttonSelectMaps)) Dialog::Message(_("Scenario"), _("Click here to select which scenario to play."), Font::BIG); - else - // difficulty - if(coordDifficulty.end() != (itr = std::find_if(coordDifficulty.begin(), coordDifficulty.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - Dialog::Message(_("Game Difficulty"), _("This lets you change the starting difficulty at which you will play. Higher difficulty levels start you of with fewer resources, and at the higher settings, give extra resources to the computer."), Font::BIG); - else - // color - if(coordColors.end() != (itr = std::find_if(coordColors.begin(), coordColors.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor()))) && - conf.KingdomColors(Color::GetFromIndex(itr - coordColors.begin()))) - Dialog::Message(_("Opponents"), _("This lets you change player starting positions and colors. A particular color will always start in a particular location. Some positions may only be played by a computer player or only by a human player."), Font::BIG); - else - // class - if(coordClass.end() != (itr = std::find_if(coordClass.begin(), coordClass.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor()))) && - conf.KingdomColors(Color::GetFromIndex(itr - coordClass.begin()))) - Dialog::Message(_("Class"), _("This lets you change the class of a player. Classes are not always changeable. Depending on the scenario, a player may receive additional towns and/or heroes not of their primary alignment."), Font::BIG); - else - if(le.MousePressRight(rating.GetRect())) Dialog::Message(_("Difficulty Rating"), _("The difficulty rating reflects a combination of various settings for your game. This number will be applied to your final score."), Font::BIG); - else - if(le.MousePressRight(buttonOk)) Dialog::Message(_("OK"), _("Click to accept these settings and start a new game."), Font::BIG); - else - if(le.MousePressRight(buttonCancel)) Dialog::Message(_("Cancel"), _("Click to return to the main menu."), Font::BIG); - } - } - - cursor.Hide(); - - if(result == STARTGAME) - { - if(Settings::Get().ExtUseFade()) display.Fade(); - Game::ShowLoadMapsText(); - // Load maps - world.LoadMaps(conf.MapsFile()); - } - - return result; -} - -u16 GetStepFor(u16 current, u16 width, u16 count) -{ - return current * width * 6 / count + (width * (6 - count) / (2 * count)); -} - -void UpdateCoordClassInfo(const Point & dst, std::vector & rects) -{ - UpdateCoordOpponentsInfo(dst, rects); -} - -void UpdateCoordOpponentsInfo(const Point & dst, std::vector & rects) -{ - const Settings & conf = Settings::Get(); - const u8 count = conf.KingdomColorsCount(); - const Sprite &sprite = AGG::GetICN(ICN::NGEXTRA, 3); - u8 current = 0; - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - rects[Color::GetIndex(color)] = conf.KingdomColors(color) ? Rect(dst.x + GetStepFor(current++, sprite.w(), count), dst.y, sprite.w(), sprite.h()) : Rect(); -} - -void Game::Scenario::RedrawStaticInfo(const Point & pt) -{ - Display & display = Display::Get(); - const Settings & conf = Settings::Get(); - - // image panel - const Sprite &panel = AGG::GetICN(ICN::NGHSBKG, 0); - display.Blit(panel, pt); - - // text scenario - Text text(_("Scenario:"), Font::BIG); - text.Blit(pt.x + (panel.w() - text.w()) / 2, pt.y + 20); - - // maps name - text.Set(conf.MapsName()); - text.Blit(pt.x + (panel.w() - text.w()) / 2, pt.y + 46); - - // text game difficulty - text.Set(_("Game Difficulty:")); - text.Blit(pt.x + (panel.w() - text.w()) / 2, pt.y + 75); - - // text opponents - text.Set(_("Opponents:"), Font::BIG); - text.Blit(pt.x + (panel.w() - text.w()) / 2, pt.y + 181); - - // text class - text.Set(_("Class:"), Font::BIG); - text.Blit(pt.x + (panel.w() - text.w()) / 2, pt.y + 262); -} - -void Game::Scenario::RedrawOpponentsInfo(const Point & dst, const std::vector *players) -{ - const Settings & conf = Settings::Get(); - const u8 count = conf.KingdomColorsCount(); - - u8 current = 0; - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - { - if(conf.KingdomColors(color)) - { - u8 index = 0; - - if(!(conf.AllowColors(color))) - { - // comp only - switch(color) - { - case Color::BLUE: index = players ? 39 : 15; break; - case Color::GREEN: index = players ? 40 : 16; break; - case Color::RED: index = players ? 41 : 17; break; - case Color::YELLOW: index = players ? 42 : 18; break; - case Color::ORANGE: index = players ? 43 : 19; break; - case Color::PURPLE: index = players ? 44 : 20; break; - default: break; - } - } - else - if(conf.PlayersColors() & color) - { - // cur player - switch(color) - { - case Color::BLUE: index = players ? 33 : 9; break; - case Color::GREEN: index = players ? 34 : 10; break; - case Color::RED: index = players ? 35 : 11; break; - case Color::YELLOW: index = players ? 36 : 12; break; - case Color::ORANGE: index = players ? 37 : 13; break; - case Color::PURPLE: index = players ? 38 : 14; break; - default: break; - } - } - else - { - // comp/human - switch(color) - { - case Color::BLUE: index = players ? 27 : 3; break; - case Color::GREEN: index = players ? 28 : 4; break; - case Color::RED: index = players ? 29 : 5; break; - case Color::YELLOW: index = players ? 30 : 6; break; - case Color::ORANGE: index = players ? 31 : 7; break; - case Color::PURPLE: index = players ? 32 : 8; break; - default: break; - } - } - - if(index) - { - const Sprite & sprite = AGG::GetICN(ICN::NGEXTRA, index); - Display::Get().Blit(sprite, dst.x + GetStepFor(current, sprite.w(), count), dst.y); - - // draw name - if(players) - { - std::vector::const_iterator itp = std::find_if(players->begin(), players->end(), std::bind2nd(std::mem_fun_ref(&Player::isColor), color)); - if(players->end() != itp) - { - Text name((*itp).player_name, Font::SMALL); - name.Blit(dst.x + GetStepFor(current, sprite.w(), count) + (sprite.w() - name.w()) / 2, dst.y + sprite.h() - 14); - } - } - - ++current; - } - } - } -} - -void Game::Scenario::RedrawClassInfo(const Point & dst, bool label) -{ - Display & display = Display::Get(); - const Settings & conf = Settings::Get(); - const u8 count = conf.KingdomColorsCount(); - u8 current = 0; - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(conf.KingdomColors(color)) - { - u8 index = 0; - const Race::race_t race = conf.KingdomRace(color); - switch(race) - { - case Race::KNGT: index = conf.AllowChangeRace(color) ? 51 : 70; break; - case Race::BARB: index = conf.AllowChangeRace(color) ? 52 : 71; break; - case Race::SORC: index = conf.AllowChangeRace(color) ? 53 : 72; break; - case Race::WRLK: index = conf.AllowChangeRace(color) ? 54 : 73; break; - case Race::WZRD: index = conf.AllowChangeRace(color) ? 55 : 74; break; - case Race::NECR: index = conf.AllowChangeRace(color) ? 56 : 75; break; - case Race::MULT: index = 76; break; - case Race::RAND: index = 58; break; - default: continue; - } - - const Sprite &sprite = AGG::GetICN(ICN::NGEXTRA, index); - display.Blit(sprite, dst.x + GetStepFor(current, sprite.w(), count), dst.y); - - if(label) - { - const std::string & name = (Race::NECR == race ? _("Necroman") : Race::String(race)); - Text text(name, Font::SMALL); - text.Blit(dst.x + GetStepFor(current, sprite.w(), count) + (sprite.w() - text.w()) / 2, dst.y + sprite.h() + 2); - } - - ++current; - } -} - -void Game::Scenario::RedrawDifficultyInfo(const Point & dst, bool label) -{ - Display & display = Display::Get(); - - for(u8 current = Difficulty::EASY; current <= Difficulty::IMPOSSIBLE; ++current) - { - const Sprite & sprite = AGG::GetICN(ICN::NGHSBKG, 0); - Rect src_rt(24, 94, 65, 65); - u16 offset = current * (src_rt.w + 12); - src_rt.x = src_rt.x + offset; - display.Blit(sprite, src_rt, dst.x + offset, dst.y); - - if(label) - { - Text text(Difficulty::String(current), Font::SMALL); - text.Blit(dst.x + offset + (src_rt.w - text.w()) / 2, dst.y + src_rt.h + 5); - } - } -} - -void RedrawRatingInfo(TextSprite & sprite) -{ - sprite.Hide(); - std::string str(_("Rating %{rating}%")); - String::Replace(str, "%{rating}", Game::GetRating()); - sprite.SetText(str); - sprite.Show(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/game_startgame.cpp b/project/jni/application/fheroes2/src/fheroes2/game/game_startgame.cpp deleted file mode 100644 index 896d30e00..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/game_startgame.cpp +++ /dev/null @@ -1,1672 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include - -#include "agg.h" -#include "engine.h" -#include "button.h" -#include "dialog.h" -#include "world.h" -#include "cursor.h" -#include "castle.h" -#include "heroes.h" -#include "splitter.h" -#include "maps_tiles.h" -#include "ground.h" -#include "gameevent.h" -#include "game_interface.h" -#include "game_io.h" -#include "settings.h" -#include "route.h" -#include "game_focus.h" -#include "kingdom.h" -#include "localclient.h" - -// heroes_action.cpp -u16 DialogWithArtifact(const std::string & hdr, const std::string & msg, const Artifact::artifact_t art, const u16 buttons = Dialog::OK); - -namespace Game -{ - Cursor::themes_t GetCursor(const s32); - void OpenCastle(Castle *castle); - void OpenHeroes(Heroes *heroes); - void ShowPathOrStartMoveHero(Heroes *hero, const s32 dst_index); - menu_t HumanTurn(void); - bool DiggingForArtifacts(const Heroes & hero); - void DialogPlayers(const Color::color_t, const std::string &); - void MoveHeroFromArrowKeys(Heroes & hero, Direction::vector_t direct); - - void MouseCursorAreaClickLeft(s32); - void FocusHeroesClickLeftAction(Heroes &, s32); - void FocusCastleClickLeftAction(Castle &, s32); - void MouseCursorAreaPressRight(s32); - - void StartNewGame(menu_t &); - - void KeyArrowPress(Direction::vector_t); - - void NewWeekDialog(void); - void ShowEventDay(void); - void ShowWarningLostTowns(menu_t &); -} - -void Game::MoveHeroFromArrowKeys(Heroes & hero, Direction::vector_t direct) -{ - if(Maps::isValidDirection(hero.GetIndex(), direct)) - { - s32 dst = Maps::GetDirectionIndex(hero.GetIndex(), direct); - const Maps::Tiles & tile = world.GetTiles(dst); - bool allow = false; - - switch(tile.GetObject()) - { - case MP2::OBJN_CASTLE: - { - const Castle *to_castle = world.GetCastle(dst); - if(to_castle) - { - dst = to_castle->GetIndex(); - allow = true; - } - break; - } - - case MP2::OBJ_BOAT: - case MP2::OBJ_CASTLE: - case MP2::OBJ_HEROES: - case MP2::OBJ_MONSTER: - allow = true; - break; - - default: - allow = (tile.isPassable(&hero) || MP2::isActionObject(tile.GetObject(), hero.isShipMaster())); - break; - } - - if(allow) ShowPathOrStartMoveHero(&hero, dst); - } -} - -void Game::DialogPlayers(const Color::color_t color, const std::string & str) -{ - const Sprite & border = AGG::GetICN(ICN::BRCREST, 6); - - Surface sign(border.w(), border.h()); - sign.Blit(border); - - switch(color) - { - case Color::BLUE: sign.Blit(AGG::GetICN(ICN::BRCREST, 0), 4, 4); break; - case Color::GREEN: sign.Blit(AGG::GetICN(ICN::BRCREST, 1), 4, 4); break; - case Color::RED: sign.Blit(AGG::GetICN(ICN::BRCREST, 2), 4, 4); break; - case Color::YELLOW: sign.Blit(AGG::GetICN(ICN::BRCREST, 3), 4, 4); break; - case Color::ORANGE: sign.Blit(AGG::GetICN(ICN::BRCREST, 4), 4, 4); break; - case Color::PURPLE: sign.Blit(AGG::GetICN(ICN::BRCREST, 5), 4, 4); break; - default: break; - } - - Dialog::SpriteInfo("", str, sign); -} - -Game::menu_t Game::StartGame(void) -{ - SetFixVideoMode(); - - // cursor - Cursor & cursor = Cursor::Get(); - Settings & conf = Settings::Get(); - Display & display = Display::Get(); - - GameOver::Result::Get().Reset(); - - cursor.Hide(); - - AGG::ICNRegistryFreeObjects(); - AGG::ICNRegistryEnable(false); - - AGG::Cache::Get().ResetMixer(); - - // draw interface - Interface::Basic & I = Interface::Basic::Get(); - - Interface::GameArea & areaMaps = I.gameArea; - areaMaps.Build(); - - Game::Focus & global_focus = Focus::Get(); - global_focus.Reset(); - - Interface::Radar & radar = I.radar; - Interface::StatusWindow& statusWin = I.statusWindow; - - I.iconsPanel.ResetIcons(); - - radar.Build(); - - I.Redraw(REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_BORDER); - I.iconsPanel.HideIcons(); - - Game::menu_t m = ENDTURN; - - while(m == ENDTURN) - { - if(!conf.LoadedGameVersion()) - world.NewDay(); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - { - Kingdom & kingdom = world.GetKingdom(color); - - if(!kingdom.isPlay() || - (conf.LoadedGameVersion() && color != conf.MyColor())) continue; - - if(IS_DEBUG(DBG_GAME, DBG_INFO)) kingdom.Dump(); - - radar.SetHide(true); - I.SetRedraw(REDRAW_RADAR); - conf.SetCurrentColor(color); - world.ClearFog(color); - kingdom.ActionBeforeTurn(); - - switch(kingdom.Control()) - { - case LOCAL: - if(Game::HOTSEAT == conf.GameType()) - { - cursor.Hide(); - conf.SetMyColor(Color::GRAY); - I.iconsPanel.HideIcons(); - statusWin.Reset(); - I.SetRedraw(REDRAW_GAMEAREA | REDRAW_STATUS | REDRAW_ICONS); - I.Redraw(); - display.Flip(); - std::string str = _("%{color} player's turn"); - String::Replace(str, "%{color}", Color::String(color)); - DialogPlayers(color, str); - } - I.SetRedraw(REDRAW_ICONS); - I.iconsPanel.ShowIcons(); - conf.SetMyColor(color); - m = HumanTurn(); - if(m == ENDTURN && conf.LoadedGameVersion()) conf.SetLoadedGameVersion(false); - break; - - // AI turn - default: - if(m == ENDTURN) - { - statusWin.Reset(); - statusWin.SetState(STATUS_AITURN); - - // for pocketpc: show status window - if(conf.QVGA() && !conf.ShowStatus()) - { - conf.SetShowStatus(true); - I.SetRedraw(REDRAW_STATUS); - } - - cursor.Hide(); - cursor.SetThemes(Cursor::WAIT); - I.Redraw(); - cursor.Show(); - display.Flip(); - - kingdom.AITurns(); - } - break; - } - - if(m != ENDTURN) break; - } - - DELAY(10); - } - - return m == ENDTURN ? QUITGAME : m; -} - -/* open castle wrapper */ -void Game::OpenCastle(Castle *castle) -{ - if(! castle) return; - - Mixer::Reduce(); - - Cursor & cursor = Cursor::Get(); - Kingdom & myKingdom = world.GetMyKingdom(); - const Settings & conf = Settings::Get(); - std::vector & myCastles = myKingdom.GetCastles(); - Display & display = Display::Get(); - std::vector::const_iterator it = std::find(myCastles.begin(), myCastles.end(), castle); - Game::Focus & globalfocus = Game::Focus::Get(); - Interface::StatusWindow::ResetTimer(); - bool show_position = !Settings::Get().QVGA() && (640 != display.w() || 480 != display.h()); - bool need_fade = !show_position; - - if(it != myCastles.end() || conf.IsUnions(conf.MyColor(), castle->GetColor())) - { - Dialog::answer_t result = Dialog::ZERO; - - while(Dialog::CANCEL != result) - { - if(show_position) - { - globalfocus.Set(*it); - globalfocus.SetRedraw(); - cursor.Hide(); - Interface::Basic::Get().Redraw(); - cursor.Show(); - display.Flip(); - DELAY(100); - } - - if(Settings::Get().ExtLowMemory()) - AGG::ICNRegistryEnable(true); - - result = castle->OpenDialog((conf.MyColor() != castle->GetColor()), need_fade); - if(need_fade) need_fade = false; - - if(Settings::Get().ExtLowMemory()) - { - AGG::ICNRegistryEnable(false); - AGG::ICNRegistryFreeObjects(); - } - - if(it != myCastles.end()) - { - if(Dialog::PREV == result) - { - if(it == myCastles.begin()) it = myCastles.end(); - --it; - } - else - if(Dialog::NEXT == result) - { - ++it; - if(it == myCastles.end()) it = myCastles.begin(); - } - - castle = (*it); - } - } - } - - if(it != myCastles.end()) - { - globalfocus.Set(*it); - globalfocus.Set((*it)->GetHeroes()); - } - globalfocus.SetRedraw(); - - Mixer::Enhance(); -} - -/* open heroes wrapper */ -void Game::OpenHeroes(Heroes *hero) -{ - if(! hero) return; - - Mixer::Reduce(); - - Cursor & cursor = Cursor::Get(); - Kingdom & myKingdom = world.GetMyKingdom(); - std::vector & myHeroes = myKingdom.GetHeroes(); - Display & display = Display::Get(); - std::vector::const_iterator it = std::find(myHeroes.begin(), myHeroes.end(), hero); - Game::Focus & globalfocus = Game::Focus::Get(); - Interface::StatusWindow::ResetTimer(); - Interface::Basic & I = Interface::Basic::Get(); - bool show_position = !Settings::Get().QVGA() && (640 != display.w() || 480 != display.h()); - bool need_fade = !show_position; - - if(it != myHeroes.end()) - { - Dialog::answer_t result = Dialog::ZERO; - - while(Dialog::CANCEL != result) - { - if(show_position) - { - globalfocus.Set(*it); - globalfocus.SetRedraw(); - cursor.Hide(); - I.Redraw(); - cursor.Show(); - display.Flip(); - DELAY(100); - } - - if(Settings::Get().ExtLowMemory()) - AGG::ICNRegistryEnable(true); - - result = (*it)->OpenDialog(false, need_fade); - if(need_fade) need_fade = false; - - if(Settings::Get().ExtLowMemory()) - { - AGG::ICNRegistryEnable(false); - AGG::ICNRegistryFreeObjects(); - } - - switch(result) - { - case Dialog::PREV: - if(it == myHeroes.begin()) it = myHeroes.end(); - --it; - break; - - case Dialog::NEXT: - ++it; - if(it == myHeroes.end()) it = myHeroes.begin(); - break; - - case Dialog::DISMISS: - AGG::PlaySound(M82::KILLFADE); - - (*it)->GetPath().Hide(); - I.SetRedraw(REDRAW_GAMEAREA); - - (*it)->FadeOut(); - (*it)->SetFreeman(0); - it = myHeroes.begin(); - result = Dialog::CANCEL; - break; - - default: break; - } - } - } - - if(it != myHeroes.end()) - globalfocus.Set(*it); - else - globalfocus.Reset(Game::Focus::HEROES); - globalfocus.SetRedraw(); - - Mixer::Enhance(); -} - -/* return changee cursor */ -Cursor::themes_t Game::GetCursor(const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - if(tile.isFog(Settings::Get().MyColor())) return Cursor::POINTER; - - const Game::Focus & focus = Game::Focus::Get(); - const Settings & conf = Settings::Get(); - - switch(focus.Type()) - { - case Focus::HEROES: - { - const Heroes & from_hero = focus.GetHeroes(); - - if(from_hero.Modes(Heroes::ENABLEMOVE)) return Cursor::Get().Themes(); - - if(from_hero.isShipMaster()) - { - switch(tile.GetObject()) - { - case MP2::OBJ_BOAT: - return Cursor::POINTER; - - case MP2::OBJN_CASTLE: - { - const Castle *castle = world.GetCastle(dst_index); - - if(NULL != castle) - return from_hero.GetColor() == castle->GetColor() ? Cursor::CASTLE : Cursor::POINTER; - } - break; - - case MP2::OBJ_CASTLE: - { - const Castle *castle = world.GetCastle(dst_index); - - if(NULL != castle) - return from_hero.GetColor() == castle->GetColor() ? Cursor::CASTLE : Cursor::POINTER; - } - break; - - case MP2::OBJ_HEROES: - { - const Heroes * to_hero = world.GetHeroes(dst_index); - - if(NULL != to_hero && to_hero->isShipMaster()) - { - if(to_hero->GetCenter() == from_hero.GetCenter()) - return Cursor::HEROES; - else - if(from_hero.GetColor() == to_hero->GetColor()) - return Cursor::DistanceThemes(Cursor::CHANGE, from_hero.GetRangeRouteDays(dst_index)); - else - if(conf.IsUnions(from_hero.GetColor(), to_hero->GetColor())) - return conf.ExtUnionsAllowHeroesMeetings() ? Cursor::CHANGE : Cursor::POINTER; - else - if(to_hero->AllowBattle()) - return Cursor::DistanceThemes(Cursor::FIGHT, from_hero.GetRangeRouteDays(dst_index)); - } - } - break; - - case MP2::OBJ_COAST: - return Cursor::DistanceThemes(Cursor::ANCHOR, from_hero.GetRangeRouteDays(dst_index)); - - default: - if(MP2::isWaterObject(tile.GetObject())) - return Cursor::DistanceThemes(Cursor::REDBOAT, from_hero.GetRangeRouteDays(dst_index)); - else - if(tile.isPassable(&from_hero)) - return Cursor::DistanceThemes(Cursor::BOAT, from_hero.GetRangeRouteDays(dst_index)); - else - return Cursor::POINTER; - } - } - else - { - switch(tile.GetObject()) - { - case MP2::OBJ_MONSTER: - return Cursor::DistanceThemes(Cursor::FIGHT, from_hero.GetRangeRouteDays(dst_index)); - - case MP2::OBJN_CASTLE: - { - const Castle *castle = world.GetCastle(dst_index); - - if(NULL != castle) - { - if(from_hero.GetColor() == castle->GetColor()) - return Cursor::CASTLE; - else - if(conf.IsUnions(from_hero.GetColor(), castle->GetColor())) - return conf.ExtUnionsAllowCastleVisiting() ? Cursor::ACTION : Cursor::POINTER; - else - if(castle->GetArmy().isValid()) - return Cursor::DistanceThemes(Cursor::FIGHT, from_hero.GetRangeRouteDays(dst_index)); - else - return Cursor::DistanceThemes(Cursor::ACTION, from_hero.GetRangeRouteDays(dst_index)); - } - } - break; - - case MP2::OBJ_CASTLE: - { - const Castle *castle = world.GetCastle(dst_index); - - if(NULL != castle) - { - if(from_hero.GetColor() == castle->GetColor()) - return Cursor::DistanceThemes(Cursor::ACTION, from_hero.GetRangeRouteDays(dst_index)); - else - if(conf.IsUnions(from_hero.GetColor(), castle->GetColor())) - return conf.ExtUnionsAllowCastleVisiting() ? Cursor::ACTION : Cursor::POINTER; - else - if(castle->GetArmy().isValid()) - return Cursor::DistanceThemes(Cursor::FIGHT, from_hero.GetRangeRouteDays(dst_index)); - else - return Cursor::DistanceThemes(Cursor::ACTION, from_hero.GetRangeRouteDays(dst_index)); - } - } - break; - - case MP2::OBJ_HEROES: - { - const Heroes * to_hero = world.GetHeroes(dst_index); - - if(NULL != to_hero && (!to_hero->isShipMaster() || - from_hero.CanPassToShipMaster(*to_hero))) - { - if(to_hero->GetCenter() == from_hero.GetCenter()) - return Cursor::HEROES; - else - if(from_hero.GetColor() == to_hero->GetColor()) - return Cursor::DistanceThemes(Cursor::CHANGE, from_hero.GetRangeRouteDays(dst_index)); - else - if(conf.IsUnions(from_hero.GetColor(), to_hero->GetColor())) - return conf.ExtUnionsAllowHeroesMeetings() ? Cursor::CHANGE : Cursor::POINTER; - else - return Cursor::DistanceThemes(Cursor::FIGHT, from_hero.GetRangeRouteDays(dst_index)); - } - } - break; - - case MP2::OBJ_BOAT: - return Cursor::DistanceThemes(Cursor::BOAT, from_hero.GetRangeRouteDays(dst_index)); - - default: - if(MP2::isGroundObject(tile.GetObject())) - { - bool protection = (MP2::isPickupObject(tile.GetObject()) ? false : - (Maps::TileUnderProtection(dst_index) || tile.CheckEnemyGuardians(from_hero.GetColor()))); - - return Cursor::DistanceThemes((protection ? Cursor::FIGHT : Cursor::ACTION), - from_hero.GetRangeRouteDays(dst_index)); - } - else - if(tile.isPassable(&from_hero)) - { - bool protection = Maps::TileUnderProtection(dst_index); - - return Cursor::DistanceThemes((protection ? Cursor::FIGHT : Cursor::MOVE), - from_hero.GetRangeRouteDays(dst_index)); - } - else - return Cursor::POINTER; - } - } - } - break; - - case Focus::CASTLE: - { - const Castle & from_castle = focus.GetCastle(); - - switch(tile.GetObject()) - { - case MP2::OBJN_CASTLE: - case MP2::OBJ_CASTLE: - { - const Castle *to_castle = world.GetCastle(dst_index); - - if(NULL != to_castle) - return to_castle->GetColor() == from_castle.GetColor() ? Cursor::CASTLE : Cursor::POINTER; - } - break; - - case MP2::OBJ_HEROES: - { - const Heroes *heroes = world.GetHeroes(dst_index); - - if(NULL != heroes) - return heroes->GetColor() == from_castle.GetColor() ? Cursor::HEROES : Cursor::POINTER; - } - break; - - default: - return Cursor::POINTER; - } - } - break; - - default: - break; - } - - return Cursor::POINTER; -} - -void Game::ShowPathOrStartMoveHero(Heroes *hero, const s32 dst_index) -{ - if(!hero) return; - - Route::Path & path = hero->GetPath(); - Interface::Basic & I = Interface::Basic::Get(); - Cursor & cursor = Cursor::Get(); - - // show path - if(path.GetDestinationIndex() != dst_index) - { - hero->SetMove(false); - path.Calculate(dst_index); - if(IS_DEBUG(DBG_GAME, DBG_TRACE)) path.Dump(); - path.Show(); - I.SetRedraw(REDRAW_GAMEAREA); - cursor.SetThemes(Game::GetCursor(dst_index)); - } - // start move - else - if(path.isValid()) - { - Game::Focus::Get().Set(hero); - Game::Focus::Get().SetRedraw(); - hero->SetMove(true); - cursor.SetThemes(Cursor::WAIT); - } -} - -Game::menu_t Game::HumanTurn(void) -{ - Game::Focus & global_focus = Focus::Get(); - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - Settings & conf = Settings::Get(); - - LocalEvent & le = LocalEvent::Get(); - - Game::menu_t res = CANCEL; - - cursor.Hide(); - Interface::Basic & I = Interface::Basic::Get(); - - Kingdom & myKingdom = world.GetMyKingdom(); - const std::vector & myCastles = myKingdom.GetCastles(); - const std::vector & myHeroes = myKingdom.GetHeroes(); - - GameOver::Result & gameResult = GameOver::Result::Get(); - - // set focus - if(Game::HOTSEAT == conf.GameType()) global_focus.Reset(); - - if(!conf.ExtRememberLastFocus() && myHeroes.size()) - global_focus.Set(myHeroes.front()); - else - global_focus.Reset(Focus::HEROES); - if(Focus::HEROES == global_focus.Type() && global_focus.GetHeroes().GetPath().isValid()) global_focus.GetHeroes().GetPath().Show(); - - I.radar.SetHide(false); - I.statusWindow.Reset(); - I.gameArea.SetUpdateCursor(); - I.Redraw(REDRAW_GAMEAREA | REDRAW_RADAR | REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS | REDRAW_BORDER); - - AGG::PlayMusic(MUS::FromGround(world.GetTiles(global_focus.Center()).GetGround())); - Game::EnvironmentSoundMixer(); - - cursor.Show(); - display.Flip(); - - if(!conf.LoadedGameVersion()) - { - // new week dialog - if(1 < world.CountWeek() && world.BeginWeek()) - NewWeekDialog(); - - // show event day - ShowEventDay(); - - // check game over - gameResult.CheckGameOver(res); - } - - // warning lost all town - if(myCastles.empty()) ShowWarningLostTowns(res); - - // check around actions (and skip for h2 orig, bug?) - if(!conf.ExtOnlyFirstMonsterAttack()) myKingdom.HeroesActionNewPosition(); - - // auto hide status - bool autohide_status = conf.QVGA() && conf.ShowStatus(); - if(autohide_status) AnimateDelayReset(AUTOHIDE_STATUS_DELAY); - - // startgame loop - while(CANCEL == res && le.HandleEvents()) - { - // for pocketpc: auto hide status if start turn - if(autohide_status && AnimateInfrequent(AUTOHIDE_STATUS_DELAY)) - { - EventSwitchShowStatus(); - autohide_status = false; - } - - // hot keys - if(le.KeyPress()) - { -#ifdef WITHOUT_MOUSE - if(HotKeyPress(EVENT_EMULATETOGGLE)) le.ToggleEmulateMouse(); - else -#endif - // exit dialog - if(HotKeyPress(EVENT_DEFAULT_EXIT)) EventExit(res); - else - // end turn - if(HotKeyPress(EVENT_ENDTURN)) EventEndTurn(res); - else - // next hero - if(HotKeyPress(EVENT_NEXTHERO)) EventNextHero(); - else - // next town - if(HotKeyPress(EVENT_NEXTTOWN)) EventNextTown(); - else - // hero movement - if(HotKeyPress(EVENT_CONTINUE)) EventContinueMovement(); - else - // save game - if(HotKeyPress(EVENT_SAVEGAME)) EventSaveGame(); - else - // load game - if(HotKeyPress(EVENT_LOADGAME)) - { - EventLoadGame(res); - if(res != CANCEL) break; - } - else - // file options - if(HotKeyPress(EVENT_FILEOPTIONS)) EventFileDialog(res); - else - // system options - if(HotKeyPress(EVENT_SYSTEMOPTIONS)) EventSystemDialog(); - else - // puzzle map - if(HotKeyPress(EVENT_PUZZLEMAPS)) EventPuzzleMaps(); - else - // info game - if(HotKeyPress(EVENT_INFOGAME)) EventGameInfo(); - else - // dig artifact - if(HotKeyPress(EVENT_DIGARTIFACT)) EventDigArtifact(res); - else - // cast spell - if(HotKeyPress(EVENT_CASTSPELL)) EventCastSpell(); - else - // show/hide control panel - if(HotKeyPress(EVENT_CTRLPANEL)) EventSwitchShowControlPanel(); - else - // hide/show radar - if(HotKeyPress(EVENT_SHOWRADAR)) EventSwitchShowRadar(); - else - // hide/show buttons - if(HotKeyPress(EVENT_SHOWBUTTONS)) EventSwitchShowButtons(); - else - // hide/show status window - if(HotKeyPress(EVENT_SHOWSTATUS)) EventSwitchShowStatus(); - else - // hide/show hero/town icons - if(HotKeyPress(EVENT_SHOWICONS)) EventSwitchShowIcons(); - else - // move hero - if(HotKeyPress(EVENT_MOVELEFT)) KeyArrowPress(Direction::LEFT); - else - if(HotKeyPress(EVENT_MOVERIGHT)) KeyArrowPress(Direction::RIGHT); - else - if(HotKeyPress(EVENT_MOVETOP)) KeyArrowPress(Direction::TOP); - else - if(HotKeyPress(EVENT_MOVEBOTTOM)) KeyArrowPress(Direction::BOTTOM); - else - if(HotKeyPress(EVENT_MOVETOPLEFT)) KeyArrowPress(Direction::TOP_LEFT); - else - if(HotKeyPress(EVENT_MOVETOPRIGHT)) KeyArrowPress(Direction::TOP_RIGHT); - else - if(HotKeyPress(EVENT_MOVEBOTTOMLEFT)) KeyArrowPress(Direction::BOTTOM_LEFT); - else - if(HotKeyPress(EVENT_MOVEBOTTOMRIGHT)) KeyArrowPress(Direction::BOTTOM_RIGHT); - else - // scroll maps - if(HotKeyPress(EVENT_SCROLLLEFT)) I.gameArea.SetScroll(SCROLL_LEFT); - else - if(HotKeyPress(EVENT_SCROLLRIGHT)) I.gameArea.SetScroll(SCROLL_RIGHT); - else - if(HotKeyPress(EVENT_SCROLLUP)) I.gameArea.SetScroll(SCROLL_TOP); - else - if(HotKeyPress(EVENT_SCROLLDOWN)) I.gameArea.SetScroll(SCROLL_BOTTOM); - // default action - else - if(HotKeyPress(EVENT_DEFAULTACTION)) EventDefaultAction(); - // open focus - else - if(HotKeyPress(EVENT_OPENFOCUS)) EventOpenFocus(); - // switch group - else - if(HotKeyPress(EVENT_SWITCHGROUP)) EventSwitchGroup(); - } - - if(conf.ExtTapMode()) - { - // scroll area maps left - if(le.MouseCursor(I.GetAreaScrollLeft()) && le.MousePressLeft()) I.gameArea.SetScroll(SCROLL_LEFT); - else - // scroll area maps right - if(le.MouseCursor(I.GetAreaScrollRight()) && le.MousePressLeft()) I.gameArea.SetScroll(SCROLL_RIGHT); - else - // scroll area maps top - if(le.MouseCursor(I.GetAreaScrollTop()) && le.MousePressLeft()) I.gameArea.SetScroll(SCROLL_TOP); - else - // scroll area maps bottom - if(le.MouseCursor(I.GetAreaScrollBottom()) && le.MousePressLeft()) I.gameArea.SetScroll(SCROLL_BOTTOM); - - // disable right click emulation - if(I.gameArea.NeedScroll()) le.SetTapMode(false); - } - else - { - // scroll area maps left - if(le.MouseCursor(I.GetAreaScrollLeft())) I.gameArea.SetScroll(SCROLL_LEFT); - else - // scroll area maps right - if(le.MouseCursor(I.GetAreaScrollRight())) I.gameArea.SetScroll(SCROLL_RIGHT); - else - // scroll area maps top - if(le.MouseCursor(I.GetAreaScrollTop())) I.gameArea.SetScroll(SCROLL_TOP); - else - // scroll area maps bottom - if(le.MouseCursor(I.GetAreaScrollBottom())) I.gameArea.SetScroll(SCROLL_BOTTOM); - } - - // cursor over radar - if((!conf.HideInterface() || conf.ShowRadar()) && - le.MouseCursor(I.radar.GetArea())) - { - if(Cursor::POINTER != cursor.Themes()) - { - cursor.SetThemes(Cursor::POINTER); - } - I.radar.QueueEventProcessing(); - } - else - // cursor over icons panel - if((!conf.HideInterface() || conf.ShowIcons()) && - le.MouseCursor(I.iconsPanel.GetArea())) - { - if(Cursor::POINTER != cursor.Themes()) - { - cursor.SetThemes(Cursor::POINTER); - } - I.iconsPanel.QueueEventProcessing(); - } - else - // cursor over buttons area - if((!conf.HideInterface() || conf.ShowButtons()) && - le.MouseCursor(I.buttonsArea.GetArea())) - { - if(Cursor::POINTER != cursor.Themes()) - { - cursor.SetThemes(Cursor::POINTER); - } - I.buttonsArea.QueueEventProcessing(res); - } - else - // cursor over status area - if((!conf.HideInterface() || conf.ShowStatus()) && - le.MouseCursor(I.statusWindow.GetArea())) - { - if(Cursor::POINTER != cursor.Themes()) - { - cursor.SetThemes(Cursor::POINTER); - } - I.statusWindow.QueueEventProcessing(); - } - else - // cursor over control panel - if(conf.HideInterface() && conf.ShowControlPanel() && - le.MouseCursor(I.controlPanel.GetArea())) - { - if(Cursor::POINTER != cursor.Themes()) - { - cursor.SetThemes(Cursor::POINTER); - } - I.controlPanel.QueueEventProcessing(res); - } - else - // cursor over game area - if(le.MouseCursor(I.gameArea.GetArea()) && !I.gameArea.NeedScroll()) - { - I.gameArea.QueueEventProcessing(); - } - - // fast scroll - if(I.gameArea.NeedScroll() && AnimateInfrequent(SCROLL_DELAY)) - { - cursor.Hide(); - - if(le.MouseCursor(I.GetAreaScrollLeft()) || - le.MouseCursor(I.GetAreaScrollRight()) || - le.MouseCursor(I.GetAreaScrollTop()) || - le.MouseCursor(I.GetAreaScrollBottom())) - cursor.SetThemes(I.gameArea.GetScrollCursor()); - - I.gameArea.Scroll(); - - // need stop hero - if(Game::Focus::HEROES == global_focus.Type() && global_focus.GetHeroes().isEnableMove()) - global_focus.GetHeroes().SetMove(false); - - I.SetRedraw(REDRAW_GAMEAREA|REDRAW_RADAR); - I.Redraw(); - cursor.Show(); - display.Flip(); - - // enable right click emulation - if(conf.ExtTapMode()) - le.SetTapMode(true); - - continue; - } - - // heroes move animation - if(AnimateInfrequent(CURRENT_HERO_DELAY)) - { - if(Game::Focus::HEROES == global_focus.Type()) - { - Heroes & hero = global_focus.GetHeroes(); - if(hero.isEnableMove()) - { - if(hero.Move(0 == conf.HeroesMoveSpeed())) - { - I.gameArea.Center(global_focus.Center()); - global_focus.Reset(Focus::HEROES); - global_focus.SetRedraw(); - - I.gameArea.SetUpdateCursor(); - } - else - { - I.SetRedraw(REDRAW_GAMEAREA); - } - - if(hero.isAction()) - { - // check game over - gameResult.CheckGameOver(res); - hero.ResetAction(); - } - } - else - { - hero.SetMove(false); - if(Cursor::WAIT == cursor.Themes()) cursor.SetThemes(Cursor::POINTER); - } - } - } - - // slow maps objects animation - if(AnimateInfrequent(MAPS_DELAY)) - { - Maps::IncreaseAnimationTicket(); - I.SetRedraw(REDRAW_GAMEAREA); - } - - if(I.NeedRedraw()) - { - cursor.Hide(); - I.Redraw(); - cursor.Show(); - display.Flip(); - } - else - if(!cursor.isVisible()) - { - cursor.Show(); - display.Flip(); - } - } - - if(ENDTURN == res) - { - // warning lost all town - if(myHeroes.size() && myCastles.empty() && Game::GetLostTownDays() < myKingdom.GetLostTownDays()) - { - std::string str = _("%{color} player, you have lost your last town. If you do not conquer another town in next week, you will be eliminated."); - String::Replace(str, "%{color}", Color::String(conf.MyColor())); - DialogPlayers(conf.MyColor(), str); - } - - if(Game::Focus::HEROES == global_focus.Type()) - { - global_focus.GetHeroes().ShowPath(false); - global_focus.SetRedraw(); - } - - if(conf.ExtAutoSaveOn()) - { - std::string filename(conf.LocalPrefix() + SEPARATOR + "files" + SEPARATOR + "save" + SEPARATOR + "autosave.sav"); - Game::Save(filename); - } - } - - return res; -} - -bool Game::DiggingForArtifacts(const Heroes & hero) -{ - if(hero.GetMaxMovePoints() == hero.GetMovePoints()) - { - if(! world.GetTiles(hero.GetCenter()).GoodForUltimateArtifact()) - { - Dialog::Message("", _("Try searching on clear ground."), Font::BIG, Dialog::OK); - return false; - } - - AGG::PlaySound(M82::DIGSOUND); - - const_cast(hero).ResetMovePoints(); - const Artifact ultimate(world.GetUltimateArtifact()); - - if(world.DiggingForUltimateArtifact(hero.GetCenter()) && ultimate != Artifact::UNKNOWN) - { - AGG::PlaySound(M82::TREASURE); - // check returns - const_cast(hero).PickupArtifact(ultimate()); - std::string msg(_("After spending many hours digging here, you have uncovered the ")); - msg.append(ultimate.GetName()); - DialogWithArtifact(_("Congratulations!"), msg, ultimate()); - } - else - Dialog::Message("", _("Nothing here. Where could it be?"), Font::BIG, Dialog::OK); - - Cursor::Get().Hide(); - Interface::IconsPanel::Get().RedrawIcons(ICON_HEROES); - Cursor::Get().Show(); - Display::Get().Flip(); - } - else - Dialog::Message("", _("Digging for artifacts requires a whole day, try again tomorrow."), Font::BIG, Dialog::OK); - - return false; -} - -void Game::MouseCursorAreaClickLeft(s32 index_maps) -{ - Game::Focus & global_focus = Focus::Get(); - switch(global_focus.Type()) - { - case Focus::HEROES: FocusHeroesClickLeftAction(global_focus.GetHeroes(), index_maps); break; - case Focus::CASTLE: FocusCastleClickLeftAction(global_focus.GetCastle(), index_maps); break; - default: break; - } -} - -void Game::FocusHeroesClickLeftAction(Heroes & from_hero, s32 index_maps) -{ - Game::Focus & global_focus = Focus::Get(); - Maps::Tiles & tile = world.GetTiles(index_maps); - - switch(tile.GetObject()) - { - // from hero to castle - case MP2::OBJN_CASTLE: - { - const Castle *to_castle = world.GetCastle(index_maps); - if(NULL == to_castle) break; - else - if(from_hero.GetColor() == to_castle->GetColor()) - { - global_focus.Set(const_cast(to_castle)); - global_focus.SetRedraw(); - } - else - ShowPathOrStartMoveHero(&from_hero, to_castle->GetIndex()); - } - break; - - // from hero to hero - case MP2::OBJ_HEROES: - { - const Heroes * to_hero = world.GetHeroes(index_maps); - if(NULL == to_hero) break; - else - if(from_hero.GetCenter() == to_hero->GetCenter()) - OpenHeroes(&from_hero); - else - ShowPathOrStartMoveHero(&from_hero, index_maps); - } - break; - - default: - if(tile.isPassable(&from_hero) || MP2::isActionObject(tile.GetObject(), from_hero.isShipMaster())) - ShowPathOrStartMoveHero(&from_hero, index_maps); - break; - } -} - -void Game::FocusCastleClickLeftAction(Castle & from_castle, s32 index_maps) -{ - Game::Focus & global_focus = Focus::Get(); - Maps::Tiles & tile = world.GetTiles(index_maps); - - switch(tile.GetObject()) - { - // from castle to castle - case MP2::OBJN_CASTLE: - case MP2::OBJ_CASTLE: - { - const Castle *to_castle = world.GetCastle(index_maps); - if(NULL != to_castle && - from_castle.GetColor() == to_castle->GetColor()) - { - // is selected open dialog - if(from_castle.GetCenter() == to_castle->GetCenter()) - OpenCastle(&from_castle); - // select other castle - else - { - global_focus.Set(const_cast(to_castle)); - global_focus.SetRedraw(); - } - } - } - break; - - // from castle to heroes - case MP2::OBJ_HEROES: - { - const Heroes *to_hero = world.GetHeroes(index_maps); - if(NULL != to_hero && - from_castle.GetColor() == to_hero->GetColor()) - { - global_focus.Set(const_cast(to_hero)); - global_focus.SetRedraw(); - } - } - break; - - default: break; - } -} - -void Game::MouseCursorAreaPressRight(s32 index_maps) -{ - Focus & global_focus = Focus::Get(); - - // stop hero - if(Game::Focus::HEROES == global_focus.Type() && global_focus.GetHeroes().isEnableMove()) - { - global_focus.GetHeroes().SetMove(false); - Cursor::Get().SetThemes(Game::GetCursor(index_maps)); - } - else - { - Settings & conf = Settings::Get(); - Maps::Tiles & tile = world.GetTiles(index_maps); - - if(IS_DEVEL()) tile.DebugInfo(); - - if(!IS_DEVEL() && tile.isFog(conf.MyColor())) - Dialog::QuickInfo(tile); - else - switch(tile.GetObject()) - { - case MP2::OBJN_CASTLE: - case MP2::OBJ_CASTLE: - { - const Castle *castle = world.GetCastle(tile.GetIndex()); - if(castle) Dialog::QuickInfo(*castle); - } - break; - - case MP2::OBJ_HEROES: - { - const Heroes *heroes = world.GetHeroes(tile.GetIndex()); - if(heroes) Dialog::QuickInfo(*heroes); - } - break; - - default: - Dialog::QuickInfo(tile); - break; - } - } -} - -void Game::EventNextHero(void) -{ - Game::Focus & global_focus = Focus::Get(); - - const Kingdom & myKingdom = world.GetMyKingdom(); - const std::vector & myHeroes = myKingdom.GetHeroes(); - - if(myHeroes.empty()) return; - - if(Game::Focus::HEROES != global_focus.Type()) - { - global_focus.Reset(Game::Focus::HEROES); - } - else - { - std::vector::const_iterator it = std::find(myHeroes.begin(), myHeroes.end(), &global_focus.GetHeroes()); - ++it; - if(it == myHeroes.end()) it = myHeroes.begin(); - global_focus.Set(*it); - } - global_focus.SetRedraw(); -} - -void Game::EventContinueMovement(void) -{ - Game::Focus & global_focus = Focus::Get(); - if(Game::Focus::HEROES == global_focus.Type() && - global_focus.GetHeroes().GetPath().isValid()) - global_focus.GetHeroes().SetMove(!global_focus.GetHeroes().isEnableMove()); -} - -void Game::EventKingdomInfo(void) -{ -} - -void Game::EventCastSpell(void) -{ - Game::Focus & global_focus = Focus::Get(); - Interface::Basic & I = Interface::Basic::Get(); - - if(Game::Focus::HEROES == global_focus.Type()) - { - Heroes & hero = global_focus.GetHeroes(); - // apply cast spell - hero.ActionSpellCast(hero.OpenSpellBook(SpellBook::ADVN, true)); - I.SetRedraw(REDRAW_ICONS); - } -} - -void Game::EventEndTurn(Game::menu_t & ret) -{ - Game::Focus & global_focus = Focus::Get(); - const Kingdom & myKingdom = world.GetMyKingdom(); - - if(Game::Focus::HEROES == global_focus.Type()) - global_focus.GetHeroes().SetMove(false); - - if(!myKingdom.HeroesMayStillMove() || - Dialog::YES == Dialog::Message("", _("One or more heroes may still move, are you sure you want to end your turn?"), Font::BIG, Dialog::YES | Dialog::NO)) - ret = ENDTURN; -} - -void Game::EventAdventureDialog(Game::menu_t & ret) -{ - Game::Focus & global_focus = Focus::Get(); - Mixer::Reduce(); - switch(Dialog::AdventureOptions(Game::Focus::HEROES == global_focus.Type())) - { - case Dialog::WORLD: - break; - - case Dialog::PUZZLE: - EventPuzzleMaps(); - break; - - case Dialog::INFO: - EventGameInfo(); - break; - - case Dialog::DIG: - EventDigArtifact(ret); - break; - - default: break; - } - Mixer::Enhance(); -} - -void Game::StartNewGame(Game::menu_t & ret) -{ - if(Dialog::YES == Dialog::Message("", _("Are you sure you want to restart? (Your current game will be lost)"), Font::BIG, Dialog::YES|Dialog::NO)) - ret = NEWGAME; -} - -void Game::EventFileDialog(Game::menu_t & ret) -{ - switch(Dialog::FileOptions()) - { - case NEWGAME: - StartNewGame(ret); - break; - - case QUITGAME: - ret = QUITGAME; - break; - - case LOADGAME: - EventLoadGame(ret); - break; - - case SAVEGAME: - EventSaveGame(); - break; - - default: - break; - } -} - -void Game::EventSystemDialog(void) -{ - // Change and save system settings - const u8 changes = Dialog::SystemOptions(); - Interface::Basic & I = Interface::Basic::Get(); - - if(0x10 & changes) - { - Game::Focus & focus = Game::Focus::Get(); - // hardcore reset pos - I.gameArea.Center(0, 0); - I.gameArea.Center(focus.Center()); - I.SetRedraw(REDRAW_GAMEAREA); - - if(Settings::Get().HideInterface()) - I.controlPanel.ResetTheme(); - } - - if(0x08 & changes) - I.SetRedraw(REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_STATUS | REDRAW_BORDER); -} - -void Game::EventExit(menu_t & ret) -{ - Focus & global_focus = Focus::Get(); - - // stop hero - if(Game::Focus::HEROES == global_focus.Type() && global_focus.GetHeroes().isEnableMove()) - global_focus.GetHeroes().SetMove(false); - else - if(Dialog::YES & Dialog::Message("", _("Are you sure you want to quit?"), Font::BIG, Dialog::YES|Dialog::NO)) - ret = QUITGAME; -} - -void Game::EventNextTown(void) -{ - Kingdom & myKingdom = world.GetMyKingdom(); - std::vector & myCastles = myKingdom.GetCastles(); - - if(myCastles.size()) - { - Focus & global_focus = Focus::Get(); - - if(Game::Focus::CASTLE != global_focus.Type()) - global_focus.Reset(Game::Focus::CASTLE); - else - { - std::vector::const_iterator it = std::find(myCastles.begin(), myCastles.end(), &global_focus.GetCastle()); - ++it; - if(it == myCastles.end()) it = myCastles.begin(); - global_focus.Set(*it); - } - global_focus.SetRedraw(); - } -} - -void Game::EventSaveGame(void) -{ - std::string filename; - if(Dialog::SelectFileSave(filename) && filename.size()) - { - Game::Save(filename); - Dialog::Message("", _("Game saved successfully."), Font::BIG, Dialog::OK); - } -} - -void Game::EventLoadGame(menu_t & ret) -{ - if(Dialog::YES == Dialog::Message("", _("Are you sure you want to load a new game? (Your current game will be lost)"), Font::BIG, Dialog::YES|Dialog::NO)) - ret = LOADGAME; -} - -void Game::EventPuzzleMaps(void) -{ - world.GetMyKingdom().PuzzleMaps().ShowMapsDialog(); -} - -void Game::EventGameInfo(void) -{ - Dialog::GameInfo(); -} - -void Game::EventDigArtifact(menu_t & ret) -{ - Focus & global_focus = Focus::Get(); - if(Game::Focus::HEROES == global_focus.Type()) - { - DiggingForArtifacts(global_focus.GetHeroes()); - // check game over for ultimate artifact - GameOver::Result::Get().CheckGameOver(ret); - } -} - -void Game::EventDefaultAction(void) -{ - Focus & global_focus = Focus::Get(); - if(Game::Focus::HEROES == global_focus.Type()) - { - Heroes & hero = global_focus.GetHeroes(); - Interface::Basic & I = Interface::Basic::Get(); - - // 1. continue - if(global_focus.GetHeroes().GetPath().isValid()) - global_focus.GetHeroes().SetMove(true); - else - // 2. action object - if(MP2::isActionObject(hero.GetUnderObject(), hero.isShipMaster())) - { - hero.Action(hero.GetIndex()); - if(MP2::OBJ_STONELIGHTS == hero.GetUnderObject() || MP2::OBJ_WHIRLPOOL == hero.GetUnderObject()) - { - hero.ApplyPenaltyMovement(); - I.SetRedraw(REDRAW_HEROES); - } - I.SetRedraw(REDRAW_GAMEAREA); - } - else - // 3. hero dialog - OpenHeroes(&hero); - } - else - // 4. town dialog - if(Game::Focus::CASTLE == global_focus.Type()) - { - Castle & castl = global_focus.GetCastle(); - OpenCastle(&castl); - } -} - -void Game::EventOpenFocus(void) -{ - Focus & global_focus = Focus::Get(); - if(Game::Focus::HEROES == global_focus.Type()) - { - Heroes & hero = global_focus.GetHeroes(); - OpenHeroes(&hero); - } - else - if(Game::Focus::CASTLE == global_focus.Type()) - { - Castle & castl = global_focus.GetCastle(); - OpenCastle(&castl); - } -} - -void Game::KeyArrowPress(Direction::vector_t dir) -{ - Focus & global_focus = Focus::Get(); - Interface::GameArea & area = Interface::GameArea::Get(); - - // move hero - if(Focus::HEROES == global_focus.Type()) MoveHeroFromArrowKeys(global_focus.GetHeroes(), dir); - else - // scroll map - switch(dir) - { - case Direction::TOP_LEFT: area.SetScroll(SCROLL_TOP); area.SetScroll(SCROLL_LEFT); break; - case Direction::TOP: area.SetScroll(SCROLL_TOP); break; - case Direction::TOP_RIGHT: area.SetScroll(SCROLL_TOP); area.SetScroll(SCROLL_RIGHT); break; - case Direction::RIGHT: area.SetScroll(SCROLL_RIGHT); break; - case Direction::BOTTOM_RIGHT: area.SetScroll(SCROLL_BOTTOM); area.SetScroll(SCROLL_RIGHT); break; - case Direction::BOTTOM: area.SetScroll(SCROLL_BOTTOM); break; - case Direction::BOTTOM_LEFT: area.SetScroll(SCROLL_BOTTOM); area.SetScroll(SCROLL_LEFT); break; - case Direction::LEFT: area.SetScroll(SCROLL_LEFT); break; - default: break; - } -} - -void Game::NewWeekDialog(void) -{ - const Week::type_t name = world.GetWeekType(); - std::string message = world.BeginMonth() ? _("Astrologers proclaim month of the %{name}.") : _("Astrologers proclaim week of the %{name}."); - AGG::PlayMusic(world.BeginMonth() ? MUS::WEEK2_MONTH1 : MUS::WEEK1, false); - String::Replace(message, "%{name}", Week::GetString(name)); - message += "\n \n"; - message += (name == Week::PLAGUE ? _(" All populations are halved.") : _(" All dwellings increase population.")); - Dialog::Message("", message, Font::BIG, Dialog::OK); -} - -void Game::ShowEventDay(void) -{ - Kingdom & myKingdom = world.GetMyKingdom(); - std::vector events; - events.reserve(5); - world.GetEventDay(myKingdom.GetColor(), events); - std::vector::const_iterator it1 = events.begin(); - std::vector::const_iterator it2 = events.end(); - - for(; it1 != it2; ++it1) if(*it1) - { - AGG::PlayMusic(MUS::NEWS, false); - if((*it1)->GetResource().GetValidItems()) - Dialog::ResourceInfo("", (*it1)->GetMessage(), (*it1)->GetResource()); - else - if((*it1)->GetMessage().size()) - Dialog::Message("", (*it1)->GetMessage(), Font::BIG, Dialog::OK); - } -} - -void Game::ShowWarningLostTowns(menu_t & ret) -{ - const Kingdom & myKingdom = world.GetMyKingdom(); - Settings & conf = Settings::Get(); - if(0 == myKingdom.GetLostTownDays()) - { - AGG::PlayMusic(MUS::DEATH, false); - std::string str = _("%{color} player, your heroes abandon you, and you are banished from this land."); - String::Replace(str, "%{color}", Color::String(conf.MyColor())); - DialogPlayers(conf.MyColor(), str); - GameOver::Result::Get().SetResult(GameOver::LOSS_ALL); - ret = MAINMENU; - } - else - if(1 == myKingdom.GetLostTownDays()) - { - std::string str = _("%{color} player, this is your last day to capture a town, or you will be banished from this land."); - String::Replace(str, "%{color}", Color::String(conf.MyColor())); - DialogPlayers(conf.MyColor(), str); - } - else - if(Game::GetLostTownDays() >= myKingdom.GetLostTownDays()) - { - std::string str = _("%{color} player, you only have %{day} days left to capture a town, or you will be banished from this land."); - String::Replace(str, "%{color}", Color::String(conf.MyColor())); - String::Replace(str, "%{day}", myKingdom.GetLostTownDays()); - DialogPlayers(conf.MyColor(), str); - } -} - -void Game::EventSwitchShowRadar(void) -{ - Settings & conf = Settings::Get(); - - if(conf.HideInterface()) - { - if(conf.ShowRadar()) - { - conf.SetShowRadar(false); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - else - { - if(conf.QVGA() && (conf.ShowIcons() || conf.ShowStatus() || conf.ShowButtons())) - { - conf.SetShowIcons(false); - conf.SetShowStatus(false); - conf.SetShowButtons(false); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - conf.SetShowRadar(true); - Interface::Basic::Get().SetRedraw(REDRAW_RADAR); - } - } -} - -void Game::EventSwitchShowButtons(void) -{ - Settings & conf = Settings::Get(); - - if(conf.HideInterface()) - { - if(conf.ShowButtons()) - { - conf.SetShowButtons(false); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - else - { - if(conf.QVGA() && (conf.ShowRadar() || conf.ShowStatus() || conf.ShowIcons())) - { - conf.SetShowIcons(false); - conf.SetShowStatus(false); - conf.SetShowRadar(false); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - conf.SetShowButtons(true); - Interface::Basic::Get().SetRedraw(REDRAW_BUTTONS); - } - } -} - -void Game::EventSwitchShowStatus(void) -{ - Settings & conf = Settings::Get(); - - if(conf.HideInterface()) - { - if(conf.ShowStatus()) - { - conf.SetShowStatus(false); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - else - { - if(conf.QVGA() && (conf.ShowRadar() || conf.ShowIcons() || conf.ShowButtons())) - { - conf.SetShowIcons(false); - conf.SetShowButtons(false); - conf.SetShowRadar(false); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - conf.SetShowStatus(true); - Interface::Basic::Get().SetRedraw(REDRAW_STATUS); - } - } -} - -void Game::EventSwitchShowIcons(void) -{ - Settings & conf = Settings::Get(); - Interface::Basic & I = Interface::Basic::Get(); - - if(conf.HideInterface()) - { - if(conf.ShowIcons()) - { - conf.SetShowIcons(false); - I.SetRedraw(REDRAW_GAMEAREA); - } - else - { - if(conf.QVGA() && (conf.ShowRadar() || conf.ShowStatus() || conf.ShowButtons())) - { - conf.SetShowButtons(false); - conf.SetShowRadar(false); - conf.SetShowStatus(false); - I.SetRedraw(REDRAW_GAMEAREA); - } - conf.SetShowIcons(true); - I.iconsPanel.SetCurrentVisible(); - I.SetRedraw(REDRAW_ICONS); - } - } -} - -void Game::EventSwitchShowControlPanel(void) -{ - Settings & conf = Settings::Get(); - - if(conf.HideInterface()) - { - conf.SetShowPanel(!conf.ShowControlPanel()); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/gameevent.cpp b/project/jni/application/fheroes2/src/fheroes2/game/gameevent.cpp deleted file mode 100644 index fbdf88f18..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/gameevent.cpp +++ /dev/null @@ -1,318 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "color.h" -#include "dialog.h" -#include "settings.h" -#include "gameevent.h" - -#define SIZEMESSAGE 400 - -GameEvent::Day::Day() : computer(false), first(MAXU16), subsequent(0), colors(0) -{ -} - -GameEvent::Day::Day(const void *ptr) -{ - const u8 *ptr8 = static_cast(ptr); - u16 byte16 = 0; - u32 byte32 = 0; - - // id - if(0x00 != *ptr8) - { - DEBUG(DBG_GAME , DBG_WARN, "GameEvent::Day: unknown magic id"); - return; - } - ++ptr8; - - // resource - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.wood = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.mercury = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.ore = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.sulfur = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.crystal = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.gems = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.gold = byte32; - - // skip artifact - byte16 = ReadLE16(ptr8); - ++ptr8; - ++ptr8; - - // allow computer - byte16 = ReadLE16(ptr8); - ++ptr8; - ++ptr8; - computer = byte16; - - // day of first occurent - byte16 = ReadLE16(ptr8); - ++ptr8; - ++ptr8; - first = byte16; - - // subsequent occurrences - byte16 = ReadLE16(ptr8); - ++ptr8; - ++ptr8; - subsequent = byte16; - - ptr8 += 6; - - colors = 0; - - // blue - if(*ptr8) colors |= Color::BLUE; - ++ptr8; - - // green - if(*ptr8) colors |= Color::GREEN; - ++ptr8; - - // red - if(*ptr8) colors |= Color::RED; - ++ptr8; - - // yellow - if(*ptr8) colors |= Color::YELLOW; - ++ptr8; - - // orange - if(*ptr8) colors |= Color::ORANGE; - ++ptr8; - - // purple - if(*ptr8) colors |= Color::PURPLE; - ++ptr8; - - // message - message = std::string(_(reinterpret_cast(ptr8))); - - //if(SIZEMESSAGE < message.size()) DEBUG(DBG_GAME , DBG_WARN, "GameEvent::Day: long message, incorrect block?"); - - DEBUG(DBG_GAME , DBG_INFO, "GameEvent::Day: add: " << message); -} - -GameEvent::Coord::Coord() : index_map(-1), artifact(Artifact::UNKNOWN), computer(false), cancel(true), colors(0) -{ -} - -GameEvent::Coord::Coord(s32 index, const void *ptr) : index_map(index) -{ - const u8 *ptr8 = static_cast(ptr); - u16 byte16 = 0; - u32 byte32 = 0; - - // id - if(0x01 != *ptr8) - { - DEBUG(DBG_GAME , DBG_WARN, "GameEvent::Coord: unknown magic id"); - return; - } - ++ptr8; - - // resource - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.wood = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.mercury = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.ore = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.sulfur = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.crystal = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.gems = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.gold = byte32; - - // artifact - byte16 = ReadLE16(ptr8); - ++ptr8; - ++ptr8; - artifact = (0xffff != byte16 && Artifact::MAGIC_BOOK > byte16 ? Artifact::FromInt(byte16) : Artifact::UNKNOWN); - - // allow computer - computer = *ptr8; - ++ptr8; - - // cancel event after first visit - cancel = *ptr8; - ptr8 += 11; - - colors = 0; - - // blue - if(*ptr8) colors |= Color::BLUE; - ++ptr8; - - // green - if(*ptr8) colors |= Color::GREEN; - ++ptr8; - - // red - if(*ptr8) colors |= Color::RED; - ++ptr8; - - // yellow - if(*ptr8) colors |= Color::YELLOW; - ++ptr8; - - // orange - if(*ptr8) colors |= Color::ORANGE; - ++ptr8; - - // purple - if(*ptr8) colors |= Color::PURPLE; - ++ptr8; - - // message - message = std::string(_(reinterpret_cast(ptr8))); - - DEBUG(DBG_GAME , DBG_INFO, "GameEvent::Coord: add: " << message); -} - -GameEvent::Riddle::Riddle() : index_map(-1), artifact(Artifact::UNKNOWN), quiet(true) -{ -} - -GameEvent::Riddle::Riddle(s32 index, const void *ptr) : index_map(index), quiet(true) -{ - const u8 *ptr8 = static_cast(ptr); - u16 byte16 = 0; - u32 byte32 = 0; - answers.reserve(9); - - // id - if(0x00 != *ptr8) - { - DEBUG(DBG_GAME , DBG_WARN, "GameEvent::Day: unknown magic id"); - return; - } - ++ptr8; - - // resource - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.wood = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.mercury = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.ore = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.sulfur = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.crystal = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.gems = byte32; - - byte32 = ReadLE32(ptr8); - ptr8 += 4;; - resource.gold = byte32; - - // artifact - byte16 = ReadLE16(ptr8); - ++ptr8; - ++ptr8; - artifact = (0xffff != byte16 && Artifact::MAGIC_BOOK > byte16 ? Artifact::FromInt(byte16) : Artifact::UNKNOWN); - - // count answers - u8 count = *ptr8; - ++ptr8; - - // answers - for(u8 i = 0; i < 8; ++i) - { - std::string str(reinterpret_cast(ptr8)); - String::Lower(str); - if(count-- && str.size()){ answers.push_back(str); answers.push_back(_(reinterpret_cast(ptr8))); }; - ptr8 += 13; - } - - // message - message = std::string(_(reinterpret_cast(ptr8))); - - DEBUG(DBG_GAME , DBG_INFO, "GameEvent::Riddle: add: " << message); -} - -bool GameEvent::Riddle::AnswerCorrect(const std::string & answer) -{ - return answers.end() != std::find(answers.begin(), answers.end(), answer); -} - -bool GameEvent::Riddle::isValid(void) const -{ - return !quiet; -} - -void GameEvent::Riddle::SetQuiet(void) -{ - quiet = true; - artifact = Artifact::UNKNOWN; - resource = Resource::funds_t(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/game/gameevent.h b/project/jni/application/fheroes2/src/fheroes2/game/gameevent.h deleted file mode 100644 index 504c8b569..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/game/gameevent.h +++ /dev/null @@ -1,111 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2GAMEEVENT_H -#define H2GAMEEVENT_H - -#include -#include -#include "resource.h" -#include "artifact.h" -#include "game_io.h" -#include "gamedefs.h" - -namespace GameEvent -{ - -class Day -{ -public: - Day(); - Day(const void *ptr); - - bool AllowComputer(void) const{ return computer; } - const Resource::funds_t & GetResource(void) const{ return resource; } - u16 GetFirst(void) const{ return first; } - u16 GetSubsequent(void) const{ return subsequent; } - u8 GetColors(void) const{ return colors; } - const std::string & GetMessage(void) const{ return message; } - -private: - friend class Game::IO; - - Resource::funds_t resource; - bool computer; - u16 first; - u16 subsequent; - u8 colors; - std::string message; -}; - -class Coord -{ -public: - Coord(); - Coord(s32 index, const void *ptr); - - bool AllowComputer(void) const{ return computer; } - const Resource::funds_t & GetResource(void) const{ return resource; } - s32 GetIndex(void) const{ return index_map; } - u8 GetColors(void) const{ return colors; } - const std::string & GetMessage(void) const{ return message; } - Artifact::artifact_t GetArtifact(void) const {return artifact; } - -private: - friend class Game::IO; - - s32 index_map; - Resource::funds_t resource; - Artifact::artifact_t artifact; - bool computer; - bool cancel; - u8 colors; - std::string message; -}; - -class Riddle -{ -public: - Riddle(); - Riddle(s32 index, const void *ptr); - - const Resource::funds_t & GetResource(void) const{ return resource; } - Artifact::artifact_t GetArtifact(void) const {return artifact; } - bool AnswerCorrect(const std::string & answer); - s32 GetIndex(void) const{ return index_map; } - const std::string & GetMessage(void) const{ return message; } - bool isValid(void) const; - void SetQuiet(void); - -private: - friend class Game::IO; - - s32 index_map; - Resource::funds_t resource; - Artifact::artifact_t artifact; - std::vector answers; - std::string message; - bool quiet; -}; - -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/button.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/button.cpp deleted file mode 100644 index 77e9a9f89..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/button.cpp +++ /dev/null @@ -1,228 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "cursor.h" -#include "settings.h" -#include "dialog.h" -#include "button.h" - -Button::Button() : icn(ICN::UNKNOWN), index1(0), index2(0), pressed(false), disable(false) -{ -} - -Button::Button(const Point &pt, const ICN::icn_t n, u16 i1, u16 i2) : icn(n), index1(i1), index2(i2), - pressed(false), disable(false) -{ - SetPos(pt); - - const Sprite & sprite1 = AGG::GetICN(icn, index1); - - w = sprite1.w(); - h = sprite1.h(); -} - -Button::Button(u16 ox, u16 oy, const ICN::icn_t n, u16 i1, u16 i2) : icn(n), index1(i1), index2(i2), - pressed(false), disable(false) -{ - SetPos(ox, oy); - - const Sprite & sprite1 = AGG::GetICN(icn, index1); - - w = sprite1.w(); - h = sprite1.h(); -} - -void Button::SetPos(const Point & pt) -{ - SetPos(pt.x, pt.y); -} - -void Button::SetPos(const u16 ox, const u16 oy) -{ - x = ox; - y = oy; -} - -void Button::SetSprite(const ICN::icn_t n, const u16 i1, const u16 i2) -{ - icn = n; - index1 = i1; - index2 = i2; - - const Sprite & sprite1 = AGG::GetICN(icn, index1); - - w = sprite1.w(); - h = sprite1.h(); -} - -void Button::Press(void) -{ - if(disable || pressed) return; - - pressed = true; -} - -void Button::Release(void) -{ - if(disable || !pressed) return; - - pressed = false; -} - -void Button::PressDraw(void) -{ - if(disable || pressed) return; - - Press(); - - Draw(); - - Display::Get().Flip(); -} - -void Button::ReleaseDraw(void) -{ - if(disable || !pressed) return; - - Release(); - - Draw(); - - Display::Get().Flip(); -} - -void Button::Draw(void) -{ - bool localcursor = false; - Cursor & cursor = Cursor::Get(); - if(*this & cursor.GetRect() && cursor.isVisible()){ cursor.Hide(); localcursor = true; } - - const Sprite & sprite1 = AGG::GetICN(icn, index1); - const Sprite & sprite2 = AGG::GetICN(icn, index2); - - Display::Get().Blit(pressed ? sprite2 : sprite1, x, y); - - if(localcursor) cursor.Show(); -} - -ButtonGroups::ButtonGroups(const Rect & pos, u16 btns) : button1(NULL), button2(NULL), result1(Dialog::ZERO), result2(Dialog::ZERO), buttons(btns) -{ - Point pt; - const ICN::icn_t system = Settings::Get().EvilInterface() ? ICN::SYSTEME : ICN::SYSTEM; - - switch(buttons) - { - case Dialog::YES|Dialog::NO: - pt.x = pos.x; - pt.y = pos.y + pos.h - AGG::GetICN(system, 5).h(); - button1 = new Button(pt, system, 5, 6); - result1 = Dialog::YES; - pt.x = pos.x + pos.w - AGG::GetICN(system, 7).w(); - pt.y = pos.y + pos.h - AGG::GetICN(system, 7).h(); - button2 = new Button(pt, system, 7, 8); - result2 = Dialog::NO; - break; - - case Dialog::OK|Dialog::CANCEL: - pt.x = pos.x; - pt.y = pos.y + pos.h - AGG::GetICN(system, 1).h(); - button1 = new Button(pt, system, 1, 2); - result1 = Dialog::OK; - pt.x = pos.x + pos.w - AGG::GetICN(system, 3).w(); - pt.y = pos.y + pos.h - AGG::GetICN(system, 3).h(); - button2 = new Button(pt, system, 3, 4); - result2 = Dialog::CANCEL; - break; - - case Dialog::OK: - pt.x = pos.x + (pos.w - AGG::GetICN(system, 1).w()) / 2; - pt.y = pos.y + pos.h - AGG::GetICN(system, 1).h(); - button1 = new Button(pt, system, 1, 2); - result1 = Dialog::OK; - break; - - case Dialog::CANCEL: - pt.x = pos.x + (pos.w - AGG::GetICN(system, 3).w()) / 2; - pt.y = pos.y + pos.h - AGG::GetICN(system, 3).h(); - button2 = new Button(pt, system, 3, 4); - result2 = Dialog::CANCEL; - break; - - default: - break; - } -} - -ButtonGroups::~ButtonGroups() -{ - if(button1) delete button1; - if(button2) delete button2; -} - -void ButtonGroups::Draw(void) -{ - if(button1) (*button1).Draw(); - if(button2) (*button2).Draw(); -} - -u16 ButtonGroups::QueueEventProcessing(void) -{ - LocalEvent & le = LocalEvent::Get(); - - if(button1 && button1->isEnable()) le.MousePressLeft(*button1) ? button1->PressDraw() : button1->ReleaseDraw(); - if(button2 && button2->isEnable()) le.MousePressLeft(*button2) ? button2->PressDraw() : button2->ReleaseDraw(); - - if(button1 && button1->isEnable() && le.MouseClickLeft(*button1)) return result1; - if(button2 && button2->isEnable() && le.MouseClickLeft(*button2)) return result2; - - if(button1 && button2) - { - if(buttons == (Dialog::YES|Dialog::NO) || - buttons == (Dialog::OK|Dialog::CANCEL)) - { - if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY)) return result1; - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) return result2; - } - - if(Game::HotKeyPress(Game::EVENT_DEFAULT_LEFT)) return result1; - else - if(Game::HotKeyPress(Game::EVENT_DEFAULT_RIGHT)) return result2; - } - else - // one button - { - if(HotKeyCloseWindow) return buttons; - } - - return Dialog::ZERO; -} - -void ButtonGroups::DisableButton1(bool f) -{ - if(button1) button1->SetDisable(f); -} - -void ButtonGroups::DisableButton2(bool f) -{ - if(button1) button2->SetDisable(f); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/button.h b/project/jni/application/fheroes2/src/fheroes2/gui/button.h deleted file mode 100644 index be0e9f712..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/button.h +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2BUTTON_H -#define H2BUTTON_H - -#include "icn.h" -#include "gamedefs.h" - -class Sprite; - -class Button : public Rect -{ -public: - Button(); - Button(const Point &pt, const ICN::icn_t icn, u16 index1, u16 index2); - Button(u16 ox, u16 oy, const ICN::icn_t icn, u16 index1, u16 index2); - - bool isEnable(void) const{ return !disable; } - bool isDisable(void) const{ return disable; } - bool isPressed(void) const{ return pressed; } - bool isReleased(void) const{ return !pressed; } - - void Press(void); - void Release(void); - - void SetPos(const Point & pt); - void SetPos(const u16 ox, const u16 oy); - void SetSprite(const ICN::icn_t icn, const u16 index1, const u16 index2); - void SetDisable(bool fl){ disable = fl; pressed = fl; } - - void Draw(void); - void PressDraw(void); - void ReleaseDraw(void); - -private: - ICN::icn_t icn; - u16 index1; - u16 index2; - bool pressed; - bool disable; -}; - -class ButtonGroups -{ -public: - ButtonGroups(const Rect &, u16); - ~ButtonGroups(); - - void Draw(void); - u16 QueueEventProcessing(void); - - void DisableButton1(bool); - void DisableButton2(bool); - -private: - Button *button1; - Button *button2; - u16 result1; - u16 result2; - u16 buttons; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/cursor.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/cursor.cpp deleted file mode 100644 index a542352a4..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/cursor.cpp +++ /dev/null @@ -1,335 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "sprite.h" - -/* constructor */ -Cursor::Cursor() : theme(NONE), offset_x(0), offset_y(0) -{ -} - -Cursor & Cursor::Get(void) -{ - static Cursor cursor; - - return cursor; -} - -/* get theme cursor */ -Cursor::themes_t Cursor::Themes(void) -{ - return SP_ARROW >= theme ? static_cast(theme) : NONE; -} - -/* set cursor theme */ -bool Cursor::SetThemes(u16 name, bool force) -{ - if(force || theme != name) - { - if(isVisible()) Hide(); - theme = name; - - switch(0xF000 & name) - { - case 0x3000: - SetSprite(AGG::GetICN(ICN::SPELCO, 0xFF & name)); - DEBUG(DBG_ENGINE , DBG_TRACE, "Cursor::Set: SPELCO.ICN, " << static_cast(0xFF & name)); - break; - - case 0x2000: - SetSprite(AGG::GetICN(ICN::CMSECO, 0xFF & name)); - DEBUG(DBG_ENGINE , DBG_TRACE, "Cursor::Set: CMSECO.ICN, " << static_cast(0xFF & name)); - break; - - case 0x1000: - SetSprite(AGG::GetICN(ICN::ADVMCO, 0xFF & name)); - DEBUG(DBG_ENGINE , DBG_TRACE, "Cursor::Set: ADVMCO.ICN, " << static_cast(0xFF & name)); - break; - - default: - // default Cursor::POINTER - SetSprite(AGG::GetICN(ICN::ADVMCO, 0)); - break; - } - - SetOffset(name); - return true; - } - - return false; -} - -/* redraw cursor wrapper for local event */ -void Cursor::Redraw(u16 x, u16 y) -{ - Cursor & cur = Cursor::Get(); - - if(cur.isVisible()) - { - cur.Move(x, y); - - Display::Get().Flip(); - } -} - -/* move cursor */ -void Cursor::Move(u16 x, u16 y) -{ - if(isVisible()) SpriteCursor::Move(x + offset_x, y + offset_y); -} - -/* set offset big cursor */ -void Cursor::SetOffset(u16 name) -{ - switch(name) - { - case Cursor::MOVE: - case Cursor::MOVE2: - case Cursor::MOVE3: - case Cursor::MOVE4: - offset_x = -12; - offset_y = -8; - break; - - case Cursor::ACTION: - case Cursor::ACTION2: - case Cursor::ACTION3: - case Cursor::ACTION4: - offset_x = -14; - offset_y = -10; - break; - - case Cursor::BOAT: - case Cursor::BOAT2: - case Cursor::BOAT3: - case Cursor::BOAT4: - case Cursor::REDBOAT: - case Cursor::REDBOAT2: - case Cursor::REDBOAT3: - case Cursor::REDBOAT4: - offset_x = -12; - offset_y = -12; - break; - - case Cursor::CASTLE: - offset_x = -6; - offset_y = -4; - break; - - case Cursor::SCROLL_TOPRIGHT: - case Cursor::SCROLL_RIGHT: - offset_x = -15; - offset_y = 0; - break; - - case Cursor::SCROLL_BOTTOM: - case Cursor::SCROLL_BOTTOMLEFT: - offset_x = 0; - offset_y = -15; - break; - - case Cursor::SCROLL_BOTTOMRIGHT: - case Cursor::SWORD_BOTTOMRIGHT: - offset_x = -20; - offset_y = -20; - break; - - case Cursor::SWORD_BOTTOMLEFT: - offset_x = -5; - offset_y = -20; - break; - - case Cursor::SWORD_TOPLEFT: - offset_x = -5; - offset_y = -5; - break; - - case Cursor::SWORD_TOPRIGHT: - offset_x = -20; - offset_y = -5; - break; - - case Cursor::SWORD_LEFT: - offset_x = -5; - offset_y = -7; - break; - - case Cursor::SWORD_RIGHT: - offset_x = -25; - offset_y = -7; - break; - - case Cursor::WAR_MOVE: - case Cursor::WAR_FLY: - offset_x = -7; - offset_y = -14; - break; - - case Cursor::WAR_NONE: - case Cursor::WAR_HERO: - case Cursor::WAR_ARROW: - case Cursor::WAR_INFO: - case Cursor::WAR_BROKENARROW: - offset_x = -7; - offset_y = -7; - break; - - case Cursor::SP_SLOW: - case Cursor::SP_UNKNOWN: - case Cursor::SP_CURSE: - case Cursor::SP_LIGHTNINGBOLT: - case Cursor::SP_CHAINLIGHTNING: - case Cursor::SP_CURE: - case Cursor::SP_BLESS: - case Cursor::SP_FIREBALL: - case Cursor::SP_FIREBLAST: - case Cursor::SP_TELEPORT: - case Cursor::SP_ELEMENTALSTORM: - case Cursor::SP_RESURRECT: - case Cursor::SP_RESURRECTTRUE: - case Cursor::SP_HASTE: - case Cursor::SP_SHIELD: - case Cursor::SP_ARMAGEDDON: - case Cursor::SP_ANTIMAGIC: - case Cursor::SP_DISPEL: - case Cursor::SP_BERSERKER: - case Cursor::SP_PARALYZE: - case Cursor::SP_BLIND: - case Cursor::SP_HOLYWORD: - case Cursor::SP_HOLYSHOUT: - case Cursor::SP_METEORSHOWER: - case Cursor::SP_ANIMATEDEAD: - case Cursor::SP_MIRRORIMAGE: - case Cursor::SP_BLOODLUST: - case Cursor::SP_DEATHRIPPLE: - case Cursor::SP_DEATHWAVE: - case Cursor::SP_STEELSKIN: - case Cursor::SP_STONESKIN: - case Cursor::SP_DRAGONSLAYER: - case Cursor::SP_EARTHQUAKE: - case Cursor::SP_DISRUPTINGRAY: - case Cursor::SP_COLDRING: - case Cursor::SP_COLDRAY: - case Cursor::SP_HYPNOTIZE: - case Cursor::SP_ARROW: - { - const ::Sprite &spr = AGG::GetICN(ICN::SPELCO, 0xFF & name); - offset_x = -spr.w() / 2; - offset_y = -spr.h() / 2; - break; - } - - default: - offset_x = 0; - offset_y = 0; - break; - } -} - -/* draw simple cursor */ -void Cursor::DrawCursor(Surface &surface, const u8 indexcolor, bool solid) -{ - if(! surface.isValid()) return; - - surface.SetColorKey(); - - u16 width = surface.w(); - u16 height = surface.h(); - - // draw cursor - u32 color = surface.GetColor(indexcolor); - surface.Lock(); - if(solid) - { - for(u8 i = 0; i < width; ++i) - { - surface.SetPixel(i, 0, color); - surface.SetPixel(i, height - 1, color); - } - - for(u8 i = 0; i < height; ++i) - { - surface.SetPixel(0, i, color); - surface.SetPixel(width - 1, i, color); - } - } - else - { - for(u8 i = 0; i < width; ++i) - { - surface.SetPixel(i, 0, color); - if(i + 1 < width) surface.SetPixel(i + 1, 0, color); - i += 3; - } - for(u8 i = 0; i < width; ++i) - { - surface.SetPixel(i, height - 1, color); - if(i + 1 < width) surface.SetPixel(i + 1, height - 1, color); - i += 3; - } - for(u8 i = 0; i < height; ++i) - { - surface.SetPixel(0, i, color); - if(i + 1 < height) surface.SetPixel(0, i + 1, color); - i += 3; - } - for(u8 i = 0; i < height; ++i) - { - surface.SetPixel(width - 1, i, color); - if(i + 1 < height) surface.SetPixel(width - 1, i + 1, color); - i += 3; - } - } - surface.Unlock(); -} - -void Cursor::Show(void) -{ - if(! Settings::Get().ExtHideCursor()) SpriteCursor::Show(); -} - -Cursor::themes_t Cursor::DistanceThemes(themes_t theme, u16 dist) -{ - if(0 == dist) return POINTER; - else - if(dist > 4) dist = 4; - - switch(theme) - { - case MOVE: - case FIGHT: - case BOAT: - case ANCHOR: - case CHANGE: - case ACTION: - return static_cast(theme + 6 * (dist - 1)); - - case REDBOAT: - return static_cast(REDBOAT + dist - 1); - - default: return theme; - } - -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/cursor.h b/project/jni/application/fheroes2/src/fheroes2/gui/cursor.h deleted file mode 100644 index 477c938a8..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/cursor.h +++ /dev/null @@ -1,155 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2CURSOR_H -#define H2CURSOR_H - -#include "gamedefs.h" - -class Cursor : public SpriteCursor -{ -public: - - enum themes_t - { - NONE = 0x0000, - // ADVMCO.ICN - POINTER = 0x1000, - WAIT = 0x1001, - HEROES = 0x1002, - CASTLE = 0x1003, - MOVE = 0x1004, - FIGHT = 0x1005, - BOAT = 0x1006, - ANCHOR = 0x1007, - CHANGE = 0x1008, - ACTION = 0x1009, - MOVE2 = 0x100A, - FIGHT2 = 0x100B, - BOAT2 = 0x100C, - ANCHOR2 = 0x100D, - CHANGE2 = 0x100E, - ACTION2 = 0x100F, - MOVE3 = 0x1010, - FIGHT3 = 0x1011, - BOAT3 = 0x1012, - ANCHOR3 = 0x1013, - CHANGE3 = 0x1014, - ACTION3 = 0x1015, - MOVE4 = 0x1016, - FIGHT4 = 0x1017, - BOAT4 = 0x1018, - ANCHOR4 = 0x1019, - CHANGE4 = 0x101A, - ACTION4 = 0x101B, - REDBOAT = 0x101C, - REDBOAT2 = 0x101D, - REDBOAT3 = 0x101E, - REDBOAT4 = 0x101F, - SCROLL_TOP = 0x1020, - SCROLL_TOPRIGHT = 0x1021, - SCROLL_RIGHT = 0x1022, - SCROLL_BOTTOMRIGHT = 0x1023, - SCROLL_BOTTOM = 0x1024, - SCROLL_BOTTOMLEFT = 0x1025, - SCROLL_LEFT = 0x1026, - SCROLL_TOPLEFT = 0x1027, - POINTER2 = 0x1028, - // CMSECO.ICN - WAR_NONE = 0x2000, - WAR_MOVE = 0x2001, - WAR_FLY = 0x2002, - WAR_ARROW = 0x2003, - WAR_HERO = 0x2004, - WAR_INFO = 0x2005, - WAR_POINTER = 0x2006, - SWORD_TOPRIGHT = 0x2007, - SWORD_RIGHT = 0x2008, - SWORD_BOTTOMRIGHT = 0x2009, - SWORD_BOTTOMLEFT = 0x200A, - SWORD_LEFT = 0x200B, - SWORD_TOPLEFT = 0x200C, - SWORD_TOP = 0x200D, - SWORD_BOTTOM = 0x200E, - WAR_BROKENARROW = 0x200F, - // SPELCO.ICN - SP_NONE = WAR_NONE, - SP_SLOW = 0x3001, - SP_UNKNOWN = 0x3002, - SP_CURSE = 0x3003, - SP_LIGHTNINGBOLT = 0x3004, - SP_CHAINLIGHTNING = 0x3005, - SP_CURE = 0x3006, - SP_BLESS = 0x3007, - SP_FIREBALL = 0x3008, - SP_FIREBLAST = 0x3009, - SP_TELEPORT = 0x300A, - SP_ELEMENTALSTORM = 0x300B, - SP_RESURRECTTRUE = 0x300C, - SP_RESURRECT = 0x300D, - SP_HASTE = 0x300E, - SP_SHIELD = 0x300F, - SP_ARMAGEDDON = 0x3010, - SP_ANTIMAGIC = 0x3011, - SP_DISPEL = 0x3012, - SP_BERSERKER = 0x3013, - SP_PARALYZE = 0x3014, - SP_BLIND = 0x3015, - SP_HOLYWORD = 0x3016, - SP_HOLYSHOUT = 0x3017, - SP_METEORSHOWER = 0x3018, - SP_ANIMATEDEAD = 0x3019, - SP_MIRRORIMAGE = 0x301A, - SP_BLOODLUST = 0x301B, - SP_DEATHRIPPLE = 0x301C, - SP_DEATHWAVE = 0x301D, - SP_STEELSKIN = 0x301E, - SP_STONESKIN = 0x301F, - SP_DRAGONSLAYER = 0x3020, - SP_EARTHQUAKE = 0x3021, - SP_DISRUPTINGRAY = 0x3022, - SP_COLDRING = 0x3023, - SP_COLDRAY = 0x3024, - SP_HYPNOTIZE = 0x3025, - SP_ARROW = 0x3026 - }; - - static Cursor & Get(void); - - static void Redraw(u16 x, u16 y); - static void DrawCursor(Surface &surface, const u8 indexcolor, bool solid = false); - static themes_t DistanceThemes(themes_t, u16); - - themes_t Themes(void); - bool SetThemes(u16 cursor, bool force = false); - void Show(void); - -private: - Cursor(); - void SetOffset(u16 name); - void Move(u16 x, u16 y); - - u16 theme; - s16 offset_x; - s16 offset_y; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_border.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/interface_border.cpp deleted file mode 100644 index d376763c6..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_border.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "maps.h" -#include "settings.h" -#include "interface_border.h" - -Interface::BorderWindow::BorderWindow() -{ -} - -Interface::BorderWindow & Interface::BorderWindow::Get(void) -{ - static BorderWindow borderWindow; - return borderWindow; -} - -void Interface::BorderWindow::Redraw(void) -{ - const Settings & conf = Settings::Get(); - if(conf.HideInterface()) return; - - Display & display = Display::Get(); - - const bool evil = Settings::Get().EvilInterface(); - u8 count_w = (display.w() - 640) / TILEWIDTH; - u8 count_h = (display.h() - 480) / TILEWIDTH; - const u8 count_icons = count_h > 3 ? 8 : ( count_h < 3 ? 4 : 7); - - if(display.w() % TILEWIDTH) ++count_w; - if(display.h() % TILEWIDTH) ++count_h; - - Rect srcrt; - Point dstpt; - const Sprite &icnadv = AGG::GetICN(evil ? ICN::ADVBORDE : ICN::ADVBORD, 0); - - // TOP BORDER - srcrt.x = 0; - srcrt.y = 0; - srcrt.w = 223; - srcrt.h = BORDERWIDTH; - dstpt.x = srcrt.x; - dstpt.y = srcrt.y; - display.Blit(icnadv, srcrt, dstpt); - srcrt.x = 223; - srcrt.w = TILEWIDTH; - dstpt.x = srcrt.x; - dstpt.y = 0; - for(u8 ii = 0; ii < count_w + 1; ++ii) - { - display.Blit(icnadv, srcrt, dstpt); - dstpt.x += TILEWIDTH; - } - srcrt.x += TILEWIDTH; - srcrt.w = icnadv.w() - srcrt.x; - display.Blit(icnadv, srcrt, dstpt); - - - // LEFT BORDER - srcrt.x = 0; - srcrt.y = 0; - srcrt.w = BORDERWIDTH; - srcrt.h = 255; - dstpt.x = srcrt.x; - dstpt.y = srcrt.y; - display.Blit(icnadv, srcrt, dstpt); - srcrt.y = 255; - srcrt.h = TILEWIDTH; - dstpt.x = srcrt.x; - dstpt.y = srcrt.y; - for(u8 ii = 0; ii < count_h + 1; ++ii) - { - display.Blit(icnadv, srcrt, dstpt); - dstpt.y += TILEWIDTH; - } - srcrt.y += TILEWIDTH; - srcrt.h = icnadv.h() - srcrt.y; - display.Blit(icnadv, srcrt, dstpt); - - // MIDDLE BORDER - srcrt.x = icnadv.w() - RADARWIDTH - 2 * BORDERWIDTH; - srcrt.y = 0; - srcrt.w = BORDERWIDTH; - srcrt.h = 255; - dstpt.x = display.w() - RADARWIDTH - 2 * BORDERWIDTH; - dstpt.y = srcrt.y; - display.Blit(icnadv, srcrt, dstpt); - srcrt.y = 255; - srcrt.h = TILEWIDTH; - dstpt.x = display.w() - RADARWIDTH - 2 * BORDERWIDTH; - dstpt.y = srcrt.y; - for(u8 ii = 0; ii < count_h + 1; ++ii) - { - display.Blit(icnadv, srcrt, dstpt); - dstpt.y += TILEWIDTH; - } - srcrt.y += TILEWIDTH; - srcrt.h = icnadv.h() - srcrt.y; - display.Blit(icnadv, srcrt, dstpt); - - // RIGHT BORDER - srcrt.x = icnadv.w() - BORDERWIDTH; - srcrt.y = 0; - srcrt.w = BORDERWIDTH; - srcrt.h = 255; - dstpt.x = display.w() - BORDERWIDTH; - dstpt.y = srcrt.y; - display.Blit(icnadv, srcrt, dstpt); - srcrt.y = 255; - srcrt.h = TILEWIDTH; - dstpt.x = display.w() - BORDERWIDTH; - dstpt.y = srcrt.y; - for(u8 ii = 0; ii < count_h + 1; ++ii) - { - display.Blit(icnadv, srcrt, dstpt); - dstpt.y += TILEWIDTH; - } - srcrt.y += TILEWIDTH; - srcrt.h = icnadv.h() - srcrt.y; - display.Blit(icnadv, srcrt, dstpt); - - // BOTTOM BORDER - srcrt.x = 0; - srcrt.y = icnadv.h() - BORDERWIDTH; - srcrt.w = 223; - srcrt.h = BORDERWIDTH; - dstpt.x = srcrt.x; - dstpt.y = display.h() - BORDERWIDTH; - display.Blit(icnadv, srcrt, dstpt); - srcrt.x = 223; - srcrt.w = TILEWIDTH; - dstpt.x = srcrt.x; - dstpt.y = display.h() - BORDERWIDTH; - for(u8 ii = 0; ii < count_w + 1; ++ii) - { - display.Blit(icnadv, srcrt, dstpt); - dstpt.x += TILEWIDTH; - } - srcrt.x += TILEWIDTH; - srcrt.w = icnadv.w() - srcrt.x; - display.Blit(icnadv, srcrt, dstpt); - - // ICON BORDER - srcrt.x = icnadv.w() - RADARWIDTH - BORDERWIDTH; - srcrt.y = RADARWIDTH + BORDERWIDTH; - srcrt.w = RADARWIDTH; - srcrt.h = BORDERWIDTH; - dstpt.x = display.w() - RADARWIDTH - BORDERWIDTH; - dstpt.y = srcrt.y; - display.Blit(icnadv, srcrt, dstpt); - dstpt.y = srcrt.y + BORDERWIDTH + count_icons * 32; - srcrt.y = srcrt.y + BORDERWIDTH + 4 * 32; - display.Blit(icnadv, srcrt, dstpt); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_border.h b/project/jni/application/fheroes2/src/fheroes2/gui/interface_border.h deleted file mode 100644 index 21b8be570..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_border.h +++ /dev/null @@ -1,42 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2INTERFACE_BORDER_H -#define H2INTERFACE_BORDER_H - -#include "gamedefs.h" - -namespace Interface -{ - class BorderWindow - { - public: - static BorderWindow & Get(void); - - void Redraw(void); - - private: - BorderWindow(); - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_buttons.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/interface_buttons.cpp deleted file mode 100644 index 1f708f86e..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_buttons.cpp +++ /dev/null @@ -1,235 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "dialog.h" -#include "game.h" -#include "game_interface.h" -#include "interface_buttons.h" - -Interface::ButtonsArea::ButtonsArea() : Rect(0, 0, 144, 72) -{ -} - -Interface::ButtonsArea & Interface::ButtonsArea::Get(void) -{ - static ButtonsArea buttonsArea; - - return buttonsArea; -} - -const Rect & Interface::ButtonsArea::GetArea(void) -{ - return Settings::Get().HideInterface() && border.isValid() ? border.GetRect() : *this; -} - -void Interface::ButtonsArea::SetPos(s16 ox, s16 oy) -{ - if(Settings::Get().HideInterface()) - { - FixOutOfDisplay(*this, ox, oy); - - Rect::x = ox + BORDERWIDTH; - Rect::y = oy + BORDERWIDTH; - - border.SetPosition(ox, oy, Rect::w, Rect::h); - - Settings::Get().SetPosButtons(*this); - } - else - { - Rect::x = ox; - Rect::y = oy; - } - - const ICN::icn_t icnbtn = Settings::Get().EvilInterface() ? ICN::ADVEBTNS : ICN::ADVBTNS; - - buttonNextHero.SetSprite(icnbtn, 0, 1); - buttonMovement.SetSprite(icnbtn, 2, 3); - buttonKingdom.SetSprite(icnbtn, 4, 5); - buttonSpell.SetSprite(icnbtn, 6, 7); - buttonEndTur.SetSprite(icnbtn, 8, 9); - buttonAdventure.SetSprite(icnbtn, 10, 11); - buttonFile.SetSprite(icnbtn, 12, 13); - buttonSystem.SetSprite(icnbtn, 14, 15); - - ox = Rect::x; - oy = Rect::y; - - buttonNextHero.SetPos(ox, oy); - buttonMovement.SetPos(buttonNextHero.x + buttonNextHero.w, oy); - buttonKingdom.SetPos(buttonMovement.x + buttonMovement.w, oy); - buttonSpell.SetPos(buttonKingdom.x + buttonKingdom.w, oy); - - oy = buttonNextHero.y + buttonNextHero.h; - - buttonEndTur.SetPos(ox, oy); - buttonAdventure.SetPos(buttonEndTur.x + buttonEndTur.w, oy); - buttonFile.SetPos(buttonAdventure.x + buttonAdventure.w, oy); - buttonSystem.SetPos(buttonFile.x + buttonFile.w, oy); -} - -void Interface::ButtonsArea::Redraw(void) -{ - const Settings & conf = Settings::Get(); - if(conf.HideInterface() && !conf.ShowButtons()) return; - - const ICN::icn_t icnbtn = Settings::Get().EvilInterface() ? ICN::ADVEBTNS : ICN::ADVBTNS; - - buttonNextHero.SetSprite(icnbtn, 0, 1); - buttonMovement.SetSprite(icnbtn, 2, 3); - buttonKingdom.SetSprite(icnbtn, 4, 5); - buttonSpell.SetSprite(icnbtn, 6, 7); - buttonEndTur.SetSprite(icnbtn, 8, 9); - buttonAdventure.SetSprite(icnbtn, 10, 11); - buttonFile.SetSprite(icnbtn, 12, 13); - buttonSystem.SetSprite(icnbtn, 14, 15); - - buttonNextHero.Draw(); - buttonMovement.Draw(); - buttonKingdom.Draw(); - buttonSpell.Draw(); - buttonEndTur.Draw(); - buttonAdventure.Draw(); - buttonFile.Draw(); - buttonSystem.Draw(); - - // redraw border - if(conf.HideInterface()) border.Redraw(); -} - -void Interface::ButtonsArea::QueueEventProcessing(Game::menu_t & ret) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - - le.MousePressLeft(buttonNextHero) ? buttonNextHero.PressDraw() : buttonNextHero.ReleaseDraw(); - le.MousePressLeft(buttonMovement) ? buttonMovement.PressDraw() : buttonMovement.ReleaseDraw(); - le.MousePressLeft(buttonKingdom) ? buttonKingdom.PressDraw() : buttonKingdom.ReleaseDraw(); - le.MousePressLeft(buttonSpell) ? buttonSpell.PressDraw() : buttonSpell.ReleaseDraw(); - le.MousePressLeft(buttonEndTur) ? buttonEndTur.PressDraw() : buttonEndTur.ReleaseDraw(); - le.MousePressLeft(buttonAdventure) ? buttonAdventure.PressDraw() : buttonAdventure.ReleaseDraw(); - le.MousePressLeft(buttonFile) ? buttonFile.PressDraw() : buttonFile.ReleaseDraw(); - le.MousePressLeft(buttonSystem) ? buttonSystem.PressDraw() : buttonSystem.ReleaseDraw(); - - if(conf.HideInterface() && conf.ShowButtons() && le.MousePressLeft(border.GetTop())) - { - Surface sf(border.GetRect().w, border.GetRect().h); - Cursor::DrawCursor(sf, 0x70); - const Point & mp = le.GetMouseCursor(); - const s16 ox = mp.x - border.GetRect().x; - const s16 oy = mp.y - border.GetRect().y; - SpriteCursor sp(sf, border.GetRect().x, border.GetRect().y); - cursor.Hide(); - sp.Redraw(); - cursor.Show(); - display.Flip(); - while(le.HandleEvents() && le.MousePressLeft()) - { - if(le.MouseMotion()) - { - cursor.Hide(); - sp.Move(mp.x - ox, mp.y - oy); - cursor.Show(); - display.Flip(); - } - } - cursor.Hide(); - SetPos(mp.x - ox, mp.y - oy); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - else - if(le.MouseClickLeft(buttonNextHero)) - { - // for QVGA: auto hide buttons after click - if(conf.QVGA()) conf.SetShowButtons(false); - Game::EventNextHero(); - } - else - if(le.MouseClickLeft(buttonMovement)) - { - // for QVGA: auto hide buttons after click - if(conf.QVGA()) conf.SetShowButtons(false); - Game::EventContinueMovement(); - } - else - if(le.MouseClickLeft(buttonKingdom)) - { - // for QVGA: auto hide buttons after click - if(conf.QVGA()) conf.SetShowButtons(false); - Game::EventKingdomInfo(); - } - else - if(le.MouseClickLeft(buttonSpell)) - { - // for QVGA: auto hide buttons after click - if(conf.QVGA()) conf.SetShowButtons(false); - Game::EventCastSpell(); - } - else - if(le.MouseClickLeft(buttonEndTur)) - { - // for QVGA: auto hide buttons after click - if(conf.QVGA()) conf.SetShowButtons(false); - Game::EventEndTurn(ret); - } - else - if(le.MouseClickLeft(buttonAdventure)) - { - // for QVGA: auto hide buttons after click - if(conf.QVGA()) conf.SetShowButtons(false); - Game::EventAdventureDialog(ret); - } - else - if(le.MouseClickLeft(buttonFile)) - { - // for QVGA: auto hide buttons after click - if(conf.QVGA()) conf.SetShowButtons(false); - Game::EventFileDialog(ret); - } - else - if(le.MouseClickLeft(buttonSystem)) - { - // for QVGA: auto hide buttons after click - if(conf.QVGA()) conf.SetShowButtons(false); - Game::EventSystemDialog(); - } - - if(le.MousePressRight(buttonNextHero)) Dialog::Message(_("Next Hero"), _("Select the next Hero."), Font::BIG); - else - if(le.MousePressRight(buttonMovement)) Dialog::Message(_("Continue Movement"), _("Continue the Hero's movement along the current path."), Font::BIG); - else - if(le.MousePressRight(buttonKingdom)) Dialog::Message(_("Kingdom Summary"), _("View a Summary of your Kingdom."), Font::BIG); - else - if(le.MousePressRight(buttonSpell)) Dialog::Message(_("Cast Spell"), _("Cast an adventure spell."), Font::BIG); - else - if(le.MousePressRight(buttonEndTur)) Dialog::Message(_("End Turn"), _("End your turn and left the computer take its turn."), Font::BIG); - else - if(le.MousePressRight(buttonAdventure)) Dialog::Message(_("Adventure Options"), _("Bring up the adventure options menu."), Font::BIG); - else - if(le.MousePressRight(buttonFile)) Dialog::Message(_("File Options"), _("Bring up the file options menu, alloving you to load menu, save etc."), Font::BIG); - else - if(le.MousePressRight(buttonSystem)) Dialog::Message(_("System Options"), _("Bring up the system options menu, alloving you to customize your game."), Font::BIG); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_buttons.h b/project/jni/application/fheroes2/src/fheroes2/gui/interface_buttons.h deleted file mode 100644 index 3792a5a47..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_buttons.h +++ /dev/null @@ -1,59 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2INTERFACE_BUTTONS_H -#define H2INTERFACE_BUTTONS_H - -#include "gamedefs.h" -#include "button.h" -#include "dialog.h" - -namespace Interface -{ - class ButtonsArea : protected Rect - { - public: - static ButtonsArea & Get(void); - - void SetPos(s16, s16); - void Redraw(void); - void QueueEventProcessing(Game::menu_t &); - - const Rect & GetArea(void); - - private: - ButtonsArea(); - - Button buttonNextHero; - Button buttonMovement; - Button buttonKingdom; - Button buttonSpell; - Button buttonEndTur; - Button buttonAdventure; - Button buttonFile; - Button buttonSystem; - - Dialog::FrameBorder border; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_cpanel.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/interface_cpanel.cpp deleted file mode 100644 index 188475320..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_cpanel.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "game_interface.h" -#include "interface_cpanel.h" - -Interface::ControlPanel::ControlPanel() : alpha(130) -{ - w = 180; - h = 36; - - rt_radr.w = 36; - rt_radr.h = 36; - rt_icon.w = 36; - rt_icon.h = 36; - rt_bttn.w = 36; - rt_bttn.h = 36; - rt_stat.w = 36; - rt_stat.h = 36; - rt_quit.w = 36; - rt_quit.h = 36; - - btn_radr.Set(h, h); - btn_icon.Set(h, h); - btn_bttn.Set(h, h); - btn_stat.Set(h, h); - btn_quit.Set(h, h); - - ResetTheme(); -} - -void Interface::ControlPanel::ResetTheme(void) -{ - ICN::icn_t icn = Settings::Get().EvilInterface() ? ICN::ADVEBTNS : ICN::ADVBTNS; - - btn_radr.Blit(AGG::GetICN(icn, 4)); - btn_icon.Blit(AGG::GetICN(icn, 0)); - btn_bttn.Blit(AGG::GetICN(icn, 12)); - btn_stat.Blit(AGG::GetICN(icn, 10)); - btn_quit.Blit(AGG::GetICN(icn, 8)); - - btn_radr.SetAlpha(alpha); - btn_icon.SetAlpha(alpha); - btn_bttn.SetAlpha(alpha); - btn_stat.SetAlpha(alpha); - btn_quit.SetAlpha(alpha); -} - -Interface::ControlPanel & Interface::ControlPanel::Get(void) -{ - static ControlPanel cp; - return cp; -} - -const Rect & Interface::ControlPanel::GetArea(void) -{ - return *this; -} - -void Interface::ControlPanel::SetPos(s16 ox, s16 oy) -{ - x = ox; - y = oy; - - rt_radr.x = x; - rt_radr.y = y; - rt_icon.x = x + 36; - rt_icon.y = y; - rt_bttn.x = x + 72; - rt_bttn.y = y; - rt_stat.x = x + 108; - rt_stat.y = y; - rt_quit.x = x + 144; - rt_quit.y = y; -} - -void Interface::ControlPanel::Redraw(void) -{ - Display & display = Display::Get(); - - display.Blit(btn_radr, x, y); - display.Blit(btn_icon, x + 36, y); - display.Blit(btn_bttn, x + 72, y); - display.Blit(btn_stat, x + 108, y); - display.Blit(btn_quit, x + 144, y); -} - -void Interface::ControlPanel::QueueEventProcessing(Game::menu_t & ret) -{ - LocalEvent & le = LocalEvent::Get(); - - if(le.MouseClickLeft(rt_radr)) Game::EventSwitchShowRadar(); - else - if(le.MouseClickLeft(rt_icon)) Game::EventSwitchShowIcons(); - else - if(le.MouseClickLeft(rt_bttn)) Game::EventSwitchShowButtons(); - else - if(le.MouseClickLeft(rt_stat)) Game::EventSwitchShowStatus(); - else - if(le.MouseClickLeft(rt_quit)) Game::EventEndTurn(ret); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_cpanel.h b/project/jni/application/fheroes2/src/fheroes2/gui/interface_cpanel.h deleted file mode 100644 index 634b2afe5..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_cpanel.h +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2INTERFACE_CPANEL_H -#define H2INTERFACE_CPANEL_H - -#include "gamedefs.h" -#include "game.h" - -namespace Interface -{ - class ControlPanel : protected Rect - { - public: - static ControlPanel & Get(void); - - void SetPos(s16, s16); - void Redraw(void); - void ResetTheme(void); - void QueueEventProcessing(Game::menu_t &); - - const Rect & GetArea(void); - - private: - ControlPanel(); - - Surface btn_radr; - Surface btn_icon; - Surface btn_bttn; - Surface btn_stat; - Surface btn_quit; - - Rect rt_radr; - Rect rt_icon; - Rect rt_bttn; - Rect rt_stat; - Rect rt_quit; - - const u8 alpha; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_gamearea.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/interface_gamearea.cpp deleted file mode 100644 index 5f6f38742..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_gamearea.cpp +++ /dev/null @@ -1,570 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "world.h" -#include "maps.h" -#include "game.h" -#include "game_focus.h" -#include "game_interface.h" -#include "route.h" -#include "interface_gamearea.h" - -#define SCROLL_MIN 8 -#define SCROLL_MAX TILEWIDTH - -namespace Game -{ - // game_startgame.cpp - Cursor::themes_t GetCursor(s32); - void MouseCursorAreaClickLeft(s32); - void MouseCursorAreaPressRight(s32); -} - -Interface::GameArea & Interface::GameArea::Get(void) -{ - static Interface::GameArea ga; - return ga; -} - -Interface::GameArea::GameArea() : oldIndexPos(0), updateCursor(false) -{ -} - -const Rect & Interface::GameArea::GetArea(void) const -{ return areaPosition; } - -const Point& Interface::GameArea::GetMapsPos(void) const -{ return rectMapsPosition; } - -const Rect & Interface::GameArea::GetRectMaps(void) const -{ return rectMaps; } - -/* fixed src rect image */ -void Interface::GameArea::SrcRectFixed(Rect & src, Point & dst, const u16 rw, const u16 rh) -{ - SrcRectFixed(src, dst.x, dst.y, rw, rh); -} - -void Interface::GameArea::SrcRectFixed(Rect & src, s16 & dst_x, s16 & dst_y, const u16 rw, const u16 rh) -{ - src = Rect(0, 0, 0, 0); - const Rect & areaPosition = Interface::GameArea::Get().GetArea(); - - if(0 != rw && 0 != rh && - dst_x + rw > areaPosition.x && dst_y + rh > areaPosition.y && - dst_x < areaPosition.x + areaPosition.w && dst_y < areaPosition.y + areaPosition.h) - { - src.w = rw; - src.h = rh; - - if(dst_x < areaPosition.x) - { - src.x = areaPosition.x - dst_x; - dst_x = areaPosition.x; - } - - if(dst_y < areaPosition.y) - { - src.y = areaPosition.y - dst_y; - dst_y = areaPosition.y; - } - - if(dst_x + rw > areaPosition.x + areaPosition.w) - src.w = areaPosition.x + areaPosition.w - dst_x; - - if(dst_y + rh > areaPosition.y + areaPosition.h) - src.h = areaPosition.y + areaPosition.h - dst_y; - } -} - -void Interface::GameArea::Build(void) -{ - if(Settings::Get().HideInterface()) - SetAreaPosition(0, 0, - Display::Get().w(), - Display::Get().h()); - else - SetAreaPosition(BORDERWIDTH, BORDERWIDTH, - Display::Get().w() - RADARWIDTH - 3 * BORDERWIDTH, - Display::Get().h() - 2 * BORDERWIDTH); -} - -void Interface::GameArea::SetAreaPosition(s16 x, s16 y, u16 w, u16 h) -{ - areaPosition.x = x; - areaPosition.y = y; - areaPosition.w = w; - areaPosition.h = h; - - rectMaps.x = 0; - rectMaps.y = 0; - rectMaps.w = (areaPosition.w / TILEWIDTH) + 2; - rectMaps.h = (areaPosition.h / TILEWIDTH) + 2; - - scrollOffset.x = 0; - scrollOffset.y = 0; - scrollStep = Settings::Get().ScrollSpeed(); - - rectMapsPosition.x = areaPosition.x + scrollOffset.x; - rectMapsPosition.y = areaPosition.y + scrollOffset.y; -} - -void Interface::GameArea::BlitOnTile(Surface & dst, const Sprite & src, const Point & mp) const -{ - BlitOnTile(dst, src, src.x(), src.y(), mp); -} - -void Interface::GameArea::BlitOnTile(Surface & dst, const Surface & src, const s16 ox, const s16 oy, const Point & mp) const -{ - const s16 & dstx = rectMapsPosition.x + TILEWIDTH * (mp.x - rectMaps.x); - const s16 & dsty = rectMapsPosition.y + TILEWIDTH * (mp.y - rectMaps.y); - - Point dstpt(dstx + ox, dsty + oy); - - if(areaPosition & Rect(dstpt, src.w(), src.h())) - { - Rect srcrt; - SrcRectFixed(srcrt, dstpt, src.w(), src.h()); - dst.Blit(src, srcrt, dstpt); - } -} - -void Interface::GameArea::Redraw(Surface & dst, u8 flag) const -{ - return Redraw(dst, flag, Rect(0, 0, rectMaps.w, rectMaps.h)); -} - -void Interface::GameArea::Redraw(Surface & dst, u8 flag, const Rect & rt) const -{ - // tile - for(s16 oy = rt.y; oy < rt.y + rt.h; ++oy) - for(s16 ox = rt.x; ox < rt.x + rt.w; ++ox) - world.GetTiles(rectMaps.x + ox, rectMaps.y + oy).RedrawTile(dst); - - // bottom - if(flag & LEVEL_BOTTOM) - for(s16 oy = rt.y; oy < rt.y + rt.h; ++oy) - for(s16 ox = rt.x; ox < rt.x + rt.w; ++ox) - world.GetTiles(rectMaps.x + ox, rectMaps.y + oy).RedrawBottom(dst); - - // ext object - if(flag & LEVEL_OBJECTS) - for(s16 oy = rt.y; oy < rt.y + rt.h; ++oy) - for(s16 ox = rt.x; ox < rt.x + rt.w; ++ox) - world.GetTiles(rectMaps.x + ox, rectMaps.y + oy).RedrawObjects(dst); - - // top - if(flag & LEVEL_TOP) - for(s16 oy = rt.y; oy < rt.y + rt.h; ++oy) - for(s16 ox = rt.x; ox < rt.x + rt.w; ++ox) - world.GetTiles(rectMaps.x + ox, rectMaps.y + oy).RedrawTop(dst); - - // heroes - for(s16 oy = rt.y; oy < rt.y + rt.h; ++oy) - for(s16 ox = rt.x; ox < rt.x + rt.w; ++ox) - { - const Maps::Tiles & tile = world.GetTiles(rectMaps.x + ox, rectMaps.y + oy); - - if(tile.GetObject() == MP2::OBJ_HEROES && (flag & LEVEL_HEROES)) - { - const Heroes *hero = world.GetHeroes(tile.GetIndex()); - if(hero) hero->Redraw(dst, rectMapsPosition.x + TILEWIDTH * ox, rectMapsPosition.y + TILEWIDTH * oy, true); - } - } - - // route - const Game::Focus & focus = Game::Focus::Get(); - - if((flag & LEVEL_HEROES) && - Game::Focus::HEROES == focus.Type() && - focus.GetHeroes().GetPath().isShow()) - { - const Heroes & hero = focus.GetHeroes(); - s32 from = hero.GetIndex(); - s16 green = hero.GetPath().GetAllowStep(); - - const bool skipfirst = hero.isEnableMove() && 45 > hero.GetSpriteIndex() && 2 < (hero.GetSpriteIndex() % 9); - - Route::Path::const_iterator it1 = hero.GetPath().begin(); - Route::Path::const_iterator it2 = hero.GetPath().end(); - Route::Path::const_iterator it3 = it1; - - for(; it1 != it2; ++it1) - { - from = Maps::GetDirectionIndex(from, (*it1).Direction()); - const Point mp(from % world.w(), from / world.h()); - - ++it3; - --green; - - if(!(Rect(rectMaps.x + rt.x, rectMaps.y + rt.y, rt.w, rt.h) & mp)) continue; - if(it1 == hero.GetPath().begin() && skipfirst) continue; - - const u16 index = (it3 == it2 ? 0 : - Route::Path::GetIndexSprite((*it1).Direction(), (*it3).Direction(), - Maps::Ground::GetBasePenalty(from, hero.GetLevelSkill(Skill::Secondary::PATHFINDING)))); - - const Sprite & sprite = AGG::GetICN(0 > green ? ICN::ROUTERED : ICN::ROUTE, index); - BlitOnTile(dst, sprite, sprite.x() - 14, sprite.y(), mp); - } - } - - if(IS_DEVEL()) - { - // redraw grid - if(flag & LEVEL_ALL) - { - for(s16 oy = rt.y; oy < rt.y + rt.h; ++oy) - for(s16 ox = rt.x; ox < rt.x + rt.w; ++ox) - { - const Point dstpt(rectMapsPosition.x + TILEWIDTH * ox, - rectMapsPosition.y + TILEWIDTH * oy); - if(areaPosition & dstpt) - { - dst.Lock(); - dst.SetPixel(dstpt.x, dstpt.y, dst.GetColor(0x40)); - dst.Unlock(); - } - } - } - } - else - // redraw fog - if(flag & LEVEL_FOG) - for(s16 oy = rt.y; oy < rt.y + rt.h; ++oy) - for(s16 ox = rt.x; ox < rt.x + rt.w; ++ox) - { - const Maps::Tiles & tile = world.GetTiles(rectMaps.x + ox, rectMaps.y + oy); - if(tile.isFog(Settings::Get().MyColor())) - tile.RedrawFogs(dst, Settings::Get().MyColor()); - } -} - -/* scroll area */ -void Interface::GameArea::Scroll(void) -{ - if(scrollDirection & SCROLL_LEFT) - { - if(0 < scrollOffset.x) - scrollOffset.x -= scrollStep; - else - if(0 < rectMaps.x) - { - scrollOffset.x = SCROLL_MAX - scrollStep; - --rectMaps.x; - } - } - else - if(scrollDirection & SCROLL_RIGHT) - { - if(scrollOffset.x < SCROLL_MAX * 2) - scrollOffset.x += scrollStep; - else - if(world.w() - rectMaps.w > rectMaps.x) - { - scrollOffset.x = SCROLL_MAX + scrollStep; - ++rectMaps.x; - } - } - - if(scrollDirection & SCROLL_TOP) - { - if(0 < scrollOffset.y) - scrollOffset.y -= scrollStep; - else - if(0 < rectMaps.y) - { - scrollOffset.y = SCROLL_MAX - scrollStep; - --rectMaps.y; - } - } - else - if(scrollDirection & SCROLL_BOTTOM) - { - if(scrollOffset.y < SCROLL_MAX * 2) - scrollOffset.y += scrollStep; - else - if(world.h() - rectMaps.h > rectMaps.y) - { - scrollOffset.y = SCROLL_MAX + scrollStep; - ++rectMaps.y; - } - } - - rectMapsPosition.x = areaPosition.x - scrollOffset.x; - rectMapsPosition.y = areaPosition.y - scrollOffset.y; - - scrollDirection = 0; -} - -/* scroll area to center point maps */ -void Interface::GameArea::Center(const Point &pt) -{ - Center(pt.x, pt.y); -} - -void Interface::GameArea::Center(s16 px, s16 py) -{ - Point pos(px - rectMaps.w / 2, py - rectMaps.h / 2); - - // our of range - if(pos.x < 0) pos.x = 0; - else - if(pos.x > world.w() - rectMaps.w) pos.x = world.w() - rectMaps.w; - - if(pos.y < 0) pos.y = 0; - else - if(pos.y > world.h() - rectMaps.h) pos.y = world.h() - rectMaps.h; - - if(pos.x == rectMaps.x && pos.y == rectMaps.y) return; - - // possible fast scroll - if(pos.y == rectMaps.y && 1 == (pos.x - rectMaps.x)) scrollDirection |= SCROLL_RIGHT; - else - if(pos.y == rectMaps.y && -1 == (pos.x - rectMaps.x)) scrollDirection |= SCROLL_LEFT; - else - if(pos.x == rectMaps.x && 1 == (pos.y - rectMaps.y)) scrollDirection |= SCROLL_BOTTOM; - else - if(pos.x == rectMaps.x && -1 == (pos.y - rectMaps.y)) scrollDirection |= SCROLL_TOP; - else - // diagonal - if(-1 == (pos.y - rectMaps.y) && 1 == (pos.x - rectMaps.x)) - { - scrollDirection |= SCROLL_TOP | SCROLL_RIGHT; - } - else - if(-1 == (pos.y - rectMaps.y) && -1 == (pos.x - rectMaps.x)) - { - scrollDirection |= SCROLL_TOP | SCROLL_LEFT; - } - else - if(1 == (pos.y - rectMaps.y) && 1 == (pos.x - rectMaps.x)) - { - scrollDirection |= SCROLL_BOTTOM | SCROLL_RIGHT; - } - else - if(1 == (pos.y - rectMaps.y) && -1 == (pos.x - rectMaps.x)) - { - scrollDirection |= SCROLL_BOTTOM | SCROLL_LEFT; - } - - else - { - rectMaps.x = pos.x; - rectMaps.y = pos.y; - scrollDirection = 0; - - if(pos.x == 0) scrollOffset.x = 0; - else - if(pos.x == world.w() - rectMaps.w) - scrollOffset.x = SCROLL_MAX * 2; - else - scrollOffset.x = SCROLL_MAX + TILEWIDTH / 2; - - if(pos.y == 0) scrollOffset.y = 0; - else - if(pos.y == world.h() - rectMaps.h) - scrollOffset.y = SCROLL_MAX * 2; - else - scrollOffset.y = SCROLL_MAX + TILEWIDTH / 2; - - rectMapsPosition.x = areaPosition.x - scrollOffset.x; - rectMapsPosition.y = areaPosition.y - scrollOffset.y; - - scrollStep = Settings::Get().ScrollSpeed(); - } - - if(scrollDirection) Scroll(); -} - -void Interface::GameArea::GenerateUltimateArtifactAreaSurface(const s32 index, Surface & sf) -{ - if(Interface::NoGUI()) return; - - if(Maps::isValidAbsIndex(index)) - { - sf.Set(448, 448); - - GameArea & gamearea = Get(); - const Rect origPosition(gamearea.areaPosition); - gamearea.SetAreaPosition(0, 0, sf.w(), sf.h()); - - const Rect & rectMaps = gamearea.GetRectMaps(); - const Rect & areaPosition = gamearea.GetArea(); - Point pt(index % world.w(), index / world.h()); - - gamearea.Center(pt); - gamearea.Redraw(sf, LEVEL_BOTTOM | LEVEL_TOP); - - // blit marker - for(u8 ii = 0; ii < rectMaps.h; ++ii) if(index < Maps::GetIndexFromAbsPoint(rectMaps.x + rectMaps.w - 1, rectMaps.y + ii)) - { - pt.y = ii; - break; - } - for(u8 ii = 0; ii < rectMaps.w; ++ii) if(index == Maps::GetIndexFromAbsPoint(rectMaps.x + ii, rectMaps.y + pt.y)) - { - pt.x = ii; - break; - } - const Sprite & marker = AGG::GetICN(ICN::ROUTE, 0); - const Point dst(areaPosition.x + pt.x * TILEWIDTH, areaPosition.y + pt.y * TILEWIDTH); - sf.Blit(marker, dst.x, dst.y + 8); - - Settings::Get().EvilInterface() ? sf.GrayScale() : sf.Sepia(); - - if(Settings::Get().QVGA()) - { - Surface sf2; - Surface::ScaleMinifyByTwo(sf2, sf); - Surface::Swap(sf2, sf); - } - - gamearea.SetAreaPosition(origPosition.x, origPosition.y, origPosition.w, origPosition.h); - } - else - DEBUG(DBG_ENGINE , DBG_WARN, "Interface::GameArea::GenerateUltimateArtifactAreaSurface: artifact not found"); -} - -bool Interface::GameArea::NeedScroll(void) const -{ - return scrollDirection; -} - -Cursor::themes_t Interface::GameArea::GetScrollCursor(void) const -{ - switch(scrollDirection) - { - case SCROLL_TOP: return Cursor::SCROLL_TOP; - case SCROLL_BOTTOM: return Cursor::SCROLL_BOTTOM; - case SCROLL_RIGHT: return Cursor::SCROLL_RIGHT; - case SCROLL_LEFT: return Cursor::SCROLL_LEFT; - case SCROLL_LEFT | SCROLL_TOP: return Cursor::SCROLL_TOPLEFT; - case SCROLL_LEFT | SCROLL_BOTTOM: return Cursor::SCROLL_BOTTOMLEFT; - case SCROLL_RIGHT | SCROLL_TOP: return Cursor::SCROLL_TOPRIGHT; - case SCROLL_RIGHT | SCROLL_BOTTOM:return Cursor::SCROLL_BOTTOMRIGHT; - - default: break; - } - - return Cursor::NONE; -} - -void Interface::GameArea::SetScroll(scroll_t direct) -{ - switch(direct) - { - case SCROLL_LEFT: - if(0 < rectMaps.x || 0 < scrollOffset.x) - { - scrollDirection |= direct; - updateCursor = true; - } - break; - - case SCROLL_RIGHT: - if(world.w() - rectMaps.w > rectMaps.x || SCROLL_MAX * 2 > scrollOffset.x) - { - scrollDirection |= direct; - updateCursor = true; - } - break; - - case SCROLL_TOP: - if(0 < rectMaps.y || 0 < scrollOffset.y) - { - scrollDirection |= direct; - updateCursor = true; - } - break; - - case SCROLL_BOTTOM: - if(world.h() - rectMaps.h > rectMaps.y || SCROLL_MAX * 2 > scrollOffset.y) - { - scrollDirection |= direct; - updateCursor = true; - } - break; - - default: break; - } - - scrollTime.Start(); -} - -/* convert area point to index maps */ -s32 Interface::GameArea::GetIndexFromMousePoint(const Point & pt) const -{ - s32 result = (rectMaps.y + (pt.y - rectMapsPosition.y) / TILEWIDTH) * world.w() + - rectMaps.x + (pt.x - rectMapsPosition.x) / TILEWIDTH; - const s32 & max = world.w() * world.h() - 1; - - return result > max || result < Maps::GetIndexFromAbsPoint(rectMaps.x, rectMaps.y) ? -1 : result; -} - -void Interface::GameArea::SetUpdateCursor(void) -{ - updateCursor = true; -} - -void Interface::GameArea::QueueEventProcessing(void) -{ - const Settings & conf = Settings::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - const Point & mp = le.GetMouseCursor(); - - s32 index = GetIndexFromMousePoint(mp); - - // out of range - if(index < 0) return; - - const Rect tile_pos(rectMapsPosition.x + ((u16) (mp.x - rectMapsPosition.x) / TILEWIDTH) * TILEWIDTH, - rectMapsPosition.y + ((u16) (mp.y - rectMapsPosition.y) / TILEWIDTH) * TILEWIDTH, - TILEWIDTH, TILEWIDTH); - - // change cusor if need - if(updateCursor || index != oldIndexPos) - { - cursor.SetThemes(Game::GetCursor(index)); - oldIndexPos = index; - updateCursor = false; - } - - // fixed pocket pc tap mode - if(conf.HideInterface() && conf.ShowControlPanel() && le.MouseCursor(Interface::ControlPanel::Get().GetArea())) return; - - // fixed pocket pc: click on maps after scroll (pause: ~800 ms) - if(conf.ExtTapMode()) - { - scrollTime.Stop(); - if(800 > scrollTime.Get()) return; - } - - if(le.MouseClickLeft(tile_pos) && Cursor::POINTER != cursor.Themes()) - Game::MouseCursorAreaClickLeft(index); - else - if(le.MousePressRight(tile_pos)) - Game::MouseCursorAreaPressRight(index); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_gamearea.h b/project/jni/application/fheroes2/src/fheroes2/gui/interface_gamearea.h deleted file mode 100644 index b9efb5274..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_gamearea.h +++ /dev/null @@ -1,104 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2INTERFACE_GAMEAREA_H -#define H2INTERFACE_GAMEAREA_H - -#include "gamedefs.h" -#include "cursor.h" - -enum scroll_t -{ - SCROLL_NONE = 0x00, - SCROLL_LEFT = 0x01, - SCROLL_RIGHT = 0x02, - SCROLL_TOP = 0x04, - SCROLL_BOTTOM = 0x08 -}; - -enum level_t -{ - LEVEL_BOTTOM = 0x01, - LEVEL_TOP = 0x02, - LEVEL_HEROES = 0x04, - LEVEL_OBJECTS = 0x08, - LEVEL_FOG = 0x20, - - LEVEL_ALL = 0xFF -}; - -namespace Maps { class Tiles; } - -namespace Interface -{ - class GameArea - { - public: - - static GameArea & Get(void); - void Build(void); - - const Rect & GetArea(void) const; - const Point& GetMapsPos(void) const; - const Rect & GetRectMaps(void) const; - - Cursor::themes_t GetScrollCursor(void) const; - bool NeedScroll(void) const; - void Scroll(void); - void SetScroll(scroll_t); - - void Center(s16, s16); - void Center(const Point &pt); - - void Redraw(Surface & dst, u8) const; - void Redraw(Surface & dst, u8, const Rect &) const; - - void BlitOnTile(Surface &, const Surface &, const s16, const s16, const Point &) const; - void BlitOnTile(Surface &, const Sprite &, const Point &) const; - - void SetUpdateCursor(void); - void QueueEventProcessing(void); - - s32 GetIndexFromMousePoint(const Point & pt) const; - - static void GenerateUltimateArtifactAreaSurface(const s32, Surface &); - static void SrcRectFixed(Rect & src, Point & dst, const u16 rw, const u16 rh); - static void SrcRectFixed(Rect & src, s16 & dstx, s16 & dsty, const u16 rw, const u16 rh); - - private: - void SetAreaPosition(s16, s16, u16, u16); - GameArea(); - - Rect areaPosition; - Rect rectMaps; - Point rectMapsPosition; - Point scrollOffset; - u16 oldIndexPos; - u8 scrollDirection; - u8 scrollStep; - bool updateCursor; - - SDL::Time scrollTime; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_icons.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/interface_icons.cpp deleted file mode 100644 index 99ce33c79..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_icons.cpp +++ /dev/null @@ -1,487 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include - -#include "agg.h" -#include "castle.h" -#include "heroes.h" -#include "race.h" -#include "cursor.h" -#include "world.h" -#include "portrait.h" -#include "settings.h" -#include "game_focus.h" -#include "kingdom.h" -#include "game_interface.h" -#include "interface_icons.h" - -namespace Game -{ - // game_startgame.cpp - void OpenCastle(Castle *); - void OpenHeroes(Heroes *); -} - -#define ICONS_WIDTH 46 -#define ICONS_HEIGHT 22 -#define ICONS_CURSOR_WIDTH 56 -#define ICONS_CURSOR_HEIGHT 32 -#define ICONS_CURSOR_COLOR 0x98 - -void RedrawCastleIcon(const Castle & castle, s16 sx, s16 sy) -{ - Display & display = Display::Get(); - const bool evil = Settings::Get().EvilInterface(); - u8 index_sprite = 1; - - switch(castle.GetRace()) - { - case Race::KNGT: index_sprite = castle.isCastle() ? 9 : 15; break; - case Race::BARB: index_sprite = castle.isCastle() ? 10 : 16; break; - case Race::SORC: index_sprite = castle.isCastle() ? 11 : 17; break; - case Race::WRLK: index_sprite = castle.isCastle() ? 12 : 18; break; - case Race::WZRD: index_sprite = castle.isCastle() ? 13 : 19; break; - case Race::NECR: index_sprite = castle.isCastle() ? 14 : 20; break; - default: DEBUG(DBG_ENGINE , DBG_WARN, "Interface::CastleIcons::Redraw: unknown race."); - } - - display.Blit(AGG::GetICN(evil ? ICN::LOCATORE : ICN::LOCATORS, index_sprite), sx, sy); - - // castle build marker - if(! castle.AllowBuild()) - display.Blit(AGG::GetICN(evil ? ICN::LOCATORE : ICN::LOCATORS, 24), sx + 39, sy + 1); -} - -void RedrawHeroesIcon(const Heroes & hero, s16 sx, s16 sy) -{ - Display & display = Display::Get(); - const Sprite & mobility = AGG::GetICN(ICN::MOBILITY, hero.GetMobilityIndexSprite()); - const Sprite & mana = AGG::GetICN(ICN::MANA, hero.GetManaIndexSprite()); - const Surface & port = Portrait::Hero(hero, Portrait::SMALL); - - display.FillRect(0, 0, 0, Rect(sx, sy, ICONS_WIDTH, ICONS_HEIGHT)); - - const u8 barw = 7; - const u32 blue = display.MapRGB(15, 30, 120); - - // mobility - display.FillRect(blue, Rect(sx, sy, barw, ICONS_HEIGHT)); - display.Blit(mobility, sx, sy + mobility.y()); - - // portrait - display.Blit(port, sx + barw + 1, sy); - - // mana - display.FillRect(blue, Rect(sx + barw + port.w() + 2, sy, barw, ICONS_HEIGHT)); - display.Blit(mana, sx + barw + port.w() + 2, sy + mana.y()); -} - -void Interface::IconsBar::RedrawBackground(const Point & pos) -{ - Display & display = Display::Get(); - const Sprite & icnadv = AGG::GetICN(Settings::Get().EvilInterface() ? ICN::ADVBORDE : ICN::ADVBORD, 0); - const Sprite & back = AGG::GetICN(Settings::Get().EvilInterface() ? ICN::LOCATORE : ICN::LOCATORS, 1); - Rect srcrt; - Point dstpt; - - srcrt.x = icnadv.w() - RADARWIDTH - BORDERWIDTH; - srcrt.y = RADARWIDTH + 2 * BORDERWIDTH; - srcrt.w = RADARWIDTH / 2; - srcrt.h = 32; - - dstpt.x = pos.x; - dstpt.y = pos.y; - display.Blit(icnadv, srcrt, dstpt); - - srcrt.y = srcrt.y + srcrt.h; - dstpt.y = dstpt.y + srcrt.h; - srcrt.h = 32; - - if(2 < icons) - for(u8 ii = 0; ii < icons - 2; ++ii) - { - display.Blit(icnadv, srcrt, dstpt); - dstpt.y += srcrt.h; - } - - srcrt.y = srcrt.y + 64; - srcrt.h = 32; - display.Blit(icnadv, srcrt, dstpt); - - for(u8 ii = 0; ii < icons; ++ii) - display.Blit(back, pos.x + 5, pos.y + 5 + ii * (ICONS_HEIGHT + 10)); -} - -/* Interface::CastleIcons */ -void Interface::CastleIcons::RedrawItem(const CASTLE & item, s16 ox, s16 oy, bool current) -{ - if(item && show) - { - RedrawCastleIcon(*item, ox, oy); - - if(current) - Display::Get().Blit(marker, ox - 5, oy - 5); - } -} - -void Interface::CastleIcons::RedrawBackground(const Point & pos) -{ - IconsBar::RedrawBackground(pos); -} - -void Interface::CastleIcons::ActionCurrentUp(void) -{ - Game::Focus::Get().Set(GetCurrent()); -} - -void Interface::CastleIcons::ActionCurrentDn(void) -{ - Game::Focus::Get().Set(GetCurrent()); -} - -void Interface::CastleIcons::ActionListDoubleClick(CASTLE & item) -{ - if(item) - { - Game::OpenCastle(item); - - // for QVGA: auto hide icons after click - if(Settings::Get().QVGA()) Settings::Get().SetShowIcons(false); - } -} - -void Interface::CastleIcons::ActionListSingleClick(CASTLE & item) -{ - if(item) - { - Game::Focus::Get().Set(item); - Game::Focus::Get().SetRedraw(); - - // for QVGA: auto hide icons after click - if(Settings::Get().QVGA()) Settings::Get().SetShowIcons(false); - } -} - -void Interface::CastleIcons::ActionListPressRight(CASTLE & item) -{ - if(item) - { - Cursor::Get().Hide(); - Dialog::QuickInfo(*item); - } -} - -void Interface::CastleIcons::SetPos(s16 px, s16 py) -{ - const ICN::icn_t icnscroll = Settings::Get().EvilInterface() ? ICN::SCROLLE : ICN::SCROLL; - - SetTopLeft(Point(px, py)); - SetScrollSplitter(AGG::GetICN(icnscroll, 4), - Rect(px + ICONS_CURSOR_WIDTH + 4, py + 18, 10, ICONS_CURSOR_HEIGHT * icons - 35)); - SetScrollButtonUp(icnscroll, 0, 1, - Point(px + ICONS_CURSOR_WIDTH + 1, py + 1)); - SetScrollButtonDn(icnscroll, 2, 3, - Point(px + ICONS_CURSOR_WIDTH + 1, py + icons * ICONS_CURSOR_HEIGHT - 15)); - SetAreaMaxItems(icons); - SetAreaItems(Rect(px + 5, py + 5, ICONS_CURSOR_WIDTH, icons * ICONS_CURSOR_HEIGHT)); - DisableHotkeys(true); - - SetListContent(world.GetMyKingdom().GetCastles()); - Reset(); -} - -/* Interface::HeroesIcons */ -void Interface::HeroesIcons::RedrawItem(const HEROES & item, s16 ox, s16 oy, bool current) -{ - if(item && show) - { - RedrawHeroesIcon(*item, ox, oy); - - if(current) - Display::Get().Blit(marker, ox - 5, oy - 5); - } -} - -void Interface::HeroesIcons::RedrawBackground(const Point & pos) -{ - IconsBar::RedrawBackground(pos); -} - -void Interface::HeroesIcons::ActionCurrentUp(void) -{ - Game::Focus::Get().Set(GetCurrent()); -} - -void Interface::HeroesIcons::ActionCurrentDn(void) -{ - Game::Focus::Get().Set(GetCurrent()); -} - -void Interface::HeroesIcons::ActionListDoubleClick(HEROES & item) -{ - if(item) - { - Game::OpenHeroes(item); - - // for QVGA: auto hide icons after click - if(Settings::Get().QVGA()) Settings::Get().SetShowIcons(false); - } -} - -void Interface::HeroesIcons::ActionListSingleClick(HEROES & item) -{ - if(item) - { - Game::Focus::Get().Set(item); - Game::Focus::Get().SetRedraw(); - - // for QVGA: auto hide icons after click - if(Settings::Get().QVGA()) Settings::Get().SetShowIcons(false); - } -} - -void Interface::HeroesIcons::ActionListPressRight(HEROES & item) -{ - if(item) - { - Cursor::Get().Hide(); - Dialog::QuickInfo(*item); - } -} - -void Interface::HeroesIcons::SetPos(s16 px, s16 py) -{ - const ICN::icn_t icnscroll = Settings::Get().EvilInterface() ? ICN::SCROLLE : ICN::SCROLL; - - SetTopLeft(Point(px, py)); - SetScrollSplitter(AGG::GetICN(icnscroll, 4), - Rect(px + ICONS_CURSOR_WIDTH + 4, py + 18, 10, ICONS_CURSOR_HEIGHT * icons - 35)); - SetScrollButtonUp(icnscroll, 0, 1, - Point(px + ICONS_CURSOR_WIDTH + 1, py + 1)); - SetScrollButtonDn(icnscroll, 2, 3, - Point(px + ICONS_CURSOR_WIDTH + 1, py + icons * ICONS_CURSOR_HEIGHT - 15)); - SetAreaMaxItems(icons); - SetAreaItems(Rect(px + 5, py + 5, ICONS_CURSOR_WIDTH, icons * ICONS_CURSOR_HEIGHT)); - DisableHotkeys(true); - - SetListContent(world.GetMyKingdom().GetHeroes()); - Reset(); -} - -/* Interface::IconsPanel */ -Interface::IconsPanel::IconsPanel() : Rect(0, 0, 144, 128), icons(4), - castleIcons(icons, sfMarker), heroesIcons(icons, sfMarker) -{ - sfMarker.Set(ICONS_CURSOR_WIDTH, ICONS_CURSOR_HEIGHT); - sfMarker.SetColorKey(); - Cursor::DrawCursor(sfMarker, ICONS_CURSOR_COLOR, true); -} - -Interface::IconsPanel & Interface::IconsPanel::Get(void) -{ - static IconsPanel iconsPanel; - return iconsPanel; -} - -const Rect & Interface::IconsPanel::GetArea(void) const -{ - return Settings::Get().HideInterface() && border.isValid() ? border.GetRect() : *this; -} - -u8 Interface::IconsPanel::CountIcons(void) const -{ - return icons; -} - -void Interface::IconsPanel::SetPos(s16 ox, s16 oy) -{ - if(Settings::Get().HideInterface()) - { - FixOutOfDisplay(*this, ox, oy); - - Rect::x = ox + BORDERWIDTH; - Rect::y = oy + BORDERWIDTH; - - border.SetPosition(ox, oy, Rect::w, Rect::h); - Settings::Get().SetPosIcons(*this); - } - else - { - Rect::x = ox; - Rect::y = oy; - } - - SetCount(icons); -} - -void Interface::IconsPanel::SetCount(u8 count) -{ - icons = count; - Rect::h = icons * ICONS_CURSOR_HEIGHT; - - heroesIcons.SetPos(x, y); - castleIcons.SetPos(x + 72, y); - - border.SetPosition(border.GetRect().x, border.GetRect().y, w, h); -} - -void Interface::IconsPanel::Redraw(void) -{ - const Settings & conf = Settings::Get(); - - // is visible - if(!conf.HideInterface() || conf.ShowIcons()) - { - //Display::Get().FillRect(0, 0, 0, *this); - - heroesIcons.Redraw(); - castleIcons.Redraw(); - - // redraw border - if(conf.HideInterface()) border.Redraw(); - } -} - -void Interface::IconsPanel::QueueEventProcessing(void) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - - if(heroesIcons.QueueEventProcessing()) - { - if(heroesIcons.isSelected()) - castleIcons.Unselect(); - - Interface::Basic::Get().SetRedraw(REDRAW_ICONS); - } - else - if(castleIcons.QueueEventProcessing()) - { - if(castleIcons.isSelected()) - heroesIcons.Unselect(); - - Interface::Basic::Get().SetRedraw(REDRAW_ICONS); - } - else - // move border - if(conf.HideInterface() && conf.ShowIcons() && le.MousePressLeft(border.GetTop())) - { - Surface sf(border.GetRect().w, border.GetRect().h); - Cursor::DrawCursor(sf, 0x70); - const Point & mp = le.GetMouseCursor(); - const s16 ox = mp.x - border.GetRect().x; - const s16 oy = mp.y - border.GetRect().y; - SpriteCursor sp(sf, border.GetRect().x, border.GetRect().y); - cursor.Hide(); - sp.Redraw(); - cursor.Show(); - display.Flip(); - while(le.HandleEvents() && le.MousePressLeft()) - { - if(le.MouseMotion()) - { - cursor.Hide(); - sp.Move(mp.x - ox, mp.y - oy); - cursor.Show(); - display.Flip(); - } - } - cursor.Hide(); - - SetPos(mp.x - ox, mp.y - oy); - Game::Focus::Get().CheckIconsPanel(); - - Interface::Basic::Get().SetRedraw(REDRAW_ICONS|REDRAW_GAMEAREA); - } -} - -void Interface::IconsPanel::Select(const Heroes & hr) -{ - castleIcons.Unselect(); - heroesIcons.SetCurrent((const HEROES) &hr); -} - -void Interface::IconsPanel::Select(const Castle & cs) -{ - heroesIcons.Unselect(); - castleIcons.SetCurrent((const CASTLE) &cs); -} - -void Interface::IconsPanel::ResetIcons(icons_t icons) -{ - if(icons & ICON_HEROES) - { - heroesIcons.SetListContent(world.GetMyKingdom().GetHeroes()); - heroesIcons.Reset(); - } - - if(icons & ICON_CASTLES) - { - castleIcons.SetListContent(world.GetMyKingdom().GetCastles()); - castleIcons.Reset(); - } -} - -void Interface::IconsPanel::HideIcons(icons_t icons) -{ - if(icons & ICON_HEROES) heroesIcons.SetShow(false); - if(icons & ICON_CASTLES) castleIcons.SetShow(false); -} - -void Interface::IconsPanel::ShowIcons(icons_t icons) -{ - if(icons & ICON_HEROES) heroesIcons.SetShow(true); - if(icons & ICON_CASTLES) castleIcons.SetShow(true); -} - -void Interface::IconsPanel::SetCurrentVisible(void) -{ - if(heroesIcons.isSelected()) - { - heroesIcons.SetCurrentVisible(); - heroesIcons.Redraw(); - } - else - if(castleIcons.isSelected()) - { - castleIcons.SetCurrentVisible(); - castleIcons.Redraw(); - } -} - -void Interface::IconsPanel::RedrawIcons(icons_t icons) -{ - if(icons & ICON_HEROES) heroesIcons.Redraw(); - if(icons & ICON_CASTLES) castleIcons.Redraw(); -} - -bool Interface::IconsPanel::IsSelected(icons_t icons) const -{ - if(icons & ICON_HEROES) return heroesIcons.isSelected(); - else - if(icons & ICON_CASTLES) return castleIcons.isSelected(); - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_icons.h b/project/jni/application/fheroes2/src/fheroes2/gui/interface_icons.h deleted file mode 100644 index cec8eb74b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_icons.h +++ /dev/null @@ -1,123 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2INTERFACE_ICONS_H -#define H2INTERFACE_ICONS_H - -#include "gamedefs.h" -#include "interface_list.h" -#include "dialog.h" - -enum icons_t { ICON_HEROES = 0x01, ICON_CASTLES = 0x02, ICON_ANY = ICON_HEROES|ICON_CASTLES }; - -namespace Interface -{ - typedef Heroes* HEROES; - typedef Castle* CASTLE; - - class IconsBar - { - public: - IconsBar(const u8 & count, const Surface & sf) : icons(count), marker(sf), show(true){}; - - void SetShow(bool f) { show = f; }; - bool IsShow(void) const { return show; }; - - void RedrawBackground(const Point &); - - protected: - const u8 & icons; - const Surface & marker; - bool show; - }; - - class HeroesIcons : public Interface::ListBox, public IconsBar - { - public: - HeroesIcons(const u8 & count, const Surface & sf) : IconsBar(count, sf) {}; - - void SetPos(s16, s16); - - protected: - void ActionCurrentUp(void); - void ActionCurrentDn(void); - void ActionListDoubleClick(HEROES &); - void ActionListSingleClick(HEROES &); - void ActionListPressRight(HEROES &); - void RedrawItem(const HEROES &, s16 ox, s16 oy, bool current); - void RedrawBackground(const Point &); - }; - - class CastleIcons : public Interface::ListBox, public IconsBar - { - public: - CastleIcons(const u8 & count, const Surface & sf) : IconsBar(count, sf) {}; - - void SetPos(s16, s16); - - protected: - void ActionCurrentUp(void); - void ActionCurrentDn(void); - void ActionListDoubleClick(CASTLE &); - void ActionListSingleClick(CASTLE &); - void ActionListPressRight(CASTLE &); - void RedrawItem(const CASTLE &, s16 ox, s16 oy, bool current); - void RedrawBackground(const Point &); - }; - - class IconsPanel : protected Rect - { - public: - static IconsPanel & Get(void); - - void SetPos(s16, s16); - void SetCount(u8); - void Redraw(void); - void QueueEventProcessing(void); - - const Rect & GetArea(void) const; - u8 CountIcons(void) const; - - void Select(const Heroes &); - void Select(const Castle &); - - bool IsSelected(icons_t) const; - void ResetIcons(icons_t = ICON_ANY); - void HideIcons(icons_t = ICON_ANY); - void ShowIcons(icons_t = ICON_ANY); - void RedrawIcons(icons_t = ICON_ANY); - void SetCurrentVisible(void); - - private: - IconsPanel(); - - u8 icons; - Dialog::FrameBorder border; - - Surface sfMarker; - - CastleIcons castleIcons; - HeroesIcons heroesIcons; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_list.h b/project/jni/application/fheroes2/src/fheroes2/gui/interface_list.h deleted file mode 100644 index 8105914de..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_list.h +++ /dev/null @@ -1,341 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2INTERFACE_LIST_H -#define H2INTERFACE_LIST_H - -#include "icn.h" -#include "button.h" -#include "splitter.h" -#include "sprite.h" -#include "cursor.h" -#include "gamedefs.h" - -namespace Interface -{ - template - class ListBox - { - public: - typedef std::vector Items; - typedef typename std::vector::iterator ItemsIterator; - - ListBox(const Point & pt) : ptRedraw(pt), maxItems(0), useHotkeys(true), content(NULL) {} - ListBox() : maxItems(0), content(NULL) {} - virtual ~ListBox(){} - - virtual void RedrawItem(const Item &, s16 ox, s16 oy, bool current) = 0; - virtual void RedrawBackground(const Point &) = 0; - - virtual void ActionCurrentUp(void) = 0; - virtual void ActionCurrentDn(void) = 0; - virtual void ActionListDoubleClick(Item &) = 0; - virtual void ActionListSingleClick(Item &) = 0; - virtual void ActionListPressRight(Item &) = 0; - - /* - void SetTopLeft(const Point & top); - void SetScrollButtonUp(const ICN::icn_t, const u16, const u16, const Point &); - void SetScrollButtonDn(const ICN::icn_t, const u16, const u16, const Point &); - void SetScrollSplitter(const Sprite &, const Rect &); - void SetAreaMaxItems(const u8); - void SetAreaItems(const Rect &); - void SetListContent(std::vector &); - void Redraw(void); - bool QueueEventProcessing(void); - Item & GetCurrent(void); - void SetCurrent(size_t); - void SetCurrent(const Item &); - void SetCurrentVisible(void); - void RemoveSelected(void); - void DisableHotkeys(bool); - bool isSelected(void) const; - void Unselect(void); - void Reset(void); - */ - - void SetTopLeft(const Point & tl) - { - ptRedraw = tl; - } - - void SetScrollButtonUp(const ICN::icn_t icn, const u16 index1, const u16 index2, const Point & pos) - { - buttonPgUp.SetSprite(icn, index1, index2); - buttonPgUp.SetPos(pos); - } - - void SetScrollButtonDn(const ICN::icn_t icn, const u16 index1, const u16 index2, const Point & pos) - { - buttonPgDn.SetSprite(icn, index1, index2); - buttonPgDn.SetPos(pos); - } - - void SetScrollSplitter(const Sprite & sp, const Rect & area) - { - splitter.SetOrientation(Splitter::VERTICAL); - splitter.SetArea(area); - splitter.SetSprite(sp); - } - - void SetAreaMaxItems(const u8 max) - { - maxItems = max; - } - - void SetAreaItems(const Rect & rt) - { - rtAreaItems = rt; - } - - void SetListContent(std::vector & list) - { - content = &list; - cur = content->begin(); - top = content->begin(); - splitter.SetRange(0, (maxItems < list.size() ? list.size() - maxItems : 0)); - } - - void Reset(void) - { - if(content) - { - cur = content->end(); - top = content->begin(); - splitter.Move(0); - } - } - - void DisableHotkeys(bool f) - { - useHotkeys = !f; - } - - void Redraw(void) - { - Cursor::Get().Hide(); - - RedrawBackground(ptRedraw); - - buttonPgUp.Draw(); - buttonPgDn.Draw(); - splitter.Redraw(); - - ItemsIterator curt = top; - ItemsIterator last = top + maxItems < content->end() ? top + maxItems : content->end(); - for(; curt != last; ++curt) - RedrawItem(*curt, rtAreaItems.x, rtAreaItems.y + (curt - top) * rtAreaItems.h / maxItems, curt == cur); - } - - Item & GetCurrent(void) - { - return *cur; - } - - Item* GetFromPosition(const Point & mp) - { - ItemsIterator click = content->end(); - float offset = (mp.y - rtAreaItems.y) * maxItems / rtAreaItems.h; - click = top + static_cast(offset); - return click < content->begin() || click >= content->end() ? NULL : &(*click); - } - - void SetCurrent(size_t pos) - { - if(pos < content->size()) - cur = content->begin() + pos; - - SetCurrentVisible(); - } - - void SetCurrentVisible(void) - { - if(top > cur || top + maxItems <= cur) - { - top = cur + maxItems > content->end() ? content->end() - maxItems : cur; - if(top < content->begin()) top = content->begin(); - splitter.Move(top - content->begin()); - } - } - - void SetCurrent(const Item & item) - { - cur = std::find(content->begin(), content->end(), item); - SetCurrentVisible(); - } - - void RemoveSelected(void) - { - if(content && cur != content->end()) content->erase(cur); - } - - bool isSelected(void) const - { - return content && cur != content->end(); - } - - void Unselect(void) - { - if(content) cur = content->end(); - } - - bool QueueEventProcessing(void) - { - LocalEvent & le = LocalEvent::Get(); - Cursor & cursor = Cursor::Get(); - - le.MousePressLeft(buttonPgUp) ? buttonPgUp.PressDraw() : buttonPgUp.ReleaseDraw(); - le.MousePressLeft(buttonPgDn) ? buttonPgDn.PressDraw() : buttonPgDn.ReleaseDraw(); - - if(!content) return false; - - if((le.MouseClickLeft(buttonPgUp) || (useHotkeys && le.KeyPress(KEY_PAGEUP))) && - (top > content->begin())) - { - cursor.Hide(); - top = (top - content->begin() > maxItems ? top - maxItems : content->begin()); - splitter.Move(top - content->begin()); - return true; - } - else - if((le.MouseClickLeft(buttonPgDn) || (useHotkeys && le.KeyPress(KEY_PAGEDOWN))) && - (top + maxItems < content->end())) - { - cursor.Hide(); - top += maxItems; - if(top + maxItems > content->end()) top = content->end() - maxItems; - splitter.Move(top - content->begin()); - return true; - } - else - if(useHotkeys && le.KeyPress(KEY_UP) && (cur > content->begin())) - { - cursor.Hide(); - --cur; - SetCurrentVisible(); - ActionCurrentUp(); - return true; - } - else - if(useHotkeys && le.KeyPress(KEY_DOWN) && (cur < (content->end() - 1))) - { - cursor.Hide(); - ++cur; - SetCurrentVisible(); - ActionCurrentDn(); - return true; - } - else - if((le.MouseWheelUp(rtAreaItems) || le.MouseWheelUp(splitter.GetRect())) && (top > content->begin())) - { - cursor.Hide(); - --top; - splitter.Backward(); - return true; - } - else - if((le.MouseWheelDn(rtAreaItems) || le.MouseWheelDn(splitter.GetRect())) && (top < (content->end() - maxItems))) - { - cursor.Hide(); - ++top; - splitter.Forward(); - return true; - } - else - if(le.MousePressLeft(splitter.GetRect()) && (content->size() > maxItems)) - { - cursor.Hide(); - s16 seek = (le.GetMouseCursor().y - splitter.GetRect().y) * 100 / splitter.GetStep(); - if(seek < splitter.Min()) seek = splitter.Min(); - else - if(seek > splitter.Max()) seek = splitter.Max(); - top = content->begin() + seek; - splitter.Move(seek); - return true; - } - else - if(le.MouseClickLeft(rtAreaItems) && content->size()) - { - float offset = (le.GetMouseReleaseLeft().y - rtAreaItems.y) * maxItems / rtAreaItems.h; - - if(offset >= 0) - { - cursor.Hide(); - - ItemsIterator click = top + static_cast(offset); - - if(click >= content->begin() && click < content->end()) - { - if(click == cur) - { - ActionListDoubleClick(*cur); - } - else - { - cur = click; - ActionListSingleClick(*cur); - } - return true; - } - } - } - else - if(le.MousePressRight(rtAreaItems) && content->size()) - { - float offset = (le.GetMouseCursor().y - rtAreaItems.y) * maxItems / rtAreaItems.h; - - if(offset >= 0) - { - cursor.Hide(); - - ItemsIterator click = top + static_cast(offset); - - if(click >= content->begin() && click < content->end()) - { - ActionListPressRight(*click); - return true; - } - } - } - - return false; - } - - protected: - Point ptRedraw; - Rect rtAreaItems; - - Button buttonPgUp; - Button buttonPgDn; - - Splitter splitter; - - u8 maxItems; - bool useHotkeys; - - Items *content; - ItemsIterator cur; - ItemsIterator top; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_radar.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/interface_radar.cpp deleted file mode 100644 index 83df84734..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_radar.cpp +++ /dev/null @@ -1,381 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "game.h" -#include "game_interface.h" -#include "ground.h" -#include "world.h" -#include "castle.h" -#include "cursor.h" -#include "interface_radar.h" - -#define RADARCOLOR 0x40 // index palette -#define COLOR_DESERT 0x70 -#define COLOR_SNOW 0x0A -#define COLOR_SWAMP 0xA0 -#define COLOR_WASTELAND 0xD6 -#define COLOR_BEACH 0xC6 -#define COLOR_LAVA 0x19 -#define COLOR_DIRT 0x30 -#define COLOR_GRASS 0x60 -#define COLOR_WATER 0xF0 -#define COLOR_ROAD 0x7A - -#define COLOR_BLUE 0x47 -#define COLOR_GREEN 0x67 -#define COLOR_RED 0xbd -#define COLOR_YELLOW 0x70 -#define COLOR_ORANGE 0xcd -#define COLOR_PURPLE 0x87 -#define COLOR_GRAY 0x10 - -u32 GetPaletteIndexFromGround(const u16 ground); - -/* constructor */ -Interface::Radar::Radar() : spriteArea(NULL), spriteCursor(NULL), cursorArea(NULL), - sf_blue(NULL), sf_green(NULL), sf_red(NULL), sf_yellow(NULL), - sf_orange(NULL), sf_purple(NULL), sf_gray(NULL), sf_black(NULL), hide(true) -{ - Rect::w = RADARWIDTH; - Rect::h = RADARWIDTH; -} - -Interface::Radar::~Radar() -{ - if(cursorArea) delete cursorArea; - if(spriteArea) delete spriteArea; - if(spriteCursor) delete spriteCursor; - if(sf_blue) delete sf_blue; - if(sf_green) delete sf_green; - if(sf_red) delete sf_red; - if(sf_yellow) delete sf_yellow; - if(sf_orange) delete sf_orange; - if(sf_purple) delete sf_purple; - if(sf_gray) delete sf_gray; - if(sf_black) delete sf_black; -} - -void Interface::Radar::SetPos(s16 ox, s16 oy) -{ - if(Settings::Get().HideInterface()) - { - FixOutOfDisplay(*this, ox, oy); - - Rect::x = ox + BORDERWIDTH; - Rect::y = oy + BORDERWIDTH; - - border.SetPosition(ox, oy, Rect::w, Rect::h); - Settings::Get().SetPosRadar(*this); - } - else - { - Rect::x = ox; - Rect::y = oy; - } -} - -const Rect & Interface::Radar::GetArea(void) const -{ - return Settings::Get().HideInterface() && border.isValid() ? border.GetRect() : *this; -} - -/* construct gui */ -void Interface::Radar::Build(void) -{ - if(cursorArea) delete cursorArea; - if(spriteArea) delete spriteArea; - if(spriteCursor) delete spriteCursor; - if(sf_blue) delete sf_blue; - if(sf_green) delete sf_green; - if(sf_red) delete sf_red; - if(sf_yellow) delete sf_yellow; - if(sf_orange) delete sf_orange; - if(sf_purple) delete sf_purple; - if(sf_gray) delete sf_gray; - if(sf_black) delete sf_black; - - spriteArea = new Surface(w, h); - const Size & rectMaps = Interface::GameArea::Get().GetRectMaps(); - const u16 & sw = static_cast(rectMaps.w * (w / static_cast(world.w()))); - const u16 & sh = static_cast(rectMaps.h * (h / static_cast(world.h()))); - spriteCursor = new Surface(sw, sh); - cursorArea = new SpriteCursor(*spriteCursor, x, y); - - const u8 n = world.w() == Maps::SMALL ? 4 : 2; - sf_blue = new Surface(n, n); - sf_green = new Surface(n, n); - sf_red = new Surface(n, n); - sf_yellow = new Surface(n, n); - sf_orange = new Surface(n, n); - sf_purple = new Surface(n, n); - sf_gray = new Surface(n, n); - sf_black = new Surface(n, n); - - sf_blue->Fill(sf_blue->GetColor(COLOR_BLUE)); - sf_green->Fill(sf_green->GetColor(COLOR_GREEN)); - sf_red->Fill(sf_red->GetColor(COLOR_RED)); - sf_yellow->Fill(sf_yellow->GetColor(COLOR_YELLOW)); - sf_orange->Fill(sf_orange->GetColor(COLOR_ORANGE)); - sf_purple->Fill(sf_purple->GetColor(COLOR_PURPLE)); - sf_gray->Fill(sf_gray->GetColor(COLOR_GRAY)); - sf_black->Fill(0); - - Generate(); - Cursor::DrawCursor(*spriteCursor, RADARCOLOR); -} - -Interface::Radar & Interface::Radar::Get(void) -{ - static Radar radar0; - - return radar0; -} - -/* generate mini maps */ -void Interface::Radar::Generate(void) -{ - const u16 world_w = world.w(); - const u16 world_h = world.h(); - - const u8 n = world.w() == Maps::SMALL ? 4 : 2; - Surface tile_surface(n, n); - - for(s32 index = 0; index < world_w * world_h; ++index) - { - const Maps::Tiles & tile = world.GetTiles(index); - u32 color = COLOR_ROAD; - - if(tile.isRoad()) - tile_surface.Fill(tile_surface.GetColor(color)); - else - if(0 != (color = GetPaletteIndexFromGround(tile.GetGround()))) - tile_surface.Fill(tile_surface.GetColor(tile.GetObject() == MP2::OBJ_MOUNTS ? color + 2 : color)); - else - continue; - - float dstx = (index % world_w) * w / world_w; - float dsty = (index / world_h) * h / world_w; - - spriteArea->Blit(tile_surface, static_cast(dstx), static_cast(dsty)); - } -} - -void Interface::Radar::SetHide(bool f) -{ - hide = f; -} - -void Interface::Radar::Redraw(void) -{ - const Settings & conf = Settings::Get(); - - if(!hide) - { - RedrawArea(conf.MyColor()); - RedrawCursor(); - } - else - if(!conf.HideInterface() || conf.ShowRadar()) - Display::Get().Blit(AGG::GetICN((conf.EvilInterface() ? ICN::HEROLOGE : ICN::HEROLOGO), 0), x, y); - - // redraw border - if(conf.HideInterface() && conf.ShowRadar()) - { - border.Redraw(); - } -} - -/* redraw radar area for color */ -void Interface::Radar::RedrawArea(const u8 color) -{ - const Settings & conf = Settings::Get(); - if(conf.HideInterface() && !conf.ShowRadar()) return; - Display & display = Display::Get(); - - - const u16 world_w = world.w(); - const u16 world_h = world.h(); - const Surface *tile_surface = NULL; - - cursorArea->Hide(); - display.Blit(*spriteArea, x, y); - - for(s32 index = 0; index < world_w * world_h; ++index) - { - const Maps::Tiles & tile = world.GetTiles(index); - - if(!IS_DEVEL() && tile.isFog(color)) - tile_surface = sf_black; - else - switch(tile.GetObject()) - { - case MP2::OBJ_HEROES: - { - const Heroes *hero = world.GetHeroes(index); - if(hero) tile_surface = GetSurfaceFromColor(hero->GetColor()); - } - break; - - case MP2::OBJ_CASTLE: - case MP2::OBJN_CASTLE: - { - const Castle *castle = world.GetCastle(index); - if(castle) tile_surface = GetSurfaceFromColor(castle->GetColor()); - } - break; - - case MP2::OBJ_DRAGONCITY: - //case MP2::OBJN_DRAGONCITY: - case MP2::OBJ_LIGHTHOUSE: - //case MP2::OBJN_LIGHTHOUSE: - case MP2::OBJ_ALCHEMYLAB: - //case MP2::OBJN_ALCHEMYLAB: - case MP2::OBJ_MINES: - //case MP2::OBJN_MINES: - case MP2::OBJ_SAWMILL: - //case MP2::OBJN_SAWMILL: - tile_surface = GetSurfaceFromColor(world.ColorCapturedObject(index)); break; - - default: continue; - } - - if(tile_surface) - { - float dstx = (index % world_w) * w / world_w; - float dsty = (index / world_h) * h / world_w; - - display.Blit(*tile_surface, x + static_cast(dstx), y + static_cast(dsty)); - } - } -} - -/* redraw radar cursor */ -void Interface::Radar::RedrawCursor(void) -{ - const Settings & conf = Settings::Get(); - if(conf.HideInterface() && !conf.ShowRadar()) return; - - const Point & rectMaps = Interface::GameArea::Get().GetRectMaps(); - cursorArea->Hide(); - cursorArea->Move(x + rectMaps.x * w / world.w(), - y + rectMaps.y * h / world.h()); - cursorArea->Show(); -} - -Surface* Interface::Radar::GetSurfaceFromColor(const u8 color) -{ - switch(color) - { - case Color::BLUE: return sf_blue; - case Color::GREEN: return sf_green; - case Color::RED: return sf_red; - case Color::YELLOW: return sf_yellow; - case Color::ORANGE: return sf_orange; - case Color::PURPLE: return sf_purple; - case Color::GRAY: return sf_gray; - default: break; - } - - return NULL; -} - -u32 GetPaletteIndexFromGround(const u16 ground) -{ - switch(ground) - { - case Maps::Ground::DESERT: return (COLOR_DESERT); - case Maps::Ground::SNOW: return (COLOR_SNOW); - case Maps::Ground::SWAMP: return (COLOR_SWAMP); - case Maps::Ground::WASTELAND: return (COLOR_WASTELAND); - case Maps::Ground::BEACH: return (COLOR_BEACH); - case Maps::Ground::LAVA: return (COLOR_LAVA); - case Maps::Ground::DIRT: return (COLOR_DIRT); - case Maps::Ground::GRASS: return (COLOR_GRASS); - case Maps::Ground::WATER: return (COLOR_WATER); - default: break; - } - - return 0; -} - -void Interface::Radar::QueueEventProcessing(void) -{ - Interface::GameArea & gamearea = Interface::GameArea::Get(); - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - - // move border - if(conf.HideInterface() && conf.ShowRadar() && le.MousePressLeft(border.GetTop())) - { - Surface sf(border.GetRect().w, border.GetRect().h); - Cursor::DrawCursor(sf, 0x70); - const Point & mp = le.GetMouseCursor(); - const s16 ox = mp.x - border.GetRect().x; - const s16 oy = mp.y - border.GetRect().y; - SpriteCursor sp(sf, border.GetRect().x, border.GetRect().y); - cursorArea->Hide(); - cursor.Hide(); - sp.Redraw(); - cursor.Show(); - display.Flip(); - while(le.HandleEvents() && le.MousePressLeft()) - { - if(le.MouseMotion()) - { - cursor.Hide(); - sp.Move(mp.x - ox, mp.y - oy); - cursor.Show(); - display.Flip(); - } - } - cursor.Hide(); - SetPos(mp.x - ox, mp.y - oy); - RedrawCursor(); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - else - // move cursor - if(le.MouseCursor(*this)) - { - if(le.MouseClickLeft() || le.MousePressLeft()) - { - const Point prev(gamearea.GetRectMaps()); - const Point & pt = le.GetMouseCursor(); - if(*this & pt) - { - gamearea.Center((pt.x - x) * world.w() / w, (pt.y - y) * world.h() / h); - if(prev != gamearea.GetRectMaps()) - { - Cursor::Get().Hide(); - RedrawCursor(); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - } - } - else - if(!conf.ExtTapMode() && le.MousePressRight(*this)) Dialog::Message(_("World Map"), _("A miniature view of the known world. Left click to move viewing area."), Font::BIG); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_radar.h b/project/jni/application/fheroes2/src/fheroes2/gui/interface_radar.h deleted file mode 100644 index 2a42efb06..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_radar.h +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2INTERFACE_RADAR_H -#define H2INTERFACE_RADAR_H - -#include "dialog.h" -#include "gamedefs.h" - -namespace Interface -{ - class Radar : protected Rect - { - public: - static Radar & Get(void); - ~Radar(); - - void SetPos(s16, s16); - const Rect & GetArea(void) const; - - void Build(void); - void Generate(void); - void Redraw(void); - void RedrawArea(const u8 color = 0xFF); - void SetHide(bool); - void RedrawCursor(void); - - void QueueEventProcessing(void); - - private: - Surface *GetSurfaceFromColor(const u8); - Radar(); - - Surface *spriteArea; - Surface *spriteCursor; - SpriteCursor *cursorArea; - - Surface* sf_blue; - Surface* sf_green; - Surface* sf_red; - Surface* sf_yellow; - Surface* sf_orange; - Surface* sf_purple; - Surface* sf_gray; - Surface* sf_black; - - Dialog::FrameBorder border; - - bool hide; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_status.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/interface_status.cpp deleted file mode 100644 index 63987abc9..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_status.cpp +++ /dev/null @@ -1,447 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "text.h" -#include "cursor.h" -#include "world.h" -#include "settings.h" -#include "kingdom.h" -#include "castle.h" -#include "heroes.h" -#include "army.h" -#include "game_focus.h" -#include "game_interface.h" -#include "interface_status.h" - -#define AITURN_REDRAW_EXPIRE 20 -#define RESOURCE_WINDOW_EXPIRE 2500 - -Interface::StatusWindow::StatusWindow() : state(STATUS_UNKNOWN), oldState(STATUS_UNKNOWN) -{ - const Sprite & ston = AGG::GetICN(Settings::Get().EvilInterface() ? ICN::STONBAKE : ICN::STONBACK, 0); - Rect::w = ston.w(); - Rect::h = ston.h(); -} - -Interface::StatusWindow & Interface::StatusWindow::Get(void) -{ - static Interface::StatusWindow wstatus; - return wstatus; -} - -void Interface::StatusWindow::Reset(void) -{ - state = STATUS_DAY; - oldState = STATUS_UNKNOWN; - lastResource = Resource::UNKNOWN; - countLastResource = 0; - ResetTimer(); -} - -info_t Interface::StatusWindow::GetState(void) const -{ - return state; -} - -u32 Interface::StatusWindow::ResetResourceStatus(u32 tick, void *ptr) -{ - if(ptr) - { - Interface::StatusWindow* status = reinterpret_cast(ptr); - if(STATUS_RESOURCE == status->state) - { - status->state = status->oldState; - Interface::Basic::Get().Redraw(REDRAW_STATUS); - } - else - SDL::Timer::Remove(status->timerShowLastResource); - } - - return tick; -} - -void Interface::StatusWindow::SetPos(s16 ox, s16 oy) -{ - if(Settings::Get().HideInterface()) - { - FixOutOfDisplay(*this, ox, oy); - - Rect::x = ox + BORDERWIDTH; - Rect::y = oy + BORDERWIDTH; - - border.SetPosition(ox, oy, Rect::w, Rect::h); - Settings::Get().SetPosStatus(*this); - } - else - { - Rect::x = ox; - Rect::y = oy; - Rect::h = Display::Get().h() - oy - BORDERWIDTH; - } -} - -const Rect & Interface::StatusWindow::GetArea(void) const -{ - return Settings::Get().HideInterface() && border.isValid() ? border.GetRect() : *this; -} - -void Interface::StatusWindow::SetState(info_t info) -{ - if(STATUS_RESOURCE != state) state = info; -} - -void Interface::StatusWindow::Redraw(void) -{ - const Settings & conf = Settings::Get(); - if(conf.HideInterface() && !conf.ShowStatus()) return; - - // restore background - DrawBackground(); - - // draw info: Day and Funds and Army - const Sprite & ston = AGG::GetICN(Settings::Get().EvilInterface() ? ICN::STONBAKE : ICN::STONBACK, 0); - if(STATUS_UNKNOWN != state && h >= (ston.h() * 3 + 15)) - { - DrawDayInfo(); - DrawKingdomInfo(ston.h() + 5); - - if(state != STATUS_RESOURCE) - DrawArmyInfo(2 * ston.h() + 10); - else - DrawResourceInfo(2 * ston.h() + 10); - } - else - switch(state) - { - case STATUS_DAY: DrawDayInfo(); break; - case STATUS_FUNDS: DrawKingdomInfo(); break; - case STATUS_ARMY: DrawArmyInfo(); break; - case STATUS_RESOURCE: DrawResourceInfo(); break; - case STATUS_AITURN: DrawAITurns(); break; - default: break; - } - - // redraw border - if(conf.HideInterface()) border.Redraw(); -} - -void Interface::StatusWindow::NextState(void) -{ - if(STATUS_DAY == state) state = STATUS_FUNDS; - else - if(STATUS_FUNDS == state) state = (Game::Focus::UNSEL == Game::Focus::Get().Type() ? STATUS_DAY : STATUS_ARMY); - else - if(STATUS_ARMY == state) state = STATUS_DAY; - else - if(STATUS_RESOURCE == state) state = STATUS_ARMY; - - if(state == STATUS_ARMY) - { - const Game::Focus & focus = Game::Focus::Get(); - // skip empty army for castle - if(Game::Focus::CASTLE == focus.Type() && !focus.GetCastle().GetArmy().isValid()) NextState(); - } -} - -void Interface::StatusWindow::DrawKingdomInfo(const u8 oh) const -{ - std::string str; - - Kingdom & myKingdom = world.GetMyKingdom(); - Display & display = Display::Get(); - - // sprite all resource - display.Blit(AGG::GetICN(ICN::RESSMALL, 0), x + 6, y + 3 + oh); - - // count castle - String::AddInt(str, myKingdom.GetCountCastle()); - Text text(str, Font::SMALL); - text.Blit(x + 26 - text.w() / 2, y + 28 + oh); - // count town - str.clear(); - String::AddInt(str, myKingdom.GetCountTown()); - text.Set(str); - text.Blit(x + 78 - text.w() / 2, y + 28 + oh); - // count gold - str.clear(); - String::AddInt(str, myKingdom.GetFundsGold()); - text.Set(str); - text.Blit(x + 122 - text.w() / 2, y + 28 + oh); - // count wood - str.clear(); - String::AddInt(str, myKingdom.GetFundsWood()); - text.Set(str); - text.Blit(x + 15 - text.w() / 2, y + 58 + oh); - // count mercury - str.clear(); - String::AddInt(str, myKingdom.GetFundsMercury()); - text.Set(str); - text.Blit(x + 37 - text.w() / 2, y + 58 + oh); - // count ore - str.clear(); - String::AddInt(str, myKingdom.GetFundsOre()); - text.Set(str); - text.Blit(x + 60 - text.w() / 2, y + 58 + oh); - // count sulfur - str.clear(); - String::AddInt(str, myKingdom.GetFundsSulfur()); - text.Set(str); - text.Blit(x + 84 - text.w() / 2, y + 58 + oh); - // count crystal - str.clear(); - String::AddInt(str, myKingdom.GetFundsCrystal()); - text.Set(str); - text.Blit(x + 108 - text.w() / 2, y + 58 + oh); - // count gems - str.clear(); - String::AddInt(str, myKingdom.GetFundsGems()); - text.Set(str); - text.Blit(x + 130 - text.w() / 2, y + 58 + oh); -} - -void Interface::StatusWindow::DrawDayInfo(const u8 oh) const -{ - std::string message; - Display & display = Display::Get(); - - display.Blit(AGG::GetICN(Settings::Get().EvilInterface() ? ICN::SUNMOONE : ICN::SUNMOON, (world.GetWeek() - 1) % 5), x, y + 1 + oh); - - message = _("Month: %{month} Week: %{week}"); - String::Replace(message, "%{month}", world.GetMonth()); - String::Replace(message, "%{week}", world.GetWeek()); - Text text(message, Font::SMALL); - text.Blit(x + (w - text.w()) / 2, y + 30 + oh); - - message = _("Day: %{day}"); - String::Replace(message, "%{day}", world.GetDay()); - text.Set(message, Font::BIG); - text.Blit(x + (w - text.w()) / 2, y + 46 + oh); -} - -void Interface::StatusWindow::SetResource(Resource::resource_t res, u16 count) -{ - lastResource = res; - countLastResource = count; - - if(timerShowLastResource.IsValid()) - SDL::Timer::Remove(timerShowLastResource); - else - oldState = state; - - state = STATUS_RESOURCE; - SDL::Timer::Run(timerShowLastResource, RESOURCE_WINDOW_EXPIRE, ResetResourceStatus, this); -} - -void Interface::StatusWindow::ResetTimer(void) -{ - StatusWindow & window = Get(); - if(window.timerShowLastResource.IsValid()) - { - SDL::Timer::Remove(window.timerShowLastResource); - ResetResourceStatus(0, &window); - } -} - -void Interface::StatusWindow::DrawResourceInfo(const u8 oh) const -{ - std::string message = _("You find a small\nquantity of %{resource}."); - String::Replace(message, "%{resource}", Resource::String(lastResource)); - TextBox text(message, Font::SMALL, w); - text.Blit(x, y + 4 + oh); - - Display & display = Display::Get(); - const Sprite &spr = AGG::GetICN(ICN::RESOURCE, Resource::GetIndexSprite2(lastResource)); - display.Blit(spr, x + (w - spr.w()) / 2, y + 6 + oh + text.h()); - - message.clear(); - String::AddInt(message, countLastResource); - text.Set(message, Font::SMALL, w); - text.Blit(x + (w - text.w()) / 2, y + oh + text.h() + spr.h() - 8); -} - -void Interface::StatusWindow::DrawArmyInfo(const u8 oh) const -{ - const Game::Focus & focus = Game::Focus::Get(); - - if(Game::Focus::UNSEL == focus.Type()) return; - - const Army::army_t & armies = (Game::Focus::HEROES == focus.Type() ? focus.GetHeroes().GetArmy() : focus.GetCastle().GetArmy()); - const u8 count = armies.GetCount(); - - if(4 > count) - { - armies.DrawMons32Line(x, y + 20 + oh, 144); - } - else - if(5 > count) - { - armies.DrawMons32Line(x, y + 15 + oh, 110, 0, 2); - armies.DrawMons32Line(x + 20, y + 30 + oh, 120, 2, 2); - } - else - { - armies.DrawMons32Line(x, y + 15 + oh, 140, 0, 3); - armies.DrawMons32Line(x + 10, y + 30 + oh, 120, 3, 2); - } -} - -void Interface::StatusWindow::DrawAITurns(void) const -{ - const Settings & conf = Settings::Get(); - if(conf.HideInterface() && !conf.ShowStatus()) return; - - // restore background - DrawBackground(); - - Display & display = Display::Get(); - const Sprite & glass = AGG::GetICN(ICN::HOURGLAS, 0); - - u16 dst_x = x + (w - glass.w()) / 2; - u16 dst_y = y + (h - glass.h()) / 2; - - display.Blit(glass, dst_x, dst_y); - - u8 color_index = 0; - - switch(conf.CurrentColor()) - { - case Color::BLUE: color_index = 0; break; - case Color::GREEN: color_index = 1; break; - case Color::RED: color_index = 2; break; - case Color::YELLOW: color_index = 3; break; - case Color::ORANGE: color_index = 4; break; - case Color::PURPLE: color_index = 5; break; - default: return; - } - - const Sprite & crest = AGG::GetICN(ICN::BRCREST, color_index); - - dst_x += 2; - dst_y += 2; - - display.Blit(crest, dst_x, dst_y); - - const Sprite & sand = AGG::GetICN(ICN::HOURGLAS, 1 + (turn_progress % 10)); - - dst_x += (glass.w() - sand.w() - sand.x() - 3); - dst_y += sand.y(); - - display.Blit(sand, dst_x, dst_y); - - // animation sand - // - // sprites ICN::HOURGLAS, 11, 30 - // -} - -void Interface::StatusWindow::DrawBackground(void) const -{ - Display & display = Display::Get(); - const Sprite & icnston = AGG::GetICN(Settings::Get().EvilInterface() ? ICN::STONBAKE : ICN::STONBACK, 0); - - if(!Settings::Get().HideInterface() && display.h() - BORDERWIDTH - icnston.h() > y) - { - Rect srcrt; - Point dstpt(x, y); - - srcrt.x = 0; - srcrt.y = 0; - srcrt.w = icnston.w(); - srcrt.h = 12; - display.Blit(icnston, srcrt, dstpt); - - srcrt.y = 12; - srcrt.h = 32; - dstpt.y = dstpt.y + 12; - - for(u8 ii = 0; ii < h / TILEWIDTH; ++ii) - { - display.Blit(icnston, srcrt, dstpt); - dstpt.y = dstpt.y + TILEWIDTH; - } - - dstpt.y = display.h() - BORDERWIDTH - 12; - srcrt.y = icnston.h() - 12; - display.Blit(icnston, srcrt, dstpt); - } - else - display.Blit(icnston, x, y); -} - -void Interface::StatusWindow::QueueEventProcessing(void) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - - if(conf.HideInterface() && conf.ShowStatus() && le.MousePressLeft(border.GetTop())) - { - Surface sf(border.GetRect().w, border.GetRect().h); - Cursor::DrawCursor(sf, 0x70); - const Point & mp = le.GetMouseCursor(); - const s16 ox = mp.x - border.GetRect().x; - const s16 oy = mp.y - border.GetRect().y; - SpriteCursor sp(sf, border.GetRect().x, border.GetRect().y); - cursor.Hide(); - sp.Redraw(); - cursor.Show(); - display.Flip(); - while(le.HandleEvents() && le.MousePressLeft()) - { - if(le.MouseMotion()) - { - cursor.Hide(); - sp.Move(mp.x - ox, mp.y - oy); - cursor.Show(); - display.Flip(); - } - } - cursor.Hide(); - SetPos(mp.x - ox, mp.y - oy); - Interface::Basic::Get().SetRedraw(REDRAW_GAMEAREA); - } - else - if(le.MouseClickLeft(*this)) - { - cursor.Hide(); - NextState(); - Redraw(); - cursor.Show(); - display.Flip(); - } - if(le.MousePressRight(*this)) Dialog::Message(_("Status Window"), _("This window provides information on the status of your hero or kingdom, and shows the date. Left click here to cycle throungh these windows."), Font::BIG); -} - -void Interface::StatusWindow::RedrawTurnProgress(u8 v) -{ - turn_progress = v; - Interface::Basic & I = Interface::Basic::Get(); - I.SetRedraw(REDRAW_STATUS); - - Cursor::Get().Hide(); - I.Redraw(); - Cursor::Get().Show(); - Display::Get().Flip(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/interface_status.h b/project/jni/application/fheroes2/src/fheroes2/gui/interface_status.h deleted file mode 100644 index eb0b9b7c3..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/interface_status.h +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2INTERFACE_STATUS_H -#define H2INTERFACE_STATUS_H - -#include "gamedefs.h" -#include "thread.h" -#include "resource.h" -#include "dialog.h" - -class Surface; -class Castle; -class Heroes; - -enum info_t { STATUS_UNKNOWN, STATUS_DAY, STATUS_FUNDS, STATUS_ARMY, STATUS_RESOURCE, STATUS_AITURN }; - -namespace Interface -{ - class StatusWindow : protected Rect - { - public: - static StatusWindow & Get(void); - - void SetPos(s16, s16); - const Rect & GetArea(void) const; - void Reset(void); - - void Redraw(void); - void NextState(void); - info_t GetState(void) const; - void SetState(info_t info); - void SetResource(Resource::resource_t, u16); - void RedrawTurnProgress(u8); - void QueueEventProcessing(void); - - static void ResetTimer(void); - - private: - StatusWindow(); - - void DrawKingdomInfo(const u8 oh = 0) const; - void DrawDayInfo(const u8 oh = 0) const; - void DrawArmyInfo(const u8 oh = 0) const; - void DrawResourceInfo(const u8 oh = 0) const; - void DrawBackground(void) const; - void DrawAITurns(void) const; - static u32 ResetResourceStatus(u32, void *); - static u32 RedrawAIStatus(u32, void *); - - info_t state; - info_t oldState; - Resource::resource_t lastResource; - u16 countLastResource; - SDL::Timer timerShowLastResource; - SDL::Timer timerRedrawAIStatus; - Dialog::FrameBorder border; - - u8 turn_progress; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/selectarmybar.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/selectarmybar.cpp deleted file mode 100644 index 47b8b6f17..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/selectarmybar.cpp +++ /dev/null @@ -1,564 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "engine.h" -#include "agg.h" -#include "cursor.h" -#include "monster.h" -#include "text.h" -#include "world.h" -#include "payment.h" -#include "kingdom.h" -#include "army.h" -#include "tools.h" -#include "castle.h" -#include "localclient.h" -#include "selectarmybar.h" - -void DialogRedistributeArmy(Army::army_t &, u8, Army::army_t &, u8); - -enum -{ - FLAGS_READONLY = 0x01, - FLAGS_USEMONS32 = 0x02, - FLAGS_SAVELAST = 0x04, - FLAGS_COUNT2SPRITE = 0x08 -}; - -SelectArmyBar::SelectArmyBar() : army(NULL), interval(0), selected(-1), flags(0), background(NULL), castle(NULL) -{ -} - -const Rect & SelectArmyBar::GetArea(void) const -{ - return pos; -} - -bool SelectArmyBar::isValid(void) const -{ - return background && army; -} - -bool SelectArmyBar::isSelected(void) const -{ - return 0 <= selected; -} - -s8 SelectArmyBar::Selected(void) const -{ - return selected; -} - -s8 SelectArmyBar::GetIndexFromCoord(const Point & coord) -{ - if(!background || !army) return -1; - - for(u8 ii = 0; ii < ARMYMAXTROOPS; ++ii) - { - const Rect rt(pos.x + ii * (background->w() + interval), pos.y, background->w(), background->h()); - if(rt & coord) return ii; - } - - return -1; -} - -void SelectArmyBar::SetArmy(Army::army_t & a) -{ - army = &a; -} - -void SelectArmyBar::SetPos(const Point & pt) -{ - SetPos(pt.x, pt.y); -} - -void SelectArmyBar::SetPos(s16 cx, s16 cy) - -{ - pos.x = cx; - pos.y = cy; - spritecursor.Save(cx, cy); -} - -void SelectArmyBar::SetBackgroundSprite(const Surface & sf) -{ - background = &sf; - pos.w = ARMYMAXTROOPS * sf.w() + (ARMYMAXTROOPS - 1) * interval; - pos.h = background->h(); - - offset.x = (background->w() - spritecursor.w()) / 2; - offset.y = (background->h() - spritecursor.h()) / 2; -} - -void SelectArmyBar::SetCursorSprite(const Surface & sf) -{ - spritecursor.SetSprite(sf); - - if(background) - { - offset.x = (background->w() - sf.w()) / 2; - offset.y = (background->h() - sf.h()) / 2; - } -} - -void SelectArmyBar::SetInterval(const u8 it) -{ - interval = it; - pos.w = (ARMYMAXTROOPS - 1) * interval; - if(background) pos.w += ARMYMAXTROOPS * background->w(); -} - -void SelectArmyBar::SetSaveLastTroop(void) -{ - flags |= FLAGS_SAVELAST; -} - -void SelectArmyBar::SetReadOnly(void) -{ - flags |= FLAGS_READONLY; -} - -void SelectArmyBar::SetUseMons32Sprite(void) -{ - flags |= FLAGS_USEMONS32; -} - -void SelectArmyBar::SetCount2Sprite(void) -{ - flags |= FLAGS_COUNT2SPRITE; -} - -void SelectArmyBar::SetCastle(const Castle & c) -{ - castle = &c; -} - -bool SelectArmyBar::SaveLastTroop(void) const -{ - return (flags & FLAGS_SAVELAST) && army && (1 == army->GetCount()); -} - -bool SelectArmyBar::ReadOnly(void) const -{ - return flags & FLAGS_READONLY; -} - -void SelectArmyBar::Redraw(Surface & display) -{ - if(!background || !army) return; - - spritecursor.Hide(); - Point pt(pos); - - for(u8 ii = 0; ii < army->Size(); ++ii) - { - const Army::Troop & troop = army->At(ii); - if(troop.isValid()) - { - // blit alt background - if(flags & FLAGS_USEMONS32) - display.Blit(*background, pt); - else - switch(troop.GetRace()) - { - case Race::KNGT: display.Blit(AGG::GetICN(ICN::STRIP, 4), pt); break; - case Race::BARB: display.Blit(AGG::GetICN(ICN::STRIP, 5), pt); break; - case Race::SORC: display.Blit(AGG::GetICN(ICN::STRIP, 6), pt); break; - case Race::WRLK: display.Blit(AGG::GetICN(ICN::STRIP, 7), pt); break; - case Race::WZRD: display.Blit(AGG::GetICN(ICN::STRIP, 8), pt); break; - case Race::NECR: display.Blit(AGG::GetICN(ICN::STRIP, 9), pt); break; - default: display.Blit(AGG::GetICN(ICN::STRIP, 10), pt); break; - } - - const Sprite & spmonh = AGG::GetICN(troop.ICNMonh(), 0); - const Sprite & mons32 = AGG::GetICN(ICN::MONS32, Monster::GetSpriteIndex(troop())); - - if(flags & FLAGS_USEMONS32) - { - if(flags & FLAGS_COUNT2SPRITE) - display.Blit(mons32, pt.x + (background->w() - mons32.w()) / 2, pt.y + background->h() - mons32.h() - 1); - else - display.Blit(mons32, pt.x + (background->w() - mons32.w()) / 2, pt.y + background->h() - mons32.h() - 11); - - // draw count - std::string str; - String::AddInt(str, troop.GetCount()); - Text text(str, Font::SMALL); - - if(flags & FLAGS_COUNT2SPRITE) - text.Blit(pt.x + background->w() - text.w() - 3, pt.y + background->h() - text.h() - 2); - else - text.Blit(pt.x + (background->w() - text.w()) / 2, pt.y + background->h() - 11); - } - else - { - display.Blit(spmonh, pt.x + spmonh.x(), pt.y + spmonh.y()); - - // draw count - std::string str; - String::AddInt(str, troop.GetCount()); - Text text(str, Font::SMALL); - text.Blit(pt.x + background->w() - text.w() - 3, pt.y + background->h() - 13); - } - } - else - { - display.Blit(*background, pt); - } - pt.x += background->w() + interval; - } - - if(0 <= selected) spritecursor.Show(pos.x + selected * (background->w() + interval) + offset.x, flags & FLAGS_USEMONS32 ? pos.y : pos.y + offset.y); -} - -void SelectArmyBar::Reset(void) -{ - selected = -1; - if(Cursor::Get().isVisible()) Cursor::Get().Hide(); - spritecursor.Hide(); -} - -void SelectArmyBar::Select(u8 index) -{ - if(army && background && index < ARMYMAXTROOPS) - { - selected = index; - spritecursor.Hide(); - spritecursor.Show(pos.x + index * (background->w() + interval) + offset.x, flags & FLAGS_USEMONS32 ? pos.y : pos.y + offset.y); - } -} - -bool SelectArmyBar::QueueEventProcessing(SelectArmyBar & bar) -{ - LocalEvent & le = LocalEvent::Get(); - - if(! bar.isValid()) return false; - - const s8 index1 = bar.GetIndexFromCoord(le.GetMouseCursor()); - if(0 > index1 || ARMYMAXTROOPS <= index1) return false; - - bool change = false; - Army::Troop & troop1 = bar.army->At(index1); - Cursor::Get().Hide(); - - const s8 index_p = bar.GetIndexFromCoord(le.GetMousePressLeft()); - - // drag drop - redistribute troops - if(0 <= index_p && ARMYMAXTROOPS > index_p && - bar.army->At(index_p).isValid() && !troop1.isValid()) - { - while(le.HandleEvents() && le.MousePressLeft()){ Cursor::Get().Show(); Display::Get().Flip(); DELAY(1); }; - const s8 index_r = bar.GetIndexFromCoord(le.GetMouseReleaseLeft()); - if(!bar.army->At(index_r).isValid()) - { - DialogRedistributeArmy(*bar.army, index_p, *bar.army, index_r); - bar.Reset(); - bar.Redraw(); - } - le.ResetPressLeft(); - } - else - // left click - if(le.MouseClickLeft(bar.GetArea())) - { - if(bar.isSelected()) - { - const s8 index2 = bar.Selected(); - Army::Troop & troop2 = bar.army->At(index2); - - // dialog - if(index1 == index2) - { - u16 flags = (bar.ReadOnly() || bar.SaveLastTroop() ? Dialog::READONLY | Dialog::BUTTONS : Dialog::BUTTONS); - PaymentConditions::UpgradeMonster payment(troop1()); - payment *= troop1.GetCount(); - - if(troop1.isAllowUpgrade() && - bar.castle && - bar.castle->GetRace() == troop1.GetRace() && - bar.castle->isBuild(Monster::GetDwelling(Monster::Upgrade(troop1))) && - payment <= world.GetMyKingdom().GetFundsResource()) - flags |= Dialog::UPGRADE; - - switch(Dialog::ArmyInfo(troop1, flags)) - { - case Dialog::UPGRADE: - world.GetMyKingdom().OddFundsResource(payment); - troop1.Upgrade(); - change = true; -#ifdef WITH_NET - FH2LocalClient::SendArmyUpgradeTroop(*bar.army, index1); -#endif - break; - - case Dialog::DISMISS: - troop1.Reset(); - change = true; -#ifdef WITH_NET - FH2LocalClient::SendArmyDismissTroop(*bar.army, index1); -#endif - break; - - default: break; - } - } - else - // combine - if(troop1() == troop2()) - { - troop1.SetCount(troop1.GetCount() + troop2.GetCount()); - troop2.Reset(); - change = true; -#ifdef WITH_NET - FH2LocalClient::SendArmyJoinTroops(*bar.army, index1, *bar.army, index2); -#endif - } - // exchange - else - { - Army::SwapTroops(troop1, troop2); - change = true; -#ifdef WITH_NET - FH2LocalClient::SendArmySwapTroops(*bar.army, index1, *bar.army, index2); -#endif - } - - bar.Reset(); - bar.Redraw(); - } - else - // select - if(!bar.ReadOnly() && troop1.isValid()) - { - bar.Select(index1); - change = true; - } - } - else - // press right - if(le.MousePressRight(bar.GetArea())) - { - // show quick info - if(troop1.isValid()) - { - bar.Reset(); - Dialog::ArmyInfo(troop1, 0); - } - else - // empty troops - redistribute troops - if(bar.isSelected()) - { - const s8 index2 = bar.Selected(); - //Army::Troop & troop2 = bar.army->At(index2); - - DialogRedistributeArmy(*bar.army, index2, *bar.army, index1); - - bar.Reset(); - bar.Redraw(); - } - } - - Cursor::Get().Show(); - Display::Get().Flip(); - - return change; -} - -bool SelectArmyBar::QueueEventProcessing(SelectArmyBar & bar1, SelectArmyBar & bar2) -{ - LocalEvent & le = LocalEvent::Get(); - - if(!bar1.isValid() || !bar2.isValid()) return false; - bool change = false; - - if((bar1.isSelected() || (!bar1.isSelected() && !bar2.isSelected())) && le.MouseCursor(bar1.GetArea())) - return QueueEventProcessing(bar1); - else - if((bar2.isSelected() || (!bar1.isSelected() && !bar2.isSelected())) && le.MouseCursor(bar2.GetArea())) - return QueueEventProcessing(bar2); - else - if(bar1.isSelected() && le.MouseCursor(bar2.GetArea())) - { - const s8 index1 = bar2.GetIndexFromCoord(le.GetMouseCursor()); - if(0 > index1 || ARMYMAXTROOPS <= index1) return false; - const s8 index2 = bar1.Selected(); - - Army::Troop & troop1 = bar2.army->At(index1); - Army::Troop & troop2 = bar1.army->At(index2); - - Cursor::Get().Hide(); - - // left click - if(le.MouseClickLeft(bar2.GetArea())) - { - // combine - if(!bar1.SaveLastTroop() && troop1() == troop2()) - { - troop1.SetCount(troop1.GetCount() + troop2.GetCount()); - troop2.Reset(); - change = true; -#ifdef WITH_NET - FH2LocalClient::SendArmyJoinTroops(*bar2.army, index1, *bar1.army, index2); -#endif - } - // exchange - else - if(!bar1.SaveLastTroop() || troop1.isValid()) - { - Army::SwapTroops(troop1, troop2); - change = true; -#ifdef WITH_NET - FH2LocalClient::SendArmySwapTroops(*bar2.army, index1, *bar1.army, index1); -#endif - } - - bar1.Reset(); - bar2.Reset(); - - bar1.Redraw(); - bar2.Redraw(); - } - else - // press right - if(le.MousePressRight(bar2.GetArea())) - { - // show quick info - if(troop1.isValid()) - { - bar1.Reset(); - Dialog::ArmyInfo(troop1, 0); - } - else - // empty troops - redistribute troops - { - DialogRedistributeArmy(*bar1.army, index2, *bar2.army, index1); - - bar1.Reset(); - bar2.Reset(); - - bar1.Redraw(); - bar2.Redraw(); - } - } - - Cursor::Get().Show(); - Display::Get().Flip(); - } - else - if(bar2.isSelected() && le.MouseCursor(bar1.GetArea())) - { - const s8 index1 = bar1.GetIndexFromCoord(le.GetMouseCursor()); - if(0 > index1 || ARMYMAXTROOPS <= index1) return false; - const s8 index2 = bar2.Selected(); - - Army::Troop & troop1 = bar1.army->At(index1); - Army::Troop & troop2 = bar2.army->At(index2); - - Cursor::Get().Hide(); - - // left click - if(le.MouseClickLeft(bar1.GetArea())) - { - // combine - if(!bar2.SaveLastTroop() && troop1() == troop2()) - { - troop1.SetCount(troop1.GetCount() + troop2.GetCount()); - troop2.Reset(); - change = true; -#ifdef WITH_NET - FH2LocalClient::SendArmyJoinTroops(*bar1.army, index1, *bar2.army, index2); -#endif - } - // exchange - else - if(!bar2.SaveLastTroop() || troop1.isValid()) - { - Army::SwapTroops(troop1, troop2); - change = true; -#ifdef WITH_NET - FH2LocalClient::SendArmySwapTroops(*bar1.army, index1, *bar2.army, index2); -#endif - } - - bar1.Reset(); - bar2.Reset(); - - bar1.Redraw(); - bar2.Redraw(); - } - else - // press right - if(le.MousePressRight(bar1.GetArea())) - { - // show quick info - if(troop1.isValid()) - { - bar2.Reset(); - Dialog::ArmyInfo(troop1, 0); - } - else - // empty troops - redistribute troops - { - DialogRedistributeArmy(*bar2.army, index2, *bar1.army, index1); - - bar1.Reset(); - bar2.Reset(); - - bar1.Redraw(); - bar2.Redraw(); - } - } - - Cursor::Get().Show(); - Display::Get().Flip(); - } - - return change; -} - -void DialogRedistributeArmy(Army::army_t & army1, u8 index1, Army::army_t & army2, u8 index2) -{ - Army::Troop & troop1 = army1.At(index1); - Army::Troop & troop2 = army2.At(index2); - const bool last = (1 == troop1.GetArmy()->GetCount()); - - if(2 > troop1.Count()) - { - if(!last || troop2.isValid()) - Army::SwapTroops(troop1, troop2); -#ifdef WITH_NET - FH2LocalClient::SendArmySwapTroops(army1, index1, army2, index2); -#endif - } - else - { - u32 redistr_count = troop1.Count() / 2; - if(Dialog::SelectCount(_("Move how many troops?"), 1, (last ? troop1.Count() - 1 : troop1.Count()), redistr_count)) - { - troop2.Set(troop1, redistr_count); - troop1.SetCount(troop1.Count() - redistr_count); -#ifdef WITH_NET - FH2LocalClient::SendArmySplitTroop(army1, index1, army2, index2, redistr_count); -#endif - } - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/selectarmybar.h b/project/jni/application/fheroes2/src/fheroes2/gui/selectarmybar.h deleted file mode 100644 index 6f56813f5..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/selectarmybar.h +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2SELECTARMYBAR_H -#define H2SELECTARMYBAR_H - -#include "gamedefs.h" -#include "army.h" - -class Rect; -class Surface; -class SpriteCursor; -class LocalEvent; -class Castle; - -class SelectArmyBar -{ -public: - SelectArmyBar(); - - const Rect &GetArea(void) const; - bool isSelected(void) const; - s8 GetIndexFromCoord(const Point &); - s8 Selected(void) const; - - bool ReadOnly(void) const; - bool SaveLastTroop(void) const; - bool isValid(void) const; - - void SetArmy(Army::army_t &); - void SetPos(const Point &); - void SetPos(s16, s16); - void SetBackgroundSprite(const Surface &); - void SetCursorSprite(const Surface &); - void SetInterval(u8); - void SetCastle(const Castle &); - - void SetReadOnly(void); - void SetSaveLastTroop(void); - void SetUseMons32Sprite(void); // second variant: for small sprite ICN::MONS32 - void SetCount2Sprite(void); - - void Redraw(Surface & display = Display::Get()); - void Reset(void); - void Select(u8); - - static bool QueueEventProcessing(SelectArmyBar &); - static bool QueueEventProcessing(SelectArmyBar &, SelectArmyBar &); - -private: - Army::army_t * army; - Rect pos; - u8 interval; - s8 selected; - u8 flags; - Point offset; - - const Surface * background; - SpriteCursor spritecursor; - - const Castle * castle; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/selectartifactbar.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/selectartifactbar.cpp deleted file mode 100644 index dc5621985..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/selectartifactbar.cpp +++ /dev/null @@ -1,419 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "engine.h" -#include "agg.h" -#include "cursor.h" -#include "text.h" -#include "world.h" -#include "payment.h" -#include "kingdom.h" -#include "tools.h" -#include "heroes.h" -#include "artifact.h" -#include "selectartifactbar.h" -#include "localclient.h" - -#define MAXARTIFACTLINE 7 - -enum -{ - FLAGS_READONLY = 0x01, - FLAGS_USEART32 = 0x02 -}; - -SelectArtifactsBar::SelectArtifactsBar(Heroes &h) : hero(h), interval(0), selected(-1), flags(0), background(NULL) -{ -} - -const Rect & SelectArtifactsBar::GetArea(void) const -{ - return pos; -} - -bool SelectArtifactsBar::isValid(void) const -{ - return background; -} - -bool SelectArtifactsBar::isSelected(void) const -{ - return 0 <= selected; -} - -s8 SelectArtifactsBar::Selected(void) const -{ - return selected; -} - -s8 SelectArtifactsBar::GetIndexFromCoord(const Point & coord) -{ - if(!background) return -1; - - if(coord.y < pos.y + background->h()) - for(u8 ii = 0; ii < MAXARTIFACTLINE; ++ii) - { - const Rect rt(pos.x + ii * (background->w() + interval), pos.y, background->w(), background->h()); - if(rt & coord) return ii; - } - else - if(coord.y > pos.y + background->h() + interval) - for(u8 ii = 0; ii < MAXARTIFACTLINE; ++ii) - { - const Rect rt(pos.x + ii * (background->w() + interval), pos.y + background->h() + interval, background->w(), background->h()); - if(rt & coord) return ii + MAXARTIFACTLINE; - } - - return -1; -} - -void SelectArtifactsBar::SetPos(const Point & pt) -{ - SetPos(pt.x, pt.y); -} - -void SelectArtifactsBar::SetPos(s16 cx, s16 cy) - -{ - pos.x = cx; - pos.y = cy; - spritecursor.Save(cx, cy); -} - -void SelectArtifactsBar::SetBackgroundSprite(const Surface & sf) -{ - background = &sf; - pos.w = MAXARTIFACTLINE * sf.w() + (MAXARTIFACTLINE - 1) * interval; - pos.h = 2 * background->h() + interval; - - offset.x = (background->w() - spritecursor.w()) / 2; - offset.y = (background->h() - spritecursor.h()) / 2; -} - -void SelectArtifactsBar::SetCursorSprite(const Surface & sf) -{ - spritecursor.SetSprite(sf); - - if(background) - { - offset.x = (background->w() - sf.w()) / 2; - offset.y = (background->h() - sf.h()) / 2; - } -} - -void SelectArtifactsBar::SetInterval(const u8 it) -{ - interval = it; - pos.w = (MAXARTIFACTLINE - 1) * interval; - if(background) - { - pos.w += MAXARTIFACTLINE * background->w(); - pos.h += interval; - } -} - -void SelectArtifactsBar::SetReadOnly(void) -{ - flags |= FLAGS_READONLY; -} - -void SelectArtifactsBar::SetUseArts32Sprite(void) -{ - flags |= FLAGS_USEART32; -} - -bool SelectArtifactsBar::ReadOnly(void) const -{ - return flags & FLAGS_READONLY; -} - -void SelectArtifactsBar::Redraw(Surface & display) -{ - if(!background) return; - - spritecursor.Hide(); - Point pt(pos); - BagArtifacts & arts = hero.GetBagArtifacts(); - - for(u8 ii = 0; ii < MAXARTIFACTLINE; ++ii) - { - const Artifact & art = arts[ii]; - - display.Blit(*background, pt); - if(art != Artifact::UNKNOWN) - { - if(flags & FLAGS_USEART32) - display.Blit(AGG::GetICN(ICN::ARTFX, art.GetIndexSprite32()), pt.x + 1, pt.y + 1); - else - display.Blit(AGG::GetICN(ICN::ARTIFACT, art.GetIndexSprite64()), pt); - } - pt.x += background->w() + interval; - } - - pt.x = pos.x; - pt.y += background->h() + interval; - - for(u8 ii = 0; ii < MAXARTIFACTLINE; ++ii) - { - const Artifact & art = arts[ii + MAXARTIFACTLINE]; - - display.Blit(*background, pt); - if(art != Artifact::UNKNOWN) - { - if(flags & FLAGS_USEART32) - display.Blit(AGG::GetICN(ICN::ARTFX, art.GetIndexSprite32()), pt.x + 1, pt.y + 1); - else - display.Blit(AGG::GetICN(ICN::ARTIFACT, art.GetIndexSprite64()), pt); - } - - pt.x += background->w() + interval; - } - - if(0 <= selected) - { - MAXARTIFACTLINE > selected ? - spritecursor.Show(pos.x + selected * (background->w() + interval) + offset.x, flags & FLAGS_USEART32 ? pos.y : pos.y + offset.y) : - spritecursor.Show(pos.x + (selected - MAXARTIFACTLINE) * (background->w() + interval) + offset.x, flags & FLAGS_USEART32 ? pos.y + background->h() + interval : pos.y + background->h() + interval + offset.y); - } -} - -void SelectArtifactsBar::Reset(void) -{ - selected = -1; - if(Cursor::Get().isVisible()) Cursor::Get().Hide(); - spritecursor.Hide(); -} - -void SelectArtifactsBar::Select(u8 index) -{ - if(background && index < MAXARTIFACTLINE * 2) - { - selected = index; - spritecursor.Hide(); - MAXARTIFACTLINE > index ? - spritecursor.Show(pos.x + selected * (background->w() + interval) + offset.x, flags & FLAGS_USEART32 ? pos.y : pos.y + offset.y) : - spritecursor.Show(pos.x + (selected - MAXARTIFACTLINE) * (background->w() + interval) + offset.x, flags & FLAGS_USEART32 ? pos.y + background->h() + interval : pos.y + background->h() + interval + offset.y); - } -} - -bool SelectArtifactsBar::QueueEventProcessing(SelectArtifactsBar & bar) -{ - LocalEvent & le = LocalEvent::Get(); - - if(! bar.isValid()) return false; - - const s8 index1 = bar.GetIndexFromCoord(le.GetMouseCursor()); - if(0 > index1 || HEROESMAXARTIFACT <= index1) return false; - BagArtifacts & arts = bar.hero.GetBagArtifacts(); - - Artifact & art1 = arts[index1]; - bool change = false; - Cursor::Get().Hide(); - - // left click - if(le.MouseClickLeft(bar.GetArea())) - { - if(bar.isSelected()) - { - const s8 index2 = bar.Selected(); - Artifact & art2 = arts[index2]; - - // dialog - if(index1 == index2) - { - if(art1 == Artifact::MAGIC_BOOK) - bar.hero.OpenSpellBook(SpellBook::ALL, false); - else - if(art1 == Artifact::SPELL_SCROLL) - { - std::string msg = art1.GetDescription(); - String::Replace(msg, "%{spell}", Spell::GetName(Spell::FromInt(art1.GetExt()))); - Dialog::Message(art1.GetName(), msg, Font::BIG, Dialog::OK); - } - else - Dialog::Message(art1.GetName(), art1.GetDescription(), Font::BIG, Dialog::OK); - } - // exchange - else - { - std::swap(art1, art2); - change = true; -#ifdef WITH_NET - FH2LocalClient::SendHeroesSwapArtifacts(bar.hero, index1, bar.hero, index2); -#endif - } - - bar.Reset(); - bar.Redraw(); - } - else - // select - if(!bar.ReadOnly() && art1 != Artifact::UNKNOWN) - { - bar.Select(index1); - change = true; - } - } - else - // press right - if(le.MousePressRight(bar.GetArea())) - { - bar.Reset(); - // show quick info - if(art1 != Artifact::UNKNOWN) - { - if(art1 == Artifact::SPELL_SCROLL) - { - std::string msg = art1.GetDescription(); - String::Replace(msg, "%{spell}", Spell::GetName(Spell::FromInt(art1.GetExt()))); - Dialog::Message(art1.GetName(), msg, Font::BIG); - } - else - Dialog::Message(art1.GetName(), art1.GetDescription(), Font::BIG); - } - } - - Cursor::Get().Show(); - Display::Get().Flip(); - - return change; -} - -bool SelectArtifactsBar::QueueEventProcessing(SelectArtifactsBar & bar1, SelectArtifactsBar & bar2) -{ - LocalEvent & le = LocalEvent::Get(); - bool change = false; - - if(!bar1.isValid() || !bar2.isValid()) return false; - - if((bar1.isSelected() || (!bar1.isSelected() && !bar2.isSelected())) && le.MouseCursor(bar1.GetArea())) - return QueueEventProcessing(bar1); - else - if((bar2.isSelected() || (!bar1.isSelected() && !bar2.isSelected())) && le.MouseCursor(bar2.GetArea())) - return QueueEventProcessing(bar2); - else - if(bar1.isSelected() && le.MouseCursor(bar2.GetArea())) - { - const s8 index1 = bar2.GetIndexFromCoord(le.GetMouseCursor()); - if(0 > index1 || HEROESMAXARTIFACT <= index1) return false; - const s8 index2 = bar1.Selected(); - - BagArtifacts & arts1 = bar1.hero.GetBagArtifacts(); - BagArtifacts & arts2 = bar2.hero.GetBagArtifacts(); - - Artifact & art1 = arts1[index2]; - Artifact & art2 = arts2[index1]; - - Cursor::Get().Hide(); - - // left click - if(le.MouseClickLeft(bar2.GetArea())) - { - if(art1 != Artifact::MAGIC_BOOK && art2 != Artifact::MAGIC_BOOK) - { - std::swap(art1, art2); - change = true; - -#ifdef WITH_NET - FH2LocalClient::SendHeroesSwapArtifacts(bar1.hero, index2, bar2.hero, index1); -#endif - - bar1.Reset(); - bar2.Reset(); - - bar1.Redraw(); - bar2.Redraw(); - } - } - else - // press right - if(le.MousePressRight(bar2.GetArea())) - { - bar1.Reset(); - if(art2 == Artifact::SPELL_SCROLL) - { - std::string msg = art2.GetDescription(); - String::Replace(msg, "%{spell}", Spell::GetName(Spell::FromInt(art2.GetExt()))); - Dialog::Message(art2.GetName(), msg, Font::BIG); - } - else - Dialog::Message(art2.GetName(), art2.GetDescription(), Font::BIG); - } - - Cursor::Get().Show(); - Display::Get().Flip(); - } - else - if(bar2.isSelected() && le.MouseCursor(bar1.GetArea())) - { - const s8 index1 = bar1.GetIndexFromCoord(le.GetMouseCursor()); - if(0 > index1 || HEROESMAXARTIFACT <= index1) return false; - const s8 index2 = bar2.Selected(); - - BagArtifacts & arts1 = bar1.hero.GetBagArtifacts(); - BagArtifacts & arts2 = bar2.hero.GetBagArtifacts(); - - Artifact & art1 = arts1[index1]; - Artifact & art2 = arts2[index2]; - - Cursor::Get().Hide(); - - // left click - if(le.MouseClickLeft(bar1.GetArea())) - { - if(art1 != Artifact::MAGIC_BOOK && art2 != Artifact::MAGIC_BOOK) - { - std::swap(art1, art2); - change = true; - -#ifdef WITH_NET - FH2LocalClient::SendHeroesSwapArtifacts(bar1.hero, index1, bar2.hero, index2); -#endif - - bar1.Reset(); - bar2.Reset(); - - bar1.Redraw(); - bar2.Redraw(); - } - } - else - // press right - if(le.MousePressRight(bar1.GetArea())) - { - bar2.Reset(); - if(art1 == Artifact::SPELL_SCROLL) - { - std::string msg = art1.GetDescription(); - String::Replace(msg, "%{spell}", Spell::GetName(Spell::FromInt(art1.GetExt()))); - Dialog::Message(art1.GetName(), msg, Font::BIG); - } - else - Dialog::Message(art1.GetName(), art1.GetDescription(), Font::BIG); - } - - Cursor::Get().Show(); - Display::Get().Flip(); - } - - return change; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/selectartifactbar.h b/project/jni/application/fheroes2/src/fheroes2/gui/selectartifactbar.h deleted file mode 100644 index 0cb614fb6..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/selectartifactbar.h +++ /dev/null @@ -1,75 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2SELECTARTIFACTBAR_H -#define H2SELECTARTIFACTBAR_H - -#include "gamedefs.h" - -class Rect; -class Surface; -class Heroes; -class SpriteCursor; -class LocalEvent; - -class SelectArtifactsBar -{ -public: - SelectArtifactsBar(Heroes &); - - const Rect &GetArea(void) const; - bool isSelected(void) const; - s8 GetIndexFromCoord(const Point &); - s8 Selected(void) const; - - bool ReadOnly(void) const; - bool isValid(void) const; - - void SetPos(const Point &); - void SetPos(s16, s16); - void SetBackgroundSprite(const Surface &); - void SetCursorSprite(const Surface &); - void SetInterval(u8); - - void SetReadOnly(void); - void SetUseArts32Sprite(void); - - void Redraw(Surface & display = Display::Get()); - void Reset(void); - void Select(u8); - - static bool QueueEventProcessing(SelectArtifactsBar &); - static bool QueueEventProcessing(SelectArtifactsBar &, SelectArtifactsBar &); - -private: - Heroes & hero; - Rect pos; - u8 interval; - s8 selected; - u8 flags; - Point offset; - - const Surface * background; - SpriteCursor spritecursor; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/sizecursor.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/sizecursor.cpp deleted file mode 100644 index 20154a16a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/sizecursor.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "maps.h" -#include "cursor.h" -#include "sizecursor.h" - -SizeCursor::SizeCursor(u8 sw, u8 sh) : SpriteCursor(), cursor() -{ - ModifyCursor(sw, sh); -} - -u8 SizeCursor::w(void) -{ - return cursor.w() / TILEWIDTH; -} - -u8 SizeCursor::h(void) -{ - return cursor.h() / TILEWIDTH; -} - -void SizeCursor::ModifySize(const Size & sz) -{ - ModifySize(sz.w, sz.h); -} - -void SizeCursor::ModifySize(const u8 w, const u8 h) -{ - ModifyCursor(w, h); -} - -void SizeCursor::ModifyCursor(const u8 w, const u8 h) -{ - if(cursor.w() == w && cursor.h() == h) return; - - cursor = Surface(w * TILEWIDTH, h * TILEWIDTH); - - cursor.SetColorKey(); - - Cursor::DrawCursor(cursor, 0x40); - - SetSprite(cursor); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/sizecursor.h b/project/jni/application/fheroes2/src/fheroes2/gui/sizecursor.h deleted file mode 100644 index d480bb2a8..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/sizecursor.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2SIZECURSOR_H -#define H2SIZECURSOR_H - -#include "gamedefs.h" - -class Surface; -class Size; - -class SizeCursor : public SpriteCursor -{ -public: - SizeCursor(u8 sw = 1, u8 sh = 1); - - void ModifySize(const u8 w, const u8 h); - void ModifySize(const Size & sz); - - u8 w(void); - u8 h(void); - -private: - void ModifyCursor(const u8 w, const u8 h); - - Surface cursor; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/splitter.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/splitter.cpp deleted file mode 100644 index 6cfc45250..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/splitter.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "cursor.h" -#include "settings.h" -#include "splitter.h" - -/* splitter constructor */ -Splitter::Splitter() -{ -} - -Splitter::Splitter(const Surface &sf, const Rect &rt, positions_t pos) - : SpriteCursor(sf, rt.x, rt.y), area(rt), step(0), min(0), max(0), cur(0), position(pos) -{ - SpriteCursor::Hide(); - SpriteCursor::Move(rt.x, rt.y); - SpriteCursor::Show(); -} - -void Splitter::SetArea(s16 rx, s16 ry, u16 rw, u16 rh) -{ - area.x = rx; - area.y = ry; - area.w = rw; - area.h = rh; -} - -void Splitter::SetArea(const Rect & rt) -{ - area = rt; - SpriteCursor::Move(rt.x, rt.y); -} - -void Splitter::SetOrientation(positions_t ps) -{ - position = ps; -} - -/* set range */ -void Splitter::SetRange(u16 smin, u16 smax) -{ - min = smin; - max = smax; - - // recalculate step - if(max) step = (Splitter::VERTICAL == position ? 100 * (area.h - h()) / (max - min) : 100 * (area.w - w()) / (max - min)); - - Splitter::Move(min); -} - -/* move splitter to pos */ -void Splitter::Move(u16 pos) -{ - if(pos && cur == pos) return; - - if(pos > max || pos < min){ DEBUG(DBG_ENGINE , DBG_WARN, "Splitter::Move: out of range. min: " << min << ", max: " << max << ", cur: " << cur << ", step: " << step); return; } - - Point pt(GetRect().x, GetRect().y); - - cur = pos; - - if(Splitter::VERTICAL == position) - pt.y = area.y + cur * step / 100; - else - pt.x = area.x + cur * step / 100; - - // move center - if(!max) Splitter::VERTICAL == position ? pt.y = area.y + (area.h - h()) / 2 : pt.x = area.x + (area.w - w()); - - if(Cursor::Get().isVisible()) Cursor::Get().Hide(); - SpriteCursor::Hide(); - SpriteCursor::Move(pt); - SpriteCursor::Show(); -} - -/* forward spliter */ -void Splitter::Forward(void) -{ - if(cur == max) return; - - Point pt(GetRect().x, GetRect().y); - - ++cur; - - if(Splitter::VERTICAL == position) - pt.y = area.y + cur * step / 100; - else - pt.x = area.x + cur * step / 100; - - SpriteCursor::Hide(); - SpriteCursor::Move(pt); - SpriteCursor::Show(); -} - -/* backward spliter */ -void Splitter::Backward(void) -{ - if(! cur) return; - - Point pt(GetRect().x, GetRect().y); - - --cur; - - if(Splitter::VERTICAL == position) - pt.y = area.y + cur * step / 100; - else - pt.x = area.x + cur * step / 100; - - SpriteCursor::Hide(); - SpriteCursor::Move(pt); - SpriteCursor::Show(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/splitter.h b/project/jni/application/fheroes2/src/fheroes2/gui/splitter.h deleted file mode 100644 index 1ec9829b2..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/splitter.h +++ /dev/null @@ -1,60 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2SPLITTER_H -#define H2SPLITTER_H - -#include "gamedefs.h" - -class Splitter : public SpriteCursor -{ -public: - enum positions_t { HORIZONTAL, VERTICAL }; - - Splitter(); - Splitter(const Surface &sf, const Rect &rt, positions_t pos); - - void Forward(void); - void Backward(void); - void Move(u16 pos); - - void SetArea(s16, s16, u16, u16); - void SetArea(const Rect & rt); - void SetOrientation(positions_t ps); - void SetRange(u16 smin, u16 smax); - - u16 GetCurrent(void) const{ return cur; }; - u16 GetStep(void) const{ return step; }; - u16 Max(void) const{ return max; }; - u16 Min(void) const{ return min; }; - const Rect & GetRect(void) const{ return area; }; - const Rect & GetCursor(void) const{ return SpriteCursor::GetRect(); }; - -private: - Rect area; - u16 step; - u16 min; - u16 max; - u16 cur; - positions_t position; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/statusbar.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/statusbar.cpp deleted file mode 100644 index d0f76893e..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/statusbar.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "cursor.h" -#include "display.h" -#include "statusbar.h" - -StatusBar::StatusBar() -{ -} - -void StatusBar::SetCenter(const Point & pt) -{ - center = pt; -} - -void StatusBar::SetCenter(s16 cx, s16 cy) -{ - center.x = cx; - center.y = cy; -} - -void StatusBar::ShowMessage(const std::string & msg) -{ - if(msg != prev) - { - Cursor::Get().Hide(); - SetText(msg); - SetPos(center.x - w() / 2, center.y - h() / 2); - Show(); - Cursor::Get().Show(); - Display::Get().Flip(); - prev = msg; - } -} - -void StatusBar::Redraw(void) -{ - Hide(); - Show(); -} - -const std::string & StatusBar::GetMessage(void) const -{ - return prev; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/statusbar.h b/project/jni/application/fheroes2/src/fheroes2/gui/statusbar.h deleted file mode 100644 index 560efab44..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/statusbar.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2STATUSBAR_H -#define H2STATUSBAR_H - -#include "text.h" - -class StatusBar : public TextSprite -{ -public: - StatusBar(); - - void SetCenter(const Point & pt); - void SetCenter(s16 cx, s16 cy); - - void ShowMessage(const std::string & msg); - void Redraw(void); - - const std::string & GetMessage(void) const; - -private: - Point center; - std::string prev; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/text.cpp b/project/jni/application/fheroes2/src/fheroes2/gui/text.cpp deleted file mode 100644 index 16c8a841b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/text.cpp +++ /dev/null @@ -1,796 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "settings.h" -#include "text.h" - -TextInterface::TextInterface(Font::type_t ft) : font(ft) -{ - const Settings & conf = Settings::Get(); - if(conf.QVGA() && !conf.Unicode()) ft == Font::YELLOW_BIG || ft == Font::YELLOW_SMALL ? font = Font::YELLOW_SMALL : font = Font::SMALL; -} - -TextAscii::TextAscii(const std::string & msg, Font::type_t ft) : TextInterface(ft), message(msg) -{ -} - -void TextAscii::SetText(const std::string & msg) -{ - message = msg; -} - -void TextAscii::SetFont(const Font::type_t & ft) -{ - const Settings & conf = Settings::Get(); - if(conf.QVGA() && !conf.Unicode()) ft == Font::YELLOW_BIG || ft == Font::YELLOW_SMALL ? font = Font::YELLOW_SMALL : font = Font::SMALL; - else - font = ft; -} - -void TextAscii::Clear(void) -{ - message.clear(); -} - -size_t TextAscii::Size(void) const -{ - return message.size(); -} - -u8 TextAscii::CharWidth(char c, Font::type_t f) -{ - return (c < 0x21 ? (Font::SMALL == f || Font::YELLOW_SMALL == f ? 4 : 6) : AGG::GetLetter(c, f).w()); -} - -u8 TextAscii::CharHeight(Font::type_t f) -{ - return CharAscent(f) + CharDescent(f) + 1; -} - -u8 TextAscii::CharAscent(Font::type_t f) -{ - return Font::SMALL == f || Font::YELLOW_SMALL == f ? 8 : 13; -} - -u8 TextAscii::CharDescent(Font::type_t f) -{ - return Font::SMALL == f || Font::YELLOW_SMALL == f ? 2 : 3; -} - -u16 TextAscii::w(u16 s, u16 c) const -{ - if(message.empty()) return 0; - - u16 res = 0; - - if(s > message.size() - 1) s = message.size() - 1; - if(!c || c > message.size()) c = message.size() - s; - - for(u16 ii = s; ii < s + c; ++ii) - res += CharWidth(message[ii], font); - - return res; -} - -u16 TextAscii::w(void) const -{ - return w(0, message.size()); -} - -u16 TextAscii::h(void) const -{ - return h(0); -} - -u16 TextAscii::h(const u16 width) const -{ - if(message.empty()) return 0; - else - if(0 == width || w() <= width) return CharHeight(font); - - u16 res = 0; - u16 www = 0; - - std::string::const_iterator pos1 = message.begin(); - std::string::const_iterator pos2 = message.end(); - std::string::const_iterator space = pos2; - - while(pos1 < pos2) - { - if(std::isspace(*pos1)) space = pos1; - - if(www + CharWidth(*pos1, font) >= width) - { - www = 0; - res += CharHeight(font); - if(pos2 != space) pos1 = space + 1; - space = pos2; - continue; - } - - www += CharWidth(*pos1, font); - ++pos1; - } - - return res; -} - -void TextAscii::Blit(u16 ax, u16 ay, const u16 maxw, Surface & dst) -{ - if(message.empty()) return; - - std::string::const_iterator it = message.begin(); - std::string::const_iterator it_end = message.end(); - s8 oy = 0; - const u16 sx = ax; - - for(; it != it_end; ++it) - { - if(maxw && (ax - sx) >= maxw) break; - - // space or unknown letter - if(*it < 0x21) - { - ax += CharWidth(*it, font); - continue; - } - - const Surface & sprite = AGG::GetLetter(*it, font); - if(!sprite.isValid()) return; - - // valign - switch(*it) - { - case '-': - oy = CharAscent(font) / 2; - break; - - case '_': - oy = CharAscent(font); - break; - - // " - case 0x22: - // ' - case 0x27: - oy = 0; - break; - - case 'y': - case 'g': - case 'p': - case 'q': - case 'j': - oy = CharAscent(font) + CharDescent(font) - sprite.h(); - break; - - default: - oy = CharAscent(font) - sprite.h(); - break; - } - - dst.Blit(sprite, ax, ay + 2 + oy); - ax += sprite.w(); - } -} - -#ifdef WITH_TTF -TextUnicode::TextUnicode(const std::string & msg, Font::type_t ft) : TextInterface(ft), message(2 * msg.size(), 0) -{ - if(msg.size()) - { - String::UTF8_to_UNICODE(&message[0], msg.c_str(), msg.size()); - while(0 == message.back()) message.pop_back(); - } -} - -TextUnicode::TextUnicode(const u16 *pt, size_t sz, Font::type_t ft) : TextInterface(ft), message(pt, pt+sz) -{ -} - -bool TextUnicode::isspace(u16 c) -{ - switch(c) - { - case 0x0009: - case 0x000a: - case 0x000b: - case 0x000c: - case 0x000d: - case 0x0020: return true; - - default: break; - } - - return false; -} - -void TextUnicode::SetText(const std::string & msg) -{ - if(msg.size()) - { - message.resize(2 * msg.size(), 0); - std::fill(message.begin(), message.end(), 0); - String::UTF8_to_UNICODE(&message[0], msg.c_str(), msg.size()); - while(0 == message.back()) message.pop_back(); - } -} - -void TextUnicode::SetFont(const Font::type_t & ft) -{ - const Settings & conf = Settings::Get(); - if(conf.QVGA() && !conf.Unicode()) ft == Font::YELLOW_BIG || ft == Font::YELLOW_SMALL ? font = Font::YELLOW_SMALL : font = Font::SMALL; - else - font = ft; -} - -void TextUnicode::Clear(void) -{ - message.clear(); -} - -size_t TextUnicode::Size(void) const -{ - return message.size(); -} - -u8 TextUnicode::CharWidth(u16 c, Font::type_t f) -{ - return (c < 0x0021 ? (Font::SMALL == f || Font::YELLOW_SMALL == f ? 4 : 6) : AGG::GetUnicodeLetter(c, f).w()); -} - -u8 TextUnicode::CharHeight(Font::type_t f) -{ - return Font::SMALL == f || Font::YELLOW_SMALL ? - AGG::Cache::Get().GetSmallFont().Height() : - AGG::Cache::Get().GetMediumFont().Height(); -} - -u8 TextUnicode::CharAscent(Font::type_t f) -{ - return 0; -} - -u8 TextUnicode::CharDescent(Font::type_t f) -{ - return 0; -} - -u16 TextUnicode::w(u16 s, u16 c) const -{ - if(message.empty()) return 0; - - u16 res = 0; - - if(s > message.size() - 1) s = message.size() - 1; - if(!c || c > message.size()) c = message.size() - s; - - for(u16 ii = s; ii < s + c; ++ii) - res += CharWidth(message[ii], font); - - return res; -} - -u16 TextUnicode::w(void) const -{ - return w(0, message.size()); -} - -u16 TextUnicode::h(void) const -{ - return h(0); -} - -u16 TextUnicode::h(const u16 width) const -{ - if(message.empty()) return 0; - else - if(0 == width || w() <= width) return CharHeight(font); - - u16 res = 0; - u16 www = 0; - - std::vector::const_iterator pos1 = message.begin(); - std::vector::const_iterator pos2 = message.end(); - std::vector::const_iterator space = pos2; - - while(pos1 < pos2) - { - if(isspace(*pos1)) space = pos1; - - if(www + CharWidth(*pos1, font) >= width) - { - www = 0; - res += CharHeight(font); - if(pos2 != space) pos1 = space + 1; - space = pos2; - continue; - } - - www += CharWidth(*pos1, font); - ++pos1; - } - - return res; -} - -void TextUnicode::Blit(u16 ax, u16 ay, const u16 maxw, Surface & dst) -{ - if(message.empty()) return; - - std::vector::const_iterator it = message.begin(); - std::vector::const_iterator it_end = message.end(); - const u16 sx = ax; - - for(; it != it_end; ++it) - { - if(maxw && (ax - sx) >= maxw) break; - - // end string - if(0 == *it) continue; - - // space or unknown letter - if(*it < 0x0021) - { - ax += CharWidth(*it, font); - continue; - } - - const Surface & sprite = AGG::GetUnicodeLetter(*it, font); - if(!sprite.isValid()) return; - - dst.Blit(sprite, ax, ay); - ax += sprite.w(); - } -} - -#endif - - -Text::Text() : message(NULL), gw(0), gh(0) -{ -#ifdef WITH_TTF - if(Settings::Get().Unicode()) - message = static_cast(new TextUnicode()); - else -#endif - message = static_cast(new TextAscii()); -} - -Text::Text(const std::string & msg, Font::type_t ft) : message(NULL), gw(0), gh(0) -{ -#ifdef WITH_TTF - if(Settings::Get().Unicode()) - message = static_cast(new TextUnicode(msg, ft)); - else -#endif - message = static_cast(new TextAscii(msg, ft)); - - gw = message->w(); - gh = message->h(); -} - -#ifdef WITH_TTF -Text::Text(const u16 *pt, size_t sz, Font::type_t ft) : message(NULL), gw(0), gh(0) -{ - if(Settings::Get().Unicode() && pt) - { - message = static_cast(new TextUnicode(pt, sz, ft)); - - gw = message->w(); - gh = message->h(); - } -} -#endif - -Text::~Text() -{ - delete message; -} - -Text::Text(const Text & t) -{ -#ifdef WITH_TTF - if(Settings::Get().Unicode()) - message = static_cast(new TextUnicode(static_cast(*t.message))); - else -#endif - message = static_cast(new TextAscii(static_cast(*t.message))); - - gw = t.gw; - gh = t.gh; -} - -Text & Text::operator= (const Text & t) -{ - delete message; -#ifdef WITH_TTF - if(Settings::Get().Unicode()) - message = static_cast(new TextUnicode(static_cast(*t.message))); - else -#endif - message = static_cast(new TextAscii(static_cast(*t.message))); - - gw = t.gw; - gh = t.gh; - - return *this; -} - -void Text::Set(const std::string & msg, Font::type_t ft) -{ - message->SetText(msg); - message->SetFont(ft); - gw = message->w(); - gh = message->h(); -} - -void Text::Set(const std::string & msg) -{ - message->SetText(msg); - gw = message->w(); - gh = message->h(); -} - -void Text::Set(Font::type_t ft) -{ - message->SetFont(ft); - gw = message->w(); - gh = message->h(); -} - -void Text::Clear(void) -{ - message->Clear(); - gw = 0; - gh = 0; -} - -size_t Text::Size(void) const -{ - return message->Size(); -} - -void Text::Blit(const Point & dst_pt, Surface & dst) const -{ - return message->Blit(dst_pt.x, dst_pt.y, 0, dst); -} - -void Text::Blit(u16 ax, u16 ay, Surface & dst) const -{ - return message->Blit(ax, ay, 0, dst); -} - -void Text::Blit(u16 ax, u16 ay, u16 maxw, Surface & dst) const -{ - return message->Blit(ax, ay, maxw, dst); -} - -u16 Text::width(const std::string &str, Font::type_t ft, u16 start, u16 count) -{ -#ifdef WITH_TTF - if(Settings::Get().Unicode()) - { - TextUnicode text(str, ft); - return text.w(start, count); - } - else -#endif - { - TextAscii text(str, ft); - return text.w(start, count); - } - - return 0; -} - -u16 Text::height(const std::string &str, Font::type_t ft, u16 width) -{ - if(str.empty()) return 0; - -#ifdef WITH_TTF - if(Settings::Get().Unicode()) - { - TextUnicode text(str, ft); - return text.h(width); - } -#endif - else - { - TextAscii text(str, ft); - return text.h(width); - } - - return 0; -} - -TextBox::TextBox() : align(ALIGN_CENTER) -{ -} - -TextBox::TextBox(const std::string & msg, Font::type_t ft, u16 width) : align(ALIGN_CENTER) -{ - Set(msg, ft, width); -} - -TextBox::TextBox(const std::string & msg, Font::type_t ft, const Rect & rt) : align(ALIGN_CENTER) -{ - Set(msg, ft, rt.w); - Blit(rt.x, rt.y); -} - -void TextBox::Set(const std::string & msg, Font::type_t ft, u16 width) -{ - if(messages.size()) messages.clear(); - if(msg.empty()) return; - -#ifdef WITH_TTF - if(Settings::Get().Unicode()) - { - std::vector unicode(2 * msg.size(), 0); - String::UTF8_to_UNICODE(&unicode[0], msg.c_str(), msg.size()); - while(0 == unicode.back()) unicode.pop_back(); - - const u16 sep = '\n'; - std::vector substr; - substr.reserve(msg.size()); - std::vector::iterator pos1 = unicode.begin(); - std::vector::iterator pos2; - while(unicode.end() != (pos2 = std::find(pos1, unicode.end(), sep))) - { - substr.assign(pos1, pos2); - Append(substr, ft, width); - pos1 = pos2 + 1; - } - if(pos1 < unicode.end()) - { - substr.assign(pos1, unicode.end()); - Append(substr, ft, width); - } - } - else -#endif - { - const char sep = '\n'; - std::string substr; - substr.reserve(msg.size()); - std::string::const_iterator pos1 = msg.begin(); - std::string::const_iterator pos2; - while(msg.end() != (pos2 = std::find(pos1, msg.end(), sep))) - { - substr.assign(pos1, pos2); - Append(substr, ft, width); - pos1 = pos2 + 1; - } - if(pos1 < msg.end()) - { - substr.assign(pos1, msg.end()); - Append(substr, ft, width); - } - } -} - -void TextBox::SetAlign(u8 f) -{ - align = f; -} - -void TextBox::Append(const std::string & msg, Font::type_t ft, u16 width) -{ - if(msg.empty()) return; - const Settings & conf = Settings::Get(); - if(conf.QVGA() && !conf.Unicode()) ft == Font::YELLOW_BIG || ft == Font::YELLOW_SMALL ? ft = Font::YELLOW_SMALL : ft = Font::SMALL; - - u16 www = 0; - Rect::w = width; - - std::string::const_iterator pos1 = msg.begin(); - std::string::const_iterator pos2 = pos1; - std::string::const_iterator pos3 = msg.end(); - std::string::const_iterator space = pos2; - - while(pos2 < pos3) - { - if(std::isspace(*pos2)) space = pos2; - u8 char_w = TextAscii::CharWidth(*pos2, ft); - - if(www + char_w >= width) - { - www = 0; - Rect::h += TextAscii::CharHeight(ft); - if(pos3 != space) pos2 = space + 1; - - if(pos3 != space) - messages.push_back(Text(msg.substr(pos1 - msg.begin(), pos2 - pos1 - 1), ft)); - else - messages.push_back(Text(msg.substr(pos1 - msg.begin(), pos2 - pos1), ft)); - - pos1 = pos2; - space = pos3; - continue; - } - - www += char_w; - ++pos2; - } - - if(pos1 != pos2) - { - Rect::h += TextAscii::CharHeight(ft); - messages.push_back(Text(msg.substr(pos1 - msg.begin(), pos2 - pos1), ft)); - } -} - -#ifdef WITH_TTF -void TextBox::Append(const std::vector & msg, Font::type_t ft, u16 width) -{ - if(msg.empty()) return; - const Settings & conf = Settings::Get(); - if(conf.QVGA() && !conf.Unicode()) ft == Font::YELLOW_BIG || ft == Font::YELLOW_SMALL ? ft = Font::YELLOW_SMALL : ft = Font::SMALL; - - u16 www = 0; - Rect::w = width; - - std::vector::const_iterator pos1 = msg.begin(); - std::vector::const_iterator pos2 = pos1; - std::vector::const_iterator pos3 = msg.end(); - std::vector::const_iterator space = pos2; - - while(pos2 < pos3) - { - if(TextUnicode::isspace(*pos2)) space = pos2; - u8 char_w = TextUnicode::CharWidth(*pos2, ft); - - if(www + char_w >= width) - { - www = 0; - Rect::h += TextUnicode::CharHeight(ft); - if(pos3 != space) pos2 = space + 1; - - if(pos3 != space) - messages.push_back(Text(&msg.at(pos1 - msg.begin()), pos2 - pos1 - 1, ft)); - else - messages.push_back(Text(&msg.at(pos1 - msg.begin()), pos2 - pos1, ft)); - - pos1 = pos2; - space = pos3; - continue; - } - - www += char_w; - ++pos2; - } - - if(pos1 != pos2) - { - Rect::h += TextUnicode::CharHeight(ft); - messages.push_back(Text(&msg.at(pos1 - msg.begin()), pos2 - pos1, ft)); - } -} -#endif - -void TextBox::Blit(u16 ax, u16 ay, Surface & sf) -{ - Rect::x = ax; - Rect::y = ay; - - std::list::const_iterator it1 = messages.begin(); - std::list::const_iterator it2 = messages.end(); - - for(; it1 != it2; ++it1) - { - switch(align) - { - case ALIGN_LEFT: - (*it1).Blit(ax, ay); - break; - - case ALIGN_RIGHT: - (*it1).Blit(ax + Rect::w - (*it1).w(), ay); - break; - - // center - default: - (*it1).Blit(ax + (Rect::w - (*it1).w()) / 2, ay); - break; - } - - ay += (*it1).h(); - } -} - -void TextBox::Blit(const Point & pt, Surface & sf) -{ - Blit(pt.x, pt.y, sf); -} - -TextSprite::TextSprite() : hide(true) -{ -} - -TextSprite::TextSprite(const std::string & msg, Font::type_t ft, const Point & pt) : Text(msg, ft), hide(true) -{ - back.Save(Rect(pt, gw, gh + 5)); -} - -TextSprite::TextSprite(const std::string & msg, Font::type_t ft, u16 ax, u16 ay) : Text(msg, ft), hide(true) -{ - back.Save(Rect(ax, ay, gw, gh + 5)); -} - -void TextSprite::Show(void) -{ - Blit(back.GetRect().x, back.GetRect().y); - hide = false; -} - -void TextSprite::Hide(void) -{ - if(!hide) back.Restore(); - hide = true; -} - -void TextSprite::SetText(const std::string & msg) -{ - Hide(); - Set(msg); - back.Save(back.GetPos().x, back.GetPos().y, gw, gh + 5); -} - -void TextSprite::SetFont(Font::type_t ft) -{ - Hide(); - Set(ft); - back.Save(back.GetPos().x, back.GetPos().y, gw, gh + 5); -} - -void TextSprite::SetPos(u16 ax, u16 ay) -{ - back.Save(ax, ay, gw, gh + 5); -} - -u16 TextSprite::w(void) -{ - return back.GetSize().w; -} - -u16 TextSprite::h(void) -{ - return back.GetSize().h; -} - -bool TextSprite::isHide(void) const -{ - return hide; -} - -bool TextSprite::isShow(void) const -{ - return !hide; -} - -const Rect & TextSprite::GetRect(void) const -{ - return back.GetRect(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/gui/text.h b/project/jni/application/fheroes2/src/fheroes2/gui/text.h deleted file mode 100644 index 7eb813299..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/gui/text.h +++ /dev/null @@ -1,207 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2TEXT_H -#define H2TEXT_H - -#include -#include -#include "gamedefs.h" - -namespace Font -{ - enum type_t { SMALL = 0x01, BIG = 0x02, YELLOW_BIG = 0x04, YELLOW_SMALL = 0x08 }; -} - -enum { ALIGN_NONE, ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT }; - -class TextInterface -{ -public: - TextInterface(Font::type_t ft = Font::BIG); - virtual ~TextInterface(){}; - - virtual void SetText(const std::string &) = 0; - virtual void SetFont(const Font::type_t &) = 0; - virtual void Clear(void) = 0; - - virtual u16 w(void) const = 0; - virtual u16 h(void) const = 0; - virtual size_t Size(void) const = 0; - - virtual void Blit(u16 ax, u16 ay, const u16 maxw, Surface & sf = Display::Get()) = 0; - - Font::type_t font; -}; - - -class TextAscii : public TextInterface -{ -public: - TextAscii() {}; - TextAscii(const std::string &, Font::type_t = Font::BIG); - - void SetText(const std::string &); - void SetFont(const Font::type_t &); - void Clear(void); - - u16 w(void) const; - u16 w(u16, u16) const; - u16 h(void) const; - u16 h(const u16) const; - size_t Size(void) const; - - void Blit(u16 ax, u16 ay, const u16 maxw, Surface & sf = Display::Get()); - static u8 CharWidth(char, Font::type_t); - static u8 CharHeight(Font::type_t); - static u8 CharAscent(Font::type_t); - static u8 CharDescent(Font::type_t); - -private: - std::string message; -}; - -#ifdef WITH_TTF -class TextUnicode : public TextInterface -{ -public: - TextUnicode() {}; - TextUnicode(const std::string & msg, Font::type_t ft = Font::BIG); - TextUnicode(const u16 *, size_t, Font::type_t ft = Font::BIG); - - void SetText(const std::string &); - void SetFont(const Font::type_t &); - void Clear(void); - - u16 w(void) const; - u16 w(u16, u16) const; - u16 h(void) const; - u16 h(const u16) const; - size_t Size(void) const; - - void Blit(u16 ax, u16 ay, u16 maxw, Surface & sf = Display::Get()); - - static bool isspace(u16); - static u8 CharWidth(u16, Font::type_t); - static u8 CharHeight(Font::type_t); - static u8 CharAscent(Font::type_t); - static u8 CharDescent(Font::type_t); - -private: - std::vector message; -}; -#endif - -class Text -{ -public: - Text(); - Text(const std::string &, Font::type_t ft = Font::BIG); -#ifdef WITH_TTF - Text(const u16 *, size_t, Font::type_t ft = Font::BIG); -#endif - Text(const Text &); - ~Text(); - - Text & operator= (const Text &); - - void Set(const std::string &, Font::type_t); - void Set(const std::string &); - void Set(Font::type_t); - - void Clear(void); - size_t Size(void) const; - - u16 w(void) const{ return gw; } - u16 h(void) const{ return gh; } - - void Blit(u16 ax, u16 ay, Surface & sf = Display::Get()) const; - void Blit(u16 ax, u16 ay, u16 maxw, Surface & sf = Display::Get()) const; - void Blit(const Point & dst_pt, Surface & sf = Display::Get()) const; - - static u16 width(const std::string &str, Font::type_t ft, u16 start = 0, u16 count = 0); - static u16 height(const std::string &str, Font::type_t ft, u16 width = 0); - -protected: - TextInterface *message; - u16 gw; - u16 gh; -}; - -class TextSprite : protected Text -{ -public: - TextSprite(); - TextSprite(const std::string & msg, Font::type_t ft, const Point & pt); - TextSprite(const std::string & msg, Font::type_t ft, u16 ax, u16 ay); - - void SetPos(const Point & pt){ SetPos(pt.x, pt.y); } - void SetPos(u16 ax, u16 ay); - void SetText(const std::string & msg); - void SetFont(Font::type_t ft); - - void Show(void); - void Hide(void); - - bool isHide(void) const; - bool isShow(void) const; - - u16 w(void); - u16 h(void); - const Rect & GetRect(void) const; - -private: - Background back; - bool hide; -}; - -class TextBox : protected Rect -{ -public: - TextBox(); - TextBox(const std::string &, Font::type_t, u16); - TextBox(const std::string &, Font::type_t, const Rect &); - - void Set(const std::string &, Font::type_t, u16); - void SetAlign(u8); - - const Rect & GetRect(void) const{ return *this; } - s16 x(void) const{ return Rect::x; } - s16 y(void) const{ return Rect::y; } - u16 w(void) const{ return Rect::w; } - u16 h(void) const{ return Rect::h; } - u16 row(void) const{ return messages.size(); } - - void Blit(u16 ax, u16 ay, Surface & sf = Display::Get()); - void Blit(const Point & pt, Surface & sf = Display::Get()); - -private: - void Append(const std::string &, Font::type_t, u16); -#ifdef WITH_TTF - void Append(const std::vector &, Font::type_t, u16); -#endif - - std::list messages; - u8 align; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/direction.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/direction.cpp deleted file mode 100644 index c4a1847c0..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/direction.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "maps.h" -#include "direction.h" - -const char* Direction::String(vector_t direct) -{ - const char* str_direct[] = { "center", "top", "top right", "right", "bottom right", "bottom", "bottom left", "left", "top left", "unknown" }; - - switch(direct) - { - case CENTER: return str_direct[0]; - case TOP: return str_direct[1]; - case TOP_RIGHT: return str_direct[2]; - case RIGHT: return str_direct[3]; - case BOTTOM_RIGHT: return str_direct[4]; - case BOTTOM: return str_direct[5]; - case BOTTOM_LEFT: return str_direct[6]; - case LEFT: return str_direct[7]; - case TOP_LEFT: return str_direct[8]; - default: break; - } - - return str_direct[9]; -} - - -Direction::vector_t Direction::Get(s32 from, s32 to) -{ - if(to == from) - return CENTER; - else - if(to == Maps::GetDirectionIndex(from, TOP)) - return TOP; - else - if(to == Maps::GetDirectionIndex(from, TOP_RIGHT)) - return TOP_RIGHT; - else - if(to == Maps::GetDirectionIndex(from, RIGHT)) - return RIGHT; - else - if(to == Maps::GetDirectionIndex(from, BOTTOM_RIGHT)) - return BOTTOM_RIGHT; - else - if(to == Maps::GetDirectionIndex(from, BOTTOM)) - return BOTTOM; - else - if(to == Maps::GetDirectionIndex(from, BOTTOM_LEFT)) - return BOTTOM_LEFT; - else - if(to == Maps::GetDirectionIndex(from, LEFT)) - return LEFT; - else - if(to == Maps::GetDirectionIndex(from, TOP_LEFT)) - return TOP_LEFT; - - return UNKNOWN; -} - -bool Direction::ShortDistanceClockWise(const vector_t from , const vector_t to) -{ - switch(from) - { - case TOP: - switch(to) - { - case TOP_RIGHT: - case RIGHT: - case BOTTOM_RIGHT: - case BOTTOM: return true; - - default: break; - } - break; - - case TOP_RIGHT: - switch(to) - { - case RIGHT: - case BOTTOM_RIGHT: - case BOTTOM: - case BOTTOM_LEFT: return true; - - default: break; - } - break; - - case RIGHT: - switch(to) - { - case BOTTOM_RIGHT: - case BOTTOM: - case BOTTOM_LEFT: - case LEFT: return true; - - default: break; - } - break; - - case BOTTOM_RIGHT: - switch(to) - { - case BOTTOM: - case BOTTOM_LEFT: - case LEFT: - case TOP_LEFT: return true; - - default: break; - } - break; - - case BOTTOM: - switch(to) - { - case BOTTOM_LEFT: - case LEFT: - case TOP_LEFT: return true; - - default: break; - } - break; - - case BOTTOM_LEFT: - switch(to) - { - case TOP: - case TOP_RIGHT: - case LEFT: - case TOP_LEFT: return true; - - default: break; - } - break; - - case LEFT: - switch(to) - { - case TOP: - case TOP_RIGHT: - case RIGHT: - case TOP_LEFT: return true; - - default: break; - } - break; - - case TOP_LEFT: - switch(to) - { - case TOP: - case TOP_RIGHT: - case RIGHT: - case BOTTOM_RIGHT: return true; - - default: break; - } - break; - - default: break; - } - - return false; -} - -Direction::vector_t Direction::Reflect(Direction::vector_t from) -{ - switch(from) - { - case TOP_LEFT: return BOTTOM_RIGHT; - case TOP: return BOTTOM; - case TOP_RIGHT: return BOTTOM_LEFT; - case RIGHT: return LEFT; - case BOTTOM_RIGHT: return TOP_LEFT; - case BOTTOM: return TOP; - case BOTTOM_LEFT: return TOP_RIGHT; - case LEFT: return RIGHT; - case CENTER: return CENTER; - default: break; - } - - return UNKNOWN; -} - -Direction::vector_t Direction::FromInt(u16 index) -{ - switch(index) - { - case 0x0001: return TOP_LEFT; - case 0x0002: return TOP; - case 0x0004: return TOP_RIGHT; - case 0x0008: return RIGHT; - case 0x0010: return BOTTOM_RIGHT; - case 0x0020: return BOTTOM; - case 0x0040: return BOTTOM_LEFT; - case 0x0080: return LEFT; - case 0x0100: return CENTER; - default: break; - } - - return UNKNOWN; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/direction.h b/project/jni/application/fheroes2/src/fheroes2/heroes/direction.h deleted file mode 100644 index a62ac6771..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/direction.h +++ /dev/null @@ -1,69 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2DIRECTION_H -#define H2DIRECTION_H - -#include -#include "gamedefs.h" - -namespace Direction -{ - enum vector_t - { - UNKNOWN = 0x0000, - TOP_LEFT = 0x0001, - TOP = 0x0002, - TOP_RIGHT = 0x0004, - RIGHT = 0x0008, - BOTTOM_RIGHT = 0x0010, - BOTTOM = 0x0020, - BOTTOM_LEFT = 0x0040, - LEFT = 0x0080, - CENTER = 0x0100 - }; - - inline vector_t& operator++ (vector_t& direct){ return direct = ( CENTER == direct ? TOP_LEFT : vector_t(direct << 1)); } - inline vector_t& operator-- (vector_t& direct){ return direct = ( TOP_LEFT == direct ? CENTER : vector_t(direct >> 1)); } - - const char* String(vector_t direct); - - vector_t FromInt(u16); - vector_t Get(s32 from, s32 to); - vector_t Reflect(vector_t from); - - bool ShortDistanceClockWise(const vector_t from, const vector_t to); -} - -#define DIRECTION_TOP_ROW (Direction::TOP_LEFT | Direction::TOP | Direction::TOP_RIGHT) -#define DIRECTION_BOTTOM_ROW (Direction::BOTTOM_LEFT | Direction::BOTTOM | Direction::BOTTOM_RIGHT) -#define DIRECTION_CENTER_ROW (Direction::LEFT | Direction::CENTER | Direction::RIGHT) -#define DIRECTION_LEFT_COL (Direction::TOP_LEFT | Direction::LEFT | Direction::BOTTOM_LEFT) -#define DIRECTION_CENTER_COL (Direction::TOP | Direction::CENTER | Direction::BOTTOM) -#define DIRECTION_RIGHT_COL (Direction::TOP_RIGHT | Direction::RIGHT | Direction::BOTTOM_RIGHT) -#define DIRECTION_ALL (DIRECTION_TOP_ROW | DIRECTION_BOTTOM_ROW | DIRECTION_CENTER_ROW) - -#define DIRECTION_TOP_RIGHT_CORNER (Direction::TOP | Direction::TOP_RIGHT | Direction::RIGHT) -#define DIRECTION_TOP_LEFT_CORNER (Direction::TOP | Direction::TOP_LEFT | Direction::LEFT) -#define DIRECTION_BOTTOM_RIGHT_CORNER (Direction::BOTTOM | Direction::BOTTOM_RIGHT | Direction::RIGHT) -#define DIRECTION_BOTTOM_LEFT_CORNER (Direction::BOTTOM | Direction::BOTTOM_LEFT | Direction::LEFT) - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes.cpp deleted file mode 100644 index 1f1f15cf0..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes.cpp +++ /dev/null @@ -1,1726 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "artifact.h" -#include "world.h" -#include "castle.h" -#include "settings.h" -#include "agg.h" -#include "speed.h" -#include "luck.h" -#include "morale.h" -#include "monster.h" -#include "payment.h" -#include "profit.h" -#include "cursor.h" -#include "kingdom.h" -#include "visit.h" -#include "battle2.h" -#include "heroes.h" -#include "localclient.h" -#include "game_focus.h" -#include "game_interface.h" - -// heroes_action.cpp -u16 DialogWithArtifact(const std::string & hdr, const std::string & msg, const Artifact::artifact_t art, const u16 buttons = Dialog::OK); -void PlayPickupSound(void); - -const char* HeroesName(Heroes::heroes_t id) -{ - const char* names[] = { - // knight - _("Lord Kilburn"), _("Sir Gallanth"), _("Ector"), _("Gwenneth"), _("Tyro"), _("Ambrose"), _("Ruby"), _("Maximus"), _("Dimitry"), - // barbarian - _("Thundax"), _("Fineous"), _("Jojosh"), _("Crag Hack"), _("Jezebel"), _("Jaclyn"), _("Ergon"), _("Tsabu"), _("Atlas"), - // sorceress - _("Astra"), _("Natasha"), _("Troyan"), _("Vatawna"), _("Rebecca"), _("Gem"), _("Ariel"), _("Carlawn"), _("Luna"), - // warlock - _("Arie"), _("Alamar"), _("Vesper"), _("Crodo"), _("Barok"), _("Kastore"), _("Agar"), _("Falagar"), _("Wrathmont"), - // wizard - _("Myra"), _("Flint"), _("Dawn"), _("Halon"), _("Myrini"), _("Wilfrey"), _("Sarakin"), _("Kalindra"), _("Mandigal"), - // necromant - _("Zom"), _("Darlana"), _("Zam"), _("Ranloo"), _("Charity"), _("Rialdo"), _("Roxana"), _("Sandro"), _("Celia"), - // campains - _("Roland"), _("Lord Corlagon"), _("Sister Eliza"), _("Archibald"), _("Lord Halton"), _("Brother Bax"), - // loyalty version - _("Solmyr"), _("Dainwin"), _("Mog"), _("Uncle Ivan"), _("Joseph"), _("Gallavant"), _("Elderian"), _("Ceallach"), _("Drakonia"), _("Martine"), _("Jarkonas"), - // debug - "SandySandy", "Unknown" }; - - return names[id]; -} - -typedef std::vector< std::pair > ObjectVisitedModifiers; - -s8 GetResultModifiers(const ObjectVisitedModifiers & modifiers, const Heroes & hero, std::string* strs) -{ - s8 result = 0; - - for(size_t ii = 0; ii < modifiers.size(); ++ii) - { - const std::pair & pair = modifiers[ii]; - - if(hero.isVisited(pair.first)) - { - result += pair.second; - - if(strs) - { - strs->append(MP2::StringObject(pair.first)); - StringAppendModifiers(*strs, pair.second); - strs->append("\n"); - } - } - } - - return result; -} - -Heroes::heroes_t Heroes::ConvertID(u8 index) -{ - return index > UNKNOWN ? UNKNOWN : static_cast(index); -} - -Heroes::Heroes() : move_point_scale(-1), army(this), path(*this), - direction(Direction::RIGHT), sprite_index(18), patrol_square(0), - ai_primary_target(-1) -{ - bag_artifacts.assign(HEROESMAXARTIFACT, Artifact::UNKNOWN); -} - -Heroes::Heroes(heroes_t ht, Race::race_t rc) : killer_color(Color::GRAY), experience(0), move_point(0), - move_point_scale(-1), army(this), portrait(ht), race(rc), - save_maps_object(MP2::OBJ_ZERO), path(*this), direction(Direction::RIGHT), sprite_index(18), patrol_square(0), - ai_primary_target(-1) -{ - name = _(HeroesName(ht)); - - bag_artifacts.assign(HEROESMAXARTIFACT, Artifact::UNKNOWN); - - u8 book, spell; - Skill::Primary::LoadDefaults(race, *this, book, spell); - - secondary_skills.reserve(HEROESMAXSKILL); - Skill::Secondary::LoadDefaults(race, secondary_skills); - - if(book) - { - SpellBookActivate(); - AppendSpellToBook(Spell::FromInt(spell)); - if(!HasArtifact(Artifact::MAGIC_BOOK)) PickupArtifact(Artifact::MAGIC_BOOK); - } - - // hero is freeman - color = Color::GRAY; - - // set default army - army.Reset(true); - - // extra hero - switch(portrait) - { - case ROLAND: - attack = 0; - defense = 1; - power = 4; - knowledge = 5; - - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::WISDOM, Skill::Level::ADVANCED)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::LEADERSHIP, Skill::Level::EXPERT)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::ARCHERY, Skill::Level::BASIC)); - break; - - case CORLAGON: - attack = 5; - defense = 3; - power = 1; - knowledge = 1; - - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::NECROMANCY, Skill::Level::EXPERT)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::BALLISTICS, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::WISDOM, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::LEADERSHIP, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::PATHFINDING, Skill::Level::BASIC)); - break; - - case ELIZA: - attack = 0; - defense = 1; - power = 2; - knowledge = 6; - - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::NAVIGATION, Skill::Level::ADVANCED)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::WISDOM, Skill::Level::EXPERT)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::ARCHERY, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::LUCK, Skill::Level::BASIC)); - break; - - case ARCHIBALD: - attack = 1; - defense = 1; - power = 4; - knowledge = 4; - - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::SCOUTING, Skill::Level::EXPERT)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::LEADERSHIP, Skill::Level::EXPERT)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::WISDOM, Skill::Level::ADVANCED)); - break; - - case HALTON: - attack = 3; - defense = 3; - power = 3; - knowledge = 2; - - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::BALLISTICS, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::LEADERSHIP, Skill::Level::ADVANCED)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::DIPLOMACY, Skill::Level::BASIC)); - break; - - case BAX: - attack = 1; - defense = 1; - power = 4; - knowledge = 3; - - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::WISDOM, Skill::Level::EXPERT)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::NECROMANCY, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::NAVIGATION, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::PATHFINDING, Skill::Level::BASIC)); - break; - - case SOLMYR: - case DRAKONIA: - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::WISDOM, Skill::Level::ADVANCED)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::LEADERSHIP, Skill::Level::BASIC)); - break; - - case DAINWIN: - case ELDERIAN: - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::WISDOM, Skill::Level::ADVANCED)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::SCOUTING, Skill::Level::BASIC)); - break; - - case MOG: - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::WISDOM, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::NECROMANCY, Skill::Level::ADVANCED)); - break; - - case UNCLEIVAN: - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::PATHFINDING, Skill::Level::ADVANCED)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::LEADERSHIP, Skill::Level::BASIC)); - break; - - case JOSEPH: - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::LEADERSHIP, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::SCOUTING, Skill::Level::BASIC)); - break; - - case GALLAVANT: - break; - - case CEALLACH: - break; - - case MARTINE: - break; - - case JARKONAS: - break; - - case SANDYSANDY: - army.Clear(); - army.JoinTroop(Monster::BLACK_DRAGON, 2); - army.JoinTroop(Monster::RED_DRAGON, 3); - - secondary_skills.clear(); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::PATHFINDING, Skill::Level::ADVANCED)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::LOGISTICS, Skill::Level::ADVANCED)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::SCOUTING, Skill::Level::BASIC)); - secondary_skills.push_back(Skill::Secondary(Skill::Secondary::MYSTICISM, Skill::Level::BASIC)); - - PickupArtifact(Artifact::STEALTH_SHIELD); - PickupArtifact(Artifact::DRAGON_SWORD); - PickupArtifact(Artifact::NOMAD_BOOTS_MOBILITY); - PickupArtifact(Artifact::TRAVELER_BOOTS_MOBILITY); - PickupArtifact(Artifact::TRUE_COMPASS_MOBILITY); - - experience = 777; - - // all spell in magic book - for(u8 spell = Spell::FIREBALL; spell < Spell::STONE; ++spell) AppendSpellToBook(Spell::FromInt(spell), true); - break; - - default: break; - } - - SetSpellPoints(GetMaxSpellPoints()); - move_point = GetMaxMovePoints(); -} - -void Heroes::LoadFromMP2(s32 map_index, const void *ptr, const Color::color_t cl, const Race::race_t rc) -{ - // reset modes - modes = 0; - - SetIndex(map_index); - - color = cl; - killer_color = Color::GRAY; - - const u8 *ptr8 = static_cast(ptr); - u16 byte16 = 0; - u32 byte32 = 0; - - // unknown - ++ptr8; - - // custom troops - bool custom_troop = false; - if(*ptr8) - { - ++ptr8; - custom_troop = true; - - // monster1 - army.At(0).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // monster2 - army.At(1).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // monster3 - army.At(2).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // monster4 - army.At(3).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // monster5 - army.At(4).SetMonster(Monster::FromInt(*ptr8 + 1)); - ++ptr8; - - // count1 - byte16 = ReadLE16(ptr8); - army.At(0).SetCount(byte16); - ++ptr8; - ++ptr8; - - // count2 - byte16 = ReadLE16(ptr8); - army.At(1).SetCount(byte16); - ++ptr8; - ++ptr8; - - // count3 - byte16 = ReadLE16(ptr8); - army.At(2).SetCount(byte16); - ++ptr8; - ++ptr8; - - // count4 - byte16 = ReadLE16(ptr8); - army.At(3).SetCount(byte16); - ++ptr8; - ++ptr8; - - // count5 - byte16 = ReadLE16(ptr8); - army.At(4).SetCount(byte16); - ++ptr8; - ++ptr8; - } - else - { - ptr8 += 16; - } - - // custom portrate - bool custom_portrait = false; - if(*ptr8) - { - custom_portrait = true; - ++ptr8; - // index sprite portrait - if(portrait != ConvertID(*ptr8)) DEBUG(DBG_GAME, DBG_WARN, "Heroes::LoadFromMP2: " << "custom portrait incorrect"); - ++ptr8; - } - else - ptr8 += 2; - - // artifacts - Artifact::artifact_t artifact = Artifact::UNKNOWN; - - // artifact 1 - if(Artifact::UNKNOWN != (artifact = Artifact::FromInt(*ptr8))) PickupArtifact(artifact); - ++ptr8; - - // artifact 2 - if(Artifact::UNKNOWN != (artifact = Artifact::FromInt(*ptr8))) PickupArtifact(artifact); - ++ptr8; - - // artifact 3 - if(Artifact::UNKNOWN != (artifact = Artifact::FromInt(*ptr8))) PickupArtifact(artifact); - ++ptr8; - - // unknown byte - ++ptr8; - - // experience - byte32 = ReadLE32(ptr8); - experience = byte32; - ptr8 += 4; - - bool custom_secskill = false; - // custom skill - if(*ptr8) - { - custom_secskill = true; - ++ptr8; - - secondary_skills.clear(); - - // skills - for(u8 ii = 0; ii < 8; ++ii) - { - const Skill::Secondary::skill_t skill = Skill::Secondary::FromMP2(*(ptr8 + ii)); - const Skill::Level::type_t lvl = Skill::Level::FromMP2(*(ptr8 + ii + 8)); - - if(Skill::Secondary::UNKNOWN != skill && Skill::Level::NONE != lvl) secondary_skills.push_back(Skill::Secondary(skill, lvl)); - } - ptr8 += 16; - } - else - { - ++ptr8; - - ptr8 += 16; - } - - // unknown - ++ptr8; - - // custom name - if(*ptr8) name = std::string(_(reinterpret_cast(ptr8 + 1))); - ptr8 += 14; - - // fixed race for custom portrait - if(custom_portrait && Settings::Get().ExtForceSelectRaceFromType()) - { - if(Race::ALL & rc) race = rc; - - // fixed default primary skills - u8 book, spell; - Skill::Primary::LoadDefaults(race, *this, book, spell); - - // fixed default troop - if(!custom_troop) - army.Reset(true); - - // fixed default sec skills - if(!custom_secskill) - Skill::Secondary::LoadDefaults(race, secondary_skills); - - // fixed default spell - if(book) - { - SpellBookActivate(); - AppendSpellToBook(Spell::FromInt(spell)); - if(!HasArtifact(Artifact::MAGIC_BOOK)) PickupArtifact(Artifact::MAGIC_BOOK); - } - } - - // patrol - if(*ptr8) - { - SetModes(PATROL); - patrol_center = GetCenter(); - } - ++ptr8; - - // count square - patrol_square = *ptr8; - ++ptr8; - - // end - - // save general object - save_maps_object = MP2::OBJ_ZERO; - - // fix zero army - if(!army.isValid()) army.Reset(true); - - // level up - u8 level = GetLevel(); - while(1 < level--) - { - Skill::Primary::skill_t primary = LevelUpPrimarySkill(); - if(!custom_secskill) LevelUpSecondarySkill(primary, true); - } - - // other param - SetSpellPoints(GetMaxSpellPoints()); - move_point = GetMaxMovePoints(); - - DEBUG(DBG_GAME , DBG_INFO, "Heroes::LoadFromMP2: " << name << ", color: " << Color::String(color) << ", race: " << Race::String(race)); -} - -Heroes::heroes_t Heroes::GetID(void) const -{ - return portrait; -} - -u8 Heroes::GetMobilityIndexSprite(void) const -{ - // valid range (0 - 25) - const u8 index = !CanMove() ? 0 : move_point / 100; - return 25 >= index ? index : 25; -} - -u8 Heroes::GetManaIndexSprite(void) const -{ - // valid range (0 - 25) - u8 r = GetSpellPoints() / 5; - return 25 >= r ? r : 25; -} - -u8 Heroes::GetAttack(void) const -{ - return GetAttack(NULL); -} - -u8 Heroes::GetAttack(std::string* strs) const -{ - s16 result = attack + GetAttackModificator(strs); - - return result < 0 ? 0 : (result > 255 ? 255 : result); -} - -u8 Heroes::GetDefense(void) const -{ - return GetDefense(NULL); -} - -u8 Heroes::GetDefense(std::string* strs) const -{ - s16 result = defense + GetDefenseModificator(strs); - - return result < 0 ? 0 : (result > 255 ? 255 : result); -} - -u8 Heroes::GetPower(void) const -{ - return GetPower(NULL); -} - -u8 Heroes::GetPower(std::string* strs) const -{ - s16 result = power + GetPowerModificator(strs); - - return result < 0 ? 0 : (result > 255 ? 255 : result); -} - -u8 Heroes::GetKnowledge(void) const -{ - return GetKnowledge(NULL); -} - -u8 Heroes::GetKnowledge(std::string* strs) const -{ - s16 result = knowledge + GetKnowledgeModificator(strs); - - return result < 0 ? 0 : (result > 255 ? 255 : result); -} - -void Heroes::IncreasePrimarySkill(const Skill::Primary::skill_t skill) -{ - switch(skill) - { - case Skill::Primary::ATTACK: ++attack; break; - case Skill::Primary::DEFENSE: ++defense; break; - case Skill::Primary::POWER: ++power; break; - case Skill::Primary::KNOWLEDGE: ++knowledge; break; - default: break; - } -} - -u32 Heroes::GetExperience(void) const -{ - return experience; -} - -void Heroes::IncreaseMovePoints(const u16 point) -{ - move_point += point; -} - -u16 Heroes::GetMovePoints(void) const -{ - return move_point; -} - -u16 Heroes::GetMaxSpellPoints(void) const -{ - return 10 * GetKnowledge(); -} - -u16 Heroes::GetMaxMovePoints(void) const -{ - u16 point = 0; - - // start point - if(isShipMaster()) - { - point = 1500; - - // skill navigation - point += point * GetSecondaryValues(Skill::Secondary::NAVIGATION) / 100; - - // artifact bonus - if(HasArtifact(Artifact::SAILORS_ASTROLABE_MOBILITY)) point += 1000; - - // visited object - if(isVisited(MP2::OBJ_LIGHTHOUSE)) point += 500; - } - else - { - switch(army.GetSlowestTroop().GetSpeed()) - { - default: break; - case Speed::CRAWLING: - case Speed::VERYSLOW: point = 1000; break; - case Speed::SLOW: point = 1100; break; - case Speed::AVERAGE: point = 1200; break; - case Speed::FAST: point = 1300; break; - case Speed::VERYFAST: point = 1400; break; - case Speed::ULTRAFAST: - case Speed::BLAZING: - case Speed::INSTANT: point = 1500; break; - } - - // skill logistics - point += point * GetSecondaryValues(Skill::Secondary::LOGISTICS) / 100; - - // artifact bonus - if(HasArtifact(Artifact::NOMAD_BOOTS_MOBILITY)) point += 600; - if(HasArtifact(Artifact::TRAVELER_BOOTS_MOBILITY)) point += 300; - - // visited object - if(isVisited(MP2::OBJ_STABLES)) point += 500; - } - - if(HasArtifact(Artifact::TRUE_COMPASS_MOBILITY)) point += 500; - - return point; -} - -s8 Heroes::GetMorale(void) const -{ - return GetMoraleWithModificators(NULL); -} - -s8 Heroes::GetMoraleWithModificators(std::string *strs) const -{ - s8 result = Morale::NORMAL; - - // bonus artifact - result += GetMoraleModificator(isShipMaster(), strs); - - if(army.AllTroopsIsRace(Race::NECR)) return Morale::NORMAL; - - // bonus leadership - result += Skill::GetLeadershipModifiers(GetLevelSkill(Skill::Secondary::LEADERSHIP), strs); - - // object visited - ObjectVisitedModifiers modifiers; - modifiers.reserve(7); - - modifiers.push_back(std::make_pair(MP2::OBJ_BUOY, 1)); - modifiers.push_back(std::make_pair(MP2::OBJ_OASIS, 1)); - modifiers.push_back(std::make_pair(MP2::OBJ_WATERINGHOLE, 1)); - modifiers.push_back(std::make_pair(MP2::OBJ_TEMPLE, 2)); - modifiers.push_back(std::make_pair(MP2::OBJ_GRAVEYARD, -1)); - modifiers.push_back(std::make_pair(MP2::OBJ_DERELICTSHIP, -1)); - modifiers.push_back(std::make_pair(MP2::OBJ_SHIPWRECK, -1)); - - // global modificator - result += GetResultModifiers(modifiers, *this, strs); - - // result - if(result < Morale::AWFUL) return Morale::TREASON; - else - if(result < Morale::POOR) return Morale::AWFUL; - else - if(result < Morale::NORMAL) return Morale::POOR; - else - if(result < Morale::GOOD) return Morale::NORMAL; - else - if(result < Morale::GREAT) return Morale::GOOD; - else - if(result < Morale::BLOOD) return Morale::GREAT; - - return Morale::BLOOD; -} - -s8 Heroes::GetLuck(void) const -{ - return GetLuckWithModificators(NULL); -} - -s8 Heroes::GetLuckWithModificators(std::string *strs) const -{ - s8 result = Luck::NORMAL; - - // bonus artifact - result += GetLuckModificator(isShipMaster(), strs); - - // bonus luck - result += Skill::GetLuckModifiers(GetLevelSkill(Skill::Secondary::LUCK), strs); - - // object visited - ObjectVisitedModifiers modifiers; - modifiers.reserve(5); - - modifiers.push_back(std::make_pair(MP2::OBJ_MERMAID, 1)); - modifiers.push_back(std::make_pair(MP2::OBJ_FAERIERING, 1)); - modifiers.push_back(std::make_pair(MP2::OBJ_FOUNTAIN, 1)); - modifiers.push_back(std::make_pair(MP2::OBJ_IDOL, 1)); - modifiers.push_back(std::make_pair(MP2::OBJ_PYRAMID, -2)); - - // global modificator - result += GetResultModifiers(modifiers, *this, strs); - - if(result < Luck::AWFUL) return Luck::CURSED; - else - if(result < Luck::BAD) return Luck::AWFUL; - else - if(result < Luck::NORMAL) return Luck::BAD; - else - if(result < Luck::GOOD) return Luck::NORMAL; - else - if(result < Luck::GREAT) return Luck::GOOD; - else - if(result < Luck::IRISH) return Luck::GREAT; - - return Luck::IRISH; -} - -/* recrut hero */ -bool Heroes::Recruit(const Color::color_t cl, const Point & pt) -{ - if(color != Color::GRAY) - { - DEBUG(DBG_GAME , DBG_WARN, "Heroes::Recrut: hero not freeman!"); - return false; - } - - Kingdom & kingdom = world.GetKingdom(cl); - - if(kingdom.AllowRecruitHero(false, 0)) - { - Maps::Tiles & tiles = world.GetTiles(pt); - color = cl; - killer_color = Color::GRAY; - SetCenter(pt); - if(!Modes(SAVEPOINTS)) move_point = GetMaxMovePoints(); - MovePointsScaleFixed(); - - if(!army.isValid()) army.Reset(false); - - // save general object - save_maps_object = tiles.GetObject(); - tiles.SetObject(MP2::OBJ_HEROES); - - kingdom.AddHeroes(this); - return true; - } - - return false; -} - -bool Heroes::Recruit(const Castle & castle) -{ - if(NULL == castle.GetHeroes() && - Recruit(castle.GetColor(), castle.GetCenter())) - { - if(castle.GetLevelMageGuild()) - { - // magic point - if(!Modes(SAVEPOINTS)) SetSpellPoints(GetMaxSpellPoints()); - // learn spell - castle.GetMageGuild().EducateHero(*this); - } - return true; - } - - return false; -} - -void Heroes::ActionNewDay(void) -{ - // increase resource - Resource::funds_t resource; - - // skip incomes for first day - if(HasArtifact(Artifact::GOLDEN_GOOSE)) resource += ProfitConditions::FromArtifact(Artifact::GOLDEN_GOOSE); - if(HasArtifact(Artifact::ENDLESS_SACK_GOLD)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_SACK_GOLD); - if(HasArtifact(Artifact::ENDLESS_BAG_GOLD)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_BAG_GOLD); - if(HasArtifact(Artifact::ENDLESS_PURSE_GOLD)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_PURSE_GOLD); - if(HasArtifact(Artifact::ENDLESS_POUCH_SULFUR)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_POUCH_SULFUR); - if(HasArtifact(Artifact::ENDLESS_VIAL_MERCURY)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_VIAL_MERCURY); - if(HasArtifact(Artifact::ENDLESS_POUCH_GEMS)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_POUCH_GEMS); - if(HasArtifact(Artifact::ENDLESS_CORD_WOOD)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_CORD_WOOD); - if(HasArtifact(Artifact::ENDLESS_CART_ORE)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_CART_ORE); - if(HasArtifact(Artifact::ENDLESS_POUCH_CRYSTAL)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_POUCH_CRYSTAL); - - // estates skill bonus - resource.gold += GetSecondaryValues(Skill::Secondary::ESTATES); - - // added - if(resource.GetValidItems()) world.GetKingdom(GetColor()).AddFundsResource(resource); - - if(HasArtifact(Artifact::TAX_LIEN)) - { - resource.Reset(); - resource.gold = 250; - world.GetKingdom(GetColor()).OddFundsResource(resource); - } - - // recovery move points - move_point = GetMaxMovePoints(); - // stables visited? - if(isVisited(MP2::OBJ_STABLES)) move_point += 400; - - // recovery spell points - if(HaveSpellBook()) - { - // possible visit arteian spring 2 * max - const u16 prev = GetSpellPoints(); - const Castle* castle = inCastle(); - - // in castle? - if(castle && castle->GetLevelMageGuild()) - { - //restore from mage guild - if(prev < GetMaxSpellPoints()) SetSpellPoints(GetMaxSpellPoints()); - } - else - { - u16 curr = GetSpellPoints(); - - // everyday - curr += Game::GetHeroRestoreSpellPointsPerDay(); - - if(HasArtifact(Artifact::POWER_RING)) curr += 2; - - // secondary skill - curr += GetSecondaryValues(Skill::Secondary::MYSTICISM); - - if((curr > GetMaxSpellPoints()) && (curr > prev)) curr = prev; - - SetSpellPoints(curr); - } - } - - // remove day visit object - visit_object.remove_if(Visit::isDayLife); - - - // new day, new capacities - ResetModes(STUPID); - ResetModes(SAVEPOINTS); -} - -void Heroes::ActionNewWeek(void) -{ - // remove week visit object - visit_object.remove_if(Visit::isWeekLife); - - // fix artesian spring effect - if(GetSpellPoints() > GetMaxSpellPoints()) SetSpellPoints(GetMaxSpellPoints()); -} - -void Heroes::ActionNewMonth(void) -{ - // remove month visit object - visit_object.remove_if(Visit::isMonthLife); -} - -void Heroes::ActionAfterBattle(void) -{ - // remove month visit object - visit_object.remove_if(Visit::isBattleLife); - // - SetModes(ACTION); -} - -s32 Heroes::FindPath(s32 dst_index) const -{ - Route::Path route(*this); - - return route.Calculate(dst_index); -} - -void Heroes::RescanPath(void) -{ - if(path.isValid()) - { - if(Game::AI == GetControl()) - { - if(path.hasObstacle()) path.Reset(); - } - else - { - path.ScanObstacleAndReduce(); - } - } -} - -/* if hero in castle */ -const Castle* Heroes::inCastle(void) const -{ - if(Color::GRAY == color) return false; - - const std::vector & castles = world.GetKingdom(color).GetCastles(); - - std::vector::const_iterator it1 = castles.begin(); - std::vector::const_iterator it2 = castles.end(); - - for(; it1 != it2; ++it1) if((**it1).GetCenter() == GetCenter()) return *it1; - - return NULL; -} - -Castle* Heroes::inCastle(void) -{ - if(Color::GRAY == color) return false; - - const std::vector & castles = world.GetKingdom(color).GetCastles(); - - std::vector::const_iterator it1 = castles.begin(); - std::vector::const_iterator it2 = castles.end(); - - for(; it1 != it2; ++it1) if((**it1).GetCenter() == GetCenter()) return *it1; - - return NULL; -} - -/* is visited cell */ -bool Heroes::isVisited(const Maps::Tiles & tile, const Visit::type_t type) const -{ - const u16 & index = tile.GetIndex(); - const MP2::object_t object = (tile.GetObject() == MP2::OBJ_HEROES ? GetUnderObject() : tile.GetObject()); - - if(Visit::GLOBAL == type) return world.GetKingdom(color).isVisited(index, object); - - return visit_object.end() != std::find(visit_object.begin(), visit_object.end(), IndexObject(index, object)); -} - -/* return true if object visited */ -bool Heroes::isVisited(const u8 object, const Visit::type_t type) const -{ - if(Visit::GLOBAL == type) return world.GetKingdom(color).isVisited(object); - - return visit_object.end() != std::find_if(visit_object.begin(), visit_object.end(), std::bind2nd(std::mem_fun_ref(&IndexObject::isObject), object)); -} - -/* set visited cell */ -void Heroes::SetVisited(const s32 index, const Visit::type_t type) -{ - const Maps::Tiles & tile = world.GetTiles(index); - - const MP2::object_t object = (tile.GetObject() == MP2::OBJ_HEROES ? GetUnderObject() : tile.GetObject()); - - if(Visit::GLOBAL == type) - world.GetKingdom(color).SetVisited(index, object); - else - if(isVisited(tile)) - return; - else - if(MP2::OBJ_ZERO != object) visit_object.push_front(IndexObject(index, object)); -} - -u8 Heroes::GetCountArtifacts(void) const -{ - return std::count_if(bag_artifacts.begin(), bag_artifacts.end(), std::mem_fun_ref(&Artifact::isValid)); -} - -bool Heroes::HasUltimateArtifact(void) const -{ - return bag_artifacts.end() != std::find_if(bag_artifacts.begin(), bag_artifacts.end(), std::mem_fun_ref(&Artifact::isUltimate)); -} - -bool Heroes::IsFullBagArtifacts(void) const -{ - return bag_artifacts.end() == std::find(bag_artifacts.begin(), bag_artifacts.end(), Artifact::UNKNOWN); -} - -bool Heroes::PickupArtifact(const Artifact::artifact_t art) -{ - return PickupArtifact(Artifact(art)); -} - -bool Heroes::PickupArtifact(const Artifact & art) -{ - BagArtifacts::iterator it = std::find(bag_artifacts.begin(), bag_artifacts.end(), Artifact::UNKNOWN); - - if(bag_artifacts.end() == it) - { - if(Settings::Get().MyColor() == color) - { - art == Artifact::MAGIC_BOOK ? - Dialog::Message("", _("You must purchase a spell book to use the mage guild, but you currently have no room for a spell book. Try giving one of your artifacts to another hero."), Font::BIG, Dialog::OK) : - Dialog::Message(art.GetName(), _("You have no room to carry another artifact!"), Font::BIG, Dialog::OK); - } - return false; - } - - *it = art; - - // book insert first - if(art == Artifact::MAGIC_BOOK && - it != bag_artifacts.begin()) std::swap(*it, bag_artifacts.front()); - - // check: anduran garb - if(HasArtifact(Artifact::BREASTPLATE_ANDURAN) && - HasArtifact(Artifact::HELMET_ANDURAN) && - HasArtifact(Artifact::SWORD_ANDURAN)) - { - it = std::find(bag_artifacts.begin(), bag_artifacts.end(), Artifact::BREASTPLATE_ANDURAN); - *it = Artifact::UNKNOWN; - it = std::find(bag_artifacts.begin(), bag_artifacts.end(), Artifact::HELMET_ANDURAN); - *it = Artifact::UNKNOWN; - it = std::find(bag_artifacts.begin(), bag_artifacts.end(), Artifact::SWORD_ANDURAN); - *it = Artifact::UNKNOWN; - it = std::find(bag_artifacts.begin(), bag_artifacts.end(), Artifact::UNKNOWN); - *it = Artifact::BATTLE_GARB; - - if(Settings::Get().MyColor() == color) - DialogWithArtifact("", _("The three Anduran artifacts magically combine into one."), Artifact::BATTLE_GARB); - } - - return true; -} - -/* return level hero */ -u8 Heroes::GetLevel(void) const -{ - return GetLevelFromExperience(experience); -} - -void Heroes::IncreaseExperience(const u32 exp) -{ - const u8 level_old = GetLevelFromExperience(experience); - const u8 level_new = GetLevelFromExperience(experience + exp); - - for(u8 ii = 0; ii < level_new - level_old; ++ii) LevelUp(); - - experience += exp; -} - -/* calc level from exp */ -u8 Heroes::GetLevelFromExperience(u32 exp) -{ - for(u8 lvl = 1; lvl < 255; ++ lvl) if(exp < GetExperienceFromLevel(lvl)) return lvl; - - return 0; -} - -/* calc exp from level */ -u32 Heroes::GetExperienceFromLevel(u8 lvl) -{ - switch(lvl) - { - case 0: return 0; - case 1: return 1000; - case 2: return 2000; - case 3: return 3200; - case 4: return 4500; - case 5: return 6000; - case 6: return 7700; - case 7: return 9000; - case 8: return 11000; - case 9: return 13200; - case 10: return 15500; - case 11: return 18500; - case 12: return 22100; - case 13: return 26400; - case 14: return 31600; - case 15: return 37800; - case 16: return 45300; - case 17: return 54200; - case 18: return 65000; - case 19: return 78000; - case 20: return 93600; - case 21: return 112300; - case 22: return 134700; - case 23: return 161600; - case 24: return 193900; - case 25: return 232700; - case 26: return 279300; - case 27: return 335200; - case 28: return 402300; - case 29: return 482800; - case 30: return 579400; - case 31: return 695300; - case 32: return 834400; - case 33: return 1001300; - case 34: return 1201600; - case 35: return 1442000; - case 36: return 1730500; - case 37: return 2076700; - case 38: return 2492100; - case 39: return 2990600; - - default: break; - } - - const u32 l1 = GetExperienceFromLevel(lvl - 1); - return (l1 + static_cast(round((l1 - GetExperienceFromLevel(lvl - 2)) * 1.2 / 100) * 100)); -} - -/* buy book */ -bool Heroes::BuySpellBook(const MageGuild* mageguild, u8 shrine) -{ - if(HaveSpellBook() || Color::GRAY == color) return false; - - const payment_t payment = PaymentConditions::BuySpellBook(shrine); - Kingdom & kingdom = world.GetKingdom(color); - - std::string header = _("To cast spells, you must first buy a spell book for %{gold} gold."); - String::Replace(header, "%{gold}", payment.gold); - - if( ! kingdom.AllowPayment(payment)) - { - if(Settings::Get().MyColor() == color) - { - header.append(". "); - header.append(_("Unfortunately, you seem to be a little short of cash at the moment.")); - Dialog::Message("", header, Font::BIG, Dialog::OK); - } - return false; - } - - if(Settings::Get().MyColor() == color) - { - const Sprite & border = AGG::GetICN(ICN::RESOURCE, 7); - Surface sprite(border.w(), border.h()); - - sprite.Blit(border); - sprite.Blit(AGG::GetICN(ICN::ARTIFACT, Artifact::IndexSprite64(Artifact::MAGIC_BOOK)), 5, 5); - - header.append(". "); - header.append(_("Do you wish to buy one?")); - - if(Dialog::NO == Dialog::SpriteInfo("", header, sprite, Dialog::YES | Dialog::NO)) return false; - } - - if(!HasArtifact(Artifact::MAGIC_BOOK) && PickupArtifact(Artifact::MAGIC_BOOK)) - { - kingdom.OddFundsResource(payment); - SpellBookActivate(); - - // add all spell to book - if(mageguild) mageguild->EducateHero(*this); -#ifdef WITH_NET - FH2LocalClient::SendHeroesBuyMagicBook(*this); -#endif - return true; - } - - return false; -} - -/* return true is move enable */ -bool Heroes::isEnableMove(void) const -{ - return Modes(ENABLEMOVE) && path.isValid() && path.GetFrontPenalty() <= move_point; -} - -bool Heroes::CanMove(void) const -{ - return move_point >= Maps::Ground::GetPenalty(GetIndex(), Direction::CENTER, GetLevelSkill(Skill::Secondary::PATHFINDING)); -} - -/* set enable move */ -void Heroes::SetMove(bool f) -{ - if(f) - SetModes(ENABLEMOVE); - else - { - ResetModes(ENABLEMOVE); - - // reset sprite position - switch(direction) - { - case Direction::TOP: sprite_index = 0; break; - case Direction::BOTTOM: sprite_index = 36; break; - case Direction::TOP_RIGHT: - case Direction::TOP_LEFT: sprite_index = 9; break; - case Direction::BOTTOM_RIGHT: - case Direction::BOTTOM_LEFT: sprite_index = 27; break; - case Direction::RIGHT: - case Direction::LEFT: sprite_index = 18; break; - default: break; - } - } -} - -void Heroes::SaveUnderObject(MP2::object_t obj) -{ - save_maps_object = obj; -} - -MP2::object_t Heroes::GetUnderObject(void) const -{ - return save_maps_object; -} - -bool Heroes::isShipMaster(void) const -{ - return Modes(SHIPMASTER); -} - -bool Heroes::CanPassToShipMaster(const Heroes & hero) const -{ - if(hero.isShipMaster()) - { - Route::Path route(*this); - - const s16 & cx = hero.GetCenter().x; - const s16 & cy = hero.GetCenter().y; - const bool full = false; - s32 coast = 0; - - for(s8 y = -1; y <= 1; ++y) - for(s8 x = -1; x <= 1; ++x) - { - if((!y && !x) || (y && x && !full)) continue; - - coast = Maps::GetIndexFromAbsPoint(cx + x, cy + y); - - if(Maps::isValidAbsIndex(coast) && - MP2::OBJ_COAST == world.GetTiles(coast).GetObject() && FindPath(coast)) return true; - } - } - return false; -} - -void Heroes::SetShipMaster(bool f) -{ - f ? SetModes(SHIPMASTER) : ResetModes(SHIPMASTER); -} - -const std::vector & Heroes::GetSecondarySkills(void) const -{ - return secondary_skills; -} - -bool Heroes::HasSecondarySkill(const Skill::Secondary::skill_t skill) const -{ - return Skill::Level::NONE != GetLevelSkill(skill); -} - -u8 Heroes::GetSecondaryValues(const Skill::Secondary::skill_t skill) const -{ - return Skill::Secondary::GetValues(skill, GetLevelSkill(skill)); -} - -bool Heroes::HasMaxSecondarySkill(void) const -{ - return HEROESMAXSKILL <= secondary_skills.size(); -} - -u8 Heroes::GetLevelSkill(const Skill::Secondary::skill_t skill) const -{ - std::vector::const_iterator it; - - it = std::find_if(secondary_skills.begin(), secondary_skills.end(), - std::bind2nd(std::mem_fun_ref(&Skill::Secondary::isSkill), skill)); - - return it == secondary_skills.end() ? Skill::Level::NONE : (*it).Level(); -} - -void Heroes::LearnBasicSkill(const Skill::Secondary::skill_t skill) -{ - std::vector::iterator it; - - it = std::find_if(secondary_skills.begin(), secondary_skills.end(), - std::bind2nd(std::mem_fun_ref(&Skill::Secondary::isSkill), skill)); - - if(it != secondary_skills.end()) - (*it).SetLevel(Skill::Level::BASIC); - else - secondary_skills.push_back(Skill::Secondary(skill, Skill::Level::BASIC)); -} - -void Heroes::LevelUpSkill(const Skill::Secondary::skill_t skill) -{ - std::vector::iterator it; - - it = std::find_if(secondary_skills.begin(), secondary_skills.end(), - std::bind2nd(std::mem_fun_ref(&Skill::Secondary::isSkill), skill)); - - if(it != secondary_skills.end()) - (*it).NextLevel(); - else - secondary_skills.push_back(Skill::Secondary(skill, Skill::Level::BASIC)); - - if(skill == Skill::Secondary::SCOUTING) - Scoute(); -} - -void Heroes::Scoute(void) -{ - Maps::ClearFog(GetIndex(), GetScoute(), color); -} - -u8 Heroes::GetScoute(void) const -{ - return (HasArtifact(Artifact::TELESCOPE) ? Game::GetViewDistance(Game::VIEW_TELESCOPE) : 0) + - Game::GetViewDistance(Game::VIEW_HEROES) + GetSecondaryValues(Skill::Secondary::SCOUTING); -} - -u8 Heroes::GetVisionsDistance(void) const -{ - u8 dist = Spell::GetExtraValue(Spell::VISIONS); - - if(HasArtifact(Artifact::CRYSTAL_BALL)) - dist = Settings::Get().UseAltResource() ? dist * 2 + 2 : 8; - - return dist; -} - -/* return route range in days */ -u8 Heroes::GetRangeRouteDays(const s32 dst) const -{ - const u32 max = GetMaxMovePoints(); - const u16 limit = max * 5 / 100; // limit ~5 day - - // approximate distance, this restriction calculation - if((4 * max / 100) < Maps::GetApproximateDistance(GetIndex(), dst)) - { - DEBUG(DBG_GAME , DBG_INFO, "Heroes::GetRangeRouteDays: distance limit"); - return 0; - } - - Route::Path test(*this); - // approximate limit, this restriction path finding algorithm - if(test.Calculate(dst, limit)) - { - u32 total = test.TotalPenalty(); - if(move_point >= total) return 1; - - total -= move_point; - if(max >= total) return 2; - - total -= move_point; - if(max >= total) return 3; - - return 4; - } - else - DEBUG(DBG_GAME , DBG_INFO, "Heroes::GetRangeRouteDays: iteration limit: " << limit); - - return 0; -} - -/* select secondary skills for level up */ -void Heroes::FindSkillsForLevelUp(Skill::Secondary & sec1, Skill::Secondary & sec2) const -{ - std::vector exclude_skills; - exclude_skills.reserve(MAXSECONDARYSKILL + HEROESMAXSKILL); - - // exclude for expert - { - std::vector::const_iterator it1 = secondary_skills.begin(); - std::vector::const_iterator it2 = secondary_skills.end(); - for(; it1 != it2; ++it1) if((*it1).Level() == Skill::Level::EXPERT) exclude_skills.push_back((*it1).Skill()); - } - - // exclude is full, add other. - if(HEROESMAXSKILL <= secondary_skills.size()) - { - std::vector skills; - Skill::Secondary::FillStandard(skills); - - std::vector::const_iterator it1 = skills.begin(); - std::vector::const_iterator it2 = skills.end(); - - for(; it1 != it2; ++it1) - if(Skill::Level::NONE == GetLevelSkill(*it1)) exclude_skills.push_back(*it1); - } - - sec1.SetSkill(Skill::Secondary::PriorityFromRace(GetRace(), exclude_skills)); - exclude_skills.push_back(sec1.Skill()); - sec2.SetSkill(Skill::Secondary::PriorityFromRace(GetRace(), exclude_skills)); - - sec1.SetLevel(GetLevelSkill(sec1.Skill())); - sec2.SetLevel(GetLevelSkill(sec2.Skill())); - - sec1.NextLevel(); - sec2.NextLevel(); -} - -/* up level */ -void Heroes::LevelUp(bool autoselect) -{ - LevelUpSecondarySkill(LevelUpPrimarySkill(), autoselect); -} - -Skill::Primary::skill_t Heroes::LevelUpPrimarySkill(void) -{ - const Skill::Primary::skill_t primary1 = Skill::Primary::FromLevelUp(race, GetLevel()); - - // upgrade primary - switch(primary1) - { - case Skill::Primary::ATTACK: ++attack; break; - case Skill::Primary::DEFENSE: ++defense; break; - case Skill::Primary::POWER: ++power; break; - case Skill::Primary::KNOWLEDGE: ++knowledge; break; - default: break; - } - DEBUG(DBG_GAME , DBG_INFO, "Heroes::LevelUpPrimarySkill: for " << GetName() << ", up " << Skill::Primary::String(primary1)); - - return primary1; -} - -void Heroes::LevelUpSecondarySkill(const Skill::Primary::skill_t primary1, bool autoselect) -{ - Skill::Secondary sec1; - Skill::Secondary sec2; - - FindSkillsForLevelUp(sec1, sec2); - DEBUG(DBG_GAME, DBG_INFO, "Heroes::LevelUpSecondarySkill: " << GetName() << " select " << Skill::Secondary::String(sec1.Skill()) << " or " << Skill::Secondary::String(sec2.Skill())); - - std::string header; - std::string message; - - if(Skill::Secondary::UNKNOWN == sec1.Skill() && Skill::Secondary::UNKNOWN == sec2.Skill()) - { - if(!autoselect && GetColor() == Settings::Get().MyColor()) - { - AGG::PlaySound(M82::NWHEROLV); - header = _("%{name} has gained a level."); - String::Replace(header, "%{name}", name); - message = _("%{skill} Skill +1"); - String::Replace(message, "%{skill}", Skill::Primary::String(primary1)); - Dialog::Message(header, message, Font::BIG, Dialog::OK); - } - } - else - if(Skill::Secondary::UNKNOWN == sec1.Skill() || Skill::Secondary::UNKNOWN == sec2.Skill()) - { - Skill::Secondary* sec = Skill::Secondary::UNKNOWN == sec2.Skill() ? &sec1 : &sec2; - - if(!autoselect && GetColor() == Settings::Get().MyColor()) - { - AGG::PlaySound(M82::NWHEROLV); - header = _("%{name} has gained a level. %{skill} Skill +1"); - String::Replace(header, "%{name}", name); - String::Replace(header, "%{skill}", Skill::Primary::String(primary1)); - message = _("You have learned %{level} %{skill}."); - String::Replace(message, "%{level}", Skill::Level::String(sec->Level())); - String::Replace(message, "%{skill}", Skill::Secondary::String(sec->Skill())); - - const Sprite & sprite_frame = AGG::GetICN(ICN::SECSKILL, 15); - Surface sf(sprite_frame.w(), sprite_frame.h()); - sf.Blit(sprite_frame); - // sprite - const Sprite & sprite_skill = AGG::GetICN(ICN::SECSKILL, Skill::Secondary::GetIndexSprite1(sec->Skill())); - sf.Blit(sprite_skill, 3, 3); - // text - const std::string &name_skill = Skill::Secondary::String(sec->Skill()); - Text text_skill(name_skill, Font::SMALL); - text_skill.Blit(3 + (sprite_skill.w() - text_skill.w()) / 2, 6, sf); - const std::string &name_level = Skill::Level::String(sec->Level()); - Text text_level(name_level, Font::SMALL); - text_level.Blit(3 + (sprite_skill.w() - text_level.w()) / 2, sprite_skill.h() - 12, sf); - - Dialog::SpriteInfo(header, message, sf); - } - LevelUpSkill(sec->Skill()); - } - else - { - Skill::Secondary::skill_t skill_select(Skill::Secondary::UNKNOWN); - - if(!autoselect && GetColor() == Settings::Get().MyColor()) - { - AGG::PlaySound(M82::NWHEROLV); - header = _("%{name} has gained a level. %{skill} Skill +1"); - String::Replace(header, "%{name}", name); - String::Replace(header, "%{skill}", Skill::Primary::String(primary1)); - skill_select = Dialog::LevelUpSelectSkill(header, sec1, sec2); - } - // AI select - else - { - skill_select = (Rand::Get(0, 1) ? sec1.Skill() : sec2.Skill()); - } - - LevelUpSkill(skill_select); - } -} - -/* apply penalty */ -bool Heroes::ApplyPenaltyMovement(void) -{ - const u16 penalty = path.isValid() ? - path.GetFrontPenalty() : - Maps::Ground::GetPenalty(GetIndex(), Direction::CENTER, GetLevelSkill(Skill::Secondary::PATHFINDING)); - - if(move_point >= penalty) move_point -= penalty; - else return false; - - return true; -} - -bool Heroes::MayStillMove(void) const -{ - if(Modes(STUPID) || isFreeman()) return false; - return path.isValid() ? (move_point >= path.GetFrontPenalty()) : CanMove(); -} - -bool Heroes::isValid(void) const -{ - return true; -} - -bool Heroes::isFreeman(void) const -{ - return Color::GRAY == color && !Modes(JAIL); -} - -void Heroes::SetFreeman(const u8 reason) -{ - if(isFreeman()) return; - - bool savepoints = false; - if((Battle2::RESULT_RETREAT | Battle2::RESULT_SURRENDER) & reason) - { - if(Settings::Get().ExtRememberPointsForHeroRetreating()) savepoints = true; - world.GetKingdom(color).GetRecruits().SetHero2(this); - } - - if(!army.isValid() || (Battle2::RESULT_RETREAT & reason)) army.Reset(false); - else - if((Battle2::RESULT_LOSS & reason) && !(Battle2::RESULT_SURRENDER & reason)) army.Reset(true); - - if(color != Color::GRAY) world.GetKingdom(color).RemoveHeroes(this); - - color = Color::GRAY; - world.GetTiles(GetIndex()).SetObject(save_maps_object); - modes = 0; - SetIndex(-1); - move_point_scale = -1; - path.Reset(); - SetMove(false); - SetModes(ACTION); - if(savepoints) SetModes(SAVEPOINTS); -} - -bool Heroes::isShow(u8 color) -{ - const s32 index_from = GetIndex(); - const Maps::Tiles & tile_from = world.GetTiles(index_from); - - if(path.isValid()) - { - const s32 index_to = Maps::GetDirectionIndex(index_from, path.GetFrontDirection()); - const Maps::Tiles & tile_to = world.GetTiles(index_to); - - return !tile_from.isFog(color) && !tile_to.isFog(color); - } - - return !tile_from.isFog(color); -} - -const Surface & Heroes::GetPortrait30x22(void) const -{ - if(Heroes::SANDYSANDY > portrait) return AGG::GetICN(ICN::MINIPORT, portrait); - else - if(Heroes::SANDYSANDY == portrait) return AGG::GetICN(ICN::MINIPORT, BAX); - - return AGG::GetICN(ICN::MINIPORT, 0); -} - -const Surface & Heroes::GetPortrait50x46(void) const -{ - if(Heroes::SANDYSANDY > portrait) return AGG::GetICN(ICN::PORTMEDI, portrait + 1); - else - if(Heroes::SANDYSANDY == portrait) return AGG::GetICN(ICN::PORTMEDI, BAX + 1); - - return AGG::GetICN(ICN::PORTMEDI, 0); -} - -const Surface & Heroes::GetPortrait101x93(void) const -{ - ICN::icn_t icn = ICN::PORTxxxx(portrait); - - return AGG::GetICN(ICN::UNKNOWN != icn ? icn : ICN::PORT0000, 0); -} - -void Heroes::SetKillerColor(Color::color_t c) -{ - killer_color = c; -} - -Color::color_t Heroes::GetKillerColor(void) const -{ - return killer_color; -} - -u8 Heroes::GetControl(void) const -{ - return world.GetKingdom(color).Control(); -} - -bool Heroes::AllowBattle(void) const -{ - switch(save_maps_object) - { - case MP2::OBJ_TEMPLE: return false; - default: break; - } - - return true; -} - -void Heroes::PreBattleAction(void) -{ -} - -void Heroes::ActionNewPosition(void) -{ - const Settings & conf = Settings::Get(); - // check around monster - const u16 dst_around = Maps::TileUnderProtection(GetIndex()); - - if(dst_around) - { - SetMove(false); - - for(Direction::vector_t dir = Direction::TOP_LEFT; dir < Direction::CENTER && !isFreeman(); ++dir) - if(dst_around & dir) - { - const s32 mons = Maps::GetDirectionIndex(GetIndex(), dir); - - // redraw gamearea for monster action sprite - if(conf.MyColor() == GetColor()) - { - Interface::Basic & I = Interface::Basic::Get(); - Game::Focus & F = Game::Focus::Get(); - Cursor::Get().Hide(); - I.gameArea.Center(F.Center()); - F.SetRedraw(); - I.Redraw(); - Cursor::Get().Show(); - // force flip, for monster attack show sprite - Display::Get().Flip(); - } - Action(mons); - if(conf.ExtOnlyFirstMonsterAttack()) break; - } - } - - ResetModes(VISIONS); -} - -const Point & Heroes::GetCenterPatrol(void) const -{ - return patrol_center; -} - -u8 Heroes::GetSquarePatrol(void) const -{ - return patrol_square; -} - -bool Heroes::CanScouteTile(s32 index) const -{ - if(Settings::Get().ExtScouteExtended()) - { - const Maps::Tiles & tile = world.GetTiles(index); - - u8 dist = GetSecondaryValues(Skill::Secondary::SCOUTING) ? GetScoute() : 0; - if(Modes(VISIONS) && dist < GetVisionsDistance()) dist = GetVisionsDistance(); - - return (dist > Maps::GetApproximateDistance(GetIndex(), tile.GetIndex())); - } - return false; -} - -void Heroes::MovePointsScaleFixed(void) -{ - move_point_scale = move_point * 1000 / GetMaxMovePoints(); -} - -void Heroes::RecalculateMovePoints(void) -{ - if(0 <= move_point_scale) move_point = GetMaxMovePoints() * move_point_scale / 1000; -} - -void Heroes::Dump(void) const -{ - std::cout << "name : " << name << std::endl; - std::cout << "race : " << Race::String(race) << std::endl; - std::cout << "color : " << Color::String(color) << std::endl; - std::cout << "experience : " << experience << std::endl; - std::cout << "magic point : " << GetSpellPoints() << std::endl; - std::cout << "position x : " << GetCenter().x << std::endl; - std::cout << "position y : " << GetCenter().y << std::endl; - std::cout << "move point : " << move_point << std::endl; - std::cout << "max magic point : " << GetMaxSpellPoints() << std::endl; - std::cout << "max move point : " << GetMaxMovePoints() << std::endl; - std::cout << "direction : " << Direction::String(direction) << std::endl; - std::cout << "index sprite : " << static_cast(sprite_index) << std::endl; - std::cout << "flags : " << (Modes(SHIPMASTER) ? "SHIPMASTER," : ",") << - (Modes(SCOUTER) ? "SCOUTER," : ",") << - (Modes(HUNTER) ? "HUNTER," : ",") << - (Modes(PATROL) ? "PATROL," : ",") << - (Modes(STUPID) ? "STUPID," : ",") << std::endl; - - std::cout << "ai primary target: " << ai_primary_target << std::endl; - std::cout << "ai sheduled visit: "; - std::deque::const_iterator it1 = ai_sheduled_visit.begin(); - std::deque::const_iterator it2 = ai_sheduled_visit.end(); - for(; it1 != it2; ++it1) std::cout << *it1 << "(" << MP2::StringObject(world.GetTiles(*it1).GetObject()) << "), "; - std::cout << std::endl; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes.h b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes.h deleted file mode 100644 index ebd2c24d3..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes.h +++ /dev/null @@ -1,289 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2HEROES_H -#define H2HEROES_H - -#include -#include -#include -#include -#include "spell.h" -#include "mp2.h" -#include "dialog.h" -#include "route.h" -#include "pairs.h" -#include "visit.h" -#include "direction.h" -#include "game_io.h" -#include "heroes_base.h" -#include "army.h" -#include "gamedefs.h" - -class Recruits; -class Surface; -class MageGuild; - -class Heroes : public HeroBase -{ -public: - enum heroes_t - { - // knight - LORDKILBURN, SIRGALLANTH, ECTOR, GVENNETH, TYRO, AMBROSE, RUBY, MAXIMUS, DIMITRY, - // barbarian - THUNDAX, FINEOUS, JOJOSH, CRAGHACK, JEZEBEL, JACLYN, ERGON, TSABU, ATLAS, - // sorceress - ASTRA, NATASHA, TROYAN, VATAWNA, REBECCA, GEM, ARIEL, CARLAWN, LUNA, - // warlock - ARIE, ALAMAR, VESPER, CRODO, BAROK, KASTORE, AGAR, FALAGAR, WRATHMONT, - // wizard - MYRA, FLINT, DAWN, HALON, MYRINI, WILFREY, SARAKIN, KALINDRA, MANDIGAL, - // necromancer - ZOM, DARLANA, ZAM, RANLOO, CHARITY, RIALDO, ROXANA, SANDRO, CELIA, - // from campain - ROLAND, CORLAGON, ELIZA, ARCHIBALD, HALTON, BAX, - // from extended - SOLMYR, DAINWIN, MOG, UNCLEIVAN, JOSEPH, GALLAVANT, ELDERIAN, CEALLACH, DRAKONIA, MARTINE, JARKONAS, - // debugger - SANDYSANDY, UNKNOWN - }; - - static heroes_t ConvertID(u8); - - enum flags_t - { - SHIPMASTER = 0x0001, - // = 0x0002, - SPELLCASTED = 0x0004, - ENABLEMOVE = 0x0008, - HUNTER = 0x0010, - SCOUTER = 0x0020, - STUPID = 0x0040, - JAIL = 0x0080, - ACTION = 0x0100, - SAVEPOINTS = 0x0200, - VISIONS = 0x4000, - PATROL = 0x8000 - }; - - Heroes(); - Heroes(heroes_t ht, Race::race_t rc); - - bool isValid(void) const; - bool isFreeman(void) const; - void SetFreeman(const u8 reason); - - const Castle* inCastle(void) const; - Castle* inCastle(void); - - void LoadFromMP2(s32 map_index, const void *ptr, const Color::color_t cl, const Race::race_t rc); - - void ResetStupidFlag(void) { ResetModes(STUPID); } - - Color::color_t GetColor(void) const{ return color; } - Race::race_t GetRace(void) const{ return race; } - const std::string & GetName(void) const{ return name; } - u8 GetType(void) const { return Skill::Primary::HEROES; } - u8 GetControl(void) const; - - Color::color_t GetKillerColor(void) const; - void SetKillerColor(Color::color_t); - - const Surface & GetPortrait30x22(void) const; - const Surface & GetPortrait50x46(void) const; - const Surface & GetPortrait101x93(void) const; - - const Army::army_t & GetArmy(void) const{ return army; } - Army::army_t & GetArmy(void) { return army; } - - heroes_t GetID(void) const; - - u8 GetAttack(void) const; - u8 GetDefense(void) const; - u8 GetPower(void) const; - u8 GetKnowledge(void) const; - - u8 GetAttack(std::string*) const; - u8 GetDefense(std::string*) const; - u8 GetPower(std::string*) const; - u8 GetKnowledge(std::string*) const; - - void IncreasePrimarySkill(const Skill::Primary::skill_t skill); - - s8 GetMorale(void) const; - s8 GetLuck(void) const; - s8 GetMoraleWithModificators(std::string *str = NULL) const; - s8 GetLuckWithModificators(std::string *str = NULL) const; - u8 GetLevel(void) const; - - const Point & GetCenterPatrol(void) const; - u8 GetSquarePatrol(void) const; - - u16 GetMaxSpellPoints(void) const; - - u16 GetMaxMovePoints(void) const; - u16 GetMovePoints(void) const; - void IncreaseMovePoints(const u16 point); - bool MayStillMove(void) const; - void ResetMovePoints(void) { move_point = 0; }; - void MovePointsScaleFixed(void); - void RecalculateMovePoints(void); - - bool HasSecondarySkill(const Skill::Secondary::skill_t skill) const; - bool HasMaxSecondarySkill(void) const; - u8 GetLevelSkill(const Skill::Secondary::skill_t skill) const; - void LearnBasicSkill(const Skill::Secondary::skill_t skill); - void LevelUpSkill(const Skill::Secondary::skill_t skill); - void FindSkillsForLevelUp(Skill::Secondary & sec1, Skill::Secondary & sec2) const; - const std::vector & GetSecondarySkills(void) const; - u8 GetSecondaryValues(const Skill::Secondary::skill_t) const; - - bool PickupArtifact(const Artifact::artifact_t); - bool PickupArtifact(const Artifact &); - bool HasUltimateArtifact(void) const; - u8 GetCountArtifacts(void) const; - bool IsFullBagArtifacts(void) const; - - u8 GetMobilityIndexSprite(void) const; - u8 GetManaIndexSprite(void) const; - - Dialog::answer_t OpenDialog(bool readonly = false, bool fade = false); - void MeetingDialog(Heroes &); - void AIMeeting(Heroes &); - - bool Recruit(const Color::color_t cl, const Point & pt); - bool Recruit(const Castle & castle); - - void ActionNewDay(void); - void ActionNewWeek(void); - void ActionNewMonth(void); - void ActionAfterBattle(void); - - bool BuySpellBook(const MageGuild*, u8 shrine = 0); - - const Route::Path & GetPath(void) const{ return path; } - Route::Path & GetPath(void) { return path; } - s32 FindPath(s32 dst_index) const; - u8 GetRangeRouteDays(const s32 dst) const; - void ShowPath(bool f){ f ? path.Show() : path.Hide(); } - void RescanPath(void); - - Direction::vector_t GetDirection(void) const{ return direction; } - - void SetVisited(const s32 index, const Visit::type_t type = Visit::LOCAL); - bool isVisited(const u8 object, const Visit::type_t type = Visit::LOCAL) const; - bool isVisited(const Maps::Tiles & tile, const Visit::type_t type = Visit::LOCAL) const; - - - bool Move(bool fast = false); - bool isShow(u8 color); - bool isEnableMove(void) const; - bool CanMove(void) const; - void SetMove(bool f); - bool isAction(void) const { return Modes(ACTION); } - void ResetAction(void) { ResetModes(ACTION); } - void Action(const s32 dst_index); - void ActionNewPosition(void); - bool ApplyPenaltyMovement(void); - bool ActionSpellCast(Spell::spell_t); - - void AIAction(const s32 dst_index); - bool AIValidObject(s32); - void AIRescueWhereMove(void); - bool AIPriorityObject(s32); - - std::deque & GetAITasks(void) { return ai_sheduled_visit; } - void ClearAITasks(void) { ai_sheduled_visit.clear(); } - s32 GetPrimaryTarget(void) const { return ai_primary_target; } - void SetPrimaryTarget(s32 target) { ai_primary_target = target; } - - void Redraw(Surface &, bool) const; - void Redraw(Surface &, const s16, const s16, bool) const; - u8 GetSpriteIndex(void) const{ return sprite_index; } - void FadeOut(void) const; - void FadeIn(void) const; - void Scoute(void); - u8 GetScoute(void) const; - bool CanScouteTile(s32) const; - u8 GetVisionsDistance(void) const; - - bool isShipMaster(void) const; - bool CanPassToShipMaster(const Heroes &) const; - void SetShipMaster(bool f); - - void SaveUnderObject(MP2::object_t obj); - MP2::object_t GetUnderObject(void) const; - - u32 GetExperience(void) const; - void IncreaseExperience(const u32 exp); - - bool AllowBattle(void) const; - void PreBattleAction(void); - - void Dump(void) const; - - static u8 GetLevelFromExperience(u32 exp); - static u32 GetExperienceFromLevel(u8 lvl); - - static void ScholarAction(Heroes &, Heroes &); - -private: - friend class Recruits; - friend class Game::IO; - - void LevelUp(bool autoselect = false); - Skill::Primary::skill_t LevelUpPrimarySkill(void); - void LevelUpSecondarySkill(const Skill::Primary::skill_t, bool autoselect = false); - void AngleStep(const Direction::vector_t to_direct); - bool MoveStep(bool fast = false); - - std::string name; - Color::color_t color; - Color::color_t killer_color; - u32 experience; - u16 move_point; - s32 move_point_scale; - - std::vector secondary_skills; - - Army::army_t army; - - heroes_t portrait; - Race::race_t race; - - MP2::object_t save_maps_object; - - Route::Path path; - - Direction::vector_t direction; - u8 sprite_index; - - Point patrol_center; - u8 patrol_square; - - std::list visit_object; - std::deque ai_sheduled_visit; - s32 ai_primary_target; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_action.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_action.cpp deleted file mode 100644 index 74f884768..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_action.cpp +++ /dev/null @@ -1,3188 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "mp2.h" -#include "world.h" -#include "settings.h" -#include "castle.h" -#include "monster.h" -#include "heroes.h" -#include "battle2.h" -#include "game_focus.h" -#include "game_interface.h" -#include "kingdom.h" -#include "morale.h" -#include "cursor.h" -#include "algorithm.h" -#include "payment.h" -#include "profit.h" -#include "gameevent.h" - -#define PlayMusicReplacement(m82) if(MUS::FromMapObject((MP2::object_t)obj) == MUS::UNKNOWN) \ - AGG::PlaySound(m82) -#define PlaySoundWarning PlayMusicReplacement(M82::EXPERNCE) -#define PlaySoundSuccess PlayMusicReplacement(M82::TREASURE) -#define PlaySoundFailure PlayMusicReplacement(M82::H2MINE) -#define PlaySoundVisited PlayMusicReplacement(M82::RSBRYFZL) - -namespace Game -{ - void OpenCastle(Castle *); -} - -void ActionToCastle(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToHeroes(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToMonster(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToBoat(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToCoast(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToWagon(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToSkeleton(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToResource(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToPickupResource(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToFlotSam(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToArtifact(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToShipwreckSurvivor(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToShrine(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToWitchsHut(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToGoodLuckObject(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToPoorLuckObject(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToSign(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToMagicWell(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToTradingPost(Heroes &hero, const u8 obj); -void ActionToPrimarySkillObject(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToPoorMoraleObject(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToGoodMoraleObject(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToExperienceObject(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToTreasureChest(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToAncientLamp(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToTeleports(Heroes &hero, const s32 dst_index); -void ActionToWhirlpools(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToObservationTower(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToCaptureObject(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToDwellingJoinMonster(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToDwellingRecruitMonster(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToDwellingBattleMonster(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToArtesianSpring(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToAbandoneMine(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToXanadu(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToUpgradeArmyObject(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToMagellanMaps(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToEvent(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToObelisk(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToTreeKnowledge(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToOracle(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToDaemonCave(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToAlchemistsTower(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToStables(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToArena(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToSirens(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToJail(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToHutMagi(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToEyeMagi(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToShinx(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToBarrier(Heroes &hero, const u8 obj, const s32 dst_index); -void ActionToTravellersTent(Heroes &hero, const u8 obj, const s32 dst_index); - -u16 DialogCaptureResourceObject(const std::string & hdr, std::string & msg, const u8 res, const u16 buttons = Dialog::OK) -{ - const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, Resource::GetIndexSprite2(res)); - - // sprite resource with x / day test - Surface sf(sprite.w() + 30, sprite.h() + 14); - sf.SetColorKey(); - sf.Blit(sprite, 15, 0); - - std::string perday = _("%{count} / day"); - payment_t info = ProfitConditions::FromMine(res); - s32* current = NULL; - - switch(res) - { - case Resource::MERCURY: current = &info.mercury; break; - case Resource::WOOD: current = &info.wood; break; - case Resource::ORE: current = &info.ore; break; - case Resource::SULFUR: current = &info.sulfur; break; - case Resource::CRYSTAL: current = &info.crystal; break; - case Resource::GEMS: current = &info.gems; break; - case Resource::GOLD: current = &info.gold; break; - default: break; - } - - if(current) - { - String::Replace(perday, "%{count}", *current); - - switch(*current) - { - case 1: String::Replace(msg, "%{count}", _("one")); break; - case 2: String::Replace(msg, "%{count}", _("two")); break; - default: String::Replace(msg, "%{count}", *current); break; - } - } - - Text text(perday, Font::SMALL); - text.Blit((sf.w() - text.w()) / 2, sf.h() - 12, sf); - - return Dialog::SpriteInfo(hdr, msg, sf, buttons); -} - -u16 DialogGoldWithExp(const std::string & hdr, const std::string & msg, const u16 count, const u16 exp, const u16 buttons = Dialog::OK) -{ - const Sprite & gold = AGG::GetICN(ICN::RESOURCE, 6); - const Sprite & sprite = AGG::GetICN(ICN::EXPMRL, 4); - Surface image(sprite.w() + gold.w() + 50, sprite.h() + 12); - image.SetColorKey(); - image.Blit(gold, 0, image.h() - gold.h() - 12); - image.Blit(sprite, gold.w() + 50, 0); - std::string str; - String::AddInt(str, count); - Text text(str, Font::SMALL); - text.Blit((gold.w() - text.w()) / 2, image.h() - 12, image); - str.clear(); - String::AddInt(str, exp); - text.Set(str); - text.Blit(gold.w() + 50 + (sprite.w() - text.w()) / 2, image.h() - 12, image); - return Dialog::SpriteInfo(hdr, msg, image, buttons); -} - -u16 DialogArtifactWithExp(const std::string & hdr, const std::string & msg, const Artifact::artifact_t art, const u16 exp, const u16 buttons = Dialog::OK) -{ - std::string str; - String::AddInt(str, exp); - const Sprite & sprite = AGG::GetICN(ICN::EXPMRL, 4); - const Sprite & border = AGG::GetICN(ICN::RESOURCE, 7); - const Sprite & artifact = AGG::GetICN(ICN::ARTIFACT, Artifact::IndexSprite64(art)); - Surface image(sprite.w() + border.w() + 50, border.h()); - image.SetColorKey(); - image.Blit(border); - image.Blit(artifact, 5, 5); - image.Blit(sprite, border.w() + 50, (border.h() - sprite.h()) / 2); - Text text(str, Font::SMALL); - text.Blit(border.w() + 50 + (sprite.w() - text.w()) / 2, image.h() - 12, image); - return Dialog::SpriteInfo(hdr, msg, image, buttons); -} - -u16 DialogWithExp(const std::string & hdr, const std::string & msg, const u16 exp, const u16 buttons = Dialog::OK) -{ - std::string str; - String::AddInt(str, exp); - const Sprite & sprite = AGG::GetICN(ICN::EXPMRL, 4); - Surface image(sprite.w(), sprite.h() + 12); - image.SetColorKey(); - image.Blit(sprite); - Text text(str, Font::SMALL); - text.Blit((sprite.w() - text.w()) / 2, sprite.h(), image); - return Dialog::SpriteInfo(hdr, msg, image, buttons); -} - -u16 DialogWithArtifactAndGold(const std::string & hdr, const std::string & msg, const Artifact::artifact_t art, const u16 count, const u16 buttons = Dialog::OK) -{ - std::string str; - String::AddInt(str, count); - const Sprite & gold = AGG::GetICN(ICN::RESOURCE, 6); - const Sprite & border = AGG::GetICN(ICN::RESOURCE, 7); - const Sprite & artifact = AGG::GetICN(ICN::ARTIFACT, Artifact::IndexSprite64(art)); - Surface image(gold.w() + border.w() + 50, border.h()); - image.SetColorKey(); - image.Blit(border); - image.Blit(artifact, 5, 5); - image.Blit(gold, border.w() + 50, (border.h() - gold.h()) / 2); - Text text(str, Font::SMALL); - text.Blit(border.w() + 50 + (gold.w() - text.w()) / 2, border.h() - 25, image); - return Dialog::SpriteInfo(hdr, msg, image, buttons); -} - -u16 DialogWithGold(const std::string & hdr, const std::string & msg, const u16 count, const u16 buttons = Dialog::OK) -{ - std::string str; - String::AddInt(str, count); - const Sprite & gold = AGG::GetICN(ICN::RESOURCE, 6); - Surface image(gold.w(), gold.h() + 12); - image.SetColorKey(); - image.Blit(gold); - Text text(str, Font::SMALL); - text.Blit((gold.w() - text.w()) / 2, gold.h(), image); - return Dialog::SpriteInfo(hdr, msg, image, buttons); -} - -u16 DialogWithArtifact(const std::string & hdr, const std::string & msg, const Artifact::artifact_t art, const u16 buttons = Dialog::OK) -{ - const Sprite & border = AGG::GetICN(ICN::RESOURCE, 7); - const Sprite & artifact = AGG::GetICN(ICN::ARTIFACT, Artifact::IndexSprite64(art)); - Surface image(border.w(), border.h()); - image.Blit(border); - image.Blit(artifact, 5, 5); - return Dialog::SpriteInfo(hdr, msg, image, buttons); -} - -u16 DialogMorale(const std::string & hdr, const std::string & msg, const bool good, u8 count) -{ - if(1 > count) count = 1; - if(3 < count) count = 3; - const Sprite & sprite = AGG::GetICN(ICN::EXPMRL, (good ? 2 : 3)); - u8 offset = sprite.w() * 4 / 3; - Surface image(sprite.w() + offset * (count - 1), sprite.h()); - image.SetColorKey(); - for(u8 ii = 0; ii < count; ++ii) image.Blit(sprite, offset * ii, 0); - return Dialog::SpriteInfo(hdr, msg, image); -} - -u16 DialogLuck(const std::string & hdr, const std::string & msg, const bool good, u8 count) -{ - if(1 > count) count = 1; - if(3 < count) count = 3; - const Sprite & sprite = AGG::GetICN(ICN::EXPMRL, (good ? 0 : 1)); - u8 offset = sprite.w() * 4 / 3; - Surface image(sprite.w() + offset * (count - 1), sprite.h()); - image.SetColorKey(); - for(u8 ii = 0; ii < count; ++ii) image.Blit(sprite, offset * ii, 0); - return Dialog::SpriteInfo(hdr, msg, image); -} - -void BattleLose(Heroes &hero, const Battle2::Result & res, bool attacker, Color::color_t color = Color::GRAY) -{ - u8 reason = attacker ? res.AttackerResult() : res.DefenderResult(); - - if(Settings::Get().ExtHeroSurrenderingGiveExp() && - Battle2::RESULT_SURRENDER == reason) - { - const u32 & exp = attacker ? res.GetExperienceAttacker() : res.GetExperienceDefender(); - - if(Settings::Get().MyColor() == hero.GetColor()) - { - std::string msg = _("Hero %{name} also got a %{count} experience."); - String::Replace(msg, "%{name}", hero.GetName()); - String::Replace(msg, "%{count}", exp); - Dialog::Message("", msg, Font::BIG, Dialog::OK); - } - hero.IncreaseExperience(exp); - } - - AGG::PlaySound(M82::KILLFADE); - hero.FadeOut(); - hero.SetKillerColor(color); - hero.SetFreeman(reason); - Game::Focus::Get().Reset(Game::Focus::HEROES); - Game::Focus::Get().SetRedraw(); -} - -void PlayPickupSound(void) -{ - M82::m82_t wav = M82::UNKNOWN; - - switch(Rand::Get(1, 7)) - { - case 1: wav = M82::PICKUP01; break; - case 2: wav = M82::PICKUP02; break; - case 3: wav = M82::PICKUP03; break; - case 4: wav = M82::PICKUP04; break; - case 5: wav = M82::PICKUP05; break; - case 6: wav = M82::PICKUP06; break; - case 7: wav = M82::PICKUP07; break; - - default: return; - } - - AGG::PlaySound(wav); -} - -void AnimationRemoveObject(const Maps::Tiles & tile) -{ - Maps::TilesAddon *addon = NULL; - - switch(tile.GetObject()) - { - case MP2::OBJ_FLOTSAM: - case MP2::OBJ_SHIPWRECKSURVIROR: - case MP2::OBJ_WATERCHEST: - case MP2::OBJ_BOTTLE: addon = const_cast(tile).FindWaterResource(); break; - - case MP2::OBJ_TREASURECHEST: - case MP2::OBJ_ANCIENTLAMP: - case MP2::OBJ_RESOURCE: addon = const_cast(tile).FindResource(); break; - - case MP2::OBJ_ARTIFACT: addon = const_cast(tile).FindArtifact(); break; - case MP2::OBJ_CAMPFIRE: addon = const_cast(tile).FindCampFire(); break; - case MP2::OBJ_MONSTER: addon = const_cast(tile).FindMonster(); break; - - case MP2::OBJ_BARRIER: addon = const_cast(tile).FindBarrier(); break; - - default: break; - } - - if(NULL == addon) return; - - const Interface::GameArea & gamearea = Interface::GameArea::Get(); - const Point & area = gamearea.GetMapsPos(); - const Rect & rect = gamearea.GetRectMaps(); - const Point pos(tile.GetIndex() % world.w() - rect.x, tile.GetIndex() / world.w() - rect.y); - - const s16 dstx = area.x + TILEWIDTH * pos.x; - const s16 dsty = area.y + TILEWIDTH * pos.y; - - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - - std::vector heroes; - std::vector::const_iterator it; - u16 index = Maps::ScanAroundObject(tile.GetIndex(), MP2::OBJ_HEROES); - for(Direction::vector_t dir = Direction::TOP_LEFT; dir < Direction::CENTER; ++dir) - if(index & dir) - heroes.push_back(world.GetHeroes(Maps::GetDirectionIndex(tile.GetIndex(), dir))); - - const Surface & st = tile.GetTileSurface(); - Surface sf(st.w(), st.h()); - sf.Blit(st); - const Sprite & sprite = AGG::GetICN(MP2::GetICNObject(addon->object), addon->index); - sf.Blit(sprite, sprite.x(), sprite.y()); - - // if animation sprite - if(0 != (index = ICN::AnimationFrame(MP2::GetICNObject(addon->object), addon->index))) - { - const Sprite & sprite = AGG::GetICN(MP2::GetICNObject(addon->object), index); - sf.Blit(sprite, sprite.x(), sprite.y()); - } - - LocalEvent & le = LocalEvent::Get(); - u8 alpha = 250; - - while(le.HandleEvents() && alpha > 10) - { - if(Game::AnimateInfrequent(Game::HEROES_PICKUP_DELAY)) - { - cursor.Hide(); - tile.RedrawTile(display); - tile.RedrawBottom(display, addon); - sf.SetAlpha(alpha); - display.Blit(sf, dstx, dsty); - if(heroes.size()) - { - for(it = heroes.begin(); it != heroes.end(); ++it) if(*it) (*it)->Redraw(display, false); - } - else - tile.RedrawTop(display); - cursor.Show(); - display.Flip(); - alpha -= 20; - } - } -} - -// action to next cell -void Heroes::Action(const s32 dst_index) -{ - if(Game::AI == world.GetKingdom(GetColor()).Control()) return AIAction(dst_index); - - const MP2::object_t object = (dst_index == GetIndex() ? - GetUnderObject() : world.GetTiles(dst_index).GetObject()); - - if(MUS::FromMapObject(object) != MUS::UNKNOWN) - AGG::PlayMusic(MUS::FromMapObject(object), false); - - if(MP2::isActionObject(object, isShipMaster())) SetModes(ACTION); - - switch(object) - { - case MP2::OBJ_MONSTER: ActionToMonster(*this, object, dst_index); break; - - case MP2::OBJ_CASTLE: ActionToCastle(*this, object, dst_index); break; - case MP2::OBJ_HEROES: ActionToHeroes(*this, object, dst_index); break; - - case MP2::OBJ_BOAT: ActionToBoat(*this, object, dst_index); break; - case MP2::OBJ_COAST: ActionToCoast(*this, object, dst_index); break; - - // resource object - case MP2::OBJ_MAGICGARDEN: - case MP2::OBJ_LEANTO: - case MP2::OBJ_WINDMILL: - case MP2::OBJ_WATERWHEEL: ActionToResource(*this, object, dst_index); break; - - case MP2::OBJ_WAGON: ActionToWagon(*this, object, dst_index); break; - case MP2::OBJ_SKELETON: ActionToSkeleton(*this, object, dst_index); break; - - // pickup object - case MP2::OBJ_RESOURCE: - case MP2::OBJ_BOTTLE: - case MP2::OBJ_CAMPFIRE: ActionToPickupResource(*this, object, dst_index); break; - - case MP2::OBJ_WATERCHEST: - case MP2::OBJ_TREASURECHEST: ActionToTreasureChest(*this, object, dst_index); break; - case MP2::OBJ_ANCIENTLAMP: ActionToAncientLamp(*this, object, dst_index); break; - case MP2::OBJ_FLOTSAM: ActionToFlotSam(*this, object, dst_index); break; - - case MP2::OBJ_SHIPWRECKSURVIROR:ActionToShipwreckSurvivor(*this, object, dst_index); break; - case MP2::OBJ_ARTIFACT: ActionToArtifact(*this, object, dst_index); break; - - // shrine circle - case MP2::OBJ_SHRINE1: - case MP2::OBJ_SHRINE2: - case MP2::OBJ_SHRINE3: ActionToShrine(*this, object, dst_index); break; - - // witchs hut - case MP2::OBJ_WITCHSHUT: ActionToWitchsHut(*this, object, dst_index); break; - - // info message - case MP2::OBJ_SIGN: ActionToSign(*this, object, dst_index); break; - - // luck modification - case MP2::OBJ_FOUNTAIN: - case MP2::OBJ_FAERIERING: - case MP2::OBJ_IDOL: ActionToGoodLuckObject(*this, object, dst_index); break; - - case MP2::OBJ_PYRAMID: ActionToPoorLuckObject(*this, object, dst_index); break; - - case MP2::OBJ_MAGICWELL: ActionToMagicWell(*this, object, dst_index); break; - case MP2::OBJ_TRADINGPOST: ActionToTradingPost(*this, object); break; - - // primary skill modification - case MP2::OBJ_FORT: - case MP2::OBJ_MERCENARYCAMP: - case MP2::OBJ_DOCTORHUT: - case MP2::OBJ_STANDINGSTONES: ActionToPrimarySkillObject(*this, object, dst_index); break; - - // morale modification - case MP2::OBJ_OASIS: - case MP2::OBJ_TEMPLE: - case MP2::OBJ_WATERINGHOLE: - case MP2::OBJ_BUOY: ActionToGoodMoraleObject(*this, object, dst_index); break; - - case MP2::OBJ_SHIPWRECK: - case MP2::OBJ_GRAVEYARD: - case MP2::OBJ_DERELICTSHIP: ActionToPoorMoraleObject(*this, object, dst_index); break; - - // experience modification - case MP2::OBJ_GAZEBO: ActionToExperienceObject(*this, object, dst_index); break; - case MP2::OBJ_DAEMONCAVE: ActionToDaemonCave(*this, object, dst_index); break; - - // teleports - case MP2::OBJ_STONELIGHTS: ActionToTeleports(*this, dst_index); break; - case MP2::OBJ_WHIRLPOOL: ActionToWhirlpools(*this, object, dst_index); break; - - // obsv tower - case MP2::OBJ_OBSERVATIONTOWER: ActionToObservationTower(*this, object, dst_index); break; - case MP2::OBJ_MAGELLANMAPS: ActionToMagellanMaps(*this, object, dst_index); break; - - // capture color object - case MP2::OBJ_ALCHEMYLAB: - case MP2::OBJ_MINES: - case MP2::OBJ_SAWMILL: - case MP2::OBJ_LIGHTHOUSE: ActionToCaptureObject(*this, object, dst_index); break; - - case MP2::OBJ_ABANDONEDMINE: ActionToAbandoneMine(*this, object, dst_index); break; - - // accept army - case MP2::OBJ_WATCHTOWER: - case MP2::OBJ_EXCAVATION: - case MP2::OBJ_CAVE: - case MP2::OBJ_TREEHOUSE: - case MP2::OBJ_ARCHERHOUSE: - case MP2::OBJ_GOBLINHUT: - case MP2::OBJ_DWARFCOTT: - case MP2::OBJ_HALFLINGHOLE: - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_THATCHEDHUT: ActionToDwellingJoinMonster(*this, object, dst_index); break; - - // recruit army - case MP2::OBJ_RUINS: - case MP2::OBJ_TREECITY: - case MP2::OBJ_WAGONCAMP: - case MP2::OBJ_DESERTTENT: ActionToDwellingRecruitMonster(*this, object, dst_index); break; - - // battle and recruit army - case MP2::OBJ_DRAGONCITY: - case MP2::OBJ_CITYDEAD: - case MP2::OBJ_TROLLBRIDGE: ActionToDwellingBattleMonster(*this, object, dst_index); break; - - case MP2::OBJ_ARTESIANSPRING: ActionToArtesianSpring(*this, object, dst_index); break; - - case MP2::OBJ_XANADU: ActionToXanadu(*this, object, dst_index); break; - - case MP2::OBJ_HILLFORT: - case MP2::OBJ_FREEMANFOUNDRY: ActionToUpgradeArmyObject(*this, object, dst_index); break; - - case MP2::OBJ_EVENT: ActionToEvent(*this, object, dst_index); break; - - case MP2::OBJ_OBELISK: ActionToObelisk(*this, object, dst_index); break; - - case MP2::OBJ_TREEKNOWLEDGE: ActionToTreeKnowledge(*this, object, dst_index); break; - - case MP2::OBJ_ORACLE: ActionToOracle(*this, object, dst_index); break; - case MP2::OBJ_SPHINX: ActionToShinx(*this, object, dst_index); break; - - // loyalty version - case MP2::OBJ_WATERALTAR: - case MP2::OBJ_AIRALTAR: - case MP2::OBJ_FIREALTAR: - case MP2::OBJ_EARTHALTAR: - case MP2::OBJ_BARROWMOUNDS: ActionToDwellingRecruitMonster(*this, object, dst_index); break; - case MP2::OBJ_ALCHEMYTOWER: ActionToAlchemistsTower(*this, object, dst_index); break; - case MP2::OBJ_STABLES: ActionToStables(*this, object, dst_index); break; - case MP2::OBJ_ARENA: ActionToArena(*this, object, dst_index); break; - case MP2::OBJ_MERMAID: ActionToGoodLuckObject(*this, object, dst_index); break; - case MP2::OBJ_SIRENS: ActionToSirens(*this, object, dst_index); break; - case MP2::OBJ_JAIL: ActionToJail(*this, object, dst_index); break; - case MP2::OBJ_HUTMAGI: ActionToHutMagi(*this, object, dst_index); break; - case MP2::OBJ_EYEMAGI: ActionToEyeMagi(*this, object, dst_index); break; - - case MP2::OBJ_BARRIER: ActionToBarrier(*this, object, dst_index); break; - case MP2::OBJ_TRAVELLERTENT: ActionToTravellersTent(*this, object, dst_index); break; - - // object - default: break; - } -} - -void ActionToMonster(Heroes &hero, const u8 obj, const s32 dst_index) -{ - bool destroy = false; - Maps::Tiles & tile = world.GetTiles(dst_index); - const Army::Troop troop(tile); - - - u32 join = 0; - Resource::funds_t cost; - - u8 reason = Army::GetJoinSolution(hero, tile, join, cost.gold); - - // free join - if(1 == reason) - { - DEBUG(DBG_AI , DBG_INFO, "ActionToMonster: " << hero.GetName() << " join monster " << troop.GetName()); - - std::string message = _("A group of %{monster} with a desire for greater glory wish to join you.\nDo you accept?"); - std::string monst = troop.GetMultiName(); - String::Lower(monst); - String::Replace(message, "%{monster}", monst); - - if(Dialog::Message("Followers", message, Font::BIG, Dialog::YES | Dialog::NO) == Dialog::YES) - hero.GetArmy().JoinTroop(troop); - else - { - Dialog::Message("", _("Insulted by your refusal of their offer, the monsters attack!"), Font::BIG, Dialog::OK); - reason = 0; - } - } - else - // join with cost - if(2 == reason) - { - std::string message; - if(troop.GetCount() == 1) - message = _("The creature is swayed by your diplomatic tongue, and offers to join your army for the sum of %{gold} gold.\nDo you accept?"); - else - { - message = _("The creatures are swayed by your diplomatic\ntongue, and make you an offer:\n \n"); - if(join != troop.GetCount()) - message += _("%{offer} of the %{total} %{monster} will join your army, and the rest will leave you alone, for the sum of %{gold} gold.\nDo you accept?"); - else - message += _("All %{offer} of the %{monster} will join your army for the sum of %{gold} gold.\nDo you accept?"); - } - - String::Replace(message, "%{offer}", join); - String::Replace(message, "%{total}", troop.GetCount()); - std::string monst = troop.GetPluralName(join); - String::Lower(monst); - String::Replace(message, "%{monster}", monst); - String::Replace(message, "%{gold}", cost.gold); - - if(Dialog::YES == Dialog::ResourceInfo("", message, cost, Dialog::YES | Dialog::NO)) - { - DEBUG(DBG_AI , DBG_INFO, "AIToMonster: " << hero.GetName() << " join monster " << troop.GetName() << ", count: " << join << ", cost: " << cost.gold); - - hero.GetArmy().JoinTroop(troop(), join); - world.GetKingdom(hero.GetColor()).OddFundsResource(cost); - } - else - { - Dialog::Message("", _("Insulted by your refusal of their offer, the monsters attack!"), Font::BIG, Dialog::OK); - reason = 0; - } - } - else - // flee - if(3 == reason) - { - std::string message = _("The %{monster}, awed by the power of your forces, begin to scatter.\nDo you wish to pursue and engage them?"); - std::string monst = troop.GetMultiName(); - String::Lower(monst); - String::Replace(message, "%{monster}", monst); - - if(Dialog::Message("", message, Font::BIG, Dialog::YES | Dialog::NO) == Dialog::NO) - destroy = true; - else - reason = 0; - } - - // fight - if(0 == reason) - { - DEBUG(DBG_GAME , DBG_INFO, "ActionToMonster: " << hero.GetName() << " attack monster " << troop.GetName()); - - Army::army_t army; - army.JoinTroop(troop); - army.ArrangeForBattle(); - - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - destroy = true; - hero.ActionAfterBattle(); - } - else - { - BattleLose(hero, res, true); - if(Settings::Get().ExtSaveMonsterBattle()) - { - tile.SetCountMonster(army.GetCountMonsters(troop())); - // reset "can join" - if(2 == tile.GetQuantity4()) tile.SetQuantity4(1); - } - } - } - // unknown - else - destroy = true; - - if(destroy) - { - Maps::TilesAddon *addon = tile.FindMonster(); - if(addon) - { - AGG::PlaySound(M82::KILLFADE); - const u32 uniq = addon->uniq; - AnimationRemoveObject(tile); - tile.Remove(uniq); - tile.SetObject(MP2::OBJ_ZERO); - tile.ResetQuantity(); - - // remove shadow from left cell - if(Maps::isValidDirection(dst_index, Direction::LEFT)) - world.GetTiles(Maps::GetDirectionIndex(dst_index, Direction::LEFT)).Remove(uniq); - } - } -} - -void ActionToHeroes(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Heroes *other_hero = world.GetHeroes(dst_index); - const Settings & conf = Settings::Get(); - - if(! other_hero) return; - - if(hero.GetColor() == other_hero->GetColor() || - (conf.ExtUnionsAllowHeroesMeetings() && conf.IsUnions(hero.GetColor(), other_hero->GetColor()))) - { - DEBUG(DBG_GAME, DBG_INFO, "ActionToHeroes: " << hero.GetName() << " meeting " << other_hero->GetName()); - hero.MeetingDialog(*other_hero); - } - else - if(! hero.AllowBattle()) - { - DEBUG(DBG_GAME, DBG_INFO, "ActionToHeroes: " << hero.GetName() << " currently can not allow battle"); - } - else - if(! other_hero->AllowBattle()) - { - DEBUG(DBG_GAME, DBG_INFO, "ActionToHeroes: " << other_hero->GetName() << " currently can not allow battle"); - } - else - { - if(other_hero->GetUnderObject() == MP2::OBJ_CASTLE) - { - ActionToCastle(hero, MP2::OBJ_CASTLE, dst_index); - return; - } - - DEBUG(DBG_GAME, DBG_INFO, "ActionToHeroes: " << hero.GetName() << " attack enemy hero " << other_hero->GetName()); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), other_hero->GetArmy(), dst_index); - - // loss defender - if(!res.DefenderWins()) - BattleLose(*other_hero, res, false, hero.GetColor()); - - // loss attacker - if(!res.AttackerWins()) - BattleLose(hero, res, true, other_hero->GetColor()); - - // wins attacker - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - hero.ActionAfterBattle(); - } - else - // wins defender - if(res.DefenderWins()) - { - other_hero->IncreaseExperience(res.GetExperienceDefender()); - other_hero->ActionAfterBattle(); - } - } -} - -void ActionToCastle(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Castle *castle = world.GetCastle(dst_index); - const Settings & conf = Settings::Get(); - - if(! castle) return; - - if(hero.GetColor() == castle->GetColor() || - (conf.ExtUnionsAllowCastleVisiting() && conf.IsUnions(hero.GetColor(), castle->GetColor()))) - { - DEBUG(DBG_GAME , DBG_INFO, "ActionToCastle: " << hero.GetName() << " goto castle " << castle->GetName()); - Mixer::Reduce(); - if(!conf.ExtLearnSpellsWithDay()) castle->GetMageGuild().EducateHero(hero); - Game::OpenCastle(castle); - Mixer::Enhance(); - } - else - { - DEBUG(DBG_GAME , DBG_INFO, "ActionToCastle: " << hero.GetName() << " attack enemy castle " << castle->GetName()); - - castle->MergeArmies(); - Army::army_t & army = castle->GetActualArmy(); - - if(army.isValid()) - { - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - Heroes *other_hero = world.GetHeroes(dst_index); - - // loss defender - if(!res.DefenderWins() && other_hero) - BattleLose(*other_hero, res, false, hero.GetColor()); - - // loss attacker - if(!res.AttackerWins()) - BattleLose(hero, res, true, castle->GetColor()); - - // wins attacker - if(res.AttackerWins()) - { - castle->GetArmy().Clear(); - - world.GetKingdom(castle->GetColor()).RemoveCastle(castle); - world.GetKingdom(hero.GetColor()).AddCastle(castle); - world.CaptureObject(dst_index, hero.GetColor()); - castle->Scoute(); - Interface::Basic::Get().SetRedraw(REDRAW_CASTLES); - - hero.IncreaseExperience(res.GetExperienceAttacker()); - hero.ActionAfterBattle(); - } - else - // wins defender - if(res.DefenderWins() && other_hero) - { - other_hero->IncreaseExperience(res.GetExperienceDefender()); - other_hero->ActionAfterBattle(); - } - } - else - { - world.GetKingdom(castle->GetColor()).RemoveCastle(castle); - world.GetKingdom(hero.GetColor()).AddCastle(castle); - world.CaptureObject(dst_index, hero.GetColor()); - castle->Scoute(); - Interface::Basic::Get().SetRedraw(REDRAW_CASTLES); - } - } -} - -void ActionToBoat(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(hero.isShipMaster()) return; - - const s32 from_index = hero.GetIndex(); - - Maps::Tiles & tiles_from = world.GetTiles(from_index); - Maps::Tiles & tiles_to = world.GetTiles(dst_index); - - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeOut(); - hero.ResetMovePoints(); - tiles_from.SetObject(MP2::OBJ_COAST); - hero.SetIndex(dst_index); - hero.SetShipMaster(true); - tiles_to.SetObject(MP2::OBJ_HEROES); - hero.SaveUnderObject(MP2::OBJ_ZERO); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToBoat: " << hero.GetName()); -} - -void ActionToCoast(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(! hero.isShipMaster()) return; - - s32 from_index = hero.GetIndex(); - - Maps::Tiles & tiles_from = world.GetTiles(from_index); - Maps::Tiles & tiles_to = world.GetTiles(dst_index); - - hero.ResetMovePoints(); - tiles_from.SetObject(MP2::OBJ_BOAT); - hero.SetIndex(dst_index); - hero.SetShipMaster(false); - tiles_to.SetObject(MP2::OBJ_HEROES); - hero.SaveUnderObject(MP2::OBJ_ZERO); - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeIn(); - - hero.ActionNewPosition(); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToCoast: " << hero.GetName()); -} - -void ActionToPickupResource(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - Resource::funds_t resource; - Resource::resource_t res = Resource::UNKNOWN; - const u8 count = tile.GetQuantity2(); - - switch(tile.GetQuantity1()) - { - case Resource::WOOD: res = Resource::WOOD; resource.wood += count; break; - case Resource::MERCURY: res = Resource::MERCURY; resource.mercury += count; break; - case Resource::ORE: res = Resource::ORE; resource.ore += count; break; - case Resource::SULFUR: res = Resource::SULFUR; resource.sulfur += count; break; - case Resource::CRYSTAL: res = Resource::CRYSTAL; resource.crystal += count; break; - case Resource::GEMS: res = Resource::GEMS; resource.gems += count; break; - case Resource::GOLD: res = Resource::GOLD; resource.gold += 100 * count; break; - - default: break; - } - - PlayPickupSound(); - AnimationRemoveObject(tile); - tile.RemoveObjectSprite(); - - // dialog - switch(obj) - { - case MP2::OBJ_CAMPFIRE: - // force reset sound - tile.SetObject(MP2::OBJ_ZERO); - Game::EnvironmentSoundMixer(); - - resource.gold += 100 * count; - Dialog::ResourceInfo(MP2::StringObject(obj), _("Ransacking an enemy camp, you discover a hidden cache of treasures."), resource); - break; - - case MP2::OBJ_BOTTLE: - Dialog::Message(MP2::StringObject(obj), world.MessageSign(dst_index), Font::BIG, Dialog::OK); - break; - - default: - { - Interface::Basic & I = Interface::Basic::Get(); - I.statusWindow.SetResource(res, (Resource::GOLD == res ? 100 * count : count)); - I.SetRedraw(REDRAW_STATUS); -// Display::Get().Flip(); - } - break; - } - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - tile.SetObject(MP2::OBJ_ZERO); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToPickupResource: " << hero.GetName()); -} - -void ActionToResource(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - const u8 count = tile.GetQuantity2(); - Resource::funds_t resource; - - switch(tile.GetQuantity1()) - { - case Resource::WOOD: resource.wood += count; break; - case Resource::MERCURY: resource.mercury += count; break; - case Resource::ORE: resource.ore += count; break; - case Resource::SULFUR: resource.sulfur += count; break; - case Resource::CRYSTAL: resource.crystal += count; break; - case Resource::GEMS: resource.gems += count; break; - case Resource::GOLD: resource.gold += 100 * count; break; - - default: break; - } - - if(resource.GetValidItems()) - { - PlaySoundSuccess; - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - } - - // dialog - switch(obj) - { - case MP2::OBJ_WINDMILL: - if(resource.GetValidItems()) - Dialog::ResourceInfo("", _("The keeper of the mill announces:\n\"Milord, I have been working very hard to provide you with these resources, come back next week for more.\""), resource); - else - Dialog::Message("", _("The keeper of the mill announces:\n\"Milord, I am sorry, there are no resources currently available. Please try again next week.\""), Font::BIG, Dialog::OK); - break; - - case MP2::OBJ_WATERWHEEL: - if(resource.GetValidItems()) - Dialog::ResourceInfo("", _("The keeper of the mill announces:\n\"Milord, I have been working very hard to provide you with this gold, come back next week for more.\""), resource); - else - Dialog::Message("", _("The keeper of the mill announces:\n\"Milord, I am sorry, there is no gold currently available. Please try again next week.\""), Font::BIG, Dialog::OK); - break; - - case MP2::OBJ_LEANTO: - if(resource.GetValidItems()) - Dialog::ResourceInfo("", _("You've found an abandoned lean-to.\nPoking about, you discover some resources hidden nearby."), resource); - else - Dialog::Message("", _("The lean-to is long abandoned. There is nothing of value here."), Font::BIG, Dialog::OK); - break; - - case MP2::OBJ_MAGICGARDEN: - if(resource.GetValidItems()) - Dialog::ResourceInfo("", _("You catch a leprechaun foolishly sleeping amidst a cluster of magic mushrooms.\nIn exchange for his freedom, he guides you to a small pot filled with precious things."), resource); - else - Dialog::Message("", _("You've found a magic garden, the kind of place that leprechauns and faeries like to cavort in, but there is no one here today.\nPerhaps you should try again next week."), Font::BIG, Dialog::OK); - break; - - default: break; - } - - tile.SetQuantity1(0); - tile.SetQuantity2(0); - - hero.SetVisited(dst_index, Visit::GLOBAL); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToResource: " << hero.GetName()); -} - -void ActionToSkeleton(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - // artifact - if(tile.GetQuantity1() && 0 == tile.GetQuantity2()) - { - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - if(hero.PickupArtifact(art())) - { - PlayPickupSound(); - std::string message(_("You come upon the remains of an unfortunate adventurer.\nSearching through the tattered clothing, you find %{artifact}.")); - String::Replace(message, "%{artifact}", art.GetName()); - DialogWithArtifact("", message, art()); - tile.SetQuantity1(0); - tile.SetQuantity2(0); - } - } - else - { - PlaySoundVisited; - Dialog::Message("", _("You come upon the remains of an unfortunate adventurer.\nSearching through the tattered clothing, you find nothing."), Font::BIG, Dialog::OK); - } - - hero.SetVisited(dst_index, Visit::GLOBAL); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToSkeleton: " << hero.GetName()); -} - -void ActionToWagon(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - // artifact - if(tile.GetQuantity1() && 0 == tile.GetQuantity2()) - { - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - if(hero.PickupArtifact(art())) - { - PlayPickupSound(); - std::string message(_("You come across an old wagon left by a trader who didn't quite make it to safe terrain.\nSearching inside, you find the %{artifact}.")); - String::Replace(message, "%{artifact}", art.GetName()); - DialogWithArtifact("", message, art()); - tile.SetQuantity1(0); - } - } - else - if(tile.GetQuantity1() && tile.GetQuantity2()) - { - const u8 count = tile.GetQuantity2(); - Resource::funds_t resource; - - switch(tile.GetQuantity1()) - { - case Resource::WOOD: resource.wood += count; break; - case Resource::MERCURY: resource.mercury += count; break; - case Resource::ORE: resource.ore += count; break; - case Resource::SULFUR: resource.sulfur += count; break; - case Resource::CRYSTAL: resource.crystal += count; break; - case Resource::GEMS: resource.gems += count; break; - case Resource::GOLD: resource.gold += 100 * count; break; - - default: break; - } - - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - - PlayPickupSound(); - Dialog::ResourceInfo("", _("You come across an old wagon left by a trader who didn't quite make it to safe terrain.\nInside, you find some of the wagon's cargo still intact."), resource); - - tile.SetQuantity1(0); - tile.SetQuantity2(0); - - } - else - { - PlaySoundVisited; - Dialog::Message("", _("You come across an old wagon left by a trader who didn't quite make it to safe terrain.\nUnfortunately, others have found it first, and the wagon is empty."), Font::BIG, Dialog::OK); - } - - hero.SetVisited(dst_index, Visit::GLOBAL); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToWagon: " << hero.GetName()); -} - -void ActionToFlotSam(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - std::string body; - Resource::funds_t resource; - - resource.gold += 100 * tile.GetQuantity1(); - resource.wood += tile.GetQuantity2(); - - if(resource.gold && resource.wood) - body = _("You search through the flotsam, and find some wood and some gold."); - else - if(resource.wood) - body = _("You search through the flotsam, and find some wood."); - else - if(resource.gold) - body = _("You search through the flotsam, and find some gold."); - else - body = _("You search through the flotsam, but find nothing."); - - PlayPickupSound(); - AnimationRemoveObject(tile); - - - if(resource.GetValidItems()) - { - Dialog::ResourceInfo(MP2::StringObject(obj), body, resource); - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - } - else - Dialog::Message(MP2::StringObject(obj), body, Font::BIG, Dialog::OK); - - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToFlotSam: " << hero.GetName()); -} - -void ActionToShrine(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Spell spell(Spell::FromInt(world.GetTiles(dst_index).GetQuantity1())); - const u8 spell_level = spell.GetLevel(); - - std::string head; - std::string body; - - switch(spell_level) - { - case 1: - head = _("Shrine of the 1st Circle"); - body = _("You come across a small shrine attended by a group of novice acolytes.\nIn exchange for your protection, they agree to teach you a simple spell - '%{spell}'."); - break; - case 2: - head = _("Shrine of the 2nd Circle"); - body = _("You come across an ornate shrine attended by a group of rotund friars.\nIn exchange for your protection, they agree to teach you a spell - '%{spell}'."); - break; - case 3: - head = _("Shrine of the 3rd Circle"); - body = _("You come across a lavish shrine attended by a group of high priests.\nIn exchange for your protection, they agree to teach you a sophisticated spell - '%{spell}'."); - break; - default: return; - } - - String::Replace(body, "%{spell}", spell.GetName()); - - // check spell book - if(!hero.HaveSpellBook()) - { - if(!Settings::Get().ExtBuySpellBookFromShrine() || !hero.BuySpellBook(NULL, spell_level)) - { - PlaySoundFailure; - body += _("\nUnfortunately, you have no Magic Book to record the spell with."); - Dialog::Message(head, body, Font::BIG, Dialog::OK); - } - } - - if(hero.HaveSpellBook()) - { - // check valid level spell and wisdom skill - if(3 == spell_level && Skill::Level::NONE == hero.GetLevelSkill(Skill::Secondary::WISDOM)) - { - PlaySoundFailure; - body += _("\nUnfortunately, you do not have the wisdom to understand the spell, and you are unable to learn it."); - Dialog::Message(head, body, Font::BIG, Dialog::OK); - } - else - // already know - if(hero.HaveSpell(spell())) - { - PlaySoundFailure; - body += _("\nUnfortunately, you already have knowledge of this spell, so there is nothing more for them to teach you."); - Dialog::Message(head, body, Font::BIG, Dialog::OK); - } - else - { - PlaySoundSuccess; - hero.AppendSpellToBook(spell()); - hero.SetVisited(dst_index, Visit::GLOBAL); - Dialog::SpellInfo(head, body, spell()); - } - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToShrine: " << hero.GetName()); -} - -void ActionToWitchsHut(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Skill::Secondary::skill_t skill = Skill::Secondary::Skill(world.GetTiles(dst_index).GetQuantity1()); - const std::string & skill_name = Skill::Secondary::String(skill); - const std::string head = _("Witch's Hut"); - - std::string body = _("You approach the hut and observe a witch inside studying an ancient tome on %{skill}.\n \n"); - String::Replace(body, "%{skill}", skill_name); - - // check full - if(hero.HasMaxSecondarySkill()) - { - Dialog::Message(head, body + _("As you approach, she turns and focuses her one glass eye on you.\n\"You already know everything you deserve to learn!\" the witch screeches. \"NOW GET OUT OF MY HOUSE!\""), Font::BIG, Dialog::OK); - } - else - // check present skill - if(hero.HasSecondarySkill(skill)) - { - Dialog::Message(head, body + _("As you approach, she turns and speaks.\n\"You already know that which I would teach you. I can help you no further.\""), Font::BIG, Dialog::OK); - } - else - { - hero.LearnBasicSkill(skill); - - body = _("An ancient and immortal witch living in a hut with bird's legs for stilts teaches you %{skill} for her own inscrutable purposes."); - String::Replace(body, "%{skill}", skill_name); - Dialog::SecondarySkillInfo(head, body, skill, Skill::Level::BASIC); - } - - hero.SetVisited(dst_index, Visit::GLOBAL); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToWitchsHut: " << hero.GetName()); -} - -void ActionToGoodLuckObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - std::string body_true; - std::string body_false; - - switch(obj) - { - case MP2::OBJ_FOUNTAIN: - body_false = _("You drink from the enchanted fountain, but nothing happens."); - body_true = _("As you drink the sweet water, you gain luck for your next battle."); - break; - - case MP2::OBJ_FAERIERING: - body_false = _("You enter the faerie ring, but nothing happens."); - body_true = _("Upon entering the mystical faerie ring, your army gains luck for its next battle."); - break; - - case MP2::OBJ_IDOL: - body_false = _("You've found an ancient and weathered stone idol.\nIt is supposed to grant luck to visitors, but since the stars are already smiling upon you, it does nothing."); - body_true = _("You've found an ancient and weathered stone idol.\nKissing it is supposed to be lucky, so you do. The stone is very cold to the touch."); - break; - - case MP2::OBJ_MERMAID: - body_false = _("The mermaids silently entice you to return later and be blessed again."); - body_true = _("The magical, soothing beauty of the Mermaids reaches you and your crew.\nJust for a moment, you forget your worries and bask in the beauty of the moment.\nThe mermaids charms bless you with increased luck for your next combat."); - break; - - default: return; - } - - // check already visited - if(hero.isVisited(obj)) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(obj), body_false, Font::BIG, Dialog::OK); - } - else - { - // modify luck - hero.SetVisited(dst_index); - AGG::PlaySound(M82::GOODLUCK); - DialogLuck(MP2::StringObject(obj), body_true, true, 1); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToGoodLuckObject: " << hero.GetName()); -} - -void ActionToPoorLuckObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - const bool battle = tile.CheckEnemyGuardians(); - bool complete = false; - std::string body; - - switch(obj) - { - case MP2::OBJ_PYRAMID: - if(battle) - { - PlaySoundWarning; - if(Dialog::YES == Dialog::Message("", _("You come upon the pyramid of a great and ancient king.\nYou are tempted to search it for treasure, but all the old stories warn of fearful curses and undead guardians.\nWill you search?"), Font::BIG, Dialog::YES|Dialog::NO)) - { - // battle - Army::army_t army; - army.FromGuardian(tile); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - if(res.AttackerWins()) - { - PlaySoundSuccess; - hero.IncreaseExperience(res.GetExperienceAttacker()); - complete = true; - const Spell::spell_t spell(Spell::FromInt(tile.GetQuantity1())); - // check magick book - if(!hero.HasArtifact(Artifact::MAGIC_BOOK)) - Dialog::Message(MP2::StringObject(obj), _("Unfortunately, you have no Magic Book to record the spell with."), Font::BIG, Dialog::OK); - else - // check skill level for wisdom - if(Skill::Level::EXPERT > hero.GetLevelSkill(Skill::Secondary::WISDOM)) - Dialog::Message(MP2::StringObject(obj), _("Unfortunately, you do not have the wisdom to understand the spell, and you are unable to learn it."), Font::BIG, Dialog::OK); - else - { - Dialog::SpellInfo(Spell::GetName(spell), _("Upon defeating the monsters, you decipher an ancient glyph on the wall, telling the secret of the spell."), spell, true); - hero.AppendSpellToBook(spell); - } - hero.ActionAfterBattle(); - } - else - { - BattleLose(hero, res, true); - } - } - } - else - body = _("You come upon the pyramid of a great and ancient king.\nRoutine exploration reveals that the pyramid is completely empty."); - break; - - default: return; - } - - if(complete) - { - tile.ResetQuantity(); - } - else - if(!battle && !hero.isVisited(obj)) - { - // modify luck - hero.SetVisited(dst_index); - hero.SetVisited(dst_index, Visit::GLOBAL); - AGG::PlaySound(M82::BADLUCK); - DialogLuck(MP2::StringObject(obj), body, false, 2); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToPoorLuckObject: " << hero.GetName()); -} - -void ActionToSign(Heroes &hero, const u8 obj, const s32 dst_index) -{ - PlaySoundWarning; - Dialog::Message("Sign", world.MessageSign(dst_index), Font::BIG, Dialog::OK); - DEBUG(DBG_GAME , DBG_INFO, "ActionToSign: " << hero.GetName()); -} - -void ActionToMagicWell(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const u16 max = hero.GetMaxSpellPoints(); - - if(hero.GetSpellPoints() == max) - { - PlaySoundFailure; - Dialog::Message(MP2::StringObject(MP2::OBJ_MAGICWELL), _("A drink at the well is supposed to restore your spell points, but you are already at maximum."), Font::BIG, Dialog::OK); - } - else - // check already visited - if(hero.isVisited(MP2::OBJ_MAGICWELL)) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(MP2::OBJ_MAGICWELL), _("A second drink at the well in one day will not help you."), Font::BIG, Dialog::OK); - } - else - { - PlaySoundSuccess; - hero.SetVisited(dst_index); - hero.SetSpellPoints(max); - Dialog::Message(MP2::StringObject(MP2::OBJ_MAGICWELL), _("A drink from the well has restored your spell points to maximum."), Font::BIG, Dialog::OK); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToMagicWell: " << hero.GetName()); -} - -void ActionToTradingPost(Heroes &hero, const u8 obj) -{ - PlaySoundSuccess; - Dialog::Marketplace(true); - DEBUG(DBG_GAME , DBG_INFO, "ActionToTradingPost: " << hero.GetName()); -} - -void ActionToPrimarySkillObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - - std::string body_false; - std::string body_true; - Skill::Primary::skill_t skill = Skill::Primary::ATTACK; - - switch(obj) - { - case MP2::OBJ_FORT: - skill = Skill::Primary::DEFENSE; - body_false = _("\"I'm sorry sir,\" The leader of the soldiers says, \"but you already know everything we have to teach.\""); - body_true = _("The soldiers living in the fort teach you a few new defensive tricks."); - break; - - case MP2::OBJ_MERCENARYCAMP: - skill = Skill::Primary::ATTACK; - body_false = _("You've come upon a mercenary camp practicing their tactics. \"You're too advanced for us,\" the mercenary captain says. \"We can teach nothing more.\""); - body_true = _("You've come upon a mercenary camp practicing their tactics. The mercenaries welcome you and your troops and invite you to train with them."); - break; - - case MP2::OBJ_DOCTORHUT: - skill = Skill::Primary::KNOWLEDGE; - body_false = _("\"Go 'way!\", the witch doctor barks, \"you know all I know.\""); - body_true = _("An Orcish witch doctor living in the hut deepens your knowledge of magic by showing you how to cast stones, read portents, and decipher the intricacies of chicken entrails."); - break; - - case MP2::OBJ_STANDINGSTONES: - skill = Skill::Primary::POWER; - body_false = _("You've found a group of Druids worshipping at one of their strange stone edifices. Silently, the Druids turn you away, indicating they have nothing new to teach you."); - body_true = _("You've found a group of Druids worshipping at one of their strange stone edifices. Silently, they teach you new ways to cast spells."); - break; - - default: return; - } - - // check already visited - if(hero.isVisited(tile)) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(obj), body_false, Font::BIG, Dialog::OK); - } - else - { - PlaySoundSuccess; - // increase skill - hero.IncreasePrimarySkill(skill); - hero.SetVisited(dst_index); - Dialog::PrimarySkillInfo(MP2::StringObject(obj), body_true, skill); - - // fix double action tile - if(obj == MP2::OBJ_STANDINGSTONES) - { - const Maps::TilesAddon* addon = tile.FindStandingStones(); - - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::LEFT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)); - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::RIGHT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)); - } - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToPrimarySkillObject: " << hero.GetName()); -} - -void ActionToPoorMoraleObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - const bool battle = (tile.GetQuantity1() || tile.GetQuantity2()); - bool complete = false; - std::string body; - - switch(obj) - { - case MP2::OBJ_GRAVEYARD: - if(battle) - { - PlaySoundWarning; - if(Dialog::YES == Dialog::Message("", _("You tentatively approach the burial ground of ancient warriors. Do you want to search the graves?"), Font::BIG, Dialog::YES | Dialog::NO)) - { - Army::army_t army; - army.FromGuardian(tile); - army.Dump(); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - complete = true; - const Artifact::artifact_t art = Artifact::FromInt(tile.GetQuantity1()); - Resource::funds_t resource; - resource.gold = tile.GetQuantity2() * 100; - PlaySoundSuccess; - DialogWithArtifactAndGold(MP2::StringObject(obj), _("Upon defeating the zomies you search the graves and find something!"), art, resource.gold); - hero.PickupArtifact(art); - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - hero.ActionAfterBattle(); - } - else - { - BattleLose(hero, res, true); - } - } - } - else - body = _("Upon defeating the Zombies you spend several hours searching the graves and find nothing. Such a despicable act reduces your army's morale."); - break; - - case MP2::OBJ_SHIPWRECK: - if(battle) - { - PlaySoundWarning; - if(Dialog::YES == Dialog::Message("", _("The rotting hulk of a great pirate ship creaks eerily as it is pushed against the rocks. Do you wish to search the shipwreck?"), Font::BIG, Dialog::YES | Dialog::NO)) - { - Army::army_t army; - army.FromGuardian(tile); - Resource::funds_t resource; - Artifact::artifact_t art = Artifact::UNKNOWN; - switch(tile.GetQuantity2()) - { - case 10: resource.gold = 1000; break; - case 15: resource.gold = 2000; break; - case 25: resource.gold = 5000; break; - case 50: resource.gold = 2000; art = Artifact::FromInt(tile.GetQuantity1()); break; - default: DEBUG(DBG_GAME , DBG_WARN, "ActionToPoorMoraleObject: unknown variant for ShipWreck, index: " << dst_index); break; - } - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - complete = true; - PlaySoundSuccess; - if(art == Artifact::UNKNOWN) - DialogWithGold(MP2::StringObject(obj), _("Upon defeating the Ghosts you sift through the debris and find something!"), resource.gold); - else - { - DialogWithArtifactAndGold(MP2::StringObject(obj), _("Upon defeating the Ghosts you sift through the debris and find something!"), art, resource.gold); - hero.PickupArtifact(art); - } - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - hero.ActionAfterBattle(); - } - else - { - BattleLose(hero, res, true); - } - } - } - else - body = _("Upon defeating the Ghosts you spend several hours sifting through the debris and find nothing. Such a despicable act reduces your army's morale."); - break; - - case MP2::OBJ_DERELICTSHIP: - if(battle) - { - PlaySoundWarning; - if(Dialog::YES == Dialog::Message("", _("The rotting hulk of a great pirate ship creaks eerily as it is pushed against the rocks. Do you wish to search the ship?"), Font::BIG, Dialog::YES | Dialog::NO)) - { - Army::army_t army; - army.FromGuardian(tile); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - complete = true; - Resource::funds_t resource; - resource.gold = tile.GetQuantity2() * 100; - PlaySoundSuccess; - DialogWithGold(MP2::StringObject(obj), _("Upon defeating the Skeletons you sift through the debris and find something!"), resource.gold); - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - hero.ActionAfterBattle(); - } - else - { - BattleLose(hero, res, true); - } - } - } - else - body = _("Upon defeating the Skeletons you spend several hours sifting through the debris and find nothing. Such a despicable act reduces your army's morale."); - break; - - default: return; - } - - if(complete) - { - tile.ResetQuantity(); - } - else - if(!battle && !hero.isVisited(obj)) - { - // modify morale - hero.SetVisited(dst_index); - hero.SetVisited(dst_index, Visit::GLOBAL); - AGG::PlaySound(M82::BADMRLE); - DialogMorale(MP2::StringObject(obj), body, false, 1); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToPoorMoraleObject: " << hero.GetName()); -} - -void ActionToGoodMoraleObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - - std::string body_true; - std::string body_false; - u16 move = 0; - - switch(obj) - { - case MP2::OBJ_BUOY: - body_false = _("Your men spot a navigational buoy, confirming that you are on course."); - body_true = _("Your men spot a navigational buoy, confirming that you are on course and increasing their morale."); - break; - - case MP2::OBJ_OASIS: - body_false = _("The drink at the oasis is refreshing, but offers no further benefit. The oasis might help again if you fought a battle first."); - body_true = _("A drink at the oasis fills your troops with strength and lifts their spirits. You can travel a bit further today."); - move = 800; // + 8TP, from FAQ - break; - - case MP2::OBJ_WATERINGHOLE: - body_false = _("The drink at the watering hole is refreshing, but offers no further benefit. The watering hole might help again if you fought a battle first."); - body_true = _("A drink at the watering hole fills your troops with strength and lifts their spirits. You can travel a bit further today."); - move = 400; // + 4TP, from FAQ - break; - - case MP2::OBJ_TEMPLE: - body_false = _("It doesn't help to pray twice before a battle. Come back after you've fought."); - body_true = _("A visit and a prayer at the temple raises the morale of your troops."); - break; - - default: return; - } - - // check already visited - if(hero.isVisited(obj)) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(obj), body_false, Font::BIG, Dialog::OK); - } - else - { - // modify morale - hero.SetVisited(dst_index); - AGG::PlaySound(M82::GOODMRLE); - DialogMorale(MP2::StringObject(obj), body_true, true, (obj == MP2::OBJ_TEMPLE ? 2 : 1)); - hero.IncreaseMovePoints(move); - - // fix double action tile - if(obj == MP2::OBJ_OASIS) - { - const Maps::TilesAddon* addon = tile.FindOasis(); - - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::LEFT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)); - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::RIGHT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)); - } - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToGoodMoraleObject: " << hero.GetName()); -} - - -void ActionToExperienceObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - - std::string body_true; - std::string body_false; - - u32 exp = 0; - - switch(obj) - { - case MP2::OBJ_GAZEBO: - body_false = _("An old Knight appears on the steps of the gazebo. \"I am sorry, my liege, I have taught you all I can.\""); - body_true = _("An old Knight appears on the steps of the gazebo. \"My liege, I will teach you all that I know to aid you in your travels.\""); - exp = 1000; - break; - - default: return; - } - - // check already visited - if(hero.isVisited(tile)) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(obj), body_false, Font::BIG, Dialog::OK); - } - else - { - PlaySoundWarning; - DialogWithExp(MP2::StringObject(obj), body_true, exp); - - // visit - hero.SetVisited(dst_index); - hero.IncreaseExperience(exp); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToExperienceObject: " << hero.GetName()); -} - -void ActionToShipwreckSurvivor(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - - PlaySoundSuccess; - if(hero.PickupArtifact(art())) - { - std::string str = _("You've pulled a shipwreck survivor from certain death in an unforgiving ocean. Grateful, he rewards you for your act of kindness by giving you the %{art}."); - String::Replace(str, "%{art}", art.GetName()); - DialogWithArtifact(MP2::StringObject(obj), str, art()); - } - else - { - Resource::funds_t prize(Resource::GOLD, 1500); - DialogWithGold(MP2::StringObject(obj), - _("You've pulled a shipwreck survivor from certain death in an unforgiving ocean. Grateful, he says, \"I would give you an artifact as a reward, but you're all full.\""), - prize.gold, Dialog::OK); - world.GetKingdom(hero.GetColor()).OddFundsResource(prize); - } - - AnimationRemoveObject(tile); - - tile.RemoveObjectSprite(); - tile.SetQuantity1(0); - tile.SetObject(MP2::OBJ_ZERO); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToShipwreckSurvivor: " << hero.GetName()); -} - -void ActionToArtifact(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - Artifact art(Artifact::FromInt(tile.GetQuantity1())); - - // update scroll artifact - if(art.GetID() == Artifact::SPELL_SCROLL) - { - art.SetExt(tile.GetQuantity3()); - } - - if(hero.IsFullBagArtifacts()) - { - Dialog::Message(Artifact::GetName(art()), _("You have no room to carry another artifact!"), Font::BIG, Dialog::OK); - return; - } - - bool conditions = false; - - switch(tile.GetQuantity2()) - { - // 1,2,3 - 2000g, 2500g+3res,3000g+5res - case 1: - case 2: - case 3: - { - std::string header; - Resource::funds_t payment; - - if(1 == tile.GetQuantity2()) - { - header = _("A leprechaun offers you the %{art} for the small price of %{gold} Gold."); - String::Replace(header, "%{gold}", 2000); - payment += Resource::funds_t(Resource::GOLD, 2000); - } - else - if(2 == tile.GetQuantity2()) - { - header = _("A leprechaun offers you the %{art} for the small price of %{gold} Gold and %{count} %{res}."); - String::Replace(header, "%{gold}", 2500); - String::Replace(header, "%{count}", 3); - String::Replace(header, "%{res}", Resource::String(tile.GetQuantity4())); - payment += Resource::funds_t(Resource::GOLD, 2500); - payment += Resource::funds_t(tile.GetQuantity4(), 3); - } - else - { - header = _("A leprechaun offers you the %{art} for the small price of %{gold} Gold and %{count} %{res}."); - String::Replace(header, "%{gold}", 3000); - String::Replace(header, "%{count}", 5); - String::Replace(header, "%{res}", Resource::String(tile.GetQuantity4())); - payment += Resource::funds_t(Resource::GOLD, 3000); - payment += Resource::funds_t(tile.GetQuantity4(), 5); - } - String::Replace(header, "%{art}", art.GetName()); - - PlaySoundWarning; - if(Dialog::YES == DialogWithArtifact(header, _("Do you wish to buy this artifact?"), art(), Dialog::YES | Dialog::NO)) - { - if(world.GetKingdom(hero.GetColor()).AllowPayment(payment)) - { - conditions = true; - world.GetKingdom(hero.GetColor()).OddFundsResource(payment); - } - else - { - PlaySoundFailure; - Dialog::Message("", _("You try to pay the leprechaun, but realize that you can't afford it. The leprechaun stamps his foot and ignores you."), Font::BIG, Dialog::OK); - } - } - else - Dialog::Message("", _("Insulted by your refusal of his generous offer, the leprechaun stamps his foot and ignores you."), Font::BIG, Dialog::OK); - break; - } - - // 4,5 - need have skill wisard or leadership, - case 4: - case 5: - { - if(hero.HasSecondarySkill(4 == tile.GetQuantity2() ? Skill::Secondary::WISDOM : Skill::Secondary::LEADERSHIP)) - { - PlaySoundSuccess; - std::string msg(_("You've found the artifact: ")); - msg.append(art.GetName()); - DialogWithArtifact(MP2::StringObject(obj), msg, art(), Dialog::OK); - conditions = true; - } - else - { - PlaySoundFailure; - if(4 == tile.GetQuantity2()) - { - std::string str = _("You've found the humble dwelling of a withered hermit. The hermit tells you that he is willing to give the %{art} to the first wise person he meets."); - String::Replace(str, "%{art}", art.GetName()); - Dialog::Message("", str, Font::BIG, Dialog::OK); - } - else - { - std::string str = _("You've come across the spartan quarters of a retired soldier. The soldier tells you that he is willing to pass on the %{art} to the first true leader he meets."); - String::Replace(str, "%{art}", art.GetName()); - Dialog::Message("", str, Font::BIG, Dialog::OK); - } - } - break; - } - - // 6 - 50 rogues, 7 - 1 gin, 8,9,10,11,12,13 - 1 monster level4 - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - { - bool battle = true; - Army::army_t army; - army.FromGuardian(tile); - const Army::Troop & troop = army.FirstValid(); - const std::string & monster = troop.GetName(); - - PlaySoundWarning; - - if(6 == tile.GetQuantity2()) - Dialog::Message("", _("You come upon an ancient artifact. As you reach for it, a pack of Rogues leap out of the brush to guard their stolen loot."), Font::BIG, Dialog::OK); - else - { - std::string str = _("Through a clearing you observe an ancient artifact. Unfortunately, it's guarded by a nearby %{monster}. Do you want to fight the %{monster} for the artifact?"); - String::Replace(str, "%{monster}", monster); - battle = (Dialog::YES == Dialog::Message("", str, Font::BIG, Dialog::YES | Dialog::NO)); - } - - if(battle) - { - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - conditions = true; - PlaySoundSuccess; - std::string str = _("Victorious, you take your prize, the %{art}."); - String::Replace(str, "%{art}", art.GetName()); - DialogWithArtifact(MP2::StringObject(obj), str, art()); - hero.ActionAfterBattle(); - } - else - { - BattleLose(hero, res, true); - } - } - else - { - PlaySoundFailure; - Dialog::Message("", _("Discretion is the better part of valor, and you decide to avoid this fight for today."), Font::BIG, Dialog::OK); - } - break; - } - - default: - PlaySoundSuccess; - std::string msg; - - if(Artifact::GetScenario(art())) - msg = Artifact::GetScenario(art()); - else - { - msg = (_("You've found the artifact: ")); - msg.append("\n"); - msg.append(art.GetName()); - } - - DialogWithArtifact(MP2::StringObject(obj), msg, art()); - conditions = true; - break; - } - - if(conditions && hero.PickupArtifact(art)) - { - PlayPickupSound(); - AnimationRemoveObject(tile); - - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - tile.ResetQuantity(); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToArtifact: " << hero.GetName()); -} - -void ActionToTreasureChest(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - Resource::funds_t resource; - resource.gold = tile.GetQuantity2() * 100; - - PlayPickupSound(); - AnimationRemoveObject(tile); - - // dialog - if(Maps::Ground::WATER == tile.GetGround()) - { - std::string message; - - // artifact - if(tile.GetQuantity1()) - { - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - - if(hero.PickupArtifact(art())) - { - message = _("After spending hours trying to fish the chest out of the sea, you open it and find %{gold} gold and the %{art}."); - String::Replace(message, "%{gold}", resource.gold); - String::Replace(message, "%{art}", art.GetName()); - DialogWithArtifactAndGold(_("Sea Chest"), message, art(), resource.gold); - } - else - { - resource.gold = 1500; // it is from FAQ - message = _("After spending hours trying to fish the chest out of the sea, you open it and find %{gold} gold pieces."); - String::Replace(message, "%{gold}", resource.gold); - DialogWithGold(_("Sea Chest"), message, resource.gold); - } - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - } - else - // resource - if(resource.gold) - { - message = _("After spending hours trying to fish the chest out of the sea, you open it and find %{gold} gold pieces."); - String::Replace(message, "%{gold}", resource.gold); - DialogWithGold(_("Sea Chest"), message, resource.gold); - - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - } - else - { - Dialog::Message(_("Sea Chest"), _("After spending hours trying to fish the chest out of the sea, you open it, only to find it empty."), Font::BIG, Dialog::OK); - } - } - else - { - std::string message; - - if(tile.GetQuantity1()) - { - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - - if(hero.PickupArtifact(art())) - { - message = _("After scouring the area, you fall upon a hidden chest, containing the ancient artifact %{art}."); - String::Replace(message, "%{art}", art.GetName()); - DialogWithArtifact(_("Treasure Chest"), message, art()); - } - else - { - resource.gold = 1000; // it is from FAQ - message = _("After scouring the area, you fall upon a hidden chest, containing the %{gold} gold pieces."); - String::Replace(message, "%{gold}", resource.gold); - DialogWithGold(_("Treasure Chest"), message, resource.gold); - } - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - } - else - if(resource.gold >= 1000) - { - const u16 expr = resource.gold - 500; - message = _("After scouring the area, you fall upon a hidden treasure cache. You may take the gold or distribute the gold to the peasants for experience. Do you wish to keep the gold?"); - - if(Dialog::SelectGoldOrExp(_("Treasure Chest"), message, resource.gold, expr)) - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - else - hero.IncreaseExperience(expr); - } - } - - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - tile.ResetQuantity(); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToTreasureChest: " << hero.GetName()); -} - -void ActionToAncientLamp(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - const u32 count = tile.GetCountMonster(); - - PlaySoundSuccess; - if(Dialog::YES == Dialog::Message(MP2::StringObject(obj), _("You stumble upon a dented and tarnished lamp lodged deep in the earth. Do you wish to rub the lamp?"), Font::BIG, Dialog::YES|Dialog::NO)) - { - const u16 recruit = Dialog::RecruitMonster(Monster::GENIE, count); - if(recruit) - { - if(hero.GetArmy().JoinTroop(Monster::GENIE, recruit)) - { - if(recruit == count) - { - PlayPickupSound(); - AnimationRemoveObject(tile); - tile.SetCountMonster(0); - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - } - else - tile.SetCountMonster(count - recruit); - - const payment_t paymentCosts(PaymentConditions::BuyMonster(Monster::GENIE) * recruit); - world.GetKingdom(hero.GetColor()).OddFundsResource(paymentCosts); - } - else - Dialog::Message(Monster::GetName(Monster::GENIE), _("You are unable to recruit at this time, your ranks are full."), Font::BIG, Dialog::OK); - } - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToAncientLamp: " << hero.GetName()); -} - -void ActionToTeleports(Heroes &hero, const s32 index_from) -{ - s32 index_to = world.NextTeleport(index_from); - hero.ApplyPenaltyMovement(); - - if(index_from == index_to) - { - AGG::PlaySound(M82::RSBRYFZL); - DEBUG(DBG_GAME , DBG_WARN, "ActionToTeleports: action unsuccessfully..."); - return; - } - - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeOut(); - - Cursor::Get().Hide(); - hero.SetIndex(index_to); - hero.Scoute(); - - world.GetTiles(index_from).SetObject(MP2::OBJ_STONELIGHTS); - world.GetTiles(index_to).SetObject(MP2::OBJ_HEROES); - - Interface::Basic & I = Interface::Basic::Get(); - Game::Focus & F = Game::Focus::Get(); - I.gameArea.Center(F.Center()); - F.SetRedraw(); - I.Redraw(); - - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeIn(); - - hero.ActionNewPosition(); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToStoneLights: " << hero.GetName()); -} - -void ActionToWhirlpools(Heroes &hero, const u8 obj, const s32 index_from) -{ - const s32 index_to = world.NextWhirlpool(index_from); - hero.ApplyPenaltyMovement(); - - if(index_from == index_to) - { - AGG::PlaySound(M82::RSBRYFZL); - DEBUG(DBG_GAME , DBG_WARN, "ActionToWhirlpools: action unsuccessfully..."); - return; - } - - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeOut(); - - Cursor::Get().Hide(); - hero.SetIndex(index_to); - hero.Scoute(); - - world.GetTiles(index_from).SetObject(MP2::OBJ_WHIRLPOOL); - world.GetTiles(index_to).SetObject(MP2::OBJ_HEROES); - - Interface::Basic & I = Interface::Basic::Get(); - Game::Focus & F = Game::Focus::Get(); - I.gameArea.Center(F.Center()); - F.SetRedraw(); - I.Redraw(); - - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeIn(); - - Army::Troop & troops = hero.GetArmy().GetWeakestTroop(); - - if(Rand::Get(1) && 1 < troops.GetCount()) - { - PlaySoundWarning; - Dialog::Message(_("A whirlpool engulfs your ship."), _("Some of your army has fallen overboard."), Font::BIG, Dialog::OK); - troops.SetCount(Monster::GetCountFromHitPoints(troops(), troops.GetHitPoints() - troops.GetHitPoints() * Game::GetWhirlpoolPercent() / 100)); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToWhirlpools: " << hero.GetName()); -} - -void ActionToAbandoneMine(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - PlaySoundWarning; - if(Dialog::YES == Dialog::Message("", _("You come upon an abandoned gold mine. The mine appears to be haunted. Do you wish to enter?"), Font::BIG, Dialog::YES | Dialog::NO)) - { - Army::army_t army; - army.FromGuardian(tile); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - if(res.AttackerWins()) - { - payment_t info = ProfitConditions::FromMine(tile.GetQuantity4()); - hero.IncreaseExperience(res.GetExperienceAttacker()); - PlaySoundSuccess; - std::string msg = _("You beat the Ghosts and are able to restore the mine to production."); - DialogCaptureResourceObject(MP2::StringObject(obj), msg, tile.GetQuantity4()); - tile.UpdateAbandoneMineSprite(); - tile.ResetQuantity(); - hero.SaveUnderObject(MP2::OBJ_MINES); - world.CaptureObject(dst_index, hero.GetColor()); - hero.ActionAfterBattle(); - } - else - { - BattleLose(hero, res, true); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToAbandoneMine: " << hero.GetName()); - } -} - -/* capture color object */ -void ActionToCaptureObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - std::string header; - std::string body; - - Resource::resource_t res = Resource::UNKNOWN; - - switch(obj) - { - case MP2::OBJ_ALCHEMYLAB: - res = Resource::MERCURY; - header = MP2::StringObject(obj); - body = _("You have taken control of the local Alchemist shop. It will provide you with %{count} unit of Mercury per day."); - break; - - case MP2::OBJ_SAWMILL: - res = Resource::WOOD; - header = MP2::StringObject(obj); - body = _("You gain control of a sawmill. It will provide you with %{count} units of wood per day."); - break; - - case MP2::OBJ_MINES: - { - res = static_cast(tile.GetMinesType()); - header = Maps::GetMinesName(res); - - switch(res) - { - case Resource::ORE: - body = _("You gain control of an ore mine. It will provide you with %{count} units of ore per day."); break; - case Resource::SULFUR: - body = _("You gain control of a sulfur mine. It will provide you with %{count} unit of sulfur per day."); break; - case Resource::CRYSTAL: - body = _("You gain control of a crystal mine. It will provide you with %{count} unit of crystal per day."); break; - case Resource::GEMS: - body = _("You gain control of a gem mine. It will provide you with %{count} unit of gems per day."); break; - case Resource::GOLD: - body = _("You gain control of a gold mine. It will provide you with %{count} gold per day."); break; - default: break; - } - } - break; - - case MP2::OBJ_LIGHTHOUSE: - header = MP2::StringObject(obj); - body = _("The lighthouse is now under your control, and all of your ships will now move further each turn."); - break; - - default: - DEBUG(DBG_GAME , DBG_WARN, "ActionToCaptureObject: unknown captured: " << MP2::StringObject(obj)); - return; - } - - // capture object - if(hero.GetColor() != world.ColorCapturedObject(dst_index)) - { - bool capture = true; - - // check guardians - if(tile.CheckEnemyGuardians(hero.GetColor())) - { - const Army::Troop troop(tile); - Army::army_t army; - army.JoinTroop(troop); - army.SetColor(world.ColorCapturedObject(dst_index)); - - Battle2::Result result = Battle2::Loader(hero.GetArmy(), army, dst_index); - - if(result.AttackerWins()) - { - hero.IncreaseExperience(result.GetExperienceAttacker()); - hero.ActionAfterBattle(); - - tile.ResetQuantity(); - } - else - { - capture = false; - BattleLose(hero, result, true); - if(Settings::Get().ExtSaveMonsterBattle()) - tile.SetCountMonster(army.GetCountMonsters(troop())); - } - } - - if(capture) - { - world.CaptureObject(dst_index, hero.GetColor()); - - if(res == Resource::UNKNOWN) - Dialog::Message(header, body, Font::BIG, Dialog::OK); - else - DialogCaptureResourceObject(header, body, res); - } - } - else - // set guardians - if(Settings::Get().ExtAllowSetGuardian()) - { - Army::Troop troop(tile); - - // check set with spell ? - bool readonly = tile.GetQuantity4(); - - if(Dialog::SetGuardian(hero, troop, readonly)) - { - tile.SetQuantity3(troop()); - tile.SetCountMonster(troop.GetCount()); - } - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToCaptureObject: " << hero.GetName() << " captured: " << MP2::StringObject(obj)); -} - -void ActionToDwellingJoinMonster(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - const u32 count = tile.GetCountMonster(); - - if(count) - { - hero.MovePointsScaleFixed(); - - const Monster monster(Monster::FromObject(obj)); - std::string message = _("A group of %{monster} with a desire for greater glory wish to join you. Do you accept?"); - String::Replace(message, "%{monster}", monster.GetMultiName()); - - AGG::PlaySound(M82::EXPERNCE); - if(Dialog::YES == Dialog::Message(MP2::StringObject(obj), message, Font::BIG, Dialog::YES|Dialog::NO)) - { - if(!hero.GetArmy().JoinTroop(monster, count)) - Dialog::Message(monster.GetName(), _("You are unable to recruit at this time, your ranks are full."), Font::BIG, Dialog::OK); - else - { - tile.SetCountMonster(0); - - if(Settings::Get().ExtHeroRecalculateMovement()) - hero.RecalculateMovePoints(); - } - } - } - else - { - Dialog::Message("", _("As you approach the dwelling, you notice that there is no one here."), Font::BIG, Dialog::OK); - } - - hero.SetVisited(dst_index, Visit::GLOBAL); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToDwellingJoinMonster: " << hero.GetName() << ", object: " << MP2::StringObject(obj)); -} - -void ActionToDwellingRecruitMonster(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - std::string msg_full, msg_void; - - switch(obj) - { - case MP2::OBJ_RUINS: - msg_void = _("You search the ruins, but the Medusas that used to live here are gone. Perhaps there will be more next week."); - msg_full = _("You've found some Medusas living in the ruins. They are willing to join your army for a price. Do you want to recruit Medusas?"); - break; - - case MP2::OBJ_TREECITY: - msg_void = _("You've found a Sprite Tree City. Unfortunately, none of the Sprites living there wish to join an army. Maybe next week."); - msg_full = _("Some of the Sprites living in the tree city are willing to join your army for a price. Do you want to recruit Sprites?"); - break; - - case MP2::OBJ_WAGONCAMP: - msg_void = _("A colorful Rogues' wagon stands empty here. Perhaps more Rogues will be here later."); - msg_full = _("Distant sounds of music and laughter draw you to a colorful wagon housing Rogues. Do you wish to have any Rogues join your army?"); - break; - - case MP2::OBJ_DESERTTENT: - msg_void = _("A group of tattered tents, billowing in the sandy wind, beckons you. The tents are unoccupied. Perhaps more Nomads will be here later."); - msg_full = _("A group of tattered tents, billowing in the sandy wind, beckons you. Do you wish to have any Nomads join you during your travels?"); - break; - - case MP2::OBJ_EARTHALTAR: - msg_void = _("The pit of mud bubbles for a minute and then lies still."); - msg_full = _("As you approach the bubbling pit of mud, creatures begin to climb out and position themselves around it. In unison they say: \"Mother Earth would like to offer you a few of her troops. Do you want to recruit Earth Elementals?\""); - break; - - case MP2::OBJ_AIRALTAR: - msg_void = _("You enter the structure of white stone pillars, and find nothing."); - msg_full = _("White stone pillars support a roof that rises up to the sky. As you enter the structure, the dead air of the outside gives way to a whirling gust that almost pushes you back out. The air current materializes into a barely visible form. The creature asks, in what can only be described as a loud whisper: \"Why have you come? Are you here to call upon the forces of the air?\""); - break; - - case MP2::OBJ_FIREALTAR: - msg_void = _("No Fire Elementals approach you from the lava pool."); - msg_full = _("Beneath a structure that serves to hold in heat, Fire Elementals move about in a fiery pool of molten lava. A group of them approach you and offer their services. Would you like to recruit Fire Elementals?"); - break; - - case MP2::OBJ_WATERALTAR: - msg_void = _("A face forms in the water for a moment, and then is gone."); - msg_full = _("Crystalline structures cast shadows over a small reflective pool of water. You peer into the pool, and a face that is not your own peers back. It asks: \"Would you like to call upon the powers of water?\""); - break; - - case MP2::OBJ_BARROWMOUNDS: - msg_void = _("This burial site is deathly still."); - msg_full = _("Restless spirits of long dead warriors seeking their final resting place offer to join you in hopes of finding peace. Do you wish to recruit ghosts?"); - break; - - default: return; - } - - const u32 count = tile.GetCountMonster(); - - std::string name_object(MP2::StringObject(obj)); - - if(count) - { - const Monster monster(Monster::FromObject(obj)); - - hero.MovePointsScaleFixed(); - - if(Dialog::YES == Dialog::Message(name_object, msg_full, Font::BIG, Dialog::YES | Dialog::NO)) - { - const u16 recruit = Dialog::RecruitMonster(monster, count); - if(recruit) - { - if(!hero.GetArmy().JoinTroop(monster, recruit)) - Dialog::Message(name_object, _("You are unable to recruit at this time, your ranks are full."), Font::BIG, Dialog::OK); - else - { - tile.SetCountMonster(count - recruit); - - const payment_t paymentCosts(PaymentConditions::BuyMonster(monster()) * recruit); - world.GetKingdom(hero.GetColor()).OddFundsResource(paymentCosts); - - if(Settings::Get().ExtHeroRecalculateMovement()) - hero.RecalculateMovePoints(); - } - } - } - } - else - { - Dialog::Message(name_object, msg_void, Font::BIG, Dialog::OK); - } - - hero.SetVisited(dst_index, Visit::GLOBAL); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToDwellingRecruitMonster: " << hero.GetName() << ", object: " << name_object); -} - -void ActionToDwellingBattleMonster(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - // yet no one captured. - const bool battle = (Color::GRAY == world.ColorCapturedObject(dst_index) && 0 == tile.GetQuantity4()); - const u32 count = tile.GetCountMonster(); - bool complete = false; - - const char* str_empty = NULL; - const char* str_full = NULL; - const char* str_warn = NULL; - const char* str_recr = NULL; - - switch(obj) - { - case MP2::OBJ_CITYDEAD: - str_empty = _("The City of the Dead is empty of life, and empty of unlife as well. Perhaps some undead will move in next week."); - str_full = _("Some Liches living here are willing to join your army for a price. Do you want to recruit Liches?"); - str_warn = _("You've found the ruins of an ancient city, now inhabited solely by the undead. Will you search?"); - str_recr = _("Some of the surviving Liches are impressed by your victory over their fellows, and offer to join you for a price. Do you want to recruit Liches?"); - break; - - case MP2::OBJ_TROLLBRIDGE: - str_empty = _("You've found one of those bridges that Trolls are so fond of living under, but there are none here. Perhaps there will be some next week."); - str_full = _("Some Trolls living under a bridge are willing to join your army, but for a price. Do you want to recruit Trolls?"); - str_warn = _("Trolls living under the bridge challenge you. Will you fight them?"); - str_recr = _("A few Trolls remain, cowering under the bridge. They approach you and offer to join your forces as mercenaries. Do you want to buy any Trolls?"); - break; - - case MP2::OBJ_DRAGONCITY: - str_empty = _("The Dragon city has no Dragons willing to join you this week. Perhaps a Dragon will become available next week."); - str_full = _("The Dragon city is willing to offer some Dragons for your army for a price. Do you wish to recruit Dragons?"); - str_warn = _("You stand before the Dragon City, a place off-limits to mere humans. Do you wish to violate this rule and challenge the Dragons to a fight?"); - str_recr = _("Having defeated the Dragon champions, the city's leaders agree to supply some Dragons to your army for a price. Do you wish to recruit Dragons?"); - break; - - default: return; - } - - if(!battle) - { - if(0 == count) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(obj), str_empty, Font::BIG, Dialog::OK); - } - else - { - PlaySoundSuccess; - complete = (Dialog::YES == Dialog::Message(MP2::StringObject(obj), str_full, Font::BIG, Dialog::YES | Dialog::NO)); - } - } - else - { - Army::army_t army; - army.FromGuardian(tile); - - PlaySoundWarning; - if(Dialog::YES == Dialog::Message(MP2::StringObject(obj), str_warn, Font::BIG, Dialog::YES | Dialog::NO)) - { - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - world.CaptureObject(dst_index, hero.GetColor()); - PlaySoundSuccess; - complete = (Dialog::YES == Dialog::Message(MP2::StringObject(obj), str_recr, Font::BIG, Dialog::YES | Dialog::NO)); - hero.ActionAfterBattle(); - tile.SetQuantity4(hero.GetColor()); - } - else - { - BattleLose(hero, res, true); - } - } - } - - // recruit monster - if(complete) - { - if(count) - { - hero.MovePointsScaleFixed(); - - const Monster monster(Monster::FromObject(obj)); - const u16 recruit = Dialog::RecruitMonster(monster, count); - if(recruit) - { - if(!hero.GetArmy().JoinTroop(monster, recruit)) - Dialog::Message(monster.GetName(), _("You are unable to recruit at this time, your ranks are full."), Font::BIG, Dialog::OK); - else - { - tile.SetCountMonster(count - recruit); - - const payment_t paymentCosts(PaymentConditions::BuyMonster(monster()) * recruit); - world.GetKingdom(hero.GetColor()).OddFundsResource(paymentCosts); - - if(Settings::Get().ExtHeroRecalculateMovement()) - hero.RecalculateMovePoints(); - } - } - } - - hero.SetVisited(dst_index, Visit::GLOBAL); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToDwellingBattleMonster: " << hero.GetName() << ", object: " << MP2::StringObject(obj)); -} - -void ActionToObservationTower(Heroes &hero, const u8 obj, const s32 dst_index) -{ - PlaySoundWarning; - Dialog::Message(MP2::StringObject(obj), _("From the observation tower, you are able to see distant lands."), Font::BIG, Dialog::OK); - Maps::ClearFog(dst_index, Game::GetViewDistance(Game::VIEW_OBSERVATION_TOWER), hero.GetColor()); -} - -void ActionToArtesianSpring(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const u16 max = hero.GetMaxSpellPoints(); - const std::string & name = MP2::StringObject(MP2::OBJ_ARTESIANSPRING); - - if(hero.isVisited(MP2::OBJ_ARTESIANSPRING)) - { - PlaySoundVisited; - Dialog::Message(name, _("The spring only refills once a week, and someone's already been here this week."), Font::BIG, Dialog::OK); - } - else - if(hero.GetSpellPoints() == max * 2) - { - PlaySoundFailure; - Dialog::Message(name, _("A drink at the spring is supposed to give you twice your normal spell points, but you are already at that level."), Font::BIG, Dialog::OK); - } - else - { - PlaySoundSuccess; - hero.SetVisited(dst_index); - hero.SetSpellPoints(max * 2); - Dialog::Message(name, _("A drink from the spring fills your blood with magic! You have twice your normal spell points in reserve."), Font::BIG, Dialog::OK); - - // fix double action tile - { - const Maps::Tiles & tile = world.GetTiles(dst_index); - const Maps::TilesAddon* addon = tile.FindArtesianSpring(); - - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::LEFT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)); - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::RIGHT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)); - } - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToArtesianSpring: " << hero.GetName()); -} - -void ActionToXanadu(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - - if(hero.isVisited(tile)) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(obj), _("Recognizing you, the butler refuses to admit you. \"The master,\" he says, \"will not see the same student twice.\""), Font::BIG, Dialog::OK); - } - else - { - bool access = false; - switch(hero.GetLevelSkill(Skill::Secondary::DIPLOMACY)) - { - case Skill::Level::BASIC: - if(7 < hero.GetLevel()) access = true; break; - case Skill::Level::ADVANCED: - if(5 < hero.GetLevel()) access = true; break; - case Skill::Level::EXPERT: - if(3 < hero.GetLevel()) access = true; break; - default: - if(9 < hero.GetLevel()) access = true; break; - } - - if(access) - { - PlaySoundSuccess; - Dialog::Message(MP2::StringObject(obj), _("The butler admits you to see the master of the house. He trains you in the four skills a hero should know."), Font::BIG, Dialog::OK); - hero.IncreasePrimarySkill(Skill::Primary::ATTACK); - hero.IncreasePrimarySkill(Skill::Primary::DEFENSE); - hero.IncreasePrimarySkill(Skill::Primary::KNOWLEDGE); - hero.IncreasePrimarySkill(Skill::Primary::POWER); - hero.SetVisited(dst_index); - } - else - { - PlaySoundFailure; - Dialog::Message(MP2::StringObject(obj), _("The butler opens the door and looks you up and down. \"You are neither famous nor diplomatic enough to be admitted to see my master,\" he sniffs. \"Come back when you think yourself worthy.\""), Font::BIG, Dialog::OK); - } - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToXanadu: " << hero.GetName()); -} - -void ActionToUpgradeArmyObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - std::string monsters; - std::string monsters_upgrade; - std::string msg1; - std::string msg2; - std::string msg3; - - std::vector mons; - mons.reserve(3); - - hero.MovePointsScaleFixed(); - - switch(obj) - { - case MP2::OBJ_HILLFORT: - if(hero.GetArmy().HasMonster(Monster::DWARF)) - { - hero.GetArmy().UpgradeMonsters(Monster::DWARF); - mons.push_back(Monster::DWARF); - monsters = Monster(Monster::DWARF).GetMultiName(); - monsters_upgrade = Monster(Monster::Upgrade(Monster::DWARF)).GetMultiName(); - } - if(hero.GetArmy().HasMonster(Monster::ORC)) - { - hero.GetArmy().UpgradeMonsters(Monster::ORC); - mons.push_back(Monster::ORC); - if(monsters.size()) monsters += ", "; - monsters += Monster(Monster::ORC).GetMultiName(); - if(monsters_upgrade.size()) monsters_upgrade += ", "; - monsters_upgrade += Monster(Monster::Upgrade(Monster::ORC)).GetMultiName(); - } - if(hero.GetArmy().HasMonster(Monster::OGRE)) - { - hero.GetArmy().UpgradeMonsters(Monster::OGRE); - mons.push_back(Monster::OGRE); - if(monsters.size()) monsters += ", "; - monsters += Monster(Monster::OGRE).GetMultiName(); - if(monsters_upgrade.size()) monsters_upgrade += ", "; - monsters_upgrade += Monster(Monster::Upgrade(Monster::OGRE)).GetMultiName(); - } - msg1 = _("All of the %{monsters} you have in your army have been trained by the battle masters of the fort. Your army now contains %{monsters2}."); - String::Replace(msg1, "%{monsters}", monsters); - String::Replace(msg1, "%{monsters2}", monsters_upgrade); - msg2 = _("An unusual alliance of Orcs, Ogres, and Dwarves offer to train (upgrade) any such troops brought to them. Unfortunately, you have none with you."); - break; - - case MP2::OBJ_FREEMANFOUNDRY: - if(hero.GetArmy().HasMonster(Monster::PIKEMAN)) - { - hero.GetArmy().UpgradeMonsters(Monster::PIKEMAN); - mons.push_back(Monster::PIKEMAN); - monsters = Monster(Monster::PIKEMAN).GetMultiName(); - monsters_upgrade = Monster(Monster::Upgrade(Monster::PIKEMAN)).GetMultiName(); - } - if(hero.GetArmy().HasMonster(Monster::SWORDSMAN)) - { - hero.GetArmy().UpgradeMonsters(Monster::SWORDSMAN); - mons.push_back(Monster::SWORDSMAN); - if(monsters.size()) monsters += ", "; - monsters += Monster(Monster::SWORDSMAN).GetMultiName(); - if(monsters_upgrade.size()) monsters_upgrade += ", "; - monsters_upgrade += Monster(Monster::Upgrade(Monster::SWORDSMAN)).GetMultiName(); - } - if(hero.GetArmy().HasMonster(Monster::IRON_GOLEM)) - { - hero.GetArmy().UpgradeMonsters(Monster::IRON_GOLEM); - mons.push_back(Monster::IRON_GOLEM); - if(monsters.size()) monsters += ", "; - monsters += Monster(Monster::IRON_GOLEM).GetMultiName(); - if(monsters_upgrade.size()) monsters_upgrade += ", "; - monsters_upgrade += Monster(Monster::Upgrade(Monster::IRON_GOLEM)).GetMultiName(); - } - msg1 = _("All of your %{monsters} have been upgraded into %{monsters2}."); - String::Replace(msg1, "%{monsters}", monsters); - String::Replace(msg1, "%{monsters2}", monsters_upgrade); - msg2 = _("A blacksmith working at the foundry offers to convert all Pikemen and Swordsmen's weapons brought to him from iron to steel. He also says that he knows a process that will convert Iron Golems into Steel Golems. Unfortunately, you have none of these troops in your army, so he can't help you."); - break; - - default: break; - } - - if(mons.size()) - { - // composite sprite - u8 ox = 0; - const Sprite & br = AGG::GetICN(ICN::STRIP, 12); - Surface sf(br.w() * mons.size() + (mons.size() - 1) * 4, br.h()); - sf.SetColorKey(); - std::vector::const_iterator it1 = mons.begin(); - std::vector::const_iterator it2 = mons.end(); - for(; it1 != it2; ++it1) - { - sf.Blit(br, ox, 0); - switch(Monster(*it1).GetRace()) - { - case Race::KNGT: sf.Blit(AGG::GetICN(ICN::STRIP, 4), ox + 6, 6); break; - case Race::BARB: sf.Blit(AGG::GetICN(ICN::STRIP, 5), ox + 6, 6); break; - case Race::SORC: sf.Blit(AGG::GetICN(ICN::STRIP, 6), ox + 6, 6); break; - case Race::WRLK: sf.Blit(AGG::GetICN(ICN::STRIP, 7), ox + 6, 6); break; - case Race::WZRD: sf.Blit(AGG::GetICN(ICN::STRIP, 8), ox + 6, 6); break; - case Race::NECR: sf.Blit(AGG::GetICN(ICN::STRIP, 9), ox + 6, 6); break; - default: sf.Blit(AGG::GetICN(ICN::STRIP, 10), ox + 6, 6); break; - } - const Sprite & mon = AGG::GetICN(Monster(Monster::Upgrade(*it1)).ICNMonh(), 0); - sf.Blit(mon, ox + 6 + mon.x(), 6 + mon.y()); - ox += br.w() + 4; - } - Dialog::SpriteInfo(MP2::StringObject(obj), msg1, sf); - - if(Settings::Get().ExtHeroRecalculateMovement()) - hero.RecalculateMovePoints(); - } - else - { - PlaySoundFailure; - Dialog::Message(MP2::StringObject(obj), msg2, Font::BIG, Dialog::OK); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToUpgradeArmyObject: " << hero.GetName()); -} - -void ActionToMagellanMaps(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(1000 > world.GetKingdom(hero.GetColor()).GetFundsGold()) - { - PlaySoundFailure; - Dialog::Message(MP2::StringObject(obj), _("The captain sighs. \"You don't have enough money, eh? You can't expect me to give my maps away for free!\""), Font::BIG, Dialog::OK); - } - else - { - PlaySoundWarning; - if(Dialog::YES == Dialog::Message(MP2::StringObject(obj), _("A retired captain living on this refurbished fishing platform offers to sell you maps of the sea he made in his younger days for 1,000 gold. Do you wish to buy the maps?"), Font::BIG, Dialog::YES | Dialog::NO)) - world.ActionForMagellanMaps(hero.GetColor()); - - Game::Focus::Get().SetRedraw(); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToMagellanMaps: " << hero.GetName()); -} - -void ActionToEvent(Heroes &hero, const u8 obj, const s32 dst_index) -{ - // check event maps - const GameEvent::Coord* event_maps = world.GetEventMaps(hero.GetColor(), dst_index); - if(event_maps) - { - if(event_maps->GetResource().GetValidItems()) - { - world.GetKingdom(hero.GetColor()).AddFundsResource(event_maps->GetResource()); - PlaySoundSuccess; - Dialog::ResourceInfo("", event_maps->GetMessage(), event_maps->GetResource()); - } - else - if(event_maps->GetMessage().size()) - Dialog::Message("", event_maps->GetMessage(), Font::BIG, Dialog::OK); - - if(Artifact::UNKNOWN != event_maps->GetArtifact()) - { - if(hero.PickupArtifact(event_maps->GetArtifact())) - { - PlayPickupSound(); - std::string message(_("You find %{artifact}.")); - String::Replace(message, "%{artifact}", Artifact::GetName(event_maps->GetArtifact())); - DialogWithArtifact("", message, event_maps->GetArtifact()); - } - } - } - - hero.SaveUnderObject(MP2::OBJ_ZERO); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToEvent: " << hero.GetName()); -} - -void ActionToObelisk(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - if(!hero.isVisited(world.GetTiles(dst_index), Visit::GLOBAL)) - { - hero.SetVisited(dst_index, Visit::GLOBAL); - kingdom.PuzzleMaps().Update(kingdom.CountVisitedObjects(MP2::OBJ_OBELISK), world.CountObeliskOnMaps()); - AGG::PlaySound(M82::EXPERNCE); - Dialog::Message(MP2::StringObject(obj), _("You come upon an obelisk made from a type of stone you have never seen before. Staring at it intensely, the smooth surface suddenly changes to an inscription. The inscription is a piece of a lost ancient map. Quickly you copy down the piece and the inscription vanishes as abruptly as it appeared."), Font::BIG, Dialog::OK); - kingdom.PuzzleMaps().ShowMapsDialog(); - } - else - Dialog::Message(MP2::StringObject(obj), _("You have already been to this obelisk."), Font::BIG, Dialog::OK); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToObelisk: " << hero.GetName()); -} - -void ActionToTreeKnowledge(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - - if(hero.isVisited(tile)) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(obj), _("Upon your approach, the tree opens its eyes in delight. \"It is good to see you, my student. I hope my teachings have helped you.\""), Font::BIG, Dialog::OK); - } - else - { - bool conditions = false; - Resource::funds_t payment; - switch(tile.GetQuantity2()) - { - case 10: payment.gems = 10; break; - case 20: payment.gold = 2000; break; - default: conditions = true; break; - } - - if(conditions) - { - const Sprite & sprite = AGG::GetICN(ICN::EXPMRL, 4); - const std::string & body = _("Upon your approach, the tree opens its eyes in delight. \"Ahh, an adventurer! Allow me to teach you a little of what I have learned over the ages.\""); - Dialog::SpriteInfo(MP2::StringObject(obj), body, sprite); - } - else - { - if(world.GetKingdom(hero.GetColor()).AllowPayment(payment)) - { - const Sprite & sprite = AGG::GetICN(ICN::EXPMRL, 4); - std::string body = _("Upon your approach, the tree opens its eyes in delight."); - body += " "; - body += payment.gold ? _("\"Ahh, an adventurer! I will be happy to teach you a little of what I have learned over the ages for a mere 2000 gold.\"") : - _("\"Ahh, an adventurer! I will be happy to teach you a little of what I have learned over the ages for a mere 10 gems.\""); - body += " "; - body += _("(Just bury it around my roots.)"); - conditions = Dialog::YES == Dialog::SpriteInfo(MP2::StringObject(obj), body, sprite, Dialog::YES|Dialog::NO); - } - else - { - std::string body = _("Tears brim in the eyes of the tree."); - body += " "; - body += payment.gold ? _("\"I need 2000 gold.\"") : _("\"I need 10 gems.\""); - body += " "; - body += _("it whispers. (sniff) \"Well, come back when you can pay me.\""); - Dialog::Message(MP2::StringObject(obj), body, Font::BIG, Dialog::OK); - } - } - - if(conditions) - { - if(payment.GetValidItems()) world.GetKingdom(hero.GetColor()).OddFundsResource(payment); - hero.SetVisited(dst_index); - hero.IncreaseExperience(hero.GetExperienceFromLevel(hero.GetLevel()) - hero.GetExperience()); - } - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToTreeKnowledge: " << hero.GetName()); -} - -void ActionToOracle(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Dialog::ThievesGuild(true); - DEBUG(DBG_GAME , DBG_INFO, "ActionToOracle: " << hero.GetName()); -} - -void ActionToDaemonCave(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - if(Dialog::YES == Dialog::Message(MP2::StringObject(obj), _("The entrance to the cave is dark, and a foul, sulfurous smell issues from the cave mouth. Will you enter?"), Font::BIG, Dialog::YES|Dialog::NO)) - { - if(tile.GetQuantity2()) - { - Resource::funds_t resource; - - if(Dialog::YES == Dialog::Message("", _("You find a powerful and grotesque Demon in the cave. \"Today,\" it rasps, \"you will fight and surely die. But I will give you a choice of deaths. You may fight me, or you may fight my servants. Do you prefer to fight my servants?\""), Font::BIG, Dialog::YES|Dialog::NO)) - { - // battle with earth elements - Army::army_t army; - army.FromGuardian(tile); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - hero.ActionAfterBattle(); - resource.gold = 2500; - DialogWithGold("", _("Upon defeating the daemon's servants, you find a hidden cache with 2500 gold."), 2500); - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - tile.SetQuantity2(0); - } - else - { - BattleLose(hero, res, true); - } - } - // check variants - else - { - u16 exp = 0; - switch(tile.GetQuantity2()) - { - case 1: - exp = 1000; - DialogWithExp("", _("The Demon screams its challenge and attacks! After a short, desperate battle, you slay the monster and receive 1,000 experience points."), exp); - hero.IncreaseExperience(exp); - tile.SetQuantity2(0); - break; - case 2: - { - exp = 1000; - const Artifact::artifact_t art = Artifact::FromInt(tile.GetQuantity1()); - std::string str = _("The Demon screams its challenge and attacks! After a short, desperate battle, you slay the monster and find the %{art} in the back of the cave."); - String::Replace(str, "%{art}", Artifact::GetName(art)); - if(Artifact::UNKNOWN != art) DialogArtifactWithExp("", str, art, exp); - hero.PickupArtifact(art); - hero.IncreaseExperience(exp); - tile.SetQuantity1(Artifact::UNKNOWN); - tile.SetQuantity2(0); - break; - } - case 3: - exp = 1000; - resource.gold = 2500; - DialogGoldWithExp("", _("The Demon screams its challenge and attacks! After a short, desperate battle, you slay the monster and receive 1,000 experience points and 2,500 gold."), resource.gold, exp); - hero.IncreaseExperience(exp); - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - tile.SetQuantity2(0); - break; - default: - { - bool remove = true; - if(2500 <= world.GetKingdom(hero.GetColor()).GetFundsGold()) - { - if(Dialog::YES == Dialog::Message("", _("The Demon leaps upon you and has its claws at your throat before you can even draw your sword. \"Your life is mine,\" it says. \"I will sell it back to you for 2,500 gold.\""), Font::BIG, Dialog::YES|Dialog::NO)) - { - remove = false; - resource.gold = 2500; - world.GetKingdom(hero.GetColor()).OddFundsResource(resource); - } - } - else - Dialog::Message("", _("Seeing that you do not have 2500 gold, the demon slashes you with its claws, and the last thing you see is a red haze."), Font::BIG, Dialog::OK); - - if(remove) - { - Battle2::Result res; - res.army1 = Battle2::RESULT_LOSS; - BattleLose(hero, res, true); - } - tile.SetQuantity2(0); - break; - } - } - } - } - else - Dialog::Message("", _("Except for evidence of a terrible battle, the cave is empty."), Font::BIG, Dialog::OK); - - hero.SetVisited(dst_index, Visit::GLOBAL); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToDaemonCave: " << hero.GetName()); -} - -void ActionToAlchemistsTower(Heroes &hero, const u8 obj, const s32 dst_index) -{ -/* -As you enter the Alchemist's Tower, a hobbled, graying man in a brown cloak makes his way towards you. e checks your pack, and sees -that you have 1 cursed item. For 750 gold, the alchemist will remove it for you. Do you pay? -As you enter the Alchemist's Tower, a hobbled, graying man in a brown cloak makes his way towards you. He checks your pack, and sees -that you have %d cursed items. For 750 gold, the alchemist will remove them for you. Do you pay? -You hear a voice from behind the locked door, "You don't have enough gold to pay for my services." -You hear a voice from high above in the tower, "Go away! I can't help you!" -*/ - Dialog::Message("", _("You hear a voice from high above in the tower, \"Go away! I can't help you!\""), Font::BIG, Dialog::OK); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToAlchemistsTower: " << hero.GetName()); -} - -void ActionToStables(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const bool cavalry = hero.GetArmy().HasMonster(Monster::CAVALRY); - const bool visited = hero.isVisited(obj); - std::string body; - - if(!cavalry && visited) - body = _("The head groom approaches you and speaks, \"You already have a fine horse, and have no inexperienced cavalry which might make use of our trained war horses.\""); - else - if(!cavalry && !visited) - body = _("As you approach the stables, the head groom appears, leading a fine looking war horse. \"This steed will help speed you in your travels. Alas, his endurance will wane with a lot of heavy riding, and you must return for a fresh mount in a week. We also have many fine war horses which could benefit mounted soldiers, but you have none we can help.\""); - else - if(cavalry && visited) - body = _("The head groom speaks to you, \"That is a fine looking horse you have. I am afraid we can give you no better, but the horses your cavalry are riding look to be of poor breeding stock. We have many trained war horses which would aid your riders greatly. I insist you take them.\""); - else - if(cavalry && !visited) - body = _("As you approach the stables, the head groom appears, leading a fine looking war horse. \"This steed will help speed you in your travels. Alas, he will grow tired in a week. You must also let me give better horses to your mounted soldiers, their horses look shoddy and weak.\""); - - - // check already visited - if(visited) - { - PlaySoundVisited; - } - else - { - hero.SetVisited(dst_index); - PlaySoundSuccess; - hero.IncreaseMovePoints(400); - } - - if(cavalry) hero.GetArmy().UpgradeMonsters(Monster::CAVALRY); - - Dialog::Message("", body, Font::BIG, Dialog::OK); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToStables: " << hero.GetName()); -} - -void ActionToArena(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(hero.isVisited(obj)) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(obj), _("The Arena guards turn you away."), Font::BIG, Dialog::OK); - } - else - { - hero.SetVisited(dst_index); - PlaySoundSuccess; - hero.IncreasePrimarySkill(Dialog::SelectSkillFromArena()); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToArena: " << hero.GetName()); -} - -void ActionToSirens(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(hero.isVisited(obj, Visit::GLOBAL)) - { - PlaySoundVisited; - Dialog::Message(MP2::StringObject(obj), _("As the sirens sing their eerie song, your small, determined army manages to overcome the urge to dive headlong into the sea."), Font::BIG, Dialog::OK); - } - else - { - u32 exp = hero.GetArmy().ActionToSirens(); - std::string str = _("You have your crew stop up their ears with wax before the sirens' eerie song has any chance of luring them to a watery grave. An eerie wailing song emanates from the sirens perched upon the rocks. Many of your crew fall under its spell, and dive into the water where they drown. You are now wiser for the visit, and gain %{exp} experience."); - String::Replace(str, "%{exp}", exp); - - hero.SetVisited(dst_index, Visit::GLOBAL); - PlaySoundSuccess; - Dialog::Message(MP2::StringObject(obj), str, Font::BIG, Dialog::OK); - hero.IncreaseExperience(exp); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToSirens: " << hero.GetName()); -} - -void ActionToJail(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - - if(kingdom.AllowRecruitHero(false, 0)) - { - Maps::Tiles & tile = world.GetTiles(dst_index); - PlaySoundSuccess; - Dialog::Message(MP2::StringObject(obj), _("In a dazzling display of daring, you break into the local jail and free the hero imprisoned there, who, in return, pledges loyalty to your cause."), Font::BIG, Dialog::OK); - - AnimationRemoveObject(tile); - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - - Heroes *prisoner = world.FromJail(tile.GetIndex()); - - if(prisoner) - { - const Point center(tile.GetIndex() % world.w(), tile.GetIndex() / world.w()); - if(prisoner->Recruit(hero.GetColor(), center)) - prisoner->ResetModes(Heroes::JAIL); - } - } - else - { - std::string str = _("You already have %{count} heroes, and regretfully must leave the prisoner in this jail to languish in agony for untold days."); - String::Replace(str, "%{count}", Kingdom::GetMaxHeroes()); - PlaySoundFailure; - Dialog::Message(MP2::StringObject(obj), str, Font::BIG, Dialog::OK); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToJail: " << hero.GetName()); -} - -void ActionToHutMagi(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Dialog::Message(MP2::StringObject(obj), _("You enter a rickety hut and talk to the magician who lives there. He tells you of places near and far which may aid you in your journeys."), Font::BIG, Dialog::OK); - - if(!hero.isVisited(obj, Visit::GLOBAL)) - { - hero.SetVisited(dst_index, Visit::GLOBAL); - world.ActionToEyeMagi(hero.GetColor()); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToHutMagi: " << hero.GetName()); -} - -void ActionToEyeMagi(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Dialog::Message(MP2::StringObject(obj), _("This eye seems to be intently studying its surroundings."), Font::BIG, Dialog::OK); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToEyeMagi: " << hero.GetName()); -} - -void ActionToShinx(Heroes &hero, const u8 obj, const s32 dst_index) -{ - GameEvent::Riddle* riddle = world.GetSphinx(dst_index); - - if(riddle && riddle->isValid()) - { - if(Dialog::YES == Dialog::Message("", _("\"I have a riddle for you,\" the Sphinx says. \"Answer correctly, and you shall be rewarded. Answer incorrectly, and you shall be eaten. Do you accept the challenge?\""), Font::BIG, Dialog::YES|Dialog::NO)) - { - std::string header(_("The Sphinx asks you the following riddle: %{riddle}. Your answer?")); - String::Replace(header, "%{riddle}", riddle->GetMessage()); - std::string answer; - Dialog::InputString(header, answer); - if(riddle->AnswerCorrect(answer)) - { - const Resource::funds_t & res = riddle->GetResource(); - const Artifact::artifact_t art = riddle->GetArtifact(); - const std::string say = _("Looking somewhat disappointed, the Sphinx sighs. You've answered my riddle so here's your reward. Now begone."); - const u8 count = res.GetValidItems(); - - if(count) - { - if(1 == count && res.gold && Artifact::UNKNOWN != art) - DialogWithArtifactAndGold("", say, art, res.gold); - else - { - Dialog::ResourceInfo("", say, res); - if(Artifact::UNKNOWN != art) DialogWithArtifact("", say, art); - } - } - else - if(Artifact::UNKNOWN != art) DialogWithArtifact("", say, art); - - riddle->SetQuiet(); - hero.SetVisited(dst_index, Visit::GLOBAL); - } - else - { - Dialog::Message("", _("\"You guessed incorrectly,\" the Sphinx says, smiling. The Sphinx swipes at you with a paw, knocking you to the ground. Another blow makes the world go black, and you know no more."), Font::BIG, Dialog::OK); - Battle2::Result res; - res.army1 = Battle2::RESULT_LOSS; - BattleLose(hero, res, true); - } - } - } - else - Dialog::Message(MP2::StringObject(obj), _("You come across a giant Sphinx. The Sphinx remains strangely quiet."), Font::BIG, Dialog::OK); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToShinx: " << hero.GetName()); -} - -void ActionToBarrier(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - - if(kingdom.IsVisitTravelersTent(tile.GetQuantity1())) - { - Dialog::Message(MP2::StringObject(obj), - _("A magical barrier stands tall before you, blocking your way. Runes on the arch read,\n\"Speak the key and you may pass.\"\nAs you speak the magic word, the glowing barrier dissolves into nothingness."), - Font::BIG, Dialog::OK); - - AnimationRemoveObject(tile); - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - } - else - { - Dialog::Message(MP2::StringObject(obj), - _("A magical barrier stands tall before you, blocking your way. Runes on the arch read,\n\"Speak the key and you may pass.\"\nYou speak, and nothing happens."), - Font::BIG, Dialog::OK); - } - - DEBUG(DBG_GAME , DBG_INFO, "ActionToBarrier: " << hero.GetName()); -} - -void ActionToTravellersTent(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Dialog::Message(MP2::StringObject(obj), - _("You enter the tent and see an old woman gazing into a magic gem. She looks up and says,\n\"In my travels, I have learned much in the way of arcane magic. A great oracle taught me his skill. I have the answer you seek.\""), - Font::BIG, Dialog::OK); - - const Maps::Tiles & tile = world.GetTiles(dst_index); - Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - - kingdom.SetVisitTravelersTent(tile.GetQuantity1()); - - DEBUG(DBG_GAME , DBG_INFO, "ActionToTravellersTent: " << hero.GetName()); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_ai.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_ai.cpp deleted file mode 100644 index 6a55c54d4..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_ai.cpp +++ /dev/null @@ -1,2069 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "settings.h" -#include "kingdom.h" -#include "castle.h" -#include "army.h" -#include "battle2.h" -#include "luck.h" -#include "morale.h" -#include "world.h" -#include "payment.h" -#include "gameevent.h" -#include "heroes.h" - -void AIToMonster(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToPickupResource(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToTreasureChest(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToArtifact(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToResource(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToWagon(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToSkeleton(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToCaptureObject(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToFlotSam(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToObservationTower(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToMagellanMaps(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToTeleports(Heroes &hero, const s32 dst_index); -void AIToWhirlpools(Heroes &hero, const s32 dst_index); -void AIToPrimarySkillObject(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToExperienceObject(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToWitchsHut(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToShrine(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToGoodLuckObject(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToGoodMoraleObject(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToMagicWell(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToArtesianSpring(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToXanadu(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToEvent(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToUpgradeArmyObject(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToPoorMoraleObject(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToPoorLuckObject(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToObelisk(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToTreeKnowledge(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToDaemonCave(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToCastle(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToSign(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToDwellingJoinMonster(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToHeroes(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToDwellingRecruitMonster(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToStables(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToAbandoneMine(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToBarrier(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToTravellersTent(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToShipwreckSurvivor(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToBoat(Heroes &hero, const u8 obj, const s32 dst_index); -void AIToCoast(Heroes &hero, const u8 obj, const s32 dst_index); - -Skill::Primary::skill_t AISelectPrimarySkill(Heroes &hero) -{ - switch(hero.GetRace()) - { - case Race::KNGT: - { - if(5 > hero.GetDefense()) return Skill::Primary::DEFENSE; - if(5 > hero.GetAttack()) return Skill::Primary::ATTACK; - if(3 > hero.GetKnowledge()) return Skill::Primary::KNOWLEDGE; - if(3 > hero.GetPower()) return Skill::Primary::POWER; - break; - } - - case Race::BARB: - { - if(5 > hero.GetAttack()) return Skill::Primary::ATTACK; - if(5 > hero.GetDefense()) return Skill::Primary::DEFENSE; - if(3 > hero.GetPower()) return Skill::Primary::POWER; - if(3 > hero.GetKnowledge()) return Skill::Primary::KNOWLEDGE; - break; - } - - case Race::SORC: - case Race::WZRD: - { - if(5 > hero.GetKnowledge()) return Skill::Primary::KNOWLEDGE; - if(5 > hero.GetPower()) return Skill::Primary::POWER; - if(3 > hero.GetDefense()) return Skill::Primary::DEFENSE; - if(3 > hero.GetAttack()) return Skill::Primary::ATTACK; - break; - } - - case Race::WRLK: - case Race::NECR: - { - if(5 > hero.GetPower()) return Skill::Primary::POWER; - if(5 > hero.GetKnowledge()) return Skill::Primary::KNOWLEDGE; - if(3 > hero.GetAttack()) return Skill::Primary::ATTACK; - if(3 > hero.GetDefense()) return Skill::Primary::DEFENSE; - break; - } - - default: break; - } - - switch(Rand::Get(1,4)) - { - case 1: return Skill::Primary::ATTACK; - case 2: return Skill::Primary::DEFENSE; - case 3: return Skill::Primary::POWER; - case 4: return Skill::Primary::KNOWLEDGE; - default: break; - } - - return Skill::Primary::UNKNOWN; -} - -void AIBattleLose(Heroes &hero, const Battle2::Result & res, bool attacker, Color::color_t color = Color::GRAY) -{ - u8 reason = attacker ? res.AttackerResult() : res.DefenderResult(); - - if(Settings::Get().ExtHeroSurrenderingGiveExp() && - Battle2::RESULT_SURRENDER == reason) - { - const u32 & exp = attacker ? res.GetExperienceAttacker() : res.GetExperienceDefender(); - - if(Settings::Get().MyColor() == hero.GetColor()) - { - std::string msg = _("Hero %{name} also got a %{count} experience."); - String::Replace(msg, "%{name}", hero.GetName()); - String::Replace(msg, "%{count}", exp); - Dialog::Message("", msg, Font::BIG, Dialog::OK); - } - hero.IncreaseExperience(exp); - } - - hero.SetKillerColor(color); - hero.SetFreeman(reason); -} - -void Heroes::AIAction(const s32 dst_index) -{ - const MP2::object_t object = (dst_index == GetIndex() ? - GetUnderObject() : world.GetTiles(dst_index).GetObject()); - - if(MP2::isActionObject(object, isShipMaster())) SetModes(ACTION); - - switch(object) - { - case MP2::OBJ_BOAT: AIToBoat(*this, object, dst_index); break; - case MP2::OBJ_COAST: AIToCoast(*this, object, dst_index); break; - - case MP2::OBJ_MONSTER: AIToMonster(*this, object, dst_index); break; - case MP2::OBJ_HEROES: AIToHeroes(*this, object, dst_index); break; - case MP2::OBJ_CASTLE: AIToCastle(*this, object, dst_index); break; - - // pickup object - case MP2::OBJ_RESOURCE: - case MP2::OBJ_BOTTLE: - case MP2::OBJ_CAMPFIRE: AIToPickupResource(*this, object, dst_index); break; - - case MP2::OBJ_WATERCHEST: - case MP2::OBJ_TREASURECHEST: AIToTreasureChest(*this, object, dst_index); break; - case MP2::OBJ_ARTIFACT: AIToArtifact(*this, object, dst_index); break; - - case MP2::OBJ_MAGICGARDEN: - case MP2::OBJ_LEANTO: - case MP2::OBJ_WINDMILL: - case MP2::OBJ_WATERWHEEL: AIToResource(*this, object, dst_index); break; - - case MP2::OBJ_WAGON: AIToWagon(*this, object, dst_index); break; - case MP2::OBJ_SKELETON: AIToSkeleton(*this, object, dst_index); break; - case MP2::OBJ_FLOTSAM: AIToFlotSam(*this, object, dst_index); break; - - case MP2::OBJ_ALCHEMYLAB: - case MP2::OBJ_MINES: - case MP2::OBJ_SAWMILL: - case MP2::OBJ_LIGHTHOUSE: AIToCaptureObject(*this, object, dst_index); break; - case MP2::OBJ_ABANDONEDMINE: AIToAbandoneMine(*this, object, dst_index); break; - - case MP2::OBJ_SHIPWRECKSURVIROR:AIToShipwreckSurvivor(*this, object, dst_index); break; - - // event - case MP2::OBJ_EVENT: AIToEvent(*this, object, dst_index); break; - - case MP2::OBJ_SIGN: AIToSign(*this, object, dst_index); break; - - // increase view - case MP2::OBJ_OBSERVATIONTOWER: AIToObservationTower(*this, object, dst_index); break; - case MP2::OBJ_MAGELLANMAPS: AIToMagellanMaps(*this, object, dst_index); break; - - // teleports - case MP2::OBJ_STONELIGHTS: AIToTeleports(*this, dst_index); break; - case MP2::OBJ_WHIRLPOOL: AIToWhirlpools(*this, dst_index); break; - - // primary skill modification - case MP2::OBJ_FORT: - case MP2::OBJ_MERCENARYCAMP: - case MP2::OBJ_DOCTORHUT: - case MP2::OBJ_STANDINGSTONES: AIToPrimarySkillObject(*this, object, dst_index); break; - - // experience modification - case MP2::OBJ_GAZEBO: AIToExperienceObject(*this, object, dst_index); break; - - // witchs hut - case MP2::OBJ_WITCHSHUT: AIToWitchsHut(*this, object, dst_index); break; - - // shrine circle - case MP2::OBJ_SHRINE1: - case MP2::OBJ_SHRINE2: - case MP2::OBJ_SHRINE3: AIToShrine(*this, object, dst_index); break; - - // luck modification - case MP2::OBJ_FOUNTAIN: - case MP2::OBJ_FAERIERING: - case MP2::OBJ_IDOL: AIToGoodLuckObject(*this, object, dst_index); break; - - // morale modification - case MP2::OBJ_OASIS: - case MP2::OBJ_TEMPLE: - case MP2::OBJ_WATERINGHOLE: - case MP2::OBJ_BUOY: AIToGoodMoraleObject(*this, object, dst_index); break; - - case MP2::OBJ_OBELISK: AIToObelisk(*this, object, dst_index); break; - - // magic point - case MP2::OBJ_ARTESIANSPRING: AIToArtesianSpring(*this, object, dst_index); break; - case MP2::OBJ_MAGICWELL: AIToMagicWell(*this, object, dst_index); break; - - // increase skill - case MP2::OBJ_XANADU: AIToXanadu(*this, object, dst_index); break; - - case MP2::OBJ_HILLFORT: - case MP2::OBJ_FREEMANFOUNDRY: AIToUpgradeArmyObject(*this, object, dst_index); break; - - case MP2::OBJ_SHIPWRECK: - case MP2::OBJ_GRAVEYARD: - case MP2::OBJ_DERELICTSHIP: AIToPoorMoraleObject(*this, object, dst_index); break; - - case MP2::OBJ_PYRAMID: AIToPoorLuckObject(*this, object, dst_index); break; - case MP2::OBJ_DAEMONCAVE: AIToDaemonCave(*this, object, dst_index); break; - - case MP2::OBJ_TREEKNOWLEDGE: AIToTreeKnowledge(*this, object, dst_index); break; - - // accept army - case MP2::OBJ_WATCHTOWER: - case MP2::OBJ_EXCAVATION: - case MP2::OBJ_CAVE: - case MP2::OBJ_TREEHOUSE: - case MP2::OBJ_ARCHERHOUSE: - case MP2::OBJ_GOBLINHUT: - case MP2::OBJ_DWARFCOTT: - case MP2::OBJ_HALFLINGHOLE: - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_THATCHEDHUT: AIToDwellingJoinMonster(*this, object, dst_index); break; - - // recruit army - case MP2::OBJ_RUINS: - case MP2::OBJ_TREECITY: - case MP2::OBJ_WAGONCAMP: - case MP2::OBJ_DESERTTENT: - // loyalty ver - case MP2::OBJ_WATERALTAR: - case MP2::OBJ_AIRALTAR: - case MP2::OBJ_FIREALTAR: - case MP2::OBJ_EARTHALTAR: - case MP2::OBJ_BARROWMOUNDS: AIToDwellingRecruitMonster(*this, object, dst_index); break; - - // recruit army (battle) - case MP2::OBJ_DRAGONCITY: - case MP2::OBJ_CITYDEAD: - case MP2::OBJ_TROLLBRIDGE: AIToDwellingRecruitMonster(*this, object, dst_index); break; - - // recruit genie - case MP2::OBJ_ANCIENTLAMP: AIToDwellingRecruitMonster(*this, object, dst_index); break; - - case MP2::OBJ_STABLES: AIToStables(*this, object, dst_index); break; - case MP2::OBJ_ARENA: AIToPrimarySkillObject(*this, object, dst_index); break; - - case MP2::OBJ_BARRIER: AIToBarrier(*this, object, dst_index); break; - case MP2::OBJ_TRAVELLERTENT: AIToTravellersTent(*this, object, dst_index); break; - - - default: break; - } -} - -void AIToHeroes(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Settings & conf = Settings::Get(); - Heroes *other_hero = world.GetHeroes(dst_index); - if(! other_hero) return; - - if(hero.GetColor() == other_hero->GetColor() || - (conf.ExtUnionsAllowHeroesMeetings() && conf.IsUnions(hero.GetColor(), other_hero->GetColor()))) - { - DEBUG(DBG_AI, DBG_INFO, "AIToHeroes: " << hero.GetName() << " meeting " << other_hero->GetName()); - hero.AIMeeting(*other_hero); - } - else - if(! hero.AllowBattle()) - { - DEBUG(DBG_AI, DBG_INFO, "AIToHeroes: " << hero.GetName() << " currently can not allow battle"); - } - else - if(! other_hero->AllowBattle()) - { - DEBUG(DBG_AI, DBG_INFO, "AIToHeroes: " << other_hero->GetName() << " currently can not allow battle"); - } - else - { - if(other_hero->GetUnderObject() == MP2::OBJ_CASTLE) - { - AIToCastle(hero, MP2::OBJ_CASTLE, dst_index); - return; - } - - DEBUG(DBG_AI , DBG_INFO, "AIToHeroes: " << hero.GetName() << " attack enemy hero " << other_hero->GetName()); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), other_hero->GetArmy(), dst_index); - - // loss defender - if(!res.DefenderWins()) - AIBattleLose(*other_hero, res, false, hero.GetColor()); - - // loss attacker - if(!res.AttackerWins()) - AIBattleLose(hero, res, true, other_hero->GetColor()); - - // wins attacker - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - hero.ActionAfterBattle(); - } - else - // wins defender - if(res.DefenderWins()) - { - other_hero->IncreaseExperience(res.GetExperienceDefender()); - other_hero->ActionAfterBattle(); - } - } -} - -void AIToCastle(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Settings & conf = Settings::Get(); - Castle *castle = world.GetCastle(dst_index); - - if(! castle) return; - - if(hero.GetColor() == castle->GetColor() || - (conf.ExtUnionsAllowCastleVisiting() && conf.IsUnions(hero.GetColor(), castle->GetColor()))) - { - DEBUG(DBG_AI , DBG_INFO, "AIToCastle: " << hero.GetName() << " goto castle " << castle->GetName()); - castle->GetMageGuild().EducateHero(hero); - } - else - { - DEBUG(DBG_AI , DBG_INFO, "AIToCastle: " << hero.GetName() << " attack enemy castle " << castle->GetName()); - - castle->MergeArmies(); - Army::army_t & army = castle->GetActualArmy(); - - if(army.isValid()) - { - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - Heroes *other_hero = world.GetHeroes(dst_index); - - // loss defender - if(!res.DefenderWins() && other_hero) - AIBattleLose(*other_hero, res, false, hero.GetColor()); - - // loss attacker - if(!res.AttackerWins()) - AIBattleLose(hero, res, true, castle->GetColor()); - - // wins attacker - if(res.AttackerWins()) - { - castle->GetArmy().Clear(); - - world.GetKingdom(castle->GetColor()).RemoveCastle(castle); - world.GetKingdom(hero.GetColor()).AddCastle(castle); - world.CaptureObject(dst_index, hero.GetColor()); - castle->Scoute(); - - hero.IncreaseExperience(res.GetExperienceAttacker()); - hero.ActionAfterBattle(); - } - else - // wins defender - if(res.DefenderWins() && other_hero) - { - other_hero->IncreaseExperience(res.GetExperienceDefender()); - other_hero->ActionAfterBattle(); - } - } - else - { - world.GetKingdom(castle->GetColor()).RemoveCastle(castle); - world.GetKingdom(hero.GetColor()).AddCastle(castle); - world.CaptureObject(dst_index, hero.GetColor()); - castle->Scoute(); - } - } -} - -void AIToMonster(Heroes &hero, const u8 obj, const s32 dst_index) -{ - bool destroy = false; - Maps::Tiles & tile = world.GetTiles(dst_index); - const Army::Troop troop(tile); - - u32 join = 0; - Resource::funds_t cost; - - u8 reason = Army::GetJoinSolution(hero, tile, join, cost.gold); - - // free join - if(1 == reason) - { - // join if ranged or flying monsters present - if(hero.GetArmy().HasMonster(troop()) || troop.isArchers() || troop.isFly()) - { - DEBUG(DBG_AI , DBG_INFO, "AIToMonster: " << hero.GetName() << " join monster " << troop.GetName()); - hero.GetArmy().JoinTroop(troop); - destroy = true; - } - else - reason = 0; - } - else - // join with cost - if(2 == reason) - { - // join if archers or fly or present - if(hero.GetArmy().HasMonster(troop()) || troop.isArchers() || troop.isFly()) - { - DEBUG(DBG_AI , DBG_INFO, "AIToMonster: " << hero.GetName() << " join monster " << troop.GetName() << ", count: " << join << ", cost: " << cost.gold); - hero.GetArmy().JoinTroop(troop(), join); - world.GetKingdom(hero.GetColor()).OddFundsResource(cost); - destroy = true; - } - else - reason = 0; - } - - // fight - if(0 == reason) - { - DEBUG(DBG_AI , DBG_INFO, "AIToMonster: " << hero.GetName() << " attack monster " << troop.GetName()); - - Army::army_t army; - army.JoinTroop(troop); - army.ArrangeForBattle(); - - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - destroy = true; - hero.ActionAfterBattle(); - } - else - { - AIBattleLose(hero, res, true); - if(Settings::Get().ExtSaveMonsterBattle()) - { - tile.SetCountMonster(army.GetCountMonsters(troop())); - if(2 == tile.GetQuantity4()) tile.SetQuantity4(1); - } - } - } - // unknown - else - destroy = true; - - - if(destroy) - { - Maps::TilesAddon *addon = tile.FindMonster(); - if(addon) - { - const u32 uniq = addon->uniq; - tile.Remove(uniq); - tile.SetObject(MP2::OBJ_ZERO); - tile.ResetQuantity(); - - // remove shadow from left cell - if(Maps::isValidDirection(dst_index, Direction::LEFT)) - world.GetTiles(Maps::GetDirectionIndex(dst_index, Direction::LEFT)).Remove(uniq); - } - } -} - -void AIToPickupResource(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - Resource::funds_t resource; - const u8 count = tile.GetQuantity2(); - - switch(tile.GetQuantity1()) - { - case Resource::WOOD: resource.wood += count; break; - case Resource::MERCURY: resource.mercury += count; break; - case Resource::ORE: resource.ore += count; break; - case Resource::SULFUR: resource.sulfur += count; break; - case Resource::CRYSTAL: resource.crystal += count; break; - case Resource::GEMS: resource.gems += count; break; - case Resource::GOLD: resource.gold += 100 * count; break; - - default: break; - } - - switch(obj) - { - case MP2::OBJ_CAMPFIRE: - resource.gold += 100 * count; - break; - - default: break; - } - - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - tile.RemoveObjectSprite(); - - hero.GetPath().Reset(); - - tile.SetObject(MP2::OBJ_ZERO); - DEBUG(DBG_AI , DBG_INFO, "AIToPickupResource: " << hero.GetName() << " pickup small resource"); -} - -void AIToTreasureChest(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - Resource::funds_t resource; - resource.gold = tile.GetQuantity2() * 100; - - if(Maps::Ground::WATER == tile.GetGround()) - { - if(tile.GetQuantity1()) - { - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - if(!hero.PickupArtifact(art())) - resource.gold = 1500; // it is from FAQ - } - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - } - else - { - if(tile.GetQuantity1()) - { - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - - if(!hero.PickupArtifact(art())) - resource.gold = 1000; // it is from FAQ - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - } - else - if(resource.gold >= 1000) - { - const u16 expr = resource.gold - 500; - - // select gold or exp - if(Rand::Get(1)) - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - else - hero.IncreaseExperience(expr); - } - } - - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - - DEBUG(DBG_AI , DBG_INFO, "AIToTreasureChest: " << hero.GetName()); -} - -void AIToResource(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - const u8 count = tile.GetQuantity2(); - Resource::funds_t resource; - - switch(tile.GetQuantity1()) - { - case Resource::WOOD: resource.wood += count; break; - case Resource::MERCURY: resource.mercury += count; break; - case Resource::ORE: resource.ore += count; break; - case Resource::SULFUR: resource.sulfur += count; break; - case Resource::CRYSTAL: resource.crystal += count; break; - case Resource::GEMS: resource.gems += count; break; - case Resource::GOLD: resource.gold += 100 * count; break; - - default: break; - } - - if(resource.GetValidItems()) - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - - tile.SetQuantity1(0); - tile.SetQuantity2(0); - - DEBUG(DBG_AI , DBG_INFO, "AIToResource: " << hero.GetName()); -} - -void AIToSkeleton(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - // artifact - if(tile.GetQuantity1() && 0 == tile.GetQuantity2()) - { - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - - if(hero.PickupArtifact(art())) - { - tile.SetQuantity1(0); - tile.SetQuantity2(0); - } - } - - DEBUG(DBG_AI , DBG_INFO, "AIToSkeleton: " << hero.GetName()); -} - -void AIToWagon(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - // artifact - if(tile.GetQuantity1() && 0 == tile.GetQuantity2()) - { - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - if(hero.PickupArtifact(art())) - tile.SetQuantity1(0); - } - else - if(tile.GetQuantity1() && tile.GetQuantity2()) - { - const u8 count = tile.GetQuantity2(); - Resource::funds_t resource; - - switch(tile.GetQuantity1()) - { - case Resource::WOOD: resource.wood += count; break; - case Resource::MERCURY: resource.mercury += count; break; - case Resource::ORE: resource.ore += count; break; - case Resource::SULFUR: resource.sulfur += count; break; - case Resource::CRYSTAL: resource.crystal += count; break; - case Resource::GEMS: resource.gems += count; break; - case Resource::GOLD: resource.gold += 100 * count; break; - - default: break; - } - - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - - tile.SetQuantity1(0); - tile.SetQuantity2(0); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToWagon: " << hero.GetName()); -} - -void AIToCaptureObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - Resource::resource_t res = Resource::UNKNOWN; - - switch(obj) - { - case MP2::OBJ_ALCHEMYLAB: res = Resource::MERCURY; break; - case MP2::OBJ_SAWMILL: res = Resource::WOOD; break; - case MP2::OBJ_MINES: res = static_cast(tile.GetMinesType()); break; - default: break; - } - - // capture object - if(hero.GetColor() != world.ColorCapturedObject(dst_index)) - { - bool capture = true; - - if(tile.CheckEnemyGuardians(hero.GetColor())) - { - const Army::Troop troop(tile); - Army::army_t army; - army.JoinTroop(troop); - army.SetColor(world.ColorCapturedObject(dst_index)); - - Battle2::Result result = Battle2::Loader(hero.GetArmy(), army, dst_index); - - if(result.AttackerWins()) - { - hero.IncreaseExperience(result.GetExperienceAttacker()); - hero.ActionAfterBattle(); - - tile.ResetQuantity(); - } - else - { - capture = false; - AIBattleLose(hero, result, true); - if(Settings::Get().ExtSaveMonsterBattle()) - tile.SetCountMonster(army.GetCountMonsters(troop())); - } - } - - if(capture) world.CaptureObject(dst_index, hero.GetColor()); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToCaptureObject: " << hero.GetName() << " captured: " << MP2::StringObject(obj)); -} - -void AIToFlotSam(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - Resource::funds_t resource; - - resource.gold += 100 * tile.GetQuantity1(); - resource.wood += tile.GetQuantity2(); - - if(resource.GetValidItems()) world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - - DEBUG(DBG_AI , DBG_INFO, "AIToFlotSam: " << hero.GetName()); -} - -void AIToSign(Heroes &hero, const u8 obj, const s32 dst_index) -{ - hero.SetVisited(dst_index, Visit::LOCAL); - DEBUG(DBG_AI , DBG_INFO, "AIToSign: " << hero.GetName()); -} - -void AIToObservationTower(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::ClearFog(dst_index, Game::GetViewDistance(Game::VIEW_OBSERVATION_TOWER), hero.GetColor()); - hero.SetVisited(dst_index, Visit::GLOBAL); - DEBUG(DBG_AI , DBG_INFO, "AIToObservationTower: " << hero.GetName()); -} - -void AIToMagellanMaps(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(1000 <= world.GetKingdom(hero.GetColor()).GetFundsGold()) - { - hero.SetVisited(dst_index, Visit::GLOBAL); - world.ActionForMagellanMaps(hero.GetColor()); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToMagellanMaps: " << hero.GetName()); -} - -void AIToTeleports(Heroes &hero, const s32 index_from) -{ - u16 index_to = world.NextTeleport(index_from); - hero.ApplyPenaltyMovement(); - - if(index_from == index_to) - { - DEBUG(DBG_AI , DBG_WARN, "AIToTeleports: action unsuccessfully..."); - return; - } - - hero.SetIndex(index_to); - hero.Scoute(); - - world.GetTiles(index_from).SetObject(MP2::OBJ_STONELIGHTS); - world.GetTiles(index_to).SetObject(MP2::OBJ_HEROES); - - hero.ActionNewPosition(); - - DEBUG(DBG_AI , DBG_INFO, "AIToStoneLights: " << hero.GetName()); -} - -void AIToWhirlpools(Heroes &hero, const s32 index_from) -{ - const u16 index_to = world.NextWhirlpool(index_from); - hero.ApplyPenaltyMovement(); - - if(index_from == index_to) - { - DEBUG(DBG_AI , DBG_WARN, "AIToWhirlpools: action unsuccessfully..."); - return; - } - - hero.SetIndex(index_to); - hero.Scoute(); - - world.GetTiles(index_from).SetObject(MP2::OBJ_WHIRLPOOL); - world.GetTiles(index_to).SetObject(MP2::OBJ_HEROES); - - Army::Troop & troops = hero.GetArmy().GetWeakestTroop(); - - if(Rand::Get(1) && 1 < troops.GetCount()) - troops.SetCount(Monster::GetCountFromHitPoints(troops(), troops.GetHitPoints() - troops.GetHitPoints() * Game::GetWhirlpoolPercent() / 100)); - - DEBUG(DBG_AI , DBG_INFO, "AIToWhirlpools: " << hero.GetName()); -} - -void AIToPrimarySkillObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - - Skill::Primary::skill_t skill = Skill::Primary::UNKNOWN; - - switch(obj) - { - case MP2::OBJ_FORT: skill = Skill::Primary::DEFENSE; break; - case MP2::OBJ_MERCENARYCAMP: skill = Skill::Primary::ATTACK; break; - case MP2::OBJ_DOCTORHUT: skill = Skill::Primary::KNOWLEDGE; break; - case MP2::OBJ_STANDINGSTONES: skill = Skill::Primary::POWER; break; - case MP2::OBJ_ARENA: skill = AISelectPrimarySkill(hero); break; - - default: break; - } - - if(!hero.isVisited(tile)) - { - // increase skill - hero.IncreasePrimarySkill(skill); - hero.SetVisited(dst_index); - - // fix double action tile - if(obj == MP2::OBJ_STANDINGSTONES) - { - const Maps::TilesAddon* addon = tile.FindStandingStones(); - - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::LEFT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)); - - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::RIGHT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)); - } - } - - DEBUG(DBG_AI , DBG_INFO, "AIToPrimarySkillObject: " << hero.GetName()); -} - -void AIToExperienceObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - - u32 exp = 0; - - switch(obj) - { - case MP2::OBJ_GAZEBO: exp = 1000; break; - default: break; - } - - // check already visited - if(! hero.isVisited(tile) && exp) - { - hero.SetVisited(dst_index); - hero.IncreaseExperience(exp); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToExperienceObject: " << hero.GetName()); -} - -void AIToWitchsHut(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Skill::Secondary::skill_t skill = Skill::Secondary::Skill(world.GetTiles(dst_index).GetQuantity1()); - - // check full - if(!hero.HasMaxSecondarySkill() && !hero.HasSecondarySkill(skill)) - hero.LearnBasicSkill(skill); - - hero.SetVisited(dst_index); - DEBUG(DBG_AI , DBG_INFO, "AIToWitchsHut: " << hero.GetName()); -} - -void AIToShrine(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Spell::spell_t spell = Spell::FromInt(world.GetTiles(dst_index).GetQuantity1()); - const u8 spell_level = Spell::Level(spell); - - // check spell book - if(hero.HasArtifact(Artifact::MAGIC_BOOK) && - !hero.HaveSpell(spell) && - // check valid level spell and wisdom skill - !(3 == spell_level && Skill::Level::NONE == hero.GetLevelSkill(Skill::Secondary::WISDOM))) - { - hero.AppendSpellToBook(spell); - hero.SetVisited(dst_index); - } - DEBUG(DBG_AI , DBG_INFO, "AIToShrine: " << hero.GetName()); -} - -void AIToGoodLuckObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - // check already visited - if(!hero.isVisited(obj)) hero.SetVisited(dst_index); - DEBUG(DBG_AI , DBG_INFO, "AIToGoodLuckObject: " << hero.GetName()); -} - -void AIToGoodMoraleObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - - u16 move = 0; - - switch(obj) - { - case MP2::OBJ_OASIS: move = 800; break; - case MP2::OBJ_WATERINGHOLE: move = 400; break; - default: break; - } - - // check already visited - if(!hero.isVisited(obj)) - { - // modify morale - hero.SetVisited(dst_index); - hero.IncreaseMovePoints(move); - - // fix double action tile - if(obj == MP2::OBJ_OASIS) - { - const Maps::TilesAddon* addon = tile.FindOasis(); - - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::LEFT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)); - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::RIGHT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)); - } - } - - DEBUG(DBG_AI , DBG_INFO, "AIToGoodMoraleObject: " << hero.GetName()); -} - -void AIToMagicWell(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const u16 max = hero.GetMaxSpellPoints(); - - if(hero.GetSpellPoints() != max && - // check already visited - !hero.isVisited(MP2::OBJ_MAGICWELL)) - { - hero.SetVisited(dst_index); - hero.SetSpellPoints(max); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToMagicWell: " << hero.GetName()); -} - -void AIToArtesianSpring(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const u16 max = hero.GetMaxSpellPoints(); - - if(!hero.isVisited(MP2::OBJ_ARTESIANSPRING) && - hero.GetSpellPoints() < max * 2) - { - hero.SetVisited(dst_index); - hero.SetSpellPoints(max * 2); - - // fix double action tile - { - const Maps::Tiles & tile = world.GetTiles(dst_index); - const Maps::TilesAddon* addon = tile.FindArtesianSpring(); - - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::LEFT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::LEFT)); - if(addon && Maps::isValidDirection(tile.GetIndex(), Direction::RIGHT) && - world.GetTiles(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)).FindAddonLevel1(addon->uniq)) hero.SetVisited(Maps::GetDirectionIndex(tile.GetIndex(), Direction::RIGHT)); - } - } - - DEBUG(DBG_AI , DBG_INFO, "AIToArtesianSpring: " << hero.GetName()); -} - -void AIToXanadu(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - const u8 level1 = hero.GetLevelSkill(Skill::Secondary::DIPLOMACY); - const u8 level2 = hero.GetLevel(); - - if(!hero.isVisited(tile) && - ((level1 == Skill::Level::BASIC && 7 < level2) || - (level1 == Skill::Level::ADVANCED && 5 < level2) || - (level1 == Skill::Level::EXPERT && 3 < level2) || - (9 < level2))) - { - hero.IncreasePrimarySkill(Skill::Primary::ATTACK); - hero.IncreasePrimarySkill(Skill::Primary::DEFENSE); - hero.IncreasePrimarySkill(Skill::Primary::KNOWLEDGE); - hero.IncreasePrimarySkill(Skill::Primary::POWER); - hero.SetVisited(dst_index); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToXanadu: " << hero.GetName()); -} - -void AIToEvent(Heroes &hero, const u8 obj, const s32 dst_index) -{ - // check event maps - const GameEvent::Coord* event_maps = world.GetEventMaps(hero.GetColor(), dst_index); - if(event_maps) - { - if(event_maps->GetResource().GetValidItems()) - world.GetKingdom(hero.GetColor()).AddFundsResource(event_maps->GetResource()); - if(Artifact::UNKNOWN != event_maps->GetArtifact()) - hero.PickupArtifact(event_maps->GetArtifact()); - } - - hero.SaveUnderObject(MP2::OBJ_ZERO); - - DEBUG(DBG_AI , DBG_INFO, "AIToEvent: " << hero.GetName()); -} - -void AIToUpgradeArmyObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - switch(obj) - { - case MP2::OBJ_HILLFORT: - if(hero.GetArmy().HasMonster(Monster::DWARF)) - hero.GetArmy().UpgradeMonsters(Monster::DWARF); - if(hero.GetArmy().HasMonster(Monster::ORC)) - hero.GetArmy().UpgradeMonsters(Monster::ORC); - if(hero.GetArmy().HasMonster(Monster::OGRE)) - hero.GetArmy().UpgradeMonsters(Monster::OGRE); - break; - - case MP2::OBJ_FREEMANFOUNDRY: - if(hero.GetArmy().HasMonster(Monster::PIKEMAN)) - hero.GetArmy().UpgradeMonsters(Monster::PIKEMAN); - if(hero.GetArmy().HasMonster(Monster::SWORDSMAN)) - hero.GetArmy().UpgradeMonsters(Monster::SWORDSMAN); - if(hero.GetArmy().HasMonster(Monster::IRON_GOLEM)) - hero.GetArmy().UpgradeMonsters(Monster::IRON_GOLEM); - break; - - default: break; - } - - DEBUG(DBG_AI , DBG_INFO, "AIToUpgradeArmyObject: " << hero.GetName()); -} - -void AIToPoorMoraleObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - const bool battle = (tile.GetQuantity1() || tile.GetQuantity2()); - bool complete = false; - - switch(obj) - { - case MP2::OBJ_GRAVEYARD: - if(battle) - { - Army::army_t army; - army.FromGuardian(tile); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - complete = true; - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - Resource::funds_t resource; - resource.gold = tile.GetQuantity2() * 100; - hero.PickupArtifact(art()); - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - hero.ActionAfterBattle(); - } - else - { - AIBattleLose(hero, res, true); - } - } - break; - - case MP2::OBJ_SHIPWRECK: - if(battle) - { - Army::army_t army; - army.FromGuardian(tile); - Resource::funds_t resource; - Artifact::artifact_t art = Artifact::UNKNOWN; - switch(tile.GetQuantity2()) - { - case 10: resource.gold = 1000; break; - case 15: resource.gold = 2000; break; - case 25: resource.gold = 5000; break; - case 50: resource.gold = 2000; art = Artifact::FromInt(tile.GetQuantity1()); break; - default: DEBUG(DBG_AI , DBG_WARN, "ActionToPoorMoraleObject: unknown variant for ShipWreck, index: " << dst_index); break; - } - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - complete = true; - hero.PickupArtifact(art); - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - hero.ActionAfterBattle(); - } - else - { - AIBattleLose(hero, res, true); - } - } - break; - - case MP2::OBJ_DERELICTSHIP: - if(battle) - { - Army::army_t army; - army.FromGuardian(tile); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - complete = true; - Resource::funds_t resource; - resource.gold = tile.GetQuantity2() * 100; - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - hero.ActionAfterBattle(); - } - else - { - AIBattleLose(hero, res, true); - } - } - break; - - default: break; - } - - if(complete) - { - tile.SetQuantity1(0); - tile.SetQuantity2(0); - } - else - if(!battle && !hero.isVisited(obj)) - { - // modify morale - hero.SetVisited(dst_index); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToPoorMoraleObject: " << hero.GetName()); -} - -void AIToPoorLuckObject(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - const bool battle = tile.GetQuantity1(); - bool complete = false; - - switch(obj) - { - case MP2::OBJ_PYRAMID: - if(battle) - { - // battle - Army::army_t army; - army.FromGuardian(tile); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - complete = true; - const Spell::spell_t spell(static_cast(tile.GetQuantity1())); - // check magick book - if(hero.HasArtifact(Artifact::MAGIC_BOOK) && - // check skill level for wisdom - Skill::Level::EXPERT == hero.GetLevelSkill(Skill::Secondary::WISDOM)) - { - hero.AppendSpellToBook(spell); - } - hero.ActionAfterBattle(); - } - else - { - AIBattleLose(hero, res, true); - } - } - break; - - default: break; - } - - if(complete) - { - tile.SetQuantity1(0); - tile.SetQuantity2(0); - } - else - if(!battle && !hero.isVisited(obj)) - { - // modify luck - hero.SetVisited(dst_index); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToPoorLuckObject: " << hero.GetName()); -} - -void AIToObelisk(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(!hero.isVisited(obj, Visit::GLOBAL)) - { - hero.SetVisited(dst_index, Visit::GLOBAL); - Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - kingdom.PuzzleMaps().Update(kingdom.CountVisitedObjects(MP2::OBJ_OBELISK), world.CountObeliskOnMaps()); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToObelisk: " << hero.GetName()); -} - -void AIToTreeKnowledge(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - - if(!hero.isVisited(tile)) - { - Resource::funds_t payment; - switch(tile.GetQuantity2()) - { - case 10: payment.gems = 10; break; - case 20: payment.gold = 2000; break; - default: break; - } - - if(!payment.GetValidItems() || world.GetKingdom(hero.GetColor()).AllowPayment(payment)) - { - if(payment.GetValidItems()) world.GetKingdom(hero.GetColor()).OddFundsResource(payment); - hero.SetVisited(dst_index); - hero.IncreaseExperience(hero.GetExperienceFromLevel(hero.GetLevel()) - hero.GetExperience()); - } - } - - DEBUG(DBG_AI , DBG_INFO, "AIToTreeKnowledge: " << hero.GetName()); -} - - -void AIToDaemonCave(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - if(tile.GetQuantity2()) - { - Resource::funds_t resource; - - // check variants - switch(tile.GetQuantity2()) - { - case 1: - hero.IncreaseExperience(1000); - tile.SetQuantity2(0); - break; - case 2: - { - const Artifact::artifact_t art = Artifact::FromInt(tile.GetQuantity1()); - if(Artifact::UNKNOWN != art) hero.PickupArtifact(art); - hero.IncreaseExperience(1000); - tile.SetQuantity1(Artifact::UNKNOWN); - tile.SetQuantity2(0); - break; - } - case 3: - resource.gold = 2500; - hero.IncreaseExperience(1000); - world.GetKingdom(hero.GetColor()).AddFundsResource(resource); - tile.SetQuantity2(0); - break; - default: - break; - } - } - - DEBUG(DBG_AI , DBG_INFO, "AIToDaemonCave: " << hero.GetName()); -} - -void AIToDwellingJoinMonster(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - const u32 count = tile.GetCountMonster(); - - if(count && hero.GetArmy().JoinTroop(Monster(Monster::FromObject(obj)), count)) tile.SetCountMonster(0); - - DEBUG(DBG_AI , DBG_INFO, "AIToDwellingJoinMonster: " << hero.GetName()); -} - -void AIToDwellingRecruitMonster(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - const u32 count = tile.GetCountMonster(); - - if(count) - { - Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - const Monster monster(Monster::FromObject(obj)); - const payment_t paymentCosts(PaymentConditions::BuyMonster(monster()) * count); - const Resource::funds_t & kingdomResource = kingdom.GetFundsResource(); - - if(paymentCosts <= kingdomResource && hero.GetArmy().JoinTroop(monster, count)) - { - tile.SetCountMonster(0); - kingdom.OddFundsResource(paymentCosts); - - // remove ancient lamp sprite - if(MP2::OBJ_ANCIENTLAMP == obj) - { - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - } - } - } - - DEBUG(DBG_AI , DBG_INFO, "AIToDwellingJoinMonster: " << hero.GetName()); -} - -void AIToStables(Heroes &hero, const u8 obj, const s32 dst_index) -{ - // check already visited - if(!hero.isVisited(obj)) - { - hero.SetVisited(dst_index); - hero.IncreaseMovePoints(400); - } - - if(hero.GetArmy().HasMonster(Monster::CAVALRY)) hero.GetArmy().UpgradeMonsters(Monster::CAVALRY); - - DEBUG(DBG_AI , DBG_INFO, "AIToStables: " << hero.GetName()); -} - -void AIToAbandoneMine(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - - Army::army_t army; - army.FromGuardian(tile); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - tile.SetQuantity1(0); - tile.UpdateAbandoneMineSprite(); - world.CaptureObject(dst_index, hero.GetColor()); - hero.SaveUnderObject(MP2::OBJ_MINES); - hero.ActionAfterBattle(); - } - else - { - AIBattleLose(hero, res, true); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToAbandoneMine: " << hero.GetName()); -} - -void AIToBarrier(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - - if(kingdom.IsVisitTravelersTent(tile.GetQuantity1())) - { - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToBarrier: " << hero.GetName()); -} - -void AIToTravellersTent(Heroes &hero, const u8 obj, const s32 dst_index) -{ - const Maps::Tiles & tile = world.GetTiles(dst_index); - Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - - kingdom.SetVisitTravelersTent(tile.GetQuantity1()); - - DEBUG(DBG_AI , DBG_INFO, "AIToTravellersTent: " << hero.GetName()); -} - -void AIToShipwreckSurvivor(Heroes &hero, const u8 obj, const s32 dst_index) -{ - Maps::Tiles & tile = world.GetTiles(dst_index); - const Artifact art(Artifact::FromInt(tile.GetQuantity1())); - - if(!hero.PickupArtifact(art())) - { - Resource::funds_t prize(Resource::GOLD, 1500); - world.GetKingdom(hero.GetColor()).OddFundsResource(prize); - } - - tile.RemoveObjectSprite(); - tile.SetQuantity1(0); - tile.SetObject(MP2::OBJ_ZERO); - - DEBUG(DBG_AI , DBG_INFO, "AIToShipwreckSurvivor: " << hero.GetName()); -} - -void AIToArtifact(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(hero.IsFullBagArtifacts()) return; - - Maps::Tiles & tile = world.GetTiles(dst_index); - Artifact art(Artifact::FromInt(tile.GetQuantity1())); - - // update scroll artifact - if(art.GetID() == Artifact::SPELL_SCROLL) - art.SetExt(tile.GetQuantity3()); - - bool conditions = false; - - switch(tile.GetQuantity2()) - { - // 1,2,3 - 2000g, 2500g+3res,3000g+5res - case 1: - case 2: - case 3: - { - Resource::funds_t payment; - - if(1 == tile.GetQuantity2()) - payment += Resource::funds_t(Resource::GOLD, 2000); - else - if(2 == tile.GetQuantity2()) - { - payment += Resource::funds_t(Resource::GOLD, 2500); - payment += Resource::funds_t(tile.GetQuantity4(), 3); - } - else - { - payment += Resource::funds_t(Resource::GOLD, 3000); - payment += Resource::funds_t(tile.GetQuantity4(), 5); - } - - if(world.GetKingdom(hero.GetColor()).AllowPayment(payment)) - { - conditions = true; - world.GetKingdom(hero.GetColor()).OddFundsResource(payment); - } - break; - } - - // 4,5 - need have skill wisard or leadership, - case 4: - case 5: - { - conditions = hero.HasSecondarySkill(4 == tile.GetQuantity2() ? Skill::Secondary::WISDOM : Skill::Secondary::LEADERSHIP); - break; - } - - // 6 - 50 rogues, 7 - 1 gin, 8,9,10,11,12,13 - 1 monster level4 - case 6: - case 7: - case 8: - case 9: - case 10: - case 11: - case 12: - case 13: - { - Army::army_t army; - army.FromGuardian(tile); - - // new battle2 - Battle2::Result res = Battle2::Loader(hero.GetArmy(), army, dst_index); - if(res.AttackerWins()) - { - hero.IncreaseExperience(res.GetExperienceAttacker()); - conditions = true; - hero.ActionAfterBattle(); - } - else - { - AIBattleLose(hero, res, true); - } - break; - } - - default: - conditions = true; - break; - } - - if(conditions && hero.PickupArtifact(art)) - { - tile.RemoveObjectSprite(); - tile.SetObject(MP2::OBJ_ZERO); - tile.ResetQuantity(); - } - - DEBUG(DBG_AI , DBG_INFO, "AIToArtifact: " << hero.GetName()); -} - -void AIToBoat(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(hero.isShipMaster()) return; - - const s32 from_index = hero.GetIndex(); - - Maps::Tiles & tiles_from = world.GetTiles(from_index); - Maps::Tiles & tiles_to = world.GetTiles(dst_index); - - // disabled nearest coasts (on week MP2::isWeekLife) - std::vector coasts; - Maps::ScanDistanceObject(from_index, MP2::OBJ_COAST, 4, coasts); - coasts.push_back(from_index); - for(std::vector::const_iterator - it = coasts.begin(); it != coasts.end(); ++it) hero.SetVisited(*it); - - hero.ResetMovePoints(); - tiles_from.SetObject(MP2::OBJ_COAST); - hero.SetIndex(dst_index); - hero.SetShipMaster(true); - tiles_to.SetObject(MP2::OBJ_HEROES); - hero.SaveUnderObject(MP2::OBJ_ZERO); - hero.ClearAITasks(); - - DEBUG(DBG_AI, DBG_INFO, "AIToBoat: " << hero.GetName()); -} - -void AIToCoast(Heroes &hero, const u8 obj, const s32 dst_index) -{ - if(! hero.isShipMaster()) return; - - s32 from_index = hero.GetIndex(); - - Maps::Tiles & tiles_from = world.GetTiles(from_index); - Maps::Tiles & tiles_to = world.GetTiles(dst_index); - - hero.ResetMovePoints(); - tiles_from.SetObject(MP2::OBJ_BOAT); - hero.SetIndex(dst_index); - hero.SetShipMaster(false); - tiles_to.SetObject(MP2::OBJ_HEROES); - hero.SaveUnderObject(MP2::OBJ_ZERO); - hero.ClearAITasks(); - - hero.ActionNewPosition(); - - DEBUG(DBG_AI, DBG_INFO, "AIToCoast: " << hero.GetName()); -} - - - - - - - - - - - - - -/* get priority object for AI independent of distance (1 day) */ -bool Heroes::AIPriorityObject(s32 index) -{ - const Settings & conf = Settings::Get(); - Maps::Tiles & tile = world.GetTiles(index); - - if(Modes(HUNTER)) - switch(tile.GetObject()) - { - // capture enemy castle - case MP2::OBJ_CASTLE: - { - const Castle *castle = world.GetCastle(index); - return castle && - !conf.IsUnions(GetColor(), castle->GetColor()) && - AIValidObject(index); - } - break; - - // kill enemy hero - case MP2::OBJ_HEROES: - { - const Heroes *hero = world.GetHeroes(index); - return hero && - !conf.IsUnions(GetColor(), hero->GetColor()) && - AIValidObject(index); - } - break; - - case MP2::OBJ_MONSTER: - return AIValidObject(index); - - default: break; - } - - if(Modes(SCOUTER)) - switch(tile.GetObject()) - { - case MP2::OBJ_ARTIFACT: - // resource - case MP2::OBJ_RESOURCE: - case MP2::OBJ_CAMPFIRE: - case MP2::OBJ_TREASURECHEST: - // free mines - case MP2::OBJ_SAWMILL: - case MP2::OBJ_MINES: - case MP2::OBJ_ALCHEMYLAB: - return AIValidObject(index); - - default: break; - } - - return false; -} - -bool Heroes::AIValidObject(s32 index) -{ - Maps::Tiles & tile = world.GetTiles(index); - const u8 obj = tile.GetObject(); - - // check other - switch(obj) - { - // water object - case MP2::OBJ_SHIPWRECKSURVIROR: - case MP2::OBJ_WATERCHEST: - case MP2::OBJ_FLOTSAM: - case MP2::OBJ_BOTTLE: - case MP2::OBJ_BUOY: - - case MP2::OBJ_MAGELLANMAPS: - case MP2::OBJ_MERMAID: - case MP2::OBJ_SIRENS: - case MP2::OBJ_WHIRLPOOL: - case MP2::OBJ_COAST: - if(isShipMaster()) return true; - break; - - // capture objects - case MP2::OBJ_SAWMILL: - case MP2::OBJ_MINES: - case MP2::OBJ_ALCHEMYLAB: - if(GetColor() != world.ColorCapturedObject(tile.GetIndex())) - { - if(tile.CheckEnemyGuardians(GetColor())) - { - Army::army_t enemy; - enemy.FromGuardian(tile); - return !enemy.isValid() || GetArmy().StrongerEnemyArmy(enemy); - } - else return true; - } - break; - - // pickup object - case MP2::OBJ_WAGON: - case MP2::OBJ_WATERWHEEL: - case MP2::OBJ_WINDMILL: - case MP2::OBJ_LEANTO: - case MP2::OBJ_MAGICGARDEN: - case MP2::OBJ_SKELETON: - if(tile.ValidQuantity()) return true; - break; - - // pickup resource - case MP2::OBJ_RESOURCE: - case MP2::OBJ_CAMPFIRE: - case MP2::OBJ_TREASURECHEST: - return true; - - case MP2::OBJ_ARTIFACT: - { - if(IsFullBagArtifacts()) return false; - - // 1,2,3 - 2000g, 2500g+3res, 3000g+5res - if(1 <= tile.GetQuantity2() && 3 >= tile.GetQuantity2()) - { - Resource::funds_t payment; - if(1 == tile.GetQuantity2()) - payment += Resource::funds_t(Resource::GOLD, 2000); - else - if(2 == tile.GetQuantity2()) - { - payment += Resource::funds_t(Resource::GOLD, 2500); - payment += Resource::funds_t(tile.GetQuantity4(), 3); - } - else - { - payment += Resource::funds_t(Resource::GOLD, 3000); - payment += Resource::funds_t(tile.GetQuantity4(), 5); - } - return world.GetKingdom(GetColor()).AllowPayment(payment); - } - else - // 4,5 - need have skill wisard or leadership, - if(3 < tile.GetQuantity2() && 6 > tile.GetQuantity2()) - { - return HasSecondarySkill(4 == tile.GetQuantity2() ? Skill::Secondary::WISDOM : Skill::Secondary::LEADERSHIP); - } - else - // 6 - 50 rogues, 7 - 1 gin, 8,9,10,11,12,13 - 1 monster level4 - if(5 < tile.GetQuantity2() && 14 > tile.GetQuantity2()) - { - Army::army_t enemy; - enemy.FromGuardian(tile); - return !enemy.isValid() || GetArmy().StrongerEnemyArmy(enemy); - } - } - break; - - // increase view - case MP2::OBJ_OBSERVATIONTOWER: - // obelisk - case MP2::OBJ_OBELISK: - if(! isVisited(tile, Visit::GLOBAL)) return true; - break; - - case MP2::OBJ_BARRIER: - if(world.GetKingdom(GetColor()).IsVisitTravelersTent(tile.GetQuantity1())) return true; - break; - - case MP2::OBJ_TRAVELLERTENT: - if(!world.GetKingdom(GetColor()).IsVisitTravelersTent(tile.GetQuantity1())) return true; - break; - - // new spell - case MP2::OBJ_SHRINE1: - case MP2::OBJ_SHRINE2: - case MP2::OBJ_SHRINE3: - if( // check spell book - HasArtifact(Artifact::MAGIC_BOOK) && - !HaveSpell(Spell::FromInt(tile.GetQuantity1())) && - // check valid level spell and wisdom skill - !(3 == Spell::Level(Spell::FromInt(tile.GetQuantity1())) && - Skill::Level::NONE == GetLevelSkill(Skill::Secondary::WISDOM))) return true; - break; - - // primary skill - case MP2::OBJ_FORT: - case MP2::OBJ_MERCENARYCAMP: - case MP2::OBJ_DOCTORHUT: - case MP2::OBJ_STANDINGSTONES: - // sec skill - case MP2::OBJ_WITCHSHUT: - // exp - case MP2::OBJ_GAZEBO: - if(! isVisited(tile)) return true; - break; - - case MP2::OBJ_TREEKNOWLEDGE: - if(! isVisited(tile)) - { - Resource::funds_t payment; - switch(tile.GetQuantity2()) - { - case 10: payment.gems = 10; break; - case 20: payment.gold = 2000; break; - default: break; - } - - if(!payment.GetValidItems() || world.GetKingdom(GetColor()).AllowPayment(payment)) - return true; - } - break; - - // good luck - case MP2::OBJ_FOUNTAIN: - case MP2::OBJ_FAERIERING: - case MP2::OBJ_IDOL: - if(! isVisited(obj) && - Luck::IRISH > GetLuck()) return true; - break; - - // good morale - case MP2::OBJ_OASIS: - case MP2::OBJ_TEMPLE: - case MP2::OBJ_WATERINGHOLE: - if(! isVisited(obj) && - Morale::BLOOD > GetMorale()) return true; - break; - - case MP2::OBJ_MAGICWELL: - if(! isVisited(tile) && - GetMaxSpellPoints() != GetSpellPoints()) return true; - break; - - case MP2::OBJ_ARTESIANSPRING: - if(! isVisited(tile) && - 2 * GetMaxSpellPoints() > GetSpellPoints()) return true; - break; - - case MP2::OBJ_XANADU: - { - const u8 level1 = GetLevelSkill(Skill::Secondary::DIPLOMACY); - const u8 level2 = GetLevel(); - - if(!isVisited(tile) && - ((level1 == Skill::Level::BASIC && 7 < level2) || - (level1 == Skill::Level::ADVANCED && 5 < level2) || - (level1 == Skill::Level::EXPERT && 3 < level2) || (9 < level2))) return true; - break; - } - - // accept army - case MP2::OBJ_WATCHTOWER: - case MP2::OBJ_EXCAVATION: - case MP2::OBJ_CAVE: - case MP2::OBJ_TREEHOUSE: - case MP2::OBJ_ARCHERHOUSE: - case MP2::OBJ_GOBLINHUT: - case MP2::OBJ_DWARFCOTT: - case MP2::OBJ_HALFLINGHOLE: - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_THATCHEDHUT: - { - Monster mons = Monster::FromObject(obj); - if(tile.GetCountMonster() && - (army.HasMonster(mons) || - (army.GetCount() < army.Size() && (mons.isArchers() || mons.isFly())))) return true; - break; - } - - // recruit army - case MP2::OBJ_RUINS: - case MP2::OBJ_TREECITY: - case MP2::OBJ_WAGONCAMP: - case MP2::OBJ_DESERTTENT: - case MP2::OBJ_WATERALTAR: - case MP2::OBJ_AIRALTAR: - case MP2::OBJ_FIREALTAR: - case MP2::OBJ_EARTHALTAR: - case MP2::OBJ_BARROWMOUNDS: - { - const u32 count = tile.GetCountMonster(); - const Monster monster(Monster::FromObject(obj)); - const payment_t paymentCosts(PaymentConditions::BuyMonster(monster()) * count); - const Resource::funds_t & kingdomResource = world.GetKingdom(GetColor()).GetFundsResource(); - - if(count && paymentCosts <= kingdomResource && - (army.HasMonster(monster) || - (army.GetCount() < army.Size() && (monster.isArchers() || monster.isFly())))) return true; - break; - } - - // recruit army (battle) - case MP2::OBJ_DRAGONCITY: - case MP2::OBJ_CITYDEAD: - case MP2::OBJ_TROLLBRIDGE: - { - const bool battle = (Color::GRAY == world.ColorCapturedObject(index)); - const u32 count = tile.GetCountMonster(); - const Monster monster(Monster::FromObject(obj)); - const payment_t paymentCosts(PaymentConditions::BuyMonster(monster()) * count); - const Resource::funds_t & kingdomResource = world.GetKingdom(GetColor()).GetFundsResource(); - - if(!battle && count && paymentCosts <= kingdomResource && - (army.HasMonster(monster) || - (army.GetCount() < army.Size()))) return true; - break; - } - - // recruit genie - case MP2::OBJ_ANCIENTLAMP: - { - const u32 count = tile.GetCountMonster(); - const payment_t paymentCosts(PaymentConditions::BuyMonster(Monster::GENIE) * count); - const Resource::funds_t & kingdomResource = world.GetKingdom(GetColor()).GetFundsResource(); - - if(count && paymentCosts <= kingdomResource && - (army.HasMonster(Monster::GENIE) || - (army.GetCount() < army.Size()))) return true; - break; - } - - // upgrade army - case MP2::OBJ_HILLFORT: - if(army.HasMonster(Monster::DWARF) || - army.HasMonster(Monster::ORC) || - army.HasMonster(Monster::OGRE)) return true; - break; - - // upgrade army - case MP2::OBJ_FREEMANFOUNDRY: - if(army.HasMonster(Monster::PIKEMAN) || - army.HasMonster(Monster::SWORDSMAN) || - army.HasMonster(Monster::IRON_GOLEM)) return true; - break; - - // loyalty obj - case MP2::OBJ_STABLES: - if(army.HasMonster(Monster::CAVALRY) || - ! isVisited(tile)) return true; - break; - - case MP2::OBJ_ARENA: - if(! isVisited(tile)) return true; - break; - - // poor morale obj - case MP2::OBJ_SHIPWRECK: - case MP2::OBJ_GRAVEYARD: - case MP2::OBJ_DERELICTSHIP: - if(! isVisited(tile, Visit::GLOBAL)) - { - if(tile.CheckEnemyGuardians(GetColor())) - { - Army::army_t enemy; - enemy.FromGuardian(tile); - return enemy.isValid() && GetArmy().StrongerEnemyArmy(enemy); - } - } - break; - - //case MP2::OBJ_PYRAMID: - - case MP2::OBJ_DAEMONCAVE: - if(tile.GetQuantity2() && 4 != tile.GetQuantity2()) return true; - break; - - case MP2::OBJ_MONSTER: - { - Army::army_t enemy; - enemy.FromGuardian(tile); - return !enemy.isValid() || GetArmy().StrongerEnemyArmy(enemy); - } - break; - - // sign - case MP2::OBJ_SIGN: - if(!isVisited(tile)) return true; - break; - - case MP2::OBJ_CASTLE: - { - const Settings & conf = Settings::Get(); - const Castle *castle = world.GetCastle(index); - if(castle) - { - if(GetColor() == castle->GetColor()) - return NULL == castle->GetHeroes() && ! isVisited(tile); - else - // FIXME: AI skip visiting alliance - if(conf.IsUnions(GetColor(), castle->GetColor())) return false; - else - if(GetArmy().StrongerEnemyArmy(castle->GetActualArmy())) return true; - } - break; - } - - case MP2::OBJ_HEROES: - { - const Settings & conf = Settings::Get(); - const Heroes *hero = world.GetHeroes(index); - if(hero) - { - if(GetColor() == hero->GetColor()) return true; - // FIXME: AI skip visiting alliance - else - if(conf.IsUnions(GetColor(), hero->GetColor())) return false; - else - if(hero->AllowBattle() && - GetArmy().StrongerEnemyArmy(hero->GetArmy())) return true; - } - break; - } - - case MP2::OBJ_BOAT: - case MP2::OBJ_STONELIGHTS: - // check later - return true; - - /* - or add later - */ - - default: break; - } - - return false; -} - -void Heroes::AIRescueWhereMove(void) -{ - u8 scoute = GetScoute(); - - switch(Settings::Get().GameDifficulty()) - { - case Difficulty::NORMAL: scoute += 2; break; - case Difficulty::HARD: scoute += 3; break; - case Difficulty::EXPERT: scoute += 4; break; - case Difficulty::IMPOSSIBLE:scoute += 6; break; - default: break; - } - - scoute += 1; - const Point & mp = GetCenter(); - - // find unchartered territory - for(u8 ii = 1; ii <= scoute; ++ii) - { - const s32 tx = mp.x - ii; - const s32 ty = mp.y - ii; - - const s32 mx = tx + 2 * ii; - const s32 my = ty + 2 * ii; - - for(s32 iy = ty; iy <= my; ++iy) - for(s32 ix = tx; ix <= mx; ++ix) - { - if(ty < iy && iy < my && tx < ix && ix < mx) continue; - - const s32 res = Maps::GetIndexFromAbsPoint(ix, iy); - - if(Maps::isValidAbsIndex(res) && - world.GetTiles(res).isFog(color) && - world.GetTiles(res).isPassable(this, true) && - GetPath().Calculate(res)) - { - ai_sheduled_visit.push_back(res); - - DEBUG(DBG_AI , DBG_INFO, "Heroes::AIRescueMove: " << Color::String(GetColor()) << - ", hero: " << GetName() << ", added task: " << res); - - return; - } - } - } - - if(MP2::OBJ_STONELIGHTS == save_maps_object || - MP2::OBJ_WHIRLPOOL == save_maps_object) - { - AIAction(GetIndex()); - } -} - -void Heroes::AIMeeting(Heroes & heroes2) -{ - if(Settings::Get().ExtEyeEagleAsScholar()) - Heroes::ScholarAction(*this, heroes2); - - if(Modes(HUNTER)) - GetArmy().JoinStrongestFromArmy(heroes2.GetArmy()); - else - if(heroes2.Modes(HUNTER)) - heroes2.GetArmy().JoinStrongestFromArmy(GetArmy()); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_base.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_base.cpp deleted file mode 100644 index 4f228acbe..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_base.cpp +++ /dev/null @@ -1,325 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "artifact.h" -#include "army.h" -#include "castle.h" -#include "heroes_base.h" - -typedef std::vector< std::pair > ArtifactsModifiers; - -s8 GetResultModifiers(const ArtifactsModifiers & modifiers, const HeroBase & base, std::string* strs) -{ - s8 result = 0; - - for(size_t ii = 0; ii < modifiers.size(); ++ii) - { - const std::pair & pair = modifiers[ii]; - - if(base.HasArtifact(pair.first)) - { - result += pair.second; - - if(strs) - { - strs->append(Artifact::GetName(pair.first)); - StringAppendModifiers(*strs, pair.second); - strs->append("\n"); - } - } - } - - return result; -} - -HeroBase::HeroBase() : magic_point(0), spell_book() -{ -} - -u16 HeroBase::GetSpellPoints(void) const -{ - return magic_point; -} - -void HeroBase::SetSpellPoints(u16 points) -{ - magic_point = points; -} - -bool HeroBase::HaveSpellPoints(u16 points) const -{ - return magic_point >= points; -} - -void HeroBase::TakeSpellPoints(u16 points) -{ - magic_point -= (points < magic_point ? points : magic_point); -} - -Spell::spell_t HeroBase::OpenSpellBook(SpellBook::filter_t flt, bool canselect) const -{ - return spell_book.Open(*this, flt, canselect); -} - -bool HeroBase::HaveSpellBook(void) const -{ - return spell_book.isActive(); -} - -bool HeroBase::HaveSpell(Spell::spell_t spell) const -{ - BagArtifacts::const_iterator it1 = bag_artifacts.begin(); - BagArtifacts::const_iterator it2 = bag_artifacts.end(); - for(; it1 != it2; ++it1) if(*it1 == Artifact::SPELL_SCROLL) - { - if(spell == Spell::FromInt((*it1).GetExt())) return true; - } - - return spell_book.isActive() && spell_book.isPresentSpell(spell); -} - -void HeroBase::AppendSpellToBook(Spell::spell_t spell, bool without_wisdom) -{ - if(without_wisdom) - spell_book.Append(spell); - else - spell_book.Append(spell, GetLevelSkill(Skill::Secondary::WISDOM)); -} - -void HeroBase::SpellBookActivate(void) -{ - spell_book.Activate(); -} - -const BagArtifacts & HeroBase::GetBagArtifacts(void) const -{ - return bag_artifacts; -} - -BagArtifacts & HeroBase::GetBagArtifacts(void) -{ - return bag_artifacts; -} - -bool HeroBase::HasArtifact(Artifact::artifact_t art) const -{ - return bag_artifacts.size() && bag_artifacts.end() != std::find(bag_artifacts.begin(), bag_artifacts.end(), art); -} - -s8 HeroBase::GetAttackModificator(std::string* strs) const -{ - static ArtifactsModifiers modifiers; - - if(modifiers.empty()) - { - modifiers.reserve(14); - - modifiers.push_back(std::make_pair(Artifact::SPIKED_HELM, 1)); - modifiers.push_back(std::make_pair(Artifact::THUNDER_MACE, 1)); - modifiers.push_back(std::make_pair(Artifact::GIANT_FLAIL, 1)); - modifiers.push_back(std::make_pair(Artifact::SWORD_BREAKER, 1)); - modifiers.push_back(std::make_pair(Artifact::SPIKED_SHIELD, 2)); - modifiers.push_back(std::make_pair(Artifact::POWER_AXE, 2)); - modifiers.push_back(std::make_pair(Artifact::LEGENDARY_SCEPTER, 2)); - modifiers.push_back(std::make_pair(Artifact::DRAGON_SWORD, 3)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_CROWN, 4)); - modifiers.push_back(std::make_pair(Artifact::BATTLE_GARB, 5)); - modifiers.push_back(std::make_pair(Artifact::SWORD_ANDURAN, 5)); - modifiers.push_back(std::make_pair(Artifact::HOLY_HAMMER, 5)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_SHIELD, 6)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_SWORD, 12)); - } - - s8 result = GetResultModifiers(modifiers, *this, strs); - - // check castle modificator - const Castle* castle = inCastle(); - - if(castle) - result += castle->GetAttackModificator(strs); - - return result; -} - -s8 HeroBase::GetDefenseModificator(std::string* strs) const -{ - static ArtifactsModifiers modifiers; - - if(modifiers.empty()) - { - modifiers.reserve(13); - - modifiers.push_back(std::make_pair(Artifact::SPIKED_HELM, 1)); - modifiers.push_back(std::make_pair(Artifact::ARMORED_GAUNTLETS, 1)); - modifiers.push_back(std::make_pair(Artifact::DEFENDER_HELM, 1)); - modifiers.push_back(std::make_pair(Artifact::SPIKED_SHIELD, 2)); - modifiers.push_back(std::make_pair(Artifact::STEALTH_SHIELD, 2)); - modifiers.push_back(std::make_pair(Artifact::LEGENDARY_SCEPTER, 2)); - modifiers.push_back(std::make_pair(Artifact::DIVINE_BREASTPLATE, 3)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_CROWN, 4)); - modifiers.push_back(std::make_pair(Artifact::SWORD_BREAKER, 4)); - modifiers.push_back(std::make_pair(Artifact::BREASTPLATE_ANDURAN, 5)); - modifiers.push_back(std::make_pair(Artifact::BATTLE_GARB, 5)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_SHIELD, 6)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_CLOAK, 12)); - } - - s8 result = GetResultModifiers(modifiers, *this, strs); - - // check castle modificator - const Castle* castle = inCastle(); - - if(castle) - result += castle->GetDefenseModificator(strs); - - return result; -} - -s8 HeroBase::GetPowerModificator(std::string* strs) const -{ - static ArtifactsModifiers modifiers; - - if(modifiers.empty()) - { - modifiers.reserve(15); - - modifiers.push_back(std::make_pair(Artifact::BROACH_SHIELDING, -1)); - modifiers.push_back(std::make_pair(Artifact::WHITE_PEARL, 1)); - modifiers.push_back(std::make_pair(Artifact::BLACK_PEARL, 2)); - modifiers.push_back(std::make_pair(Artifact::CASTER_BRACELET, 2)); - modifiers.push_back(std::make_pair(Artifact::MAGE_RING, 2)); - modifiers.push_back(std::make_pair(Artifact::LEGENDARY_SCEPTER, 2)); - modifiers.push_back(std::make_pair(Artifact::WITCHES_BROACH, 3)); - modifiers.push_back(std::make_pair(Artifact::ARM_MARTYR, 3)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_CROWN, 4)); - modifiers.push_back(std::make_pair(Artifact::ARCANE_NECKLACE, 4)); - modifiers.push_back(std::make_pair(Artifact::BATTLE_GARB, 5)); - modifiers.push_back(std::make_pair(Artifact::STAFF_WIZARDRY, 5)); - modifiers.push_back(std::make_pair(Artifact::HELMET_ANDURAN, 5)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_STAFF, 6)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_WAND, 12)); - } - - s8 result = GetResultModifiers(modifiers, *this, strs); - - // check castle modificator - const Castle* castle = inCastle(); - - if(castle) - result += castle->GetPowerModificator(strs); - - return result; -} - -s8 HeroBase::GetKnowledgeModificator(std::string* strs) const -{ - static ArtifactsModifiers modifiers; - - if(modifiers.empty()) - { - modifiers.reserve(10); - - modifiers.push_back(std::make_pair(Artifact::WHITE_PEARL, 1)); - modifiers.push_back(std::make_pair(Artifact::BLACK_PEARL, 2)); - modifiers.push_back(std::make_pair(Artifact::MINOR_SCROLL, 2)); - modifiers.push_back(std::make_pair(Artifact::LEGENDARY_SCEPTER, 2)); - modifiers.push_back(std::make_pair(Artifact::MAJOR_SCROLL, 3)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_CROWN, 4)); - modifiers.push_back(std::make_pair(Artifact::SUPERIOR_SCROLL, 4)); - modifiers.push_back(std::make_pair(Artifact::FOREMOST_SCROLL, 5)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_STAFF, 6)); - modifiers.push_back(std::make_pair(Artifact::ULTIMATE_BOOK, 12)); - } - - s8 result = GetResultModifiers(modifiers, *this, strs); - - // check castle modificator - const Castle* castle = inCastle(); - - if(castle) - result += castle->GetKnowledgeModificator(strs); - - return result; -} - -s8 HeroBase::GetMoraleModificator(bool shipmaster, std::string* strs) const -{ - ArtifactsModifiers modifiers; - - modifiers.reserve(7); - - modifiers.push_back(std::make_pair(Artifact::MEDAL_VALOR, 1)); - modifiers.push_back(std::make_pair(Artifact::MEDAL_COURAGE, 1)); - modifiers.push_back(std::make_pair(Artifact::MEDAL_HONOR, 1)); - modifiers.push_back(std::make_pair(Artifact::MEDAL_DISTINCTION, 1)); - modifiers.push_back(std::make_pair(Artifact::FIZBIN_MISFORTUNE, -2)); - modifiers.push_back(std::make_pair(Artifact::BATTLE_GARB, 10)); - if(shipmaster) modifiers.push_back(std::make_pair(Artifact::MASTHEAD, 1)); - - s8 result = GetResultModifiers(modifiers, *this, strs); - - // check castle modificator - const Castle* castle = inCastle(); - - if(castle) - result += castle->GetMoraleModificator(strs); - - // army modificator - if(GetArmy().AllTroopsIsRace(Race::NECR)) - { - if(strs) strs->clear(); - result = 0; - } - - result += GetArmy().GetMoraleModificator(strs); - - return result; -} - -s8 HeroBase::GetLuckModificator(bool shipmaster, std::string* strs) const -{ - ArtifactsModifiers modifiers; - - modifiers.reserve(6); - - modifiers.push_back(std::make_pair(Artifact::RABBIT_FOOT, 1)); - modifiers.push_back(std::make_pair(Artifact::GOLDEN_HORSESHOE, 1)); - modifiers.push_back(std::make_pair(Artifact::GAMBLER_LUCKY_COIN, 1)); - modifiers.push_back(std::make_pair(Artifact::FOUR_LEAF_CLOVER, 1)); - modifiers.push_back(std::make_pair(Artifact::BATTLE_GARB, 10)); - if(shipmaster) modifiers.push_back(std::make_pair(Artifact::MASTHEAD, 1)); - - s8 result = GetResultModifiers(modifiers, *this, strs); - - // check castle modificator - const Castle* castle = inCastle(); - - if(castle) - result += castle->GetLuckModificator(strs); - - // army modificator - result += GetArmy().GetLuckModificator(strs); - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_base.h b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_base.h deleted file mode 100644 index 1d53dafaa..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_base.h +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2008 by Andrey Afletdinov * - * Copyright (C) 2009 by Josh Matthews * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2HEROESBASE_H -#define H2HEROESBASE_H - -#include "bitmodes.h" -#include "skill.h" -#include "spell_book.h" -#include "artifact.h" -#include "color.h" -#include "position.h" - -typedef std::vector BagArtifacts; - -namespace Army { class army_t; } - -class HeroBase : public Skill::Primary, public Maps::Position, public BitModes -{ -public: - HeroBase(); - - virtual const std::string & GetName(void) const = 0; - virtual Color::color_t GetColor(void) const = 0; - virtual u8 GetControl(void) const = 0; - virtual bool isValid(void) const = 0; - - virtual const Army::army_t & GetArmy(void) const = 0; - virtual Army::army_t & GetArmy(void) = 0; - - virtual u16 GetMaxSpellPoints(void) const = 0; - - virtual u8 GetLevelSkill(const Skill::Secondary::skill_t) const = 0; - virtual u8 GetSecondaryValues(const Skill::Secondary::skill_t) const = 0; - - virtual void PreBattleAction(void) = 0; - - virtual const Castle* inCastle(void) const = 0; - - s8 GetAttackModificator(std::string* = NULL) const; - s8 GetDefenseModificator(std::string* = NULL) const; - s8 GetPowerModificator(std::string* = NULL) const; - s8 GetKnowledgeModificator(std::string* = NULL) const; - s8 GetMoraleModificator(bool, std::string* = NULL) const; - s8 GetLuckModificator(bool, std::string* = NULL) const; - - u16 GetSpellPoints(void) const; - bool HaveSpellPoints(u16) const; - void SetSpellPoints(u16); - void TakeSpellPoints(u16); - - Spell::spell_t OpenSpellBook(SpellBook::filter_t, bool) const; - bool HaveSpellBook(void) const; - bool HaveSpell(Spell::spell_t) const; - void SpellBookActivate(void); - void AppendSpellToBook(Spell::spell_t, bool without_wisdom = false); - - BagArtifacts & GetBagArtifacts(void); - const BagArtifacts & GetBagArtifacts(void) const; - bool HasArtifact(Artifact::artifact_t) const; - -protected: - u16 magic_point; - SpellBook spell_book; - BagArtifacts bag_artifacts; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_dialog.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_dialog.cpp deleted file mode 100644 index a2654765f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_dialog.cpp +++ /dev/null @@ -1,565 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "button.h" -#include "world.h" -#include "cursor.h" -#include "settings.h" -#include "payment.h" -#include "heroes.h" -#include "skill.h" -#include "kingdom.h" -#include "text.h" -#include "castle.h" -#include "portrait.h" -#include "dialog.h" -#include "heroes_indicator.h" -#include "selectarmybar.h" -#include "statusbar.h" -#include "selectartifactbar.h" -#include "pocketpc.h" -#include "localclient.h" - -/* readonly: false, fade: false */ -Dialog::answer_t Heroes::OpenDialog(bool readonly, bool fade) -{ - if(Settings::Get().QVGA()) return PocketPC::HeroesOpenDialog(*this, readonly); - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - Dialog::FrameBorder background; - background.SetPosition((display.w() - 640 - BORDERWIDTH * 2) / 2, (display.h() - 480 - BORDERWIDTH * 2) / 2, 640, 480); - background.Redraw(); - - const Point cur_pt(background.GetArea().x, background.GetArea().y); - Point dst_pt(cur_pt); - - // fade - if(fade && Settings::Get().ExtUseFade()) display.Fade(); - display.FillRect(0, 0, 0, Rect(dst_pt, 640, 480)); - - display.Blit(AGG::GetICN(ICN::HEROBKG, 0), dst_pt); - - display.Blit(AGG::GetICN(Settings::Get().EvilInterface() ? ICN::HEROEXTE : ICN::HEROEXTG, 0), dst_pt); - - std::string message; - - // portrait - dst_pt.x = cur_pt.x + 49; - dst_pt.y = cur_pt.y + 31; - display.Blit(GetPortrait101x93(), dst_pt); - - // name - message = _("%{name} the %{race} ( Level %{level} )"); - String::Replace(message, "%{name}", name); - String::Replace(message, "%{race}", Race::String(race)); - String::Replace(message, "%{level}", GetLevel()); - Text text(message, Font::BIG); - text.Blit(cur_pt.x + 320 - text.w() / 2, cur_pt.y + 1); - - // attack - message = _("Attack Skill"); - text.Set(message, Font::SMALL); - dst_pt.x = cur_pt.x + 196; - dst_pt.y = cur_pt.y + 34; - text.Blit(dst_pt.x - text.w() / 2, dst_pt.y); - - message.clear(); - String::AddInt(message, GetAttack()); - text.Set(message, Font::BIG); - dst_pt.y += 70; - text.Blit(dst_pt.x - text.w() / 2, dst_pt.y); - - const Rect rectAttackSkill(cur_pt.x + 156, cur_pt.y + 30, 80, 92); - std::string attackDescription(_("Your attack skill is a bonus added to each creature's attack skill.")); - - message.clear(); - GetAttack(&message); - if(message.size()) - { - attackDescription.append("\n \n"); - attackDescription.append(_("Current Modifiers:")); - attackDescription.append("\n \n"); - attackDescription.append(message); - } - - // defense - message = _("Defense Skill"); - dst_pt.x = cur_pt.x + 284; - dst_pt.y = cur_pt.y + 34; - text.Set(message, Font::SMALL); - text.Blit(dst_pt.x - text.w() / 2, dst_pt.y); - - message.clear(); - String::AddInt(message, GetDefense()); - dst_pt.y += 70; - text.Set(message, Font::BIG); - text.Blit(dst_pt.x - text.w() / 2, dst_pt.y); - - const Rect rectDefenseSkill(cur_pt.x + 156 + 88, cur_pt.y + 30, 80, 92); - std::string defenseDescription(_("Your defense skill is a bonus added to each creature's defense skill.")); - - message.clear(); - GetDefense(&message); - if(message.size()) - { - defenseDescription.append("\n \n"); - defenseDescription.append(_("Current Modifiers:")); - defenseDescription.append("\n \n"); - defenseDescription.append(message); - } - - // spell - message = _("Spell Power"); - dst_pt.x = cur_pt.x + 372; - dst_pt.y = cur_pt.y + 34; - text.Set(message, Font::SMALL); - text.Blit(dst_pt.x - text.w() / 2, dst_pt.y); - - message.clear(); - String::AddInt(message, GetPower()); - dst_pt.y += 70; - text.Set(message, Font::BIG); - text.Blit(dst_pt.x - text.w() / 2, dst_pt.y); - - const Rect rectSpellSkill(cur_pt.x + 156 + 2 * 88, cur_pt.y + 30, 80, 92); - std::string powerDescription(_("Your spell power determines the length or power of a spell.")); - - message.clear(); - GetPower(&message); - if(message.size()) - { - powerDescription.append("\n \n"); - powerDescription.append(_("Current Modifiers:")); - powerDescription.append("\n \n"); - powerDescription.append(message); - } - - // knowledge - message = _("Knowledge"); - dst_pt.x = cur_pt.x + 460; - dst_pt.y = cur_pt.y + 34; - text.Set(message, Font::SMALL); - text.Blit(dst_pt.x - text.w() / 2, dst_pt.y); - - message.clear(); - String::AddInt(message, GetKnowledge()); - dst_pt.y += 70; - text.Set(message, Font::BIG); - text.Blit(dst_pt.x - text.w() / 2, dst_pt.y); - - const Rect rectKnowledgeSkill(cur_pt.x + 156 + 3 * 88, cur_pt.y + 30, 80, 92); - std::string knowledgeDescription(_("Your knowledge determines how many spell points your hero may have. Under normal cirumstances, a hero is limited to 10 spell points per level of knowledge.")); - - message.clear(); - GetKnowledge(&message); - if(message.size()) - { - knowledgeDescription.append("\n \n"); - knowledgeDescription.append(_("Current Modifiers:")); - knowledgeDescription.append("\n \n"); - knowledgeDescription.append(message); - } - - // morale - dst_pt.x = cur_pt.x + 514; - dst_pt.y = cur_pt.y + 35; - - MoraleIndicator moraleIndicator(*this); - moraleIndicator.SetPos(dst_pt); - moraleIndicator.Redraw(); - - // luck - dst_pt.x = cur_pt.x + 552; - dst_pt.y = cur_pt.y + 35; - - LuckIndicator luckIndicator(*this); - luckIndicator.SetPos(dst_pt); - luckIndicator.Redraw(); - - // army format spread - const bool combat_format = (Army::FORMAT_SPREAD == army.GetCombatFormat()); - dst_pt.x = cur_pt.x + 515; - dst_pt.y = cur_pt.y + 63; - const Sprite & sprite1 = AGG::GetICN(ICN::HSICONS, 9); - display.Blit(sprite1, dst_pt); - - const Rect rectSpreadArmyFormat(dst_pt, sprite1.w(), sprite1.h()); - const std::string descriptionSpreadArmyFormat = _("'Spread' combat formation spreads your armies from the top to the bottom of the battlefield, with at least one empty space between each army."); - const Point army1_pt(dst_pt.x - 1, dst_pt.y - 1); - - // army format grouped - dst_pt.x = cur_pt.x + 552; - dst_pt.y = cur_pt.y + 63; - const Sprite & sprite2 = AGG::GetICN(ICN::HSICONS, 10); - display.Blit(sprite2, dst_pt); - - const Rect rectGroupedArmyFormat(dst_pt, sprite2.w(), sprite2.h()); - const std::string descriptionGroupedArmyFormat = _("'Grouped' combat formation bunches your army together in the center of your side of the battlefield."); - const Point army2_pt(dst_pt.x - 1, dst_pt.y - 1); - - // cursor format - SpriteCursor cursorFormat(AGG::GetICN(ICN::HSICONS, 11), combat_format ? army1_pt : army2_pt); - cursorFormat.Show(combat_format ? army1_pt : army2_pt); - - // experience - ExperienceIndicator experienceInfo(*this); - experienceInfo.SetPos(Point(cur_pt.x + 514, cur_pt.y + 85)); - experienceInfo.Redraw(); - - // spell points - SpellPointsIndicator spellPointsInfo(*this); - spellPointsInfo.SetPos(Point(cur_pt.x + 549, cur_pt.y + 87)); - spellPointsInfo.Redraw(); - - // crest - dst_pt.x = cur_pt.x + 49; - dst_pt.y = cur_pt.y + 130; - - display.Blit(AGG::GetICN(ICN::CREST, Color::GRAY == color ? Color::GetIndex(world.GetMyKingdom().GetColor()) : Color::GetIndex(color)), dst_pt); - - // monster - dst_pt.x = cur_pt.x + 156; - dst_pt.y = cur_pt.y + 130; - - SelectArmyBar selectArmy; - selectArmy.SetArmy(army); - selectArmy.SetPos(dst_pt); - selectArmy.SetInterval(6); - selectArmy.SetBackgroundSprite(AGG::GetICN(ICN::STRIP, 2)); - selectArmy.SetCursorSprite(AGG::GetICN(ICN::STRIP, 1)); - selectArmy.SetSaveLastTroop(); - if(readonly) selectArmy.SetReadOnly(); - const Castle* castle = inCastle(); - if(castle) selectArmy.SetCastle(*castle); - selectArmy.Redraw(); - - // secskill - SecondarySkillBar secskill_bar; - secskill_bar.SetPos(cur_pt.x + 3, cur_pt.y + 233); - secskill_bar.SetInterval(5); - secskill_bar.SetSkills(secondary_skills); - secskill_bar.Redraw(); - - dst_pt.x = cur_pt.x + 51; - dst_pt.y = cur_pt.y + 308; - - SelectArtifactsBar selectArtifacts(*this); - selectArtifacts.SetPos(dst_pt); - selectArtifacts.SetInterval(15); - selectArtifacts.SetBackgroundSprite(AGG::GetICN(ICN::ARTIFACT, 0)); - selectArtifacts.SetCursorSprite(AGG::GetICN(ICN::NGEXTRA, 62)); - if(readonly) selectArtifacts.SetReadOnly(); - selectArtifacts.Redraw(); - - // bottom small bar - dst_pt.x = cur_pt.x + 22; - dst_pt.y = cur_pt.y + 460; - const Sprite & bar = AGG::GetICN(ICN::HSBTNS, 8); - display.Blit(bar, dst_pt); - - StatusBar statusBar; - statusBar.SetCenter(dst_pt.x + bar.w() / 2, dst_pt.y + 11); - - // button prev - dst_pt.x = cur_pt.x + 1; - dst_pt.y = cur_pt.y + 480 - 20; - Button buttonPrevHero(dst_pt, ICN::HSBTNS, 4, 5); - - // button next - dst_pt.x = cur_pt.x + 640 - 23; - dst_pt.y = cur_pt.y + 480 - 20; - Button buttonNextHero(dst_pt, ICN::HSBTNS, 6, 7); - - // button dismiss - dst_pt.x = cur_pt.x + 5; - dst_pt.y = cur_pt.y + 318; - Button buttonDismiss(dst_pt, ICN::HSBTNS, 0, 1); - - // button exit - dst_pt.x = cur_pt.x + 603; - dst_pt.y = cur_pt.y + 318; - Button buttonExit(dst_pt, ICN::HSBTNS, 2, 3); - - LocalEvent & le = LocalEvent::Get(); - - if(castle || readonly) - { - buttonDismiss.Press(); - buttonDismiss.SetDisable(true); - } - - if(readonly || 2 > world.GetMyKingdom().GetHeroes().size()) - { - buttonNextHero.Press(); - buttonPrevHero.Press(); - buttonNextHero.SetDisable(true); - buttonPrevHero.SetDisable(true); - } - - buttonPrevHero.Draw(); - buttonNextHero.Draw(); - buttonDismiss.Draw(); - buttonExit.Draw(); - - cursor.Show(); - display.Flip(); - - bool redrawMorale = false; - bool redrawLuck = false; - - // dialog menu loop - while(le.HandleEvents()) - { - if(redrawMorale) - { - cursor.Hide(); - moraleIndicator.Redraw(); - cursor.Show(); - display.Flip(); - redrawMorale = false; - } - - if(redrawLuck) - { - cursor.Hide(); - luckIndicator.Redraw(); - cursor.Show(); - display.Flip(); - redrawLuck = false; - } - - // exit - if(le.MouseClickLeft(buttonExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) return Dialog::CANCEL; - - // heroes troops - if(le.MouseCursor(selectArmy.GetArea())) - { - if(SelectArmyBar::QueueEventProcessing(selectArmy)) - { - redrawMorale = true; - redrawLuck = true; - } - } - - if(le.MouseCursor(selectArtifacts.GetArea())) - { - SelectArtifactsBar::QueueEventProcessing(selectArtifacts); - { - redrawMorale = true; - redrawLuck = true; - } - } - - // button click - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - if(buttonDismiss.isEnable()) le.MousePressLeft(buttonDismiss) ? buttonDismiss.PressDraw() : buttonDismiss.ReleaseDraw(); - if(buttonPrevHero.isEnable()) le.MousePressLeft(buttonPrevHero) ? buttonPrevHero.PressDraw() : buttonPrevHero.ReleaseDraw(); - if(buttonNextHero.isEnable()) le.MousePressLeft(buttonNextHero) ? buttonNextHero.PressDraw() : buttonNextHero.ReleaseDraw(); - - // prev hero - if(buttonPrevHero.isEnable() && le.MouseClickLeft(buttonPrevHero)){ return Dialog::PREV; } - - // next hero - if(buttonNextHero.isEnable() && le.MouseClickLeft(buttonNextHero)){ return Dialog::NEXT; } - - // dismiss - if(buttonDismiss.isEnable() && le.MouseClickLeft(buttonDismiss) && - Dialog::YES == Dialog::Message(GetName(), _("Are you sure you want to dismiss this Hero?"), Font::BIG, Dialog::YES | Dialog::NO)) - { return Dialog::DISMISS; } - - if(le.MouseCursor(moraleIndicator.GetArea())) MoraleIndicator::QueueEventProcessing(moraleIndicator); - else - if(le.MouseCursor(luckIndicator.GetArea())) LuckIndicator::QueueEventProcessing(luckIndicator); - else - if(le.MouseCursor(experienceInfo.GetArea())) experienceInfo.QueueEventProcessing(); - else - if(le.MouseCursor(spellPointsInfo.GetArea())) spellPointsInfo.QueueEventProcessing(); - - // left click info - if(le.MouseClickLeft(rectAttackSkill)) Dialog::Message(_("Attack Skill"), attackDescription, Font::BIG, Dialog::OK); - else - if(le.MouseClickLeft(rectDefenseSkill)) Dialog::Message(_("Defense Skill"), defenseDescription, Font::BIG, Dialog::OK); - else - if(le.MouseClickLeft(rectSpellSkill)) Dialog::Message(_("Spell Power"), powerDescription, Font::BIG, Dialog::OK); - else - if(le.MouseClickLeft(rectKnowledgeSkill)) Dialog::Message(_("Knowledge"), knowledgeDescription, Font::BIG, Dialog::OK); - else - if(!readonly && le.MouseClickLeft(rectSpreadArmyFormat) && !combat_format) - { - cursor.Hide(); - cursorFormat.Move(army1_pt); - cursor.Show(); - display.Flip(); - army.SetCombatFormat(Army::FORMAT_SPREAD); -#ifdef WITH_NET - FH2LocalClient::SendArmyCombatFormation(army); -#endif - } - else - if(!readonly && le.MouseClickLeft(rectGroupedArmyFormat) && combat_format) - { - cursor.Hide(); - cursorFormat.Move(army2_pt); - cursor.Show(); - display.Flip(); - army.SetCombatFormat(Army::FORMAT_GROUPED); -#ifdef WITH_NET - FH2LocalClient::SendArmyCombatFormation(army); -#endif - } - - if(le.MouseCursor(secskill_bar.GetArea())) secskill_bar.QueueEventProcessing(); - - // right info - if(le.MousePressRight(rectAttackSkill)) Dialog::Message(_("Attack Skill"), attackDescription, Font::BIG); - else - if(le.MousePressRight(rectDefenseSkill)) Dialog::Message(_("Defense Skill"), defenseDescription, Font::BIG); - else - if(le.MousePressRight(rectSpellSkill)) Dialog::Message(_("Spell Power"), powerDescription, Font::BIG); - else - if(le.MousePressRight(rectKnowledgeSkill)) Dialog::Message(_("Knowledge"), knowledgeDescription, Font::BIG); - else - if(le.MousePressRight(rectSpreadArmyFormat)) Dialog::Message(_("Spread Formation"), descriptionSpreadArmyFormat, Font::BIG); - else - if(le.MousePressRight(rectGroupedArmyFormat)) Dialog::Message(_("Grouped Formation"), descriptionGroupedArmyFormat, Font::BIG); - - // status message - if(le.MouseCursor(rectAttackSkill)) statusBar.ShowMessage(_("View Attack Skill Info")); - else - if(le.MouseCursor(rectDefenseSkill)) statusBar.ShowMessage(_("View Defense Skill Info")); - else - if(le.MouseCursor(rectSpellSkill)) statusBar.ShowMessage(_("View Spell Power Info")); - else - if(le.MouseCursor(rectKnowledgeSkill)) statusBar.ShowMessage(_("View Knowledge Info")); - else - if(le.MouseCursor(moraleIndicator.GetArea())) statusBar.ShowMessage(_("View Morale Info")); - else - if(le.MouseCursor(luckIndicator.GetArea())) statusBar.ShowMessage(_("View Luck Info")); - else - if(le.MouseCursor(experienceInfo.GetArea())) statusBar.ShowMessage(_("View Experience Info")); - else - if(le.MouseCursor(spellPointsInfo.GetArea())) statusBar.ShowMessage(_("View Spell Points Info")); - else - if(le.MouseCursor(rectSpreadArmyFormat)) statusBar.ShowMessage(_("Set army combat formation to 'Spread'")); - else - if(le.MouseCursor(rectGroupedArmyFormat)) statusBar.ShowMessage(_("Set army combat formation to 'Grouped'")); - else - if(le.MouseCursor(buttonExit)) statusBar.ShowMessage(_("Exit hero")); - else - if(le.MouseCursor(buttonDismiss)) statusBar.ShowMessage(_("Dismiss hero")); - else - if(le.MouseCursor(buttonPrevHero)) statusBar.ShowMessage(_("Show prev heroes")); - else - if(le.MouseCursor(buttonNextHero)) statusBar.ShowMessage(_("Show next heroes")); - else - // status message over artifact - if(le.MouseCursor(selectArtifacts.GetArea())) - { - const s8 index = selectArtifacts.GetIndexFromCoord(le.GetMouseCursor()); - if(0 <= index && index < HEROESMAXARTIFACT && bag_artifacts[index] != Artifact::UNKNOWN) - { - message = _("View %{art} Info"); - String::Replace(message, "%{art}", bag_artifacts[index].GetName()); - statusBar.ShowMessage(message); - } - else - statusBar.ShowMessage(_("Hero Screen")); - } - else - // status message over skill - if(le.MouseCursor(secskill_bar.GetArea())) - { - const u8 ii = secskill_bar.GetIndexFromCoord(le.GetMouseCursor()); - const Skill::Secondary::skill_t skill = ii < secondary_skills.size() ? secondary_skills[ii].Skill() : Skill::Secondary::UNKNOWN; - const Skill::Level::type_t level = ii < secondary_skills.size() ? secondary_skills[ii].Level() : Skill::Level::NONE; - - if(Skill::Secondary::UNKNOWN != skill && Skill::Level::NONE != level) - { - message = _("View %{level} %{skill} Info"); - String::Replace(message, "%{level}", Skill::Level::String(level)); - String::Replace(message, "%{skill}", Skill::Secondary::String(skill)); - statusBar.ShowMessage(message); - } - else - statusBar.ShowMessage(_("Hero Screen")); - } - else - // status message over troops - if(le.MouseCursor(selectArmy.GetArea())) - { - const s8 index1 = selectArmy.GetIndexFromCoord(le.GetMouseCursor()); - if(0 <= index1) - { - const Army::Troop & troop1 = army.At(index1); - const std::string & monster1 = troop1.GetName(); - - if(selectArmy.isSelected()) - { - const u8 index2 = selectArmy.Selected(); - const Army::Troop & troop2 = army.At(index2); - const std::string & monster2 = troop2.GetName(); - - if(index1 == index2) - { - message = _("View %{monster}"); - String::Replace(message, "%{monster}", monster1); - } - else - if(troop1.isValid() && troop2.isValid()) - { - message = troop1() == troop2() ? _("Combine %{monster1} armies") : _("Exchange %{monster2} with %{monster1}"); - String::Replace(message, "%{monster1}", monster1); - String::Replace(message, "%{monster2}", monster2); - } - else - { - message = _("Move and right click Redistribute %{monster}"); - String::Replace(message, "%{monster}", monster2); - } - } - else - if(troop1.isValid()) - { - message = _("Select %{monster}"); - String::Replace(message, "%{monster}", monster1); - } - else - message = _("Empty"); - - statusBar.ShowMessage(message); - } - else - statusBar.ShowMessage(_("Hero Screen")); - } - else - // clear all - statusBar.ShowMessage(_("Hero Screen")); - } - - return Dialog::ZERO; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_indicator.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_indicator.cpp deleted file mode 100644 index 2a2ba34b2..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_indicator.cpp +++ /dev/null @@ -1,254 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "luck.h" -#include "morale.h" -#include "heroes.h" -#include "heroes_indicator.h" - -const char* MoraleString(s8 morale) -{ - switch(morale) - { - case Morale::TREASON: - case Morale::AWFUL: - case Morale::POOR: - return _("Bad Morale"); - - case Morale::NORMAL: - return _("Neutral Morale"); - - case Morale::GOOD: - case Morale::GREAT: - case Morale::BLOOD: - return _("Good Morale"); - - default: break; - } - return NULL; -} - -const char* LuckString(s8 luck) -{ - switch(luck) - { - case Luck::CURSED: - case Luck::AWFUL: - case Luck::BAD: - return _("Bad Luck"); - - case Luck::NORMAL: - return _("Neutral Luck"); - - case Luck::GOOD: - case Luck::GREAT: - case Luck::IRISH: - return _("Good Luck"); - - default: break; - } - return NULL; -} - -HeroesIndicator::HeroesIndicator(const Heroes & h) : hero(h) -{ - descriptions.reserve(256); -} - -const Rect & HeroesIndicator::GetArea(void) const -{ - return area; -} - -const std::string & HeroesIndicator::GetDescriptions(void) const -{ - return descriptions; -} - -void HeroesIndicator::SetPos(const Point & pt) -{ - area.x = pt.x; - area.y = pt.y; - back.Save(area); -} - -LuckIndicator::LuckIndicator(const Heroes & h) : HeroesIndicator(h) -{ - area.w = 35; - area.h = 26; -} - -void LuckIndicator::Redraw(void) -{ - std::string modificators; - modificators.reserve(256); - luck = hero.GetLuckWithModificators(&modificators); - - descriptions.clear(); - descriptions.append(Luck::Description(luck)); - descriptions.append("\n \n"); - descriptions.append(_("Current Modifiers:")); - descriptions.append("\n \n"); - - const Sprite & sprite = AGG::GetICN(ICN::HSICONS, (0 > luck ? 3 : (0 < luck ? 2 : 6))); - const u8 inter = 6; - u8 count = (0 == luck ? 1 : static_cast(std::abs(luck))); - s16 cx = area.x + (area.w - (sprite.w() + inter * (count - 1))) / 2; - s16 cy = area.y + (area.h - sprite.h()) / 2; - - if(modificators.size()) - descriptions.append(modificators); - else - descriptions.append(_("None")); - - back.Restore(); - while(count--) - { - Display::Get().Blit(sprite, cx, cy); - cx += inter; - } -} - -void LuckIndicator::QueueEventProcessing(LuckIndicator & indicator) -{ - LocalEvent & le = LocalEvent::Get(); - - if(le.MouseClickLeft(indicator.area)) Dialog::Message(LuckString(indicator.luck), indicator.descriptions, Font::BIG, Dialog::OK); - else - if(le.MousePressRight(indicator.area)) Dialog::Message(LuckString(indicator.luck), indicator.descriptions, Font::BIG); -} - -MoraleIndicator::MoraleIndicator(const Heroes & h) : HeroesIndicator(h), morale(Morale::NORMAL) -{ - area.w = 35; - area.h = 26; -} - -void MoraleIndicator::Redraw(void) -{ - std::string modificators; - modificators.reserve(256); - morale = hero.GetMoraleWithModificators(&modificators); - - descriptions.clear(); - descriptions.append(Morale::Description(morale)); - descriptions.append("\n \n"); - descriptions.append(_("Current Modifiers:")); - descriptions.append("\n \n"); - - const Sprite & sprite = AGG::GetICN(ICN::HSICONS, (0 > morale ? 5 : (0 < morale ? 4 : 7))); - const u8 inter = 6; - u8 count = (0 == morale ? 1 : static_cast(std::abs(morale))); - s16 cx = area.x + (area.w - (sprite.w() + inter * (count - 1))) / 2; - s16 cy = area.y + (area.h - sprite.h()) / 2; - - if(modificators.size()) - descriptions.append(modificators); - else - descriptions.append(_("None")); - - back.Restore(); - while(count--) - { - Display::Get().Blit(sprite, cx, cy); - cx += inter; - } -} - -void MoraleIndicator::QueueEventProcessing(MoraleIndicator & indicator) -{ - LocalEvent & le = LocalEvent::Get(); - - if(le.MouseClickLeft(indicator.area)) Dialog::Message(MoraleString(indicator.morale), indicator.descriptions, Font::BIG, Dialog::OK); - else - if(le.MousePressRight(indicator.area)) Dialog::Message(MoraleString(indicator.morale), indicator.descriptions, Font::BIG); -} - -ExperienceIndicator::ExperienceIndicator(const Heroes & h) : HeroesIndicator(h) -{ - area.w = 39; - area.h = 36; - - descriptions = _("Current experience %{exp1} Next level %{exp2}."); - String::Replace(descriptions, "%{exp1}", hero.GetExperience()); - String::Replace(descriptions, "%{exp2}", hero.GetExperienceFromLevel(hero.GetLevelFromExperience(hero.GetExperience()))); -} - -void ExperienceIndicator::Redraw(void) -{ - const Sprite & sprite3 = AGG::GetICN(ICN::HSICONS, 1); - Display::Get().Blit(sprite3, area.x, area.y); - - std::string message; - String::AddInt(message, hero.GetExperience()); - Text text(message, Font::SMALL); - text.Blit(area.x + 18 - text.w() / 2, area.y + 23); -} - -void ExperienceIndicator::QueueEventProcessing(void) -{ - LocalEvent & le = LocalEvent::Get(); - - if(le.MouseClickLeft(area) || le.MousePressRight(area)) - { - std::string message = _("Level %{level}"); - String::Replace(message, "%{level}", hero.GetLevel()); - Dialog::Message(message, descriptions, Font::BIG, (le.MousePressRight() ? 0 : Dialog::OK)); - } -} - -SpellPointsIndicator::SpellPointsIndicator(const Heroes & h) : HeroesIndicator(h) -{ - area.w = 39; - area.h = 36; - - descriptions = _("%{name} currently has %{point} spell points out of a maximum of %{max}. The maximum number of spell points is 10 times your knowledge. It is occasionally possible to have more than your maximum spell points via special events."); - String::Replace(descriptions, "%{name}", hero.GetName()); - String::Replace(descriptions, "%{point}", hero.GetSpellPoints()); - String::Replace(descriptions, "%{max}", hero.GetMaxSpellPoints()); -} - -void SpellPointsIndicator::Redraw(void) -{ - const Sprite & sprite3 = AGG::GetICN(ICN::HSICONS, 8); - Display::Get().Blit(sprite3, area.x, area.y); - - std::string message; - String::AddInt(message, hero.GetSpellPoints()); - message += "/"; - String::AddInt(message, hero.GetMaxSpellPoints()); - Text text(message, Font::SMALL); - text.Blit(area.x + 18 - text.w() / 2, area.y + 21); -} - -void SpellPointsIndicator::QueueEventProcessing(void) -{ - LocalEvent & le = LocalEvent::Get(); - - if(le.MouseClickLeft(area) || le.MousePressRight(area)) - { - Dialog::Message(_("Spell Points"), descriptions, Font::BIG, (le.MousePressRight() ? 0 : Dialog::OK)); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_indicator.h b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_indicator.h deleted file mode 100644 index ee653496a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_indicator.h +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2HEROESIND_H -#define H2HEROESIND_H - -#include - -class Heroes; - -class HeroesIndicator -{ -public: - HeroesIndicator(const Heroes &); - - const Rect & GetArea(void) const; - const std::string & GetDescriptions(void) const; - void SetPos(const Point &); - -protected: - const Heroes & hero; - Rect area; - Background back; - std::string descriptions; -}; - -class LuckIndicator : public HeroesIndicator -{ -public: - LuckIndicator(const Heroes &); - - void Redraw(void); - static void QueueEventProcessing(LuckIndicator &); - -private: - s8 luck; -}; - -class MoraleIndicator : public HeroesIndicator -{ -public: - MoraleIndicator(const Heroes &); - - void Redraw(void); - static void QueueEventProcessing(MoraleIndicator &); - -private: - s8 morale; -}; - -class ExperienceIndicator : public HeroesIndicator -{ -public: - ExperienceIndicator(const Heroes &); - - void Redraw(void); - void QueueEventProcessing(void); -}; - -class SpellPointsIndicator : public HeroesIndicator -{ -public: - SpellPointsIndicator(const Heroes &); - - void Redraw(void); - void QueueEventProcessing(void); -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_meeting.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_meeting.cpp deleted file mode 100644 index 3f9aca407..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_meeting.cpp +++ /dev/null @@ -1,503 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ****************************************************************************/ - -#include -#include -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "text.h" -#include "army.h" -#include "background.h" -#include "heroes.h" -#include "selectarmybar.h" -#include "selectartifactbar.h" -#include "heroes_indicator.h" -#include "pocketpc.h" -#include "game_interface.h" - -void RedrawPrimarySkillInfo(const Point &, const Skill::Primary &, const Skill::Primary &); - -void Heroes::MeetingDialog(Heroes & heroes2) -{ - if(Settings::Get().QVGA()) return PocketPC::HeroesMeeting(*this, heroes2); - - Display & display = Display::Get(); - - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite &backSprite = AGG::GetICN(ICN::SWAPWIN, 0); - const Point cur_pt((display.w() - backSprite.w()) / 2, (display.h() - backSprite.h()) / 2); - Background background(cur_pt, backSprite.w(), backSprite.h()); - background.Save(); - Point dst_pt(cur_pt); - std::string message; - - Rect src_rt(0, 0, 640, 480); - - // background - dst_pt.x = cur_pt.x; - dst_pt.y = cur_pt.y; - display.Blit(backSprite, src_rt, dst_pt); - - // header - message = _("%{name1} meets %{name2}"); - String::Replace(message, "%{name1}", GetName()); - String::Replace(message, "%{name2}", heroes2.GetName()); - Text text(message, Font::BIG); - text.Blit(cur_pt.x + 320 - text.w() / 2, cur_pt.y + 26); - - // portrait - dst_pt.x = cur_pt.x + 93; - dst_pt.y = cur_pt.y + 72; - display.Blit(GetPortrait101x93(), dst_pt); - - dst_pt.x = cur_pt.x + 445; - dst_pt.y = cur_pt.y + 72; - display.Blit(heroes2.GetPortrait101x93(), dst_pt); - - dst_pt.x = cur_pt.x + 34; - dst_pt.y = cur_pt.y + 75; - MoraleIndicator moraleIndicator1(*this); - moraleIndicator1.SetPos(dst_pt); - moraleIndicator1.Redraw(); - - dst_pt.x = cur_pt.x + 34; - dst_pt.y = cur_pt.y + 115; - LuckIndicator luckIndicator1(*this); - luckIndicator1.SetPos(dst_pt); - luckIndicator1.Redraw(); - - dst_pt.x = cur_pt.x + 566; - dst_pt.y = cur_pt.y + 75; - MoraleIndicator moraleIndicator2(heroes2); - moraleIndicator2.SetPos(dst_pt); - moraleIndicator2.Redraw(); - - dst_pt.x = cur_pt.x + 566; - dst_pt.y = cur_pt.y + 115; - LuckIndicator luckIndicator2(heroes2); - luckIndicator2.SetPos(dst_pt); - luckIndicator2.Redraw(); - - // primary skill - Background backPrimary(cur_pt.x + 255, cur_pt.y + 50, 130, 135); - backPrimary.Save(); - RedrawPrimarySkillInfo(cur_pt, *this, heroes2); - - // secondary skill - SecondarySkillBar secskill_bar1; - secskill_bar1.SetPos(cur_pt.x + 23, cur_pt.y + 200); - secskill_bar1.SetUseMiniSprite(); - secskill_bar1.SetInterval(1); - secskill_bar1.SetSkills(secondary_skills); - secskill_bar1.Redraw(); - - SecondarySkillBar secskill_bar2; - secskill_bar2.SetPos(cur_pt.x + 354, cur_pt.y + 200); - secskill_bar2.SetUseMiniSprite(); - secskill_bar2.SetInterval(1); - secskill_bar2.SetSkills(heroes2.secondary_skills); - secskill_bar2.Redraw(); - - // army - dst_pt.x = cur_pt.x + 36; - dst_pt.y = cur_pt.y + 267; - - const Rect rt1(36, 267, 43, 53); - Surface sfb1(rt1.w, rt1.h); - sfb1.Blit(backSprite, rt1, 0, 0); - Surface sfc1(rt1.w, rt1.h - 10); - Cursor::DrawCursor(sfc1, 0x10, true); - - SelectArmyBar selectArmy1; - selectArmy1.SetArmy(army); - selectArmy1.SetPos(dst_pt); - selectArmy1.SetInterval(2); - selectArmy1.SetBackgroundSprite(sfb1); - selectArmy1.SetCursorSprite(sfc1); - selectArmy1.SetUseMons32Sprite(); - selectArmy1.SetSaveLastTroop(); - selectArmy1.Redraw(); - - dst_pt.x = cur_pt.x + 381; - dst_pt.y = cur_pt.y + 267; - SelectArmyBar selectArmy2; - selectArmy2.SetArmy(heroes2.GetArmy()); - selectArmy2.SetPos(dst_pt); - selectArmy2.SetInterval(2); - selectArmy2.SetBackgroundSprite(sfb1); - selectArmy2.SetCursorSprite(sfc1); - selectArmy2.SetUseMons32Sprite(); - selectArmy2.SetSaveLastTroop(); - selectArmy2.Redraw(); - - // artifact - dst_pt.x = cur_pt.x + 23; - dst_pt.y = cur_pt.y + 347; - - const Rect rt2(23, 347, 34, 34); - Surface sfb2(rt2.w, rt2.h); - sfb2.Blit(backSprite, rt2, 0, 0); - Surface sfc2(rt2.w, rt2.h); - Cursor::DrawCursor(sfc2, 0x10, true); - - SelectArtifactsBar selectArtifacts1(*this); - selectArtifacts1.SetPos(dst_pt); - selectArtifacts1.SetInterval(2); - selectArtifacts1.SetBackgroundSprite(sfb2); - selectArtifacts1.SetCursorSprite(sfc2); - selectArtifacts1.SetUseArts32Sprite(); - selectArtifacts1.Redraw(); - - dst_pt.x = cur_pt.x + 367; - dst_pt.y = cur_pt.y + 347; - SelectArtifactsBar selectArtifacts2(heroes2); - selectArtifacts2.SetPos(dst_pt); - selectArtifacts2.SetInterval(2); - selectArtifacts2.SetBackgroundSprite(sfb2); - selectArtifacts2.SetCursorSprite(sfc2); - selectArtifacts2.SetUseArts32Sprite(); - selectArtifacts2.Redraw(); - - // button exit - dst_pt.x = cur_pt.x + 280; - dst_pt.y = cur_pt.y + 428; - Button buttonExit(dst_pt, ICN::SWAPBTN, 0, 1); - - buttonExit.Draw(); - - cursor.Show(); - display.Flip(); - - MovePointsScaleFixed(); - heroes2.MovePointsScaleFixed(); - - // scholar action - if(Settings::Get().ExtEyeEagleAsScholar()) - Heroes::ScholarAction(*this, heroes2); - - LocalEvent & le = LocalEvent::Get(); - - // message loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) break; - - // selector troops event - if(le.MouseCursor(selectArmy1.GetArea()) || le.MouseCursor(selectArmy2.GetArea())) - { - if(selectArtifacts1.isSelected()) selectArtifacts1.Reset(); - else - if(selectArtifacts2.isSelected()) selectArtifacts2.Reset(); - - if(SelectArmyBar::QueueEventProcessing(selectArmy1, selectArmy2)) - { - cursor.Hide(); - moraleIndicator1.Redraw(); - moraleIndicator2.Redraw(); - luckIndicator1.Redraw(); - luckIndicator2.Redraw(); - cursor.Show(); - display.Flip(); - } - } - - // selector artifacts event - if(le.MouseCursor(selectArtifacts1.GetArea()) || le.MouseCursor(selectArtifacts2.GetArea())) - { - if(selectArmy1.isSelected()) selectArmy1.Reset(); - else - if(selectArmy2.isSelected()) selectArmy2.Reset(); - - if(SelectArtifactsBar::QueueEventProcessing(selectArtifacts1, selectArtifacts2)) - { - cursor.Hide(); - backPrimary.Restore(); - RedrawPrimarySkillInfo(cur_pt, *this, heroes2); - moraleIndicator1.Redraw(); - moraleIndicator2.Redraw(); - luckIndicator1.Redraw(); - luckIndicator2.Redraw(); - cursor.Show(); - display.Flip(); - } - } - - if(le.MouseCursor(secskill_bar1.GetArea())) secskill_bar1.QueueEventProcessing(); - if(le.MouseCursor(secskill_bar2.GetArea())) secskill_bar2.QueueEventProcessing(); - - if(le.MouseCursor(moraleIndicator1.GetArea())) MoraleIndicator::QueueEventProcessing(moraleIndicator1); - else - if(le.MouseCursor(moraleIndicator2.GetArea())) MoraleIndicator::QueueEventProcessing(moraleIndicator2); - else - if(le.MouseCursor(luckIndicator1.GetArea())) LuckIndicator::QueueEventProcessing(luckIndicator1); - else - if(le.MouseCursor(luckIndicator2.GetArea())) LuckIndicator::QueueEventProcessing(luckIndicator2); - } - - if(Settings::Get().ExtHeroRecalculateMovement()) - { - RecalculateMovePoints(); - heroes2.RecalculateMovePoints(); - } - - cursor.Hide(); - background.Restore(); - cursor.Show(); - display.Flip(); -} - -void RedrawPrimarySkillInfo(const Point & cur_pt, const Skill::Primary & p1, const Skill::Primary & p2) -{ - std::string message; - - // attack skill - message = _("Attack Skill"); - Text text(message, Font::SMALL); - text.Blit(cur_pt.x + 320 - text.w() / 2, cur_pt.y + 64); - - message.clear(); - String::AddInt(message, p1.GetAttack()); - text.Set(message); - text.Blit(cur_pt.x + 260 - text.w() / 2, cur_pt.y + 64); - - message.clear(); - String::AddInt(message, p2.GetAttack()); - text.Set(message); - text.Blit(cur_pt.x + 380 - text.w(), cur_pt.y + 64); - - // defense skill - message = _("Defense Skill"); - text.Set(message); - text.Blit(cur_pt.x + 320 - text.w() / 2, cur_pt.y + 96); - - message.clear(); - String::AddInt(message, p1.GetDefense()); - text.Set(message); - text.Blit(cur_pt.x + 260 - text.w() / 2, cur_pt.y + 96); - - message.clear(); - String::AddInt(message, p2.GetDefense()); - text.Set(message); - text.Blit(cur_pt.x + 380 - text.w(), cur_pt.y + 96); - - // spell power - message = _("Spell Power"); - text.Set(message); - text.Blit(cur_pt.x + 320 - text.w() / 2, cur_pt.y + 128); - - message.clear(); - String::AddInt(message, p1.GetPower()); - text.Set(message); - text.Blit(cur_pt.x + 260 - text.w() / 2, cur_pt.y + 128); - - message.clear(); - String::AddInt(message, p2.GetPower()); - text.Set(message); - text.Blit(cur_pt.x + 380 - text.w(), cur_pt.y + 128); - - // knowledge - message = _("Knowledge"); - text.Set(message); - text.Blit(cur_pt.x + 320 - text.w() / 2, cur_pt.y + 160); - - message.clear(); - String::AddInt(message, p1.GetKnowledge()); - text.Set(message); - text.Blit(cur_pt.x + 260 - text.w() / 2, cur_pt.y + 160); - - message.clear(); - String::AddInt(message, p2.GetKnowledge()); - text.Set(message); - text.Blit(cur_pt.x + 380 - text.w(), cur_pt.y + 160); -} - -// spell_book.cpp -void SpellBookSetFilter(const BagArtifacts &, const std::vector &, std::vector &, SpellBook::filter_t); - -struct CanTeachSpell : std::binary_function -{ - bool operator() (u8 scholar, Spell::spell_t spell) const - { - // FIXME: teach conditions for level5 - if(4 < Spell::Level(spell)) - return false; - - if(4 == Spell::Level(spell)) - return Skill::Level::EXPERT == scholar; - else - if(3 == Spell::Level(spell)) - return Skill::Level::ADVANCED <= scholar; - else - if(3 > Spell::Level(spell)) - return Skill::Level::BASIC <= scholar; - - return false; - }; -}; - -struct HeroesHaveSpell : std::binary_function -{ - bool operator() (const Heroes* hero, Spell::spell_t spell) const { return hero->HaveSpell(spell); }; -}; - -void Heroes::ScholarAction(Heroes & hero1, Heroes & hero2) -{ - if(! hero1.spell_book.isActive() || ! hero2.spell_book.isActive()) - { - DEBUG(DBG_GAME, DBG_INFO, "Heroes::ScholarDialog: " << "heroes spell_book disabled"); - return; - } - else - if(! Settings::Get().ExtEyeEagleAsScholar()) - { - DEBUG(DBG_GAME, DBG_WARN, "Heroes::ScholarDialog: " << "EyeEagleAsScholar settings disabled"); - return; - } - - const u8 scholar1 = hero1.GetLevelSkill(Skill::Secondary::EAGLEEYE); - const u8 scholar2 = hero2.GetLevelSkill(Skill::Secondary::EAGLEEYE); - u8 scholar = 0; - - Heroes* teacher = NULL; - Heroes* learner = NULL; - - if(scholar1 && scholar1 >= scholar2) - { - teacher = &hero1; - learner = &hero2; - scholar = scholar1; - } - else - if(scholar2 && scholar2 >= scholar1) - { - teacher = &hero2; - learner = &hero1; - scholar = scholar2; - } - else - { - DEBUG(DBG_GAME, DBG_WARN, "Heroes::ScholarDialog: " << "Eagle Eye skill not found"); - return; - } - - std::vector learn, teach; - std::vector::iterator res, it1, it2; - - learn.reserve(15); - teach.reserve(15); - - SpellBookSetFilter(teacher->bag_artifacts, teacher->spell_book.spells, teach, SpellBook::ALL); - SpellBookSetFilter(learner->bag_artifacts, learner->spell_book.spells, learn, SpellBook::ALL); - - VERBOSE(learner->GetName()); - for(it1 = learn.begin(); it1 != learn.end(); ++it1) - { - VERBOSE(Spell::GetName(*it1) << "(" << static_cast(Spell::Level(*it1)) << ")"); - } - - VERBOSE(teacher->GetName()); - for(it1 = teach.begin(); it1 != teach.end(); ++it1) - { - VERBOSE(Spell::GetName(*it1) << "(" << static_cast(Spell::Level(*it1)) << ")"); - } - - // remove_if for learn spells - if(learn.size()) - { - res = std::remove_if(learn.begin(), learn.end(), std::bind1st(HeroesHaveSpell(), teacher)); - learn.resize(std::distance(learn.begin(), res)); - } - - if(learn.size()) - { - res = std::remove_if(learn.begin(), learn.end(), std::not1(std::bind1st(CanTeachSpell(), scholar))); - learn.resize(std::distance(learn.begin(), res)); - } - - // remove_if for teach spells - if(teach.size()) - { - res = std::remove_if(teach.begin(), teach.end(), std::bind1st(HeroesHaveSpell(), learner)); - teach.resize(std::distance(teach.begin(), res)); - } - - if(teach.size()) - { - res = std::remove_if(teach.begin(), teach.end(), std::not1(std::bind1st(CanTeachSpell(), scholar))); - teach.resize(std::distance(teach.begin(), res)); - } - - std::string message, spells1, spells2; - - // learning - it1 = learn.begin(); - it2 = learn.end(); - for(; it1 != it2; ++it1) - { - teacher->AppendSpellToBook(*it1); - if(spells1.size()) - spells1.append(it1 + 1 == it2 ? _(" and ") : ", "); - spells1.append(Spell::GetName(*it1)); - } - - // teacher - it1 = teach.begin(); - it2 = teach.end(); - for(; it1 != it2; ++it1) - { - learner->AppendSpellToBook(*it1); - if(spells2.size()) - spells2.append(it1 + 1 == it2 ? _(" and ") : ", "); - spells2.append(Spell::GetName(*it1)); - } - - if(spells1.size() && spells2.size()) - message = _("%{teacher}, whose %{level} %{scholar} knows many magical secrets, learns %{spells1} from %{learner}, and teaches %{spells2} to %{learner}."); - else - if(spells1.size()) - message = _("%{teacher}, whose %{level} %{scholar} knows many magical secrets, learns %{spells1} from %{learner}."); - else - if(spells2.size()) - message = _("%{teacher}, whose %{level} %{scholar} knows many magical secrets, teaches %{spells2} to %{learner}."); - - if(message.size() && - (Game::LOCAL == teacher->GetControl() || Game::LOCAL == learner->GetControl())) - { - String::Replace(message, "%{teacher}", teacher->GetName()); - String::Replace(message, "%{learner}", learner->GetName()); - String::Replace(message, "%{level}", Skill::Level::String(scholar)); - String::Replace(message, "%{scholar}", Skill::Secondary::String(Skill::Secondary::EAGLEEYE)); - String::Replace(message, "%{spells1}", spells1); - String::Replace(message, "%{spells2}", spells2); - - Dialog::Message(_("Scholar Ability"), message, Font::BIG, Dialog::OK); - } - - VERBOSE(message); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_move.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_move.cpp deleted file mode 100644 index 7aeb3785a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_move.cpp +++ /dev/null @@ -1,752 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "world.h" -#include "agg.h" -#include "cursor.h" -#include "settings.h" -#include "game_interface.h" -#include "kingdom.h" -#include "maps_tiles.h" -#include "castle.h" -#include "direction.h" -#include "heroes.h" - -bool ReflectSprite(const u16 from); -void PlayWalkSound(Maps::Ground::ground_t ground); -const Sprite & SpriteHero(const Heroes & hero, const u8 index, const bool reflect, const bool rotate = false); -const Sprite & SpriteFlag(const Heroes & hero, const u8 index, const bool reflect, const bool rotate = false); -const Sprite & SpriteShad(const Heroes & hero, const u8 index); -bool isNeedStayFrontObject(const Heroes & hero, const Maps::Tiles & next); - -void PlayWalkSound(Maps::Ground::ground_t ground) -{ - M82::m82_t wav = M82::UNKNOWN; - - const u8 speed = (4 > Settings::Get().HeroesMoveSpeed() ? 1 : (7 > Settings::Get().HeroesMoveSpeed() ? 2 : 3)); - - // play sound - switch(ground) - { - case Maps::Ground::WATER: wav = (1 == speed ? M82::WSND00 : (2 == speed ? M82::WSND10 : M82::WSND20)); break; - case Maps::Ground::GRASS: wav = (1 == speed ? M82::WSND01 : (2 == speed ? M82::WSND11 : M82::WSND21)); break; - case Maps::Ground::WASTELAND: wav = (1 == speed ? M82::WSND02 : (2 == speed ? M82::WSND12 : M82::WSND22)); break; - case Maps::Ground::SWAMP: - case Maps::Ground::BEACH: wav = (1 == speed ? M82::WSND03 : (2 == speed ? M82::WSND13 : M82::WSND23)); break; - case Maps::Ground::LAVA: wav = (1 == speed ? M82::WSND04 : (2 == speed ? M82::WSND14 : M82::WSND24)); break; - case Maps::Ground::DESERT: - case Maps::Ground::SNOW: wav = (1 == speed ? M82::WSND05 : (2 == speed ? M82::WSND15 : M82::WSND25)); break; - case Maps::Ground::DIRT: wav = (1 == speed ? M82::WSND06 : (2 == speed ? M82::WSND16 : M82::WSND26)); break; - - default: break; - } - - if(wav != M82::UNKNOWN) AGG::PlaySound(wav); -} - -bool ReflectSprite(const u16 from) -{ - switch(from) - { - case Direction::BOTTOM_LEFT: - case Direction::LEFT: - case Direction::TOP_LEFT: return true; - - default: break; - } - - return false; -} - -const Sprite & SpriteHero(const Heroes & hero, const u8 index, const bool reflect, const bool rotate) -{ - ICN::icn_t icn_hero = ICN::UNKNOWN; - u16 index_sprite = 0; - - if(hero.isShipMaster()) icn_hero = ICN::BOAT32; - else - switch(hero.GetRace()) - { - case Race::KNGT: icn_hero = ICN::KNGT32; break; - case Race::BARB: icn_hero = ICN::BARB32; break; - case Race::SORC: icn_hero = ICN::SORC32; break; - case Race::WRLK: icn_hero = ICN::WRLK32; break; - case Race::WZRD: icn_hero = ICN::WZRD32; break; - case Race::NECR: icn_hero = ICN::NECR32; break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Heroes::SpriteHero: unknown race"); break; - } - - if(rotate) index_sprite = 45; - else - switch(hero.GetDirection()) - { - case Direction::TOP: index_sprite = 0; break; - case Direction::TOP_RIGHT: index_sprite = 9; break; - case Direction::RIGHT: index_sprite = 18; break; - case Direction::BOTTOM_RIGHT: index_sprite = 27; break; - case Direction::BOTTOM: index_sprite = 36; break; - case Direction::BOTTOM_LEFT: index_sprite = 27; break; - case Direction::LEFT: index_sprite = 18; break; - case Direction::TOP_LEFT: index_sprite = 9; break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Heroes::SpriteHero: unknown direction"); break; - } - - return AGG::GetICN(icn_hero, index_sprite + (index % 9), reflect); -} - -const Sprite & SpriteFlag(const Heroes & hero, const u8 index, const bool reflect, const bool rotate) -{ - ICN::icn_t icn_flag = ICN::UNKNOWN; - u16 index_sprite = 0; - - switch(hero.GetColor()) - { - case Color::BLUE: icn_flag = hero.isShipMaster() ? ICN::B_BFLG32 : ICN::B_FLAG32; break; - case Color::GREEN: icn_flag = hero.isShipMaster() ? ICN::G_BFLG32 : ICN::G_FLAG32; break; - case Color::RED: icn_flag = hero.isShipMaster() ? ICN::R_BFLG32 : ICN::R_FLAG32; break; - case Color::YELLOW: icn_flag = hero.isShipMaster() ? ICN::Y_BFLG32 : ICN::Y_FLAG32; break; - case Color::ORANGE: icn_flag = hero.isShipMaster() ? ICN::O_BFLG32 : ICN::O_FLAG32; break; - case Color::PURPLE: icn_flag = hero.isShipMaster() ? ICN::P_BFLG32 : ICN::P_FLAG32; break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Heroes::SpriteFlag: unknown color hero"); break; - } - - if(rotate) index_sprite = 45; - else - switch(hero.GetDirection()) - { - case Direction::TOP: index_sprite = 0; break; - case Direction::TOP_RIGHT: index_sprite = 9; break; - case Direction::RIGHT: index_sprite = 18; break; - case Direction::BOTTOM_RIGHT: index_sprite = 27; break; - case Direction::BOTTOM: index_sprite = 36; break; - case Direction::BOTTOM_LEFT: index_sprite = 27; break; - case Direction::LEFT: index_sprite = 18; break; - case Direction::TOP_LEFT: index_sprite = 9; break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Heroes::SpriteFlag: unknown direction"); break; - } - - return AGG::GetICN(icn_flag, index_sprite + (index % 9), reflect); -} - -const Sprite & SpriteShad(const Heroes & hero, const u8 index) -{ - const ICN::icn_t icn_shad = hero.isShipMaster() ? ICN::BOATSHAD : ICN::SHADOW32; - u16 index_sprite = 0; - - switch(hero.GetDirection()) - { - case Direction::TOP: index_sprite = 0; break; - case Direction::TOP_RIGHT: index_sprite = 9; break; - case Direction::RIGHT: index_sprite = 18; break; - case Direction::BOTTOM_RIGHT: index_sprite = 27; break; - case Direction::BOTTOM: index_sprite = 36; break; - case Direction::BOTTOM_LEFT: index_sprite = 45; break; - case Direction::LEFT: index_sprite = 54; break; - case Direction::TOP_LEFT: index_sprite = 63; break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Heroes::SpriteShadow: unknown direction"); break; - } - - return AGG::GetICN(icn_shad, index_sprite + (index % 9)); -} - -const Sprite & SpriteFroth(const Heroes & hero, const u8 index, const bool reflect) -{ - u16 index_sprite = 0; - - switch(hero.GetDirection()) - { - case Direction::TOP: index_sprite = 0; break; - case Direction::TOP_RIGHT: index_sprite = 9; break; - case Direction::RIGHT: index_sprite = 18; break; - case Direction::BOTTOM_RIGHT: index_sprite = 27; break; - case Direction::BOTTOM: index_sprite = 36; break; - case Direction::BOTTOM_LEFT: index_sprite = 27; break; - case Direction::LEFT: index_sprite = 18; break; - case Direction::TOP_LEFT: index_sprite = 9; break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Heroes::SpriteFroth: unknown direction"); break; - } - - return AGG::GetICN(ICN::FROTH, index_sprite + (index % 9), reflect); -} - -bool isNeedStayFrontObject(const Heroes & hero, const Maps::Tiles & next) -{ - if(hero.isShipMaster()) - switch(next.GetObject()) - { - case MP2::OBJ_WATERCHEST: - case MP2::OBJ_SHIPWRECKSURVIROR: - case MP2::OBJ_FLOTSAM: - case MP2::OBJ_BOTTLE: - case MP2::OBJ_COAST: - case MP2::OBJ_HEROES: - return true; - - default: break; - } - else - switch(next.GetObject()) - { - case MP2::OBJ_TREASURECHEST: - case MP2::OBJ_ANCIENTLAMP: - case MP2::OBJ_CAMPFIRE: - case MP2::OBJ_MONSTER: - case MP2::OBJ_RESOURCE: - case MP2::OBJ_ARTIFACT: - case MP2::OBJ_HEROES: - case MP2::OBJ_BOAT: - case MP2::OBJ_BARRIER: - case MP2::OBJ_JAIL: - return true; - - case MP2::OBJ_CASTLE: - { - const Castle *castle = world.GetCastle(next.GetIndex()); - - return (castle && - hero.GetColor() != castle->GetColor() && - !Settings::Get().IsUnions(hero.GetColor(), castle->GetColor())); - } - break; - - default: break; - } - - return false; -} - -void Heroes::Redraw(Surface & dst, bool with_shadow) const -{ - const Point & mp = GetCenter(); - const Interface::GameArea & gamearea = Interface::GameArea::Get(); - s16 dx = gamearea.GetMapsPos().x + TILEWIDTH * (mp.x - gamearea.GetRectMaps().x); - s16 dy = gamearea.GetMapsPos().y + TILEWIDTH * (mp.y - gamearea.GetRectMaps().y); - - Redraw(dst, dx, dy, with_shadow); -} - -void Heroes::Redraw(Surface & dst, const s16 dx, const s16 dy, bool with_shadow) const -{ - const Point & mp = GetCenter(); - const Interface::GameArea & gamearea = Interface::GameArea::Get(); - if(!(gamearea.GetRectMaps() & mp)) return; - - bool reflect = ReflectSprite(direction); - - const Sprite & sprite1 = SpriteHero(*this, sprite_index, reflect); - const Sprite & sprite2 = SpriteFlag(*this, sprite_index, reflect); - const Sprite & sprite3 = SpriteShad(*this, sprite_index); - const Sprite & sprite4 = SpriteFroth(*this, sprite_index, reflect); - - Point dst_pt1(dx + (reflect ? TILEWIDTH - sprite1.x() - sprite1.w() : sprite1.x()), dy + sprite1.y() + TILEWIDTH); - Point dst_pt2(dx + (reflect ? TILEWIDTH - sprite2.x() - sprite2.w() : sprite2.x()), dy + sprite2.y() + TILEWIDTH); - Point dst_pt3(dx + sprite3.x(), dy + sprite3.y() + TILEWIDTH); - Point dst_pt4(dx + (reflect ? TILEWIDTH - sprite4.x() - sprite4.w() : sprite4.x()), dy + sprite4.y() + TILEWIDTH); - - // apply offset - if(sprite_index < 45) - { - s16 ox = 0; - s16 oy = 0; - const u8 frame = (sprite_index % 9); - - switch(direction) - { - case Direction::TOP: oy = -4 * frame; break; - case Direction::TOP_RIGHT: ox = 4 * frame; oy = -4 * frame; break; - case Direction::TOP_LEFT: ox = -4 * frame; oy = -4 * frame; break; - case Direction::BOTTOM_RIGHT: ox = 4 * frame; oy = 4 * frame; break; - case Direction::BOTTOM: oy = 4 * frame; break; - case Direction::BOTTOM_LEFT: ox = -4 * frame; oy = 4 * frame; break; - case Direction::RIGHT: ox = 4 * frame; break; - case Direction::LEFT: ox = -4 * frame; break; - default: break; - } - - dst_pt1.x += ox; - dst_pt1.y += oy; - dst_pt2.x += ox; - dst_pt2.y += oy; - dst_pt3.x += ox; - dst_pt3.y += oy; - dst_pt4.x += ox; - dst_pt4.y += oy; - } - - Rect src_rt; - - - if(isShipMaster()) - { - gamearea.SrcRectFixed(src_rt, dst_pt4, sprite4.w(), sprite4.h()); - dst.Blit(sprite4, src_rt, dst_pt4); - } - - // redraw sprites for shadow - if(with_shadow) - { - gamearea.SrcRectFixed(src_rt, dst_pt3, sprite3.w(), sprite3.h()); - dst.Blit(sprite3, src_rt, dst_pt3); - } - - // redraw sprites hero and flag - gamearea.SrcRectFixed(src_rt, dst_pt1, sprite1.w(), sprite1.h()); - dst.Blit(sprite1, src_rt, dst_pt1); - - gamearea.SrcRectFixed(src_rt, dst_pt2, sprite2.w(), sprite2.h()); - dst.Blit(sprite2, src_rt, dst_pt2); - - // redraw dependences tiles - const s32 center = GetIndex(); - bool skip_ground = MP2::isActionObject(save_maps_object, isShipMaster()); - - world.GetTiles(center).RedrawTop(dst); - - if(Maps::isValidDirection(center, Direction::TOP)) - world.GetTiles(Maps::GetDirectionIndex(center, Direction::TOP)).RedrawTop4Hero(dst, skip_ground); - - if(Maps::isValidDirection(center, Direction::BOTTOM)) - { - Maps::Tiles & tile_bottom = world.GetTiles(Maps::GetDirectionIndex(center, Direction::BOTTOM)); - tile_bottom.RedrawBottom4Hero(dst); - tile_bottom.RedrawTop(dst); - } - - if(45 > GetSpriteIndex() && - Direction::BOTTOM != direction && - Direction::TOP != direction && - Maps::isValidDirection(center, direction)) - { - if(Maps::isValidDirection(Maps::GetDirectionIndex(center, direction), Direction::BOTTOM)) - { - Maps::Tiles & tile_dir_bottom = world.GetTiles(Maps::GetDirectionIndex(Maps::GetDirectionIndex(center, direction), Direction::BOTTOM)); - tile_dir_bottom.RedrawBottom4Hero(dst); - tile_dir_bottom.RedrawTop(dst); - } - if(Maps::isValidDirection(Maps::GetDirectionIndex(center, direction), Direction::TOP)) - { - Maps::Tiles & tile_dir_top = world.GetTiles(Maps::GetDirectionIndex(Maps::GetDirectionIndex(center, direction), Direction::TOP)); - tile_dir_top.RedrawTop4Hero(dst, skip_ground); - } - } - - if(Maps::isValidDirection(center, direction)) - { - if(Direction::TOP == direction) - world.GetTiles(Maps::GetDirectionIndex(center, direction)).RedrawTop4Hero(dst, skip_ground); - else - world.GetTiles(Maps::GetDirectionIndex(center, direction)).RedrawTop(dst); - } -} - - -bool Heroes::MoveStep(bool fast) -{ - s32 index_from = GetIndex(); - s32 index_to = Maps::GetDirectionIndex(index_from, path.GetFrontDirection()); - s32 index_dst = path.GetDestinationIndex(); - const Point & mp = GetCenter(); - - if(fast) - { - if(index_to == index_dst && isNeedStayFrontObject(*this, world.GetTiles(index_to))) - { - ApplyPenaltyMovement(); - path.Reset(); - Action(index_to); - SetMove(false); - } - else - { - Maps::Tiles & tiles_from = world.GetTiles(index_from); - Maps::Tiles & tiles_to = world.GetTiles(index_to); - - if(MP2::OBJ_HEROES != save_maps_object) tiles_from.SetObject(save_maps_object); - - SetIndex(index_to); - save_maps_object = tiles_to.GetObject(); - tiles_to.SetObject(MP2::OBJ_HEROES); - Scoute(); - ApplyPenaltyMovement(); - path.PopFront(); - - if(MP2::OBJ_EVENT == save_maps_object) - { - Action(index_to); - SetMove(false); - } - - // check protection tile - ActionNewPosition(); - - // possible hero is die - if(!isFreeman()) - { - if(index_to == index_dst) - { - path.Reset(); - Action(index_to); - SetMove(false); - } - } - } - return true; - } - else - if(0 == sprite_index % 9) - { - if(index_to == index_dst && isNeedStayFrontObject(*this, world.GetTiles(index_to))) - { - ApplyPenaltyMovement(); - path.Reset(); - Action(index_to); - SetMove(false); - return true; - } - else - { - if(Game::LOCAL == world.GetKingdom(GetColor()).Control()) - // play sound - PlayWalkSound(world.GetTiles(mp).GetGround()); - } - } - else - if(8 == sprite_index % 9) - { - Maps::Tiles & tiles_from = world.GetTiles(index_from); - Maps::Tiles & tiles_to = world.GetTiles(index_to); - - if(MP2::OBJ_HEROES != save_maps_object) tiles_from.SetObject(save_maps_object); - - SetIndex(index_to); - save_maps_object = tiles_to.GetObject(); - tiles_to.SetObject(MP2::OBJ_HEROES); - Scoute(); - ApplyPenaltyMovement(); - sprite_index -= 8; - path.PopFront(); - - if(MP2::OBJ_EVENT == save_maps_object) - { - Action(index_to); - SetMove(false); - } - - // check protection tile - ActionNewPosition(); - - // possible hero is die - if(!isFreeman()) - { - if(index_to == index_dst) - { - path.Reset(); - Action(index_to); - SetMove(false); - } - } - - return true; - } - - ++sprite_index; - - return false; -} - -void Heroes::AngleStep(const Direction::vector_t to_direct) -{ - //bool check = false; - bool clockwise = ShortDistanceClockWise(direction, to_direct); - - // start index - if(45 > sprite_index && 0 == sprite_index % 9) - { - switch(direction) - { - case Direction::TOP: sprite_index = 45; break; - case Direction::TOP_RIGHT: sprite_index = clockwise ? 47 : 46; break; - case Direction::TOP_LEFT: sprite_index = clockwise ? 46 : 47; break; - case Direction::RIGHT: sprite_index = clockwise ? 49 : 48; break; - case Direction::LEFT: sprite_index = clockwise ? 48 : 49; break; - case Direction::BOTTOM_RIGHT: sprite_index = clockwise ? 51 : 50; break; - case Direction::BOTTOM_LEFT: sprite_index = clockwise ? 50 : 51; break; - case Direction::BOTTOM: sprite_index = clockwise ? 52 : 53; break; - - default: break; - } - } - // animation process - else - { - switch(direction) - { - case Direction::TOP_RIGHT: - case Direction::RIGHT: - case Direction::BOTTOM_RIGHT: - clockwise ? ++sprite_index : --sprite_index; - break; - - case Direction::TOP: - ++sprite_index; - break; - - case Direction::TOP_LEFT: - case Direction::LEFT: - case Direction::BOTTOM_LEFT: - clockwise ? --sprite_index : ++sprite_index; - break; - - case Direction::BOTTOM: - --sprite_index; - break; - - default: break; - } - - bool end = false; - - Direction::vector_t next = Direction::UNKNOWN; - - switch(direction) - { - case Direction::TOP: next = clockwise ? Direction::TOP_RIGHT : Direction::TOP_LEFT; break; - case Direction::TOP_RIGHT: next = clockwise ? Direction::RIGHT : Direction::TOP; break; - case Direction::TOP_LEFT: next = clockwise ? Direction::TOP : Direction::LEFT; break; - case Direction::RIGHT: next = clockwise ? Direction::BOTTOM_RIGHT : Direction::TOP_RIGHT; break; - case Direction::LEFT: next = clockwise ? Direction::TOP_LEFT : Direction::BOTTOM_LEFT; break; - case Direction::BOTTOM_RIGHT: next = clockwise ? Direction::BOTTOM : Direction::RIGHT; break; - case Direction::BOTTOM_LEFT: next = clockwise ? Direction::LEFT : Direction::BOTTOM; break; - case Direction::BOTTOM: next = clockwise ? Direction::BOTTOM_LEFT : Direction::BOTTOM_RIGHT; break; - - default: break; - } - - switch(next) - { - case Direction::TOP: end = (sprite_index == 44); break; - case Direction::TOP_RIGHT: end = (sprite_index == (clockwise ? 47 : 46)); break; - case Direction::TOP_LEFT: end = (sprite_index == (clockwise ? 46 : 47)); break; - case Direction::RIGHT: end = (sprite_index == (clockwise ? 49 : 48)); break; - case Direction::LEFT: end = (sprite_index == (clockwise ? 48 : 49)); break; - case Direction::BOTTOM_RIGHT: end = (sprite_index == (clockwise ? 51 : 50)); break; - case Direction::BOTTOM_LEFT: end = (sprite_index == (clockwise ? 50 : 51)); break; - case Direction::BOTTOM: end = (sprite_index == 53); break; - - default: break; - } - - if(end) - { - switch(next) - { - case Direction::TOP: sprite_index = 0; break; - case Direction::BOTTOM: sprite_index = 36; break; - case Direction::TOP_RIGHT: - case Direction::TOP_LEFT: sprite_index = 9; break; - case Direction::BOTTOM_RIGHT: - case Direction::BOTTOM_LEFT: sprite_index = 27; break; - case Direction::RIGHT: - case Direction::LEFT: sprite_index = 18; break; - - default: break; - } - - direction = next; - } - } -} - -void Heroes::FadeOut(void) const -{ - const Point & mp = GetCenter(); - const Interface::GameArea & gamearea = Interface::GameArea::Get(); - - if(!(gamearea.GetRectMaps() & mp)) return; - - Display & display = Display::Get(); - - bool reflect = ReflectSprite(direction); - - s16 dx = gamearea.GetMapsPos().x + TILEWIDTH * (mp.x - gamearea.GetRectMaps().x); - s16 dy = gamearea.GetMapsPos().y + TILEWIDTH * (mp.y - gamearea.GetRectMaps().y); - - const Sprite & sprite1 = SpriteHero(*this, sprite_index, reflect); - - Surface sf(sprite1.w(), sprite1.h()); - sf.SetColorKey(); - sf.Blit(sprite1); - - Point dst_pt1(dx + (reflect ? TILEWIDTH - sprite1.x() - sprite1.w() : sprite1.x()), dy + sprite1.y() + TILEWIDTH); - Rect src_rt; - - gamearea.SrcRectFixed(src_rt, dst_pt1, sprite1.w(), sprite1.h()); - - LocalEvent & le = LocalEvent::Get(); - u8 alpha = 250; - - while(le.HandleEvents() && alpha > 0) - { - if(Game::AnimateInfrequent(Game::HEROES_FADE_DELAY)) - { - Cursor::Get().Hide(); - - for(s16 y = mp.y - 1; y <= mp.y + 1; ++y) - for(s16 x = mp.x - 1; x <= mp.x + 1; ++x) - if(Maps::isValidAbsPoint(x, y)) - { - const Maps::Tiles & tile = world.GetTiles(Maps::GetIndexFromAbsPoint(x, y)); - - tile.RedrawTile(display); - tile.RedrawBottom(display); - tile.RedrawObjects(display); - } - - sf.SetAlpha(alpha); - display.Blit(sf, src_rt, dst_pt1); - - for(s16 y = mp.y - 1; y <= mp.y + 1; ++y) - for(s16 x = mp.x - 1; x <= mp.x + 1; ++x) - if(Maps::isValidAbsPoint(x, y)) - { - const Maps::Tiles & tile = world.GetTiles(Maps::GetIndexFromAbsPoint(x, y)); - - tile.RedrawTop(display); - } - - Cursor::Get().Show(); - display.Flip(); - alpha -= 10; - } - } -} - -void Heroes::FadeIn(void) const -{ - const Point & mp = GetCenter(); - const Interface::GameArea & gamearea = Interface::GameArea::Get(); - - if(!(gamearea.GetRectMaps() & mp)) return; - - Display & display = Display::Get(); - - bool reflect = ReflectSprite(direction); - - s16 dx = gamearea.GetMapsPos().x + TILEWIDTH * (mp.x - gamearea.GetRectMaps().x); - s16 dy = gamearea.GetMapsPos().y + TILEWIDTH * (mp.y - gamearea.GetRectMaps().y); - - const Sprite & sprite1 = SpriteHero(*this, sprite_index, reflect); - - Surface sf(sprite1.w(), sprite1.h()); - sf.SetColorKey(); - sf.Blit(sprite1); - - Point dst_pt1(dx + (reflect ? TILEWIDTH - sprite1.x() - sprite1.w() : sprite1.x()), dy + sprite1.y() + TILEWIDTH); - Rect src_rt; - - gamearea.SrcRectFixed(src_rt, dst_pt1, sprite1.w(), sprite1.h()); - - LocalEvent & le = LocalEvent::Get(); - u8 alpha = 0; - - while(le.HandleEvents() && alpha < 250) - { - if(Game::AnimateInfrequent(Game::HEROES_FADE_DELAY)) - { - Cursor::Get().Hide(); - - for(s16 y = mp.y - 1; y <= mp.y + 1; ++y) - for(s16 x = mp.x - 1; x <= mp.x + 1; ++x) - if(Maps::isValidAbsPoint(x, y)) - { - const Maps::Tiles & tile = world.GetTiles(Maps::GetIndexFromAbsPoint(x, y)); - - tile.RedrawTile(display); - tile.RedrawBottom(display); - tile.RedrawObjects(display); - } - - sf.SetAlpha(alpha); - display.Blit(sf, src_rt, dst_pt1); - - for(s16 y = mp.y - 1; y <= mp.y + 1; ++y) - for(s16 x = mp.x - 1; x <= mp.x + 1; ++x) - if(Maps::isValidAbsPoint(x, y)) - { - const Maps::Tiles & tile = world.GetTiles(Maps::GetIndexFromAbsPoint(x, y)); - - tile.RedrawTop(display); - } - - Cursor::Get().Show(); - display.Flip(); - alpha += 10; - } - } -} - -bool Heroes::Move(bool fast) -{ - if(Modes(ACTION)) ResetModes(ACTION); - - // move hero - if(path.isValid() && - (isEnableMove() || (GetSpriteIndex() < 45 && GetSpriteIndex() % 9) || GetSpriteIndex() >= 45)) - { - // fast move for hide AI - if(fast) - { - direction = path.GetFrontDirection(); - MoveStep(true); - - return true; - } - else - { - // if need change through the circle - if(GetDirection() != path.GetFrontDirection()) - { - AngleStep(path.GetFrontDirection()); - } - else - // move - if(MoveStep()) - { - if(isFreeman()) return false; - - return true; - } - } - } - else - { - SetMove(false); - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_recruits.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_recruits.cpp deleted file mode 100644 index 1e1506899..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_recruits.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "world.h" -#include "heroes_recruits.h" - -Recruits::Recruits() : std::pair(Heroes::UNKNOWN, Heroes::UNKNOWN) -{ -} - -Heroes::heroes_t Recruits::GetID1(void) const -{ - return first; -} - -Heroes::heroes_t Recruits::GetID2(void) const -{ - return second; -} - -void Recruits::SetID1(u8 i) -{ - first = Heroes::UNKNOWN > i ? static_cast(i) : Heroes::UNKNOWN; -} - -void Recruits::SetID2(u8 i) -{ - second = Heroes::UNKNOWN > i ? static_cast(i) : Heroes::UNKNOWN; -} - -const Heroes* Recruits::GetHero1(void) const -{ - return world.GetHeroes(first); -} - -const Heroes* Recruits::GetHero2(void) const -{ - return world.GetHeroes(second); -} - -Heroes* Recruits::GetHero1(void) -{ - return world.GetHeroes(first); -} - -Heroes* Recruits::GetHero2(void) -{ - return world.GetHeroes(second); -} - -void Recruits::SetHero1(const Heroes* hero) -{ - first = hero ? hero->portrait : Heroes::UNKNOWN; -} - -void Recruits::SetHero2(const Heroes* hero) -{ - second = hero ? hero->portrait : Heroes::UNKNOWN; -} - -void Recruits::SetHero1(Heroes::heroes_t id) -{ - first = id; -} - -void Recruits::SetHero2(Heroes::heroes_t id) -{ - second = id; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_recruits.h b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_recruits.h deleted file mode 100644 index 9f9814e41..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_recruits.h +++ /dev/null @@ -1,52 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2RECRUITS_H -#define H2RECRUITS_H - -#include -#include "gamedefs.h" -#include "heroes.h" - -class Recruits : protected std::pair -{ -public: - Recruits(); - - Heroes::heroes_t GetID1(void) const; - Heroes::heroes_t GetID2(void) const; - - void SetID1(u8); - void SetID2(u8); - - const Heroes* GetHero1(void) const; - const Heroes* GetHero2(void) const; - Heroes* GetHero1(void); - Heroes* GetHero2(void); - - void SetHero1(const Heroes*); - void SetHero2(const Heroes*); - void SetHero1(Heroes::heroes_t); - void SetHero2(Heroes::heroes_t); -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_spell.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_spell.cpp deleted file mode 100644 index aab6b0034..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/heroes_spell.cpp +++ /dev/null @@ -1,562 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "monster.h" -#include "dialog.h" -#include "world.h" -#include "agg.h" -#include "cursor.h" -#include "kingdom.h" -#include "castle.h" -#include "spell.h" -#include "settings.h" -#include "game_focus.h" -#include "game_interface.h" -#include "interface_list.h" -#include "heroes.h" - -void DialogSpellFailed(Spell::spell_t); -void DialogNotAvailable(void); - -bool ActionSpellViewMines(Heroes &); -bool ActionSpellViewResources(Heroes &); -bool ActionSpellViewArtifacts(Heroes &); -bool ActionSpellViewTowns(Heroes &); -bool ActionSpellViewHeroes(Heroes &); -bool ActionSpellViewAll(Heroes &); -bool ActionSpellIdentifyHero(Heroes &); -bool ActionSpellSummonBoat(Heroes &); -bool ActionSpellDimensionDoor(Heroes &); -bool ActionSpellTownGate(Heroes &); -bool ActionSpellTownPortal(Heroes &); -bool ActionSpellVisions(Heroes &); -bool ActionSpellSetGuardian(Heroes &, Monster::monster_t); - -class CastleIndexListBox : public Interface::ListBox -{ -public: - CastleIndexListBox(const Point & pt, u16 & res) : Interface::ListBox(pt), result(res) {}; - - void RedrawItem(const s32 &, s16, s16, bool); - void RedrawBackground(const Point &); - - void ActionCurrentUp(void){}; - void ActionCurrentDn(void){}; - void ActionListDoubleClick(s32 &){ result = Dialog::OK; }; - void ActionListSingleClick(s32 &){}; - void ActionListPressRight(s32 &){}; - - u16 & result; -}; - -void CastleIndexListBox::RedrawItem(const s32 & index, s16 dstx, s16 dsty, bool current) -{ - const Castle* castle =world.GetCastle(index); - - if(castle) - { - Text text(castle->GetName(), (current ? Font::YELLOW_BIG : Font::BIG)); - text.Blit(dstx + 10, dsty); - } -} - -void CastleIndexListBox::RedrawBackground(const Point & dst) -{ - Display & display = Display::Get(); - - Text text(_("Town Portal"), Font::YELLOW_BIG); - text.Blit(dst.x + 140 - text.w() / 2, dst.y + 6); - - text.Set(_("Select town to port to."), Font::BIG); - text.Blit(dst.x + 140 - text.w() / 2, dst.y + 30); - - display.Blit(AGG::GetICN(ICN::LISTBOX, 0), dst.x + 2, dst.y + 55); - for(u8 ii = 1; ii < 5; ++ii) - display.Blit(AGG::GetICN(ICN::LISTBOX, 1), dst.x + 2, dst.y + 55 + (ii * 19)); - display.Blit(AGG::GetICN(ICN::LISTBOX, 2), dst.x + 2, dst.y + 145); - - display.Blit(AGG::GetICN(ICN::LISTBOX, 7), dst.x + 256, dst.y + 75); - for(u8 ii = 1; ii < 3; ++ii) - display.Blit(AGG::GetICN(ICN::LISTBOX, 8), dst.x + 256, dst.y + 74 + (ii * 19)); - display.Blit(AGG::GetICN(ICN::LISTBOX, 9), dst.x + 256, dst.y + 126); -} - -bool Heroes::ActionSpellCast(Spell::spell_t spell) -{ - if(! CanMove()) - { - Dialog::Message("", _("Your hero is too tired to cast this spell today. Try again tomorrow."), Font::BIG, Dialog::OK); - return false; - } - else - if(Spell::NONE == spell || Spell::isCombat(spell) || ! HaveSpellPoints(Spell::CostManaPoints(spell, this))) - { - return false; - } - - bool apply = false; - - switch(spell) - { - case Spell::VIEWMINES: apply = ActionSpellViewMines(*this); break; - case Spell::VIEWRESOURCES: apply = ActionSpellViewResources(*this); break; - case Spell::VIEWARTIFACTS: apply = ActionSpellViewArtifacts(*this); break; - case Spell::VIEWTOWNS: apply = ActionSpellViewTowns(*this); break; - case Spell::VIEWHEROES: apply = ActionSpellViewHeroes(*this); break; - case Spell::VIEWALL: apply = ActionSpellViewAll(*this); break; - case Spell::IDENTIFYHERO: apply = ActionSpellIdentifyHero(*this); break; - case Spell::SUMMONBOAT: apply = ActionSpellSummonBoat(*this); break; - case Spell::DIMENSIONDOOR: apply = ActionSpellDimensionDoor(*this); break; - case Spell::TOWNGATE: apply = ActionSpellTownGate(*this); break; - case Spell::TOWNPORTAL: apply = ActionSpellTownPortal(*this); break; - case Spell::VISIONS: apply = ActionSpellVisions(*this); break; - case Spell::HAUNT: apply = ActionSpellSetGuardian(*this, Monster::GHOST); break; - case Spell::SETEGUARDIAN: apply = ActionSpellSetGuardian(*this, Monster::EARTH_ELEMENT); break; - case Spell::SETAGUARDIAN: apply = ActionSpellSetGuardian(*this, Monster::AIR_ELEMENT); break; - case Spell::SETFGUARDIAN: apply = ActionSpellSetGuardian(*this, Monster::FIRE_ELEMENT); break; - case Spell::SETWGUARDIAN: apply = ActionSpellSetGuardian(*this, Monster::WATER_ELEMENT); break; - default: break; - } - - if(apply) - { - DEBUG(DBG_GAME, DBG_INFO, "ActionSpell: " << GetName() << " cast spell: " << Spell::GetName(spell)); - TakeSpellPoints(Spell::CostManaPoints(spell, this)); - return true; - } - return false; -} - -bool HeroesTownGate(Heroes & hero, const Castle* castle) -{ - if(castle) - { - Interface::Basic & I = Interface::Basic::Get(); - Game::Focus & F = Game::Focus::Get(); - - const s32 src = hero.GetIndex(); - const s32 dst = castle->GetIndex(); - - if(!Maps::isValidAbsIndex(src) || !Maps::isValidAbsIndex(dst)) - return false; - - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeOut(); - - Cursor::Get().Hide(); - hero.SetIndex(dst); - hero.Scoute(); - - world.GetTiles(src).SetObject(hero.GetUnderObject()); - hero.SaveUnderObject(world.GetTiles(dst).GetObject()); - world.GetTiles(dst).SetObject(MP2::OBJ_HEROES); - - I.gameArea.Center(F.Center()); - F.SetRedraw(); - I.Redraw(); - - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeIn(); - - // educate spells - if(! Settings::Get().ExtLearnSpellsWithDay()) castle->GetMageGuild().EducateHero(hero); - - return true; - } - return false; -} - -void DialogSpellFailed(Spell::spell_t spell) -{ - // failed - std::string str = "%{spell} failed!!!"; - String::Replace(str, "%{spell}", Spell::GetName(spell)); - Dialog::Message("", str, Font::BIG, Dialog::OK); -} - -void DialogNotAvailable(void) -{ - Dialog::Message("", "Not availble for current version", Font::BIG, Dialog::OK); -} - -bool ActionSpellViewMines(Heroes & hero) -{ - DialogNotAvailable(); - return false; -} - -bool ActionSpellViewResources(Heroes & hero) -{ - DialogNotAvailable(); - return false; -} - -bool ActionSpellViewArtifacts(Heroes & hero) -{ - DialogNotAvailable(); - return false; -} - -bool ActionSpellViewTowns(Heroes & hero) -{ - DialogNotAvailable(); - return false; -} - -bool ActionSpellViewHeroes(Heroes & hero) -{ - DialogNotAvailable(); - return false; -} - -bool ActionSpellViewAll(Heroes & hero) -{ - DialogNotAvailable(); - return false; -} - -bool ActionSpellIdentifyHero(Heroes & hero) -{ - world.GetKingdom(hero.GetColor()).SetModes(Kingdom::IDENTIFYHERO); - Message("", _("Enemy heroes are now fully identifiable."), Font::BIG, Dialog::OK); - - return true; -} - -bool ActionSpellSummonBoat(Heroes & hero) -{ - u8 chance = 0; - - switch(hero.GetLevelSkill(Skill::Secondary::WISDOM)) - { - case Skill::Level::BASIC: chance = 50; break; - case Skill::Level::ADVANCED: chance = 75; break; - case Skill::Level::EXPERT: chance = 100; break; - default: chance = 30; break; - } - - - const s32 center = hero.GetIndex(); - - // find water - u16 around_zero = Maps::ScanAroundObject(center, MP2::OBJ_ZERO); - s32 dst_water = -1; - for(Direction::vector_t dir = Direction::TOP_LEFT; dir < Direction::CENTER; ++dir) if(around_zero & dir) - { - const s32 dst = Maps::GetDirectionIndex(center, dir); - if(Maps::Ground::WATER == world.GetTiles(dst).GetGround()){ dst_water = dst; break; } - } - - // find boat - const s32 src = world.GetNearestObject(center, MP2::OBJ_BOAT); - - if(Rand::Get(1, 100) <= chance && - Maps::isValidAbsIndex(src) && Maps::isValidAbsIndex(dst_water)) - { - world.GetTiles(src).SetObject(MP2::OBJ_ZERO); - world.GetTiles(dst_water).SetObject(MP2::OBJ_BOAT); - } - else - DialogSpellFailed(Spell::SUMMONBOAT); - - return true; -} - -bool ActionSpellDimensionDoor(Heroes & hero) -{ - const u8 distance = Spell::CalculateDimensionDoorDistance(hero.GetPower(), hero.GetArmy().GetHitPoints()); - - Interface::Basic & I = Interface::Basic::Get(); - Game::Focus & F = Game::Focus::Get(); - Cursor & cursor = Cursor::Get(); - - // center hero - cursor.Hide(); - I.gameArea.Center(F.Center()); - F.SetRedraw(); - I.Redraw(); - - const s32 src = hero.GetIndex(); - // get destination - const s32 dst = I.GetDimensionDoorDestination(src, distance); - - if(Maps::isValidAbsIndex(src) && Maps::isValidAbsIndex(dst)) - { - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeOut(); - - cursor.Hide(); - hero.SetIndex(dst); - hero.Scoute(); - - world.GetTiles(src).SetObject(hero.GetUnderObject()); - hero.SaveUnderObject(world.GetTiles(dst).GetObject()); - world.GetTiles(dst).SetObject(MP2::OBJ_HEROES); - - I.gameArea.Center(F.Center()); - F.SetRedraw(); - I.Redraw(); - - AGG::PlaySound(M82::KILLFADE); - hero.GetPath().Hide(); - hero.FadeIn(); - - hero.ApplyPenaltyMovement(); - hero.ActionNewPosition(); - - return true; - } - - return false; -} - -bool ActionSpellTownGate(Heroes & hero) -{ - const Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - const std::vector & castles = kingdom.GetCastles(); - std::vector::const_iterator it; - - const Castle* castle = NULL; - const s32 center = hero.GetIndex(); - s32 min = -1; - - // find the nearest castle - for(it = castles.begin(); it != castles.end(); ++it) if(*it && !(*it)->GetHeroes()) - { - const u16 min2 = Maps::GetApproximateDistance(center, (*it)->GetIndex()); - if(min2 < min) - { - min = min2; - castle = *it; - } - } - - Interface::Basic & I = Interface::Basic::Get(); - Game::Focus & F = Game::Focus::Get(); - Cursor & cursor = Cursor::Get(); - - // center hero - cursor.Hide(); - I.gameArea.Center(F.Center()); - F.SetRedraw(); - I.Redraw(); - - if(!castle) - { - Dialog::Message("", _("No avaialble town. Spell Failed!!!"), Font::BIG, Dialog::OK); - return false; - } - - return HeroesTownGate(hero, castle); -} - -bool ActionSpellTownPortal(Heroes & hero) -{ - const Kingdom & kingdom = world.GetKingdom(hero.GetColor()); - std::vector castles; - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - for(std::vector::const_iterator it = kingdom.GetCastles().begin(); it != kingdom.GetCastles().end(); ++it) - if(*it && !(*it)->GetHeroes()) castles.push_back((**it).GetIndex()); - - if(castles.empty()) - { - Dialog::Message("", _("No avaialble town. Spell Failed!!!"), Font::BIG, Dialog::OK); - return false; - } - - const u16 window_w = 280; - const u16 window_h = 200; - - Dialog::FrameBorder* frameborder = new Dialog::FrameBorder(); - frameborder->SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder->Redraw(); - - const Rect & area = frameborder->GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), area); - - u16 result = Dialog::ZERO; - - CastleIndexListBox listbox(area, result); - - listbox.RedrawBackground(area); - listbox.SetScrollButtonUp(ICN::LISTBOX, 3, 4, Point(area.x + 256, area.y + 55)); - listbox.SetScrollButtonDn(ICN::LISTBOX, 5, 6, Point(area.x + 256, area.y + 145)); - listbox.SetScrollSplitter(AGG::GetICN(ICN::LISTBOX, 10), Rect(area.x + 261, area.y + 78, 14, 64)); - listbox.SetAreaMaxItems(5); - listbox.SetAreaItems(Rect(area.x + 10, area.y + 60, 250, 100)); - listbox.SetListContent(castles); - listbox.Redraw(); - - ButtonGroups btnGroups(area, Dialog::OK|Dialog::CANCEL); - btnGroups.Draw(); - - cursor.Show(); - display.Flip(); - - while(result == Dialog::ZERO && le.HandleEvents()) - { - result = btnGroups.QueueEventProcessing(); - - listbox.QueueEventProcessing(); - - if(!cursor.isVisible()) - { - listbox.Redraw(); - cursor.Show(); - display.Flip(); - } - } - - delete frameborder; - - // store - if(result == Dialog::OK) - return HeroesTownGate(hero, world.GetCastle(listbox.GetCurrent())); - - return false; -} - -bool ActionSpellVisions(Heroes & hero) -{ - std::vector monsters; - - const u8 dist = hero.GetVisionsDistance(); - - if(Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_MONSTER, dist, monsters)) - { - for(std::vector::const_iterator it = monsters.begin(); it != monsters.end(); ++it) - { - const Maps::Tiles & tile = world.GetTiles(*it); - const Army::Troop troop(tile); - - u32 join = troop.GetCount(); - Resource::funds_t cost; - - const u8 reason = Army::GetJoinSolution(hero, tile, join, cost.gold); - std::string hdr, msg; - - hdr = std::string("%{count} ") + troop.GetPluralName(join); - String::Lower(hdr); - String::Replace(hdr, "%{count}", join); - - switch(reason) - { - case 0: - msg = _("I fear these creatures are in the mood for a fight."); - break; - - case 1: - msg = _("The creatures are willing to join us!"); - break; - - case 2: - if(join == troop.GetCount()) - msg = _("All the creatures will join us..."); - else - { - msg = ngettext("The creature will join us...", "%{count} of the creatures will join us...", join); - String::Replace(msg, "%{count}", join); - } - msg.append("\n"); - msg.append("\n for a fee of %{gold} gold."); - String::Replace(msg, "%{gold}", cost.gold); - break; - - default: - msg = _("These weak creatures will surely flee before us."); - break; - } - - Dialog::Message(hdr, msg, Font::BIG, Dialog::OK); - } - } - else - { - std::string msg = _("You must be within %{count} spaces of a monster for the Visions spell to work."); - String::Replace(msg, "%{count}", dist); - Dialog::Message("", msg, Font::BIG, Dialog::OK); - return false; - } - - hero.SetModes(Heroes::VISIONS); - - return true; -} - -bool ActionSpellSetGuardian(Heroes & hero, Monster::monster_t m) -{ - if(MP2::OBJ_MINES != hero.GetUnderObject()) - { - Dialog::Message("", _("You must be standing on the entrance to a mine (sawmills and alchemists don't count) to cast this spell."), Font::BIG, Dialog::OK); - return false; - } - - const s32 index = hero.GetIndex(); - if(!Maps::isValidAbsIndex(index)) return false; - - Spell::spell_t spell = Spell::NONE; - - switch(m) - { - case Monster::GHOST: spell = Spell::HAUNT; break; - case Monster::EARTH_ELEMENT: spell = Spell::SETEGUARDIAN; break; - case Monster::AIR_ELEMENT: spell = Spell::SETAGUARDIAN; break; - case Monster::FIRE_ELEMENT: spell = Spell::SETFGUARDIAN; break; - case Monster::WATER_ELEMENT: spell = Spell::SETWGUARDIAN; break; - default: return false; - } - - - const u16 count = hero.GetPower() * Spell::GetExtraValue(spell); - - if(count) - { - Maps::Tiles & tile = world.GetTiles(index); - - // clear old spell - if(spell != tile.GetQuantity3()) tile.ResetQuantity(); - - tile.SetQuantity3(m); - tile.SetQuantity4(spell); - - //if(Settings::Get().OriginalVersion()) - tile.SetCountMonster(count); - //else - // tile.SetCountMonster(count + tile.GetCountMonster()); - - if(Spell::HAUNT == spell) - world.CaptureObject(index, Color::GRAY); - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/portrait.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/portrait.cpp deleted file mode 100644 index 14f844024..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/portrait.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "gamedefs.h" -#include "race.h" -#include "heroes.h" -#include "settings.h" -#include "portrait.h" - -const Surface & Portrait::Get(const HeroBase &hero, const Portrait::size_t sz) -{ - if(hero.GetType() == Skill::Primary::CAPTAIN) - return Captain(hero.GetRace(), sz); - else return Hero(dynamic_cast(hero), sz); -} - -const Surface & Portrait::Captain(const Race::race_t rc, const Portrait::size_t sz) -{ - switch(sz) - { - case BIG: - switch(rc) - { - case Race::KNGT: return AGG::GetICN(ICN::PORT0090, 0); - case Race::BARB: return AGG::GetICN(ICN::PORT0091, 0); - case Race::SORC: return AGG::GetICN(ICN::PORT0092, 0); - case Race::WRLK: return AGG::GetICN(ICN::PORT0093, 0); - case Race::WZRD: return AGG::GetICN(ICN::PORT0094, 0); - case Race::NECR: return AGG::GetICN(ICN::PORT0095, 0); - default: break; - } - break; - - case MEDIUM: - case SMALL: - switch(rc) - { - case Race::KNGT: return AGG::GetICN(ICN::MINICAPT, 0); - case Race::BARB: return AGG::GetICN(ICN::MINICAPT, 1); - case Race::SORC: return AGG::GetICN(ICN::MINICAPT, 2); - case Race::WRLK: return AGG::GetICN(ICN::MINICAPT, 3); - case Race::WZRD: return AGG::GetICN(ICN::MINICAPT, 4); - case Race::NECR: return AGG::GetICN(ICN::MINICAPT, 5); - default: break; - } - break; - } - - DEBUG(DBG_GAME , DBG_WARN, "Portrait::Captain: unknown race."); - - return AGG::GetICN(ICN::PORT0090, 0); -} - -const Surface & Portrait::Hero(const Heroes & hero, const size_t sz) -{ - switch(sz) - { - case BIG: return hero.GetPortrait101x93(); - case MEDIUM: return hero.GetPortrait50x46(); - case SMALL: return hero.GetPortrait30x22(); - default: break; - } - - return AGG::GetICN(ICN::PORTMEDI, 0); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/portrait.h b/project/jni/application/fheroes2/src/fheroes2/heroes/portrait.h deleted file mode 100644 index 410fb8b45..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/portrait.h +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2PORTRAIT_H -#define H2PORTRAIT_H - -class Heroes; - -namespace Portrait -{ - enum size_t { BIG, MEDIUM, SMALL }; - - const Surface & Get(const HeroBase & hero, const Portrait::size_t sz); - const Surface & Hero(const Heroes & hero, const Portrait::size_t sz); - const Surface & Captain(const Race::race_t rs, const Portrait::size_t sz); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/route.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/route.cpp deleted file mode 100644 index 5aba254b5..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/route.cpp +++ /dev/null @@ -1,334 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "world.h" -#include "heroes.h" -#include "algorithm.h" -#include "direction.h" -#include "maps.h" -#include "game.h" -#include "settings.h" -#include "route.h" - -/* construct */ -Route::Path::Path(const Heroes & h) - : hero(h), dst(h.GetIndex()), hide(true) -{ -} - -Direction::vector_t Route::Path::GetFrontDirection(void) const -{ - return size() ? front().Direction() : Direction::CENTER; -} - -u16 Route::Path::GetFrontPenalty(void) const -{ - return size() ? front().Penalty() : 0; -} - -void Route::Path::PopFront(void) -{ - if(size()) pop_front(); -} - -/* return length path */ -s32 Route::Path::Calculate(const s32 dst_index, const u16 limit) -{ - clear(); - - Algorithm::PathFind(this, hero.GetIndex(), dst_index, limit, &hero); - - dst = empty() ? hero.GetIndex() : dst_index; - - return !empty(); -} - -void Route::Path::Reset(void) -{ - if(empty()) return; - - dst = hero.GetIndex(); - - clear(); - - hide = true; -} - -u16 Route::Path::GetIndexSprite(const Direction::vector_t & from, const Direction::vector_t & to, u8 mod) -{ - // ICN::ROUTE - // start index 1, 25, 49, 73, 97, 121 (size arrow path) - u16 index = 1; - - switch(mod) - { - case 200: index = 121; break; - case 175: index = 97; break; - case 150: index = 73; break; - case 125: index = 49; break; - case 100: index = 25; break; - - default: break; - } - - switch(from) - { - case Direction::TOP: - switch(to) - { - case Direction::TOP: index += 8; break; - case Direction::TOP_RIGHT: index += 17; break; - case Direction::RIGHT: index += 18; break; - case Direction::LEFT: index += 6; break; - case Direction::TOP_LEFT: index += 7; break; - case Direction::BOTTOM_LEFT: index += 5; break; - case Direction::BOTTOM_RIGHT: index += 19; break; - default: index = 0; break; - } - break; - - case Direction::TOP_RIGHT: - switch(to) - { - case Direction::TOP: index += 0; break; - case Direction::TOP_RIGHT: index += 9; break; - case Direction::RIGHT: index += 18; break; - case Direction::BOTTOM_RIGHT: index += 19; break; - case Direction::TOP_LEFT: index += 7; break; - case Direction::BOTTOM: index += 20; break; - case Direction::LEFT: index += 6; break; - default: index = 0; break; - } - break; - - case Direction::RIGHT: - switch(to) - { - case Direction::TOP: index += 0; break; - case Direction::BOTTOM: index += 20; break; - case Direction::BOTTOM_RIGHT: index += 19; break; - case Direction::RIGHT: index += 10; break; - case Direction::TOP_RIGHT: index += 1; break; - case Direction::TOP_LEFT: index += 7; break; - case Direction::BOTTOM_LEFT: index += 21; break; - default: index = 0; break; - } - break; - - case Direction::BOTTOM_RIGHT: - switch(to) - { - case Direction::TOP_RIGHT: index += 1; break; - case Direction::RIGHT: index += 2; break; - case Direction::BOTTOM_RIGHT: index += 11; break; - case Direction::BOTTOM: index += 20; break; - case Direction::BOTTOM_LEFT: index += 21; break; - case Direction::TOP: index += 0; break; - case Direction::LEFT: index += 6; break; - default: index = 0; break; - } - break; - - case Direction::BOTTOM: - switch(to) - { - case Direction::RIGHT: index += 2; break; - case Direction::BOTTOM_RIGHT: index += 3; break; - case Direction::BOTTOM: index += 12; break; - case Direction::BOTTOM_LEFT: index += 21; break; - case Direction::LEFT: index += 22; break; - case Direction::TOP_LEFT: index += 16; break; - case Direction::TOP_RIGHT: index += 1; break; - default: index = 0; break; - } - break; - - case Direction::BOTTOM_LEFT: - switch(to) - { - case Direction::BOTTOM_RIGHT: index += 3; break; - case Direction::BOTTOM: index += 4; break; - case Direction::BOTTOM_LEFT: index += 13; break; - case Direction::LEFT: index += 22; break; - case Direction::TOP_LEFT: index += 23; break; - case Direction::TOP: index += 16; break; - case Direction::RIGHT: index += 2; break; - default: index = 0; break; - } - break; - - case Direction::LEFT: - switch(to) - { - case Direction::TOP: index += 16; break; - case Direction::BOTTOM: index += 4; break; - case Direction::BOTTOM_LEFT: index += 5; break; - case Direction::LEFT: index += 14; break; - case Direction::TOP_LEFT: index += 23; break; - case Direction::TOP_RIGHT: index += 17; break; - case Direction::BOTTOM_RIGHT: index += 3; break; - default: index = 0; break; - } - break; - - case Direction::TOP_LEFT: - switch(to) - { - case Direction::TOP: index += 16; break; - case Direction::TOP_RIGHT: index += 17; break; - case Direction::BOTTOM_LEFT: index += 5; break; - case Direction::LEFT: index += 6; break; - case Direction::TOP_LEFT: index += 15; break; - case Direction::BOTTOM: index += 4; break; - case Direction::RIGHT: index += 18; break; - default: index = 0; break; - } - break; - - default: index = 0; break; - } - - return index; -} - -/* total penalty cast */ -u32 Route::Path::TotalPenalty(void) const -{ - u32 result = 0; - - const_iterator it1 = begin(); - const_iterator it2 = end(); - - for(; it1 != it2; ++it1) result += (*it1).Penalty(); - - return result; -} - -u16 Route::Path::GetAllowStep(void) const -{ - u16 green = 0; - - const_iterator it1 = begin(); - const_iterator it2 = end(); - - u16 move_point = hero.GetMovePoints(); - - for(; it1 != it2; ++it1) - { - if(move_point >= (*it1).Penalty()) - { - move_point -= (*it1).Penalty(); - ++green; - } - else break; - } - - return green; -} - -void Route::Path::Dump(void) const -{ - std::cout << "Path::Dump: from: " << hero.GetIndex() << ", to: " << dst << ", obj: " << MP2::StringObject(world.GetTiles(dst).GetObject()) << std::endl; - - const_iterator it1 = begin(); - const_iterator it2 = end(); - - for(; it1 != it2; ++it1) std::cout << "Path::Dump: " << Direction::String((*it1).Direction()) << ", " << (*it1).Penalty() << std::endl; -} - -u16 Route::Path::isUnderProtection(s32 & pos) const -{ - const_iterator it = begin(); - s32 next = hero.GetIndex(); - - for(; it != end(); ++it) - { - if(Maps::isValidDirection(next, (*it).Direction())) - next = Maps::GetDirectionIndex(next, (*it).Direction()); - - const u16 res = Maps::TileUnderProtection(next); - - if(res) - { - pos = next; - return res; - } - } - - return 0; -} - -bool Route::Path::hasObstacle(s32* res) const -{ - const_iterator it = begin(); - s32 next = hero.GetIndex(); - - for(; it != end(); ++it) - { - if(Maps::isValidDirection(next, (*it).Direction())) - next = Maps::GetDirectionIndex(next, (*it).Direction()); - - // skip end point - if(next == dst) return false; - - switch(world.GetTiles(next).GetObject()) - { - case MP2::OBJ_HEROES: - case MP2::OBJ_MONSTER: - if(res) *res = next; - return true; - - default: break; - } - } - - return false; -} - -void Route::Path::ScanObstacleAndReduce(void) -{ - iterator it = begin(); - s32 next = hero.GetIndex(); - - for(; it != end(); ++it) - { - if(Maps::isValidDirection(next, (*it).Direction())) - next = Maps::GetDirectionIndex(next, (*it).Direction()); - - - switch(world.GetTiles(next).GetObject()) - { - case MP2::OBJ_HEROES: - // skip end point - if(next == dst) return; - - case MP2::OBJ_MONSTER: - dst = Maps::GetDirectionIndex(next, Direction::Reflect((*it).Direction())); - erase(it, end()); - return; - - default: break; - } - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/route.h b/project/jni/application/fheroes2/src/fheroes2/heroes/route.h deleted file mode 100644 index b5e2bdd09..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/route.h +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2HEROPATH_H -#define H2HEROPATH_H - -#include -#include "gamedefs.h" -#include "direction.h" -#include "game_io.h" - -class Heroes; - -namespace Route -{ - class Step : public std::pair - { - public: - Step() : std::pair(Direction::CENTER, 0) {} - Step(const Direction::vector_t v, const u16 c) : std::pair(v, c) {} - - Direction::vector_t Direction() const { return first; } - u16 Penalty() const { return second; } - }; - - class Path : public std::list - { - public: - Path(const Heroes & h); - - s32 GetDestinationIndex(void) const{ return dst; } - Direction::vector_t GetFrontDirection(void) const; - u16 GetFrontPenalty(void) const; - s32 Calculate(const s32 dst_index, const u16 limit = MAXU16); - - void Show(void){ hide = false; } - void Hide(void){ hide = true; } - void Reset(void); - void PopFront(void); - void ScanObstacleAndReduce(void); - - bool isValid(void) const { return size(); } - bool isShow(void) const { return !hide; } - u16 isUnderProtection(s32 & pos) const; - bool hasObstacle(s32* res = NULL) const; - - void Dump(void) const; - - u16 GetAllowStep(void) const; - u32 TotalPenalty(void) const; - - const_iterator Begin(void) const{ return begin(); } - const_iterator End(void) const{ return end(); } - - static u16 GetIndexSprite(const Direction::vector_t & from, const Direction::vector_t & to, u8 mod); - - private: - friend class Game::IO; - const Heroes & hero; - s32 dst; - bool hide; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/skill.cpp b/project/jni/application/fheroes2/src/fheroes2/heroes/skill.cpp deleted file mode 100644 index 8d3415dff..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/skill.cpp +++ /dev/null @@ -1,931 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "gamedefs.h" -#include "race.h" -#include "agg.h" -#include "cursor.h" -#include "dialog.h" -#include "heroes.h" -#include "settings.h" -#include "skill.h" - -#ifdef WITH_XML -#include "xmlccwrap.h" -#endif - -struct level_t -{ - u16 basic; - u16 advanced; - u16 expert; -}; - -struct primary_t -{ - u8 attack; - u8 defense; - u8 power; - u8 knowledge; -}; - -struct secondary_t -{ - u8 archery; - u8 ballistics; - u8 diplomacy; - u8 eagleeye; - u8 estates; - u8 leadership; - u8 logistics; - u8 luck; - u8 mysticism; - u8 navigation; - u8 necromancy; - u8 pathfinding; - u8 scouting; - u8 wisdom; -}; - -struct skillstats_t -{ - const char* id; - primary_t captain_primary; - primary_t initial_primary; - u8 initial_book; - u8 initial_spell; - secondary_t initial_secondary; - u8 over_level; - primary_t mature_primary_under; - primary_t mature_primary_over; - secondary_t mature_secondary; -}; - -struct skillvalues_t -{ - const char *id; - level_t values; -}; - -static skillstats_t _skillstats[] = { - { "knight", { 1, 1, 1, 1 }, { 2, 2, 1, 1 }, 0, 0, { 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }, 10, {35,45,10,10 }, {25,25,25,25 }, { 2, 4, 3, 1, 3, 5, 3, 1, 1, 2, 0, 3, 2, 2 } }, - { "barbarian", { 1, 1, 1, 1 }, { 3, 1, 1, 1 }, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 }, 10, {55,35, 5, 5 }, {30,30,20,20 }, { 3, 3, 2, 1, 2, 3, 3, 2, 1, 3, 0, 4, 4, 1 } }, - { "sorceress", { 0, 0, 2, 2 }, { 0, 0, 2, 3 }, 1,15, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1 }, 10, {10,10,30,50 }, {20,20,30,30 }, { 3, 3, 2, 2, 2, 1, 2, 3, 3, 4, 0, 2, 1, 4 } }, - { "warlock", { 0, 0, 2, 2 }, { 0, 0, 3, 2 }, 1,19, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 1 }, 10, {10,10,50,30 }, {20,20,30,30 }, { 1, 3, 2, 3, 2, 1, 2, 1, 3, 2, 1, 2, 4, 5 } }, - { "wizard", { 0, 0, 2, 2 }, { 0, 1, 2, 2 }, 1,17, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2 }, 10, {10,10,40,40 }, {20,20,30,30 }, { 1, 3, 2, 3, 2, 2, 2, 2, 4, 2, 0, 2, 2, 5 } }, - { "necromancer", { 0, 0, 2, 2 }, { 1, 0, 2, 2 }, 1,10, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1 }, 10, {15,15,35,35 }, {25,25,25,25 }, { 1, 3, 2, 3, 2, 0, 2, 1, 3, 2, 5, 3, 1, 4 } }, - { NULL, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 10, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } } -}; - -static skillvalues_t _skillvalues[] = { - { "pathfinding", { 25, 50,100} }, - { "archery", { 10, 25, 50} }, - { "logistics", { 10, 20, 30} }, - { "scouting", { 1, 2, 3} }, - { "diplomacy", { 25, 50,100} }, - { "navigation", { 33, 66,100} }, - { "leadership", { 1, 2, 3} }, - { "wisdom", { 3, 4, 5} }, - { "mysticism", { 2, 3, 4} }, - { "luck", { 1, 2, 3} }, - { "ballistics", { 0, 0, 0} }, - { "eagleeye", { 20, 30, 40} }, - { "necromancy", { 10, 20, 30} }, - { "estates", {100,250,500} }, - { NULL, { 0, 0, 0} }, -}; - -const skillstats_t* GetSkillStats(u8 race) -{ - const char* id = NULL; - - switch(race) - { - case Race::KNGT: id = "knight"; break; - case Race::BARB: id = "barbarian"; break; - case Race::SORC: id = "sorceress"; break; - case Race::WRLK: id = "warlock"; break; - case Race::WZRD: id = "wizard"; break; - case Race::NECR: id = "necromancer"; break; - default: - DEBUG(DBG_GAME, DBG_WARN, "GetSkillStats:: return is NULL"); break; - } - - const skillstats_t* ptr = &_skillstats[0]; - while(ptr->id && id && std::strcmp(id, ptr->id)) ++ptr; - - return id ? ptr : NULL; -} - -#ifdef WITH_XML -void LoadPrimarySection(const TiXmlElement* xml, primary_t & skill) -{ - if(!xml) return; - int value; - xml->Attribute("attack", &value); skill.attack = value; - xml->Attribute("defense", &value); skill.defense = value; - xml->Attribute("power", &value); skill.power = value; - xml->Attribute("knowledge", &value); skill.knowledge = value; -} - -void LoadSecondarySection(const TiXmlElement* xml, secondary_t & sec) -{ - if(!xml) return; - int value; - xml->Attribute("archery", &value); sec.archery = value; - xml->Attribute("ballistics", &value); sec.ballistics = value; - xml->Attribute("diplomacy", &value); sec.diplomacy = value; - xml->Attribute("eagleeye", &value); sec.eagleeye = value; - xml->Attribute("estates", &value); sec.estates = value; - xml->Attribute("leadership", &value); sec.leadership = value; - xml->Attribute("logistics", &value); sec.logistics = value; - xml->Attribute("luck", &value); sec.luck = value; - xml->Attribute("mysticism", &value); sec.mysticism = value; - xml->Attribute("navigation", &value); sec.navigation = value; - xml->Attribute("necromancy", &value); sec.necromancy = value; - xml->Attribute("pathfinding", &value); sec.pathfinding = value; - xml->Attribute("scouting", &value); sec.scouting = value; - xml->Attribute("wisdom", &value); sec.wisdom = value; -} -#endif - -void Skill::UpdateStats(const std::string & spec) -{ -#ifdef WITH_XML - // parse skills.xml - TiXmlDocument doc; - const TiXmlElement* xml_skills = NULL; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_skills = doc.FirstChildElement("skills"))) - { - const TiXmlElement* xml_captain = xml_skills->FirstChildElement("captain"); - const TiXmlElement* xml_initial = xml_skills->FirstChildElement("initial"); - const TiXmlElement* xml_maturity = xml_skills->FirstChildElement("maturity"); - const TiXmlElement* xml_secondary = xml_maturity ? xml_maturity->FirstChildElement("secondary") : NULL; - const TiXmlElement* xml_primary = xml_maturity ? xml_maturity->FirstChildElement("primary") : NULL; - const TiXmlElement* xml_under = xml_primary ? xml_primary->FirstChildElement("under") : NULL; - const TiXmlElement* xml_over = xml_primary ? xml_primary->FirstChildElement("over") : NULL; - skillstats_t *ptr = &_skillstats[0]; - int value; - - while(ptr->id) - { - const TiXmlElement* initial_race = xml_initial ? xml_initial->FirstChildElement(ptr->id) : NULL; - - if(initial_race) - { - LoadPrimarySection(initial_race, ptr->initial_primary); - LoadSecondarySection(initial_race, ptr->initial_secondary); - - initial_race->Attribute("book", &value); ptr->initial_book = value; - initial_race->Attribute("spell", &value); ptr->initial_spell = value; - } - - const TiXmlElement* captain_race = xml_captain ? xml_captain->FirstChildElement(ptr->id) : NULL; - if(captain_race) LoadPrimarySection(captain_race, ptr->captain_primary); - - const TiXmlElement* under_race = xml_under ? xml_under->FirstChildElement(ptr->id) : NULL; - if(under_race) LoadPrimarySection(under_race, ptr->mature_primary_under); - - const TiXmlElement* over_race = xml_over ? xml_over->FirstChildElement(ptr->id) : NULL; - if(over_race) - { - LoadPrimarySection(over_race, ptr->mature_primary_over); - over_race->Attribute("level", &value); - if(value) ptr->over_level = value; - } - - const TiXmlElement* secondary_race = xml_secondary ? xml_secondary->FirstChildElement(ptr->id) : NULL; - if(secondary_race) LoadSecondarySection(secondary_race, ptr->mature_secondary); - - ++ptr; - } - - xml_secondary = xml_skills->FirstChildElement("secondary"); - if(xml_secondary) - { - skillvalues_t* ptr2 = &_skillvalues[0]; - - while(ptr2->id) - { - const TiXmlElement* xml_sec = xml_secondary->FirstChildElement(ptr2->id); - - if(xml_sec) - { - xml_sec->Attribute("basic", &value); ptr2->values.basic = value; - xml_sec->Attribute("advanced", &value); ptr2->values.advanced = value; - xml_sec->Attribute("expert", &value); ptr2->values.expert = value; - } - - ++ptr2; - } - } - } - else - VERBOSE(spec << ": " << doc.ErrorDesc()); -#endif -} - -u16 Skill::Secondary::GetValues(skill_t skill, u8 level) -{ - switch(level) - { - case Level::BASIC: return _skillvalues[skill - 1].values.basic; - case Level::ADVANCED: return _skillvalues[skill - 1].values.advanced; - case Level::EXPERT: return _skillvalues[skill - 1].values.expert; - default: break; - } - return 0; -} - -Skill::Primary::Primary() : attack(0), defense(0), power(0), knowledge(0) -{ -} - -// primary skill from level up (dependence from race and hero level) -Skill::Primary::skill_t Skill::Primary::FromLevelUp(const u8 race, const u8 level) -{ - Rand::Queue percents(MAXPRIMARYSKILL); - - const skillstats_t* ptr = GetSkillStats(race); - if(ptr) - { - if(ptr->over_level > level) - { - percents.Push(ATTACK, ptr->mature_primary_under.attack); - percents.Push(DEFENSE, ptr->mature_primary_under.defense); - percents.Push(POWER, ptr->mature_primary_under.power); - percents.Push(KNOWLEDGE, ptr->mature_primary_under.knowledge); - } - else - { - percents.Push(ATTACK, ptr->mature_primary_over.attack); - percents.Push(DEFENSE, ptr->mature_primary_over.defense); - percents.Push(POWER, ptr->mature_primary_over.power); - percents.Push(KNOWLEDGE, ptr->mature_primary_over.knowledge); - } - } - - if(percents.Size()) - switch(percents.Get()) - { - case ATTACK: return ATTACK; - case DEFENSE: return DEFENSE; - case POWER: return POWER; - case KNOWLEDGE: return KNOWLEDGE; - default: break; - } - - DEBUG(DBG_GAME , DBG_WARN, "Skill::Primary::LevelUp: unknown result."); - return UNKNOWN; -} - -const char* Skill::Primary::String(const Skill::Primary::skill_t skill) -{ - const char* str_skill[] = { _("Attack"), _("Defense"), _("Power"), _("Knowledge"), "Unknown" }; - - switch(skill) - { - case ATTACK: return str_skill[0]; - case DEFENSE: return str_skill[1]; - case POWER: return str_skill[2]; - case KNOWLEDGE: return str_skill[3]; - default: break; - } - - return str_skill[4]; -} - -Skill::Level::type_t Skill::Level::FromMP2(const u8 byte) -{ - switch(byte) - { - case 1: return BASIC; - case 2: return ADVANCED; - case 3: return EXPERT; - - default: break; - } - - return NONE; -} - -const char* Skill::Level::String(u8 level) -{ - const char* str_level[] = { "None", _("Basic"), _("Advanced"), _("Expert") }; - - switch(level) - { - case BASIC: return str_level[1]; - case ADVANCED: return str_level[2]; - case EXPERT: return str_level[3]; - default: break; - } - - return str_level[0]; -} - -Skill::Secondary::Secondary() : std::pair(Skill::Secondary::UNKNOWN, Skill::Level::NONE) -{ -} - -Skill::Secondary::Secondary(const skill_t s, const Level::type_t t) : std::pair(s, t) -{ -} - -void Skill::Secondary::SetSkill(const skill_t skill) -{ - if(UNKNOWN == skill) return; - - first = skill; -} - -void Skill::Secondary::SetLevel(const u8 level) -{ - switch(level) - { - case Level::BASIC: - case Level::ADVANCED: - case Level::EXPERT: second = level; break; - default: break; - } -} - -void Skill::Secondary::NextLevel(void) -{ - switch(second) - { - case Level::NONE: second = Level::BASIC; break; - case Level::BASIC: second = Level::ADVANCED; break; - case Level::ADVANCED: second = Level::EXPERT; break; - default: break; - } -} - -Skill::Level::type_t Skill::Secondary::Level(void) const -{ - return second > Level::EXPERT ? Level::NONE : static_cast(second); -} - -Skill::Secondary::skill_t Skill::Secondary::Skill(void) const -{ - return Skill(first); -} - -bool Skill::Secondary::isLevel(u8 level) const -{ - return level == second; -} - -bool Skill::Secondary::isSkill(u8 skill) const -{ - return skill == first; -} - -Skill::Secondary::skill_t Skill::Secondary::Skill(const u8 index) -{ - return index > ESTATES ? UNKNOWN : static_cast(index); -} - -Skill::Secondary::skill_t Skill::Secondary::FromMP2(const u8 byte) -{ - switch(byte) - { - case 0: return PATHFINDING; - case 1: return ARCHERY; - case 2: return LOGISTICS; - case 3: return SCOUTING; - case 4: return DIPLOMACY; - case 5: return NAVIGATION; - case 6: return LEADERSHIP; - case 7: return WISDOM; - case 8: return MYSTICISM; - case 9: return LUCK; - case 10: return BALLISTICS; - case 11: return EAGLEEYE; - case 12: return NECROMANCY; - case 13: return ESTATES; - - default: break; - } - - return UNKNOWN; -} - -Skill::Secondary::skill_t Skill::Secondary::RandForWitchsHut(void) -{ - switch(Rand::Get(11)) - { - case 0: return PATHFINDING; - case 1: return ARCHERY; - case 2: return LOGISTICS; - case 3: return SCOUTING; - case 4: return DIPLOMACY; - case 5: return NAVIGATION; - case 6: return WISDOM; - case 7: return MYSTICISM; - case 8: return LUCK; - case 9: return BALLISTICS; - case 10: return EAGLEEYE; - case 11: return ESTATES; - - default: break; - } - - return UNKNOWN; -} - -/* index sprite from SECSKILL */ -u8 Skill::Secondary::GetIndexSprite1(const skill_t skill) -{ - switch(skill) - { - case PATHFINDING: return 1; - case ARCHERY: return 2; - case LOGISTICS: return 3; - case SCOUTING: return 4; - case DIPLOMACY: return 5; - case NAVIGATION: return 6; - case LEADERSHIP: return 7; - case WISDOM: return 8; - case MYSTICISM: return 9; - case LUCK: return 10; - case BALLISTICS: return 11; - case EAGLEEYE: return 12; - case NECROMANCY: return 13; - case ESTATES: return 14; - - default: break; - } - - return 0; -} - -/* index sprite from MINISS */ -u8 Skill::Secondary::GetIndexSprite2(const skill_t skill) -{ - switch(skill) - { - case PATHFINDING: return 0; - case ARCHERY: return 1; - case LOGISTICS: return 2; - case SCOUTING: return 3; - case DIPLOMACY: return 4; - case NAVIGATION: return 5; - case LEADERSHIP: return 6; - case WISDOM: return 7; - case MYSTICISM: return 8; - case LUCK: return 9; - case BALLISTICS: return 10; - case EAGLEEYE: return 11; - case NECROMANCY: return 12; - case ESTATES: return 13; - - default: break; - } - - DEBUG(DBG_GAME , DBG_WARN, "Skill::Secondary::GetIndexSprite2: unknown skill, index out of range"); - - return 0xff; -} - -const char* Skill::Secondary::String(const skill_t skill) -{ - const char* str_skill[] = { _("Pathfinding"), _("Archery"), _("Logistics"), _("Scouting"), _("Diplomacy"), _("Navigation"), - _("Leadership"), _("Wisdom"), _("Mysticism"), _("Luck"), _("Ballistics"), _("Eagle Eye"), _("Necromancy"), _("Estates"), "Unknown" }; - - switch(skill) - { - case PATHFINDING: return str_skill[0]; - case ARCHERY: return str_skill[1]; - case LOGISTICS: return str_skill[2]; - case SCOUTING: return str_skill[3]; - case DIPLOMACY: return str_skill[4]; - case NAVIGATION: return str_skill[5]; - case LEADERSHIP: return str_skill[6]; - case WISDOM: return str_skill[7]; - case MYSTICISM: return str_skill[8]; - case LUCK: return str_skill[9]; - case BALLISTICS: return str_skill[10]; - case EAGLEEYE: return str_skill[11]; - case NECROMANCY: return str_skill[12]; - case ESTATES: return str_skill[13]; - - default: break; - } - - return str_skill[14]; -} - -const char* Skill::Secondary::Description(const skill_t skill, const Level::type_t level) -{ - const char* description_skill[] = - { - _("Basic Pathfinding reduces the movement penalty for rough terrain by %{count} percent."), - _("Advanced Pathfinding reduces the movement penalty for rough terrain by %{count} percent."), - _("Expert Pathfinding eliminates the movement penalty for rough terrain by %{count} percent."), - - _("Basic Archery increases the damage done by range attacking creatures by %{count} percent."), - _("Advanced Archery increases the damage done by range attacking creatures by %{count} percent."), - _("Expert Archery increases the damage done by range attacking creatures by %{count} percent."), - - _("Basic Logistics increases your hero's movement points by %{count} percent."), - _("Advanced Logistics increases your hero's movement points by %{count} percent."), - _("Expert Logistics increases your hero's movement points by %{count} percent."), - - _("Basic Scouting increases your hero's viewable area by %{count} square."), - _("Advanced Scouting increases your hero's viewable area by %{count} squares."), - _("Expert Scouting increases your hero's viewable area by %{count} squares."), - - _("Basic Diplomacy allows you to negotiate with monsters who are weaker than your group. Approximately %{count} percent of the creatures may offer to join you."), - _("Advanced Diplomacy allows you to negotiate with monsters who are weaker than your group. Approximately %{count} percent of the creatures may offer to join you."), - _("Expert Diplomacy allows you to negotiate with monsters who are weaker than your group. %{count} percent of the creatures may offer to join you."), - - _("Basic Navigation increases your hero's movement points over water by %{count} percent."), - _("Advanced Navigation increases your hero's movement points over water by %{count} percent."), - _("Expert Navigation increases your hero's movement points over water by %{count} percent."), - - _("Basic Leadership increases your hero's troops' morale by %{count}."), - _("Advanced Leadership increases your hero's troops' morale by %{count}."), - _("Expert Leadership increases your hero's troops' morale by %{count}."), - - _("Basic Wisdom allows your hero to learn third level spells."), - _("Advanced Wisdom allows your hero to learn fourth level spells."), - _("Expert Wisdom allows your hero to learn fifth level spells."), - - _("Basic Mysticism regenerates %{count} of your hero's spell points per day."), - _("Advanced Mysticism regenerates %{count} of your hero's spell points per day."), - _("Expert Mysticism regenerates %{count} of your hero's spell points per day."), - - _("Basic Luck increases your hero's luck by %{count}."), - _("Advanced Luck increases your hero's luck by %{count}."), - _("Expert Luck increases your hero's luck by %{count}."), - - _("Basic Ballistics gives your hero's catapult shots a greater chance to hit and do damage to castle walls."), - _("Advanced Ballistics gives your hero's catapult an extra shot, and each shot has a greater chance to hit and do damage to castle walls."), - _("Expert Ballistics gives your hero's catapult an extra shot, and each shot automatically destroys any wall, except a fortified wall in a Knight town."), - - _("Basic Eagle Eye gives your hero a %{count} percent chance to learn any given 1st or 2nd level enemy spell used against him in a combat."), - _("Advanced Eagle Eye gives your hero a %{count} percent chance to learn any given 3rd level spell (or below) used against him in combat."), - _("Expert Eagle Eye gives your hero a %{count} percent chance to learn any given 4th level spell (or below) used against him in combat."), - - _("Basic Necromancy allows %{count} percent of the creatures killed in combat to be brought back from the dead as Skeletons."), - _("Advanced Necromancy allows %{count} percent of the creatures killed in combat to be brought back from the dead as Skeletons."), - _("Expert Necromancy allows %{count} percent of the creatures killed in combat to be brought back from the dead as Skeletons."), - - _("Your hero produces %{count} gold pieces per turn as tax revenue from estates."), - _("Your hero produces %{count} gold pieces per turn as tax revenue from estates."), - _("Your hero produces %{count} gold pieces per turn as tax revenue from estates.") }; - - u8 index = 0; - - switch(level) - { - case Level::BASIC: index = 0; break; - case Level::ADVANCED: index = 1; break; - case Level::EXPERT: index = 2; break; - default: break; - } - switch(skill) - { - case PATHFINDING: break; - case ARCHERY: index += 3; break; - case LOGISTICS: index += 6; break; - case SCOUTING: index += 9; break; - case DIPLOMACY: index += 12; break; - case NAVIGATION: index += 15; break; - case LEADERSHIP: index += 18; break; - case WISDOM: index += 21; break; - case MYSTICISM: index += 24; break; - case LUCK: index += 27; break; - case BALLISTICS: index += 30; break; - case EAGLEEYE: index += 33; break; - case NECROMANCY: index += 36; break; - case ESTATES: index += 39; break; - - default: break; - } - - return description_skill[index]; -} - -void Skill::Secondary::FillStandard(std::vector & v) -{ - v.clear(); - v.reserve(MAXSECONDARYSKILL); - v.push_back(PATHFINDING); - v.push_back(ARCHERY); - v.push_back(LOGISTICS); - v.push_back(SCOUTING); - v.push_back(DIPLOMACY); - v.push_back(NAVIGATION); - v.push_back(LEADERSHIP); - v.push_back(WISDOM); - v.push_back(MYSTICISM); - v.push_back(LUCK); - v.push_back(BALLISTICS); - v.push_back(EAGLEEYE); - v.push_back(NECROMANCY); - v.push_back(ESTATES); -} - -u8 Skill::Secondary::GetWeightSkillFromRace(u8 race, u8 skill) -{ - const skillstats_t* ptr = GetSkillStats(race); - - if(ptr) - { - if(skill == PATHFINDING) return ptr->mature_secondary.pathfinding; - else - if(skill == ARCHERY) return ptr->mature_secondary.archery; - else - if(skill == LOGISTICS) return ptr->mature_secondary.logistics; - else - if(skill == SCOUTING) return ptr->mature_secondary.scouting; - else - if(skill == DIPLOMACY) return ptr->mature_secondary.diplomacy; - else - if(skill == NAVIGATION) return ptr->mature_secondary.navigation; - else - if(skill == LEADERSHIP) return ptr->mature_secondary.leadership; - else - if(skill == WISDOM) return ptr->mature_secondary.wisdom; - else - if(skill == MYSTICISM) return ptr->mature_secondary.mysticism; - else - if(skill == LUCK) return ptr->mature_secondary.luck; - else - if(skill == BALLISTICS) return ptr->mature_secondary.ballistics; - else - if(skill == EAGLEEYE) return ptr->mature_secondary.eagleeye; - else - if(skill == NECROMANCY) return ptr->mature_secondary.necromancy; - else - if(skill == ESTATES) return ptr->mature_secondary.estates; - } - - return 0; -} - -Skill::Secondary::skill_t Skill::Secondary::PriorityFromRace(u8 race, const std::vector& exclude) -{ - Rand::Queue parts(MAXSECONDARYSKILL); - - std::vector skills; - FillStandard(skills); - - std::vector::const_iterator it1 = skills.begin(); - std::vector::const_iterator it2 = skills.end(); - - for(; it1 != it2; ++it1) - if(exclude.empty() || exclude.end() == std::find(exclude.begin(), exclude.end(), *it1)) - parts.Push(*it1, GetWeightSkillFromRace(race, *it1)); - - return parts.Size() ? Skill(parts.Get()) : UNKNOWN; -} - -SecondarySkillBar::SecondarySkillBar() : skills(NULL), use_mini_sprite(false) -{ -} - -const Rect & SecondarySkillBar::GetArea(void) const -{ - return pos; -} - -void SecondarySkillBar::SetSkills(const std::vector & v) -{ - skills = &v; - CalcSize(); -} - -void SecondarySkillBar::SetUseMiniSprite(void) -{ - use_mini_sprite = true; -} - -void SecondarySkillBar::SetInterval(u8 i) -{ - interval = i; - CalcSize(); -} - -void SecondarySkillBar::SetPos(s16 sx, s16 sy) -{ - pos.x = sx; - pos.y = sy; - CalcSize(); -} - -void SecondarySkillBar::CalcSize(void) -{ - pos.w = 0; - pos.h = 0; - - if(skills) - { - const Sprite & sprite = AGG::GetICN((use_mini_sprite ? ICN::MINISS : ICN::SECSKILL), 0); - pos.h = sprite.h(); - pos.w = HEROESMAXSKILL * (sprite.w() + interval); - } -} - -void SecondarySkillBar::Redraw(void) -{ - Display & display = Display::Get(); - Point dst_pt(pos); - std::string message; - Text text; - text.Set(Font::SMALL); - - for(u8 ii = 0; ii < HEROESMAXSKILL; ++ii) - { - const Skill::Secondary::skill_t skill = ii < skills->size() ? skills->at(ii).Skill() : Skill::Secondary::UNKNOWN; - const Skill::Level::type_t level = ii < skills->size() ? skills->at(ii).Level() : Skill::Level::NONE; - - if(Skill::Secondary::UNKNOWN != skill && Skill::Level::NONE != level) - { - const Sprite & sprite_skill = AGG::GetICN((use_mini_sprite ? ICN::MINISS : ICN::SECSKILL), (use_mini_sprite ? Skill::Secondary::GetIndexSprite2(skill) : Skill::Secondary::GetIndexSprite1(skill))); - display.Blit(sprite_skill, dst_pt); - - if(use_mini_sprite) - { - message.clear(); - String::AddInt(message, level); - text.Set(message); - text.Blit(dst_pt.x + (sprite_skill.w() - text.w()) - 3, dst_pt.y + sprite_skill.h() - 12); - } - else - { - text.Set(Skill::Secondary::String(skill)); - text.Blit(dst_pt.x + (sprite_skill.w() - text.w()) / 2, dst_pt.y + 3); - - text.Set(Skill::Level::String(level)); - text.Blit(dst_pt.x + (sprite_skill.w() - text.w()) / 2, dst_pt.y + 50); - } - - dst_pt.x += (use_mini_sprite ? 32 : sprite_skill.w()) + interval; - } - else - { - const Sprite & sprite_skill = AGG::GetICN((use_mini_sprite ? ICN::HSICONS : ICN::SECSKILL), 0); - - if(use_mini_sprite) - display.Blit(sprite_skill, Rect((sprite_skill.w() - 32) / 2, 20, 32, 32), dst_pt); - else - display.Blit(sprite_skill, dst_pt); - - dst_pt.x += (use_mini_sprite ? 32 : sprite_skill.w()) + interval; - } - } -} - -u8 SecondarySkillBar::GetIndexFromCoord(const Point & cu) -{ - const Sprite & sprite_skill = AGG::GetICN((use_mini_sprite ? ICN::MINISS : ICN::SECSKILL), 0); - return (pos & cu) ? (cu.x - pos.x) / (sprite_skill.w() + interval) : 0; -} - -void SecondarySkillBar::QueueEventProcessing(void) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - LocalEvent & le = LocalEvent::Get(); - const Point & cu = le.GetMouseCursor(); - - if(!(pos & cu) || !skills) return; - - u8 ii = GetIndexFromCoord(cu); - const Sprite & sprite_skill = AGG::GetICN((use_mini_sprite ? ICN::MINISS : ICN::SECSKILL), 0); - const Rect tile(pos.x + (ii * (sprite_skill.w() + interval)), pos.y, sprite_skill.w(), sprite_skill.h()); - - if(ii < skills->size() && (le.MouseClickLeft(tile) || le.MousePressRight(tile))) - { - const Skill::Secondary::skill_t & skill = skills->at(ii).Skill(); - const Skill::Level::type_t & level = skills->at(ii).Level(); - - if(Skill::Secondary::UNKNOWN != skill && Skill::Level::NONE != level) - { - cursor.Hide(); - Dialog::SecondarySkillInfo(skill, level, !le.MousePressRight()); - cursor.Show(); - display.Flip(); - } - } -} - -void Skill::Primary::LoadDefaults(u8 race, Primary & skill, u8 & book, u8 & spell) -{ - const skillstats_t* ptr = GetSkillStats(race); - - if(ptr) - { - if(CAPTAIN == skill.GetType()) - { - skill.attack = ptr->captain_primary.attack; - skill.defense = ptr->captain_primary.defense; - skill.power = ptr->captain_primary.power; - skill.knowledge = ptr->captain_primary.knowledge; - book = ptr->initial_book; - spell = 0; - } - else - if(HEROES == skill.GetType()) - { - skill.attack = ptr->initial_primary.attack; - skill.defense = ptr->initial_primary.defense; - skill.power = ptr->initial_primary.power; - skill.knowledge = ptr->initial_primary.knowledge; - book = ptr->initial_book; - spell = ptr->initial_spell; - } - } -} - -void Skill::Secondary::LoadDefaults(u8 race, std::vector & skills) -{ - const skillstats_t* ptr = GetSkillStats(race); - - if(skills.size()) skills.clear(); - - if(ptr) - { - if(ptr->initial_secondary.archery) skills.push_back(Secondary(ARCHERY, Level::FromMP2(ptr->initial_secondary.archery))); - if(ptr->initial_secondary.ballistics) skills.push_back(Secondary(BALLISTICS, Level::FromMP2(ptr->initial_secondary.ballistics))); - if(ptr->initial_secondary.diplomacy) skills.push_back(Secondary(DIPLOMACY, Level::FromMP2(ptr->initial_secondary.diplomacy))); - if(ptr->initial_secondary.eagleeye) skills.push_back(Secondary(EAGLEEYE, Level::FromMP2(ptr->initial_secondary.eagleeye))); - if(ptr->initial_secondary.estates) skills.push_back(Secondary(ESTATES, Level::FromMP2(ptr->initial_secondary.estates))); - if(ptr->initial_secondary.leadership) skills.push_back(Secondary(LEADERSHIP, Level::FromMP2(ptr->initial_secondary.leadership))); - if(ptr->initial_secondary.logistics) skills.push_back(Secondary(LOGISTICS, Level::FromMP2(ptr->initial_secondary.logistics))); - if(ptr->initial_secondary.luck) skills.push_back(Secondary(LUCK, Level::FromMP2(ptr->initial_secondary.luck))); - if(ptr->initial_secondary.mysticism) skills.push_back(Secondary(MYSTICISM, Level::FromMP2(ptr->initial_secondary.mysticism))); - if(ptr->initial_secondary.navigation) skills.push_back(Secondary(NAVIGATION, Level::FromMP2(ptr->initial_secondary.navigation))); - if(ptr->initial_secondary.necromancy) skills.push_back(Secondary(NECROMANCY, Level::FromMP2(ptr->initial_secondary.necromancy))); - if(ptr->initial_secondary.pathfinding) skills.push_back(Secondary(PATHFINDING, Level::FromMP2(ptr->initial_secondary.pathfinding))); - if(ptr->initial_secondary.scouting) skills.push_back(Secondary(SCOUTING, Level::FromMP2(ptr->initial_secondary.scouting))); - if(ptr->initial_secondary.wisdom) skills.push_back(Secondary(WISDOM, Level::FromMP2(ptr->initial_secondary.wisdom))); - } -} - -void StringAppendModifiers(std::string & str, s8 value) -{ - if(value < 0) str.append(" -"); - else - if(value > 0) str.append(" +"); - - String::AddInt(str, value); -} - -s8 Skill::GetLeadershipModifiers(u8 level, std::string* strs = NULL) -{ - level = Secondary::GetValues(Secondary::LEADERSHIP, level); - - if(level && strs) - { - strs->append(Level::String(level)); - strs->append(" "); - strs->append(Secondary::String(Secondary::LEADERSHIP)); - StringAppendModifiers(*strs, level); - strs->append("\n"); - } - - return level; -} - -s8 Skill::GetLuckModifiers(u8 level, std::string* strs = NULL) -{ - level = Secondary::GetValues(Secondary::LUCK, level); - - if(level && strs) - { - strs->append(Level::String(level)); - strs->append(" "); - strs->append(Secondary::String(Secondary::LUCK)); - StringAppendModifiers(*strs, level); - strs->append("\n"); - } - - return level; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/heroes/skill.h b/project/jni/application/fheroes2/src/fheroes2/heroes/skill.h deleted file mode 100644 index cd53b6a61..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/heroes/skill.h +++ /dev/null @@ -1,176 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2SKILL_H -#define H2SKILL_H - -#include -#include -#include -#include "race.h" -#include "color.h" -#include "gamedefs.h" - -void StringAppendModifiers(std::string &, s8); - -namespace Skill -{ - s8 GetLeadershipModifiers(u8 level, std::string* strs); - s8 GetLuckModifiers(u8 level, std::string* strs); - - void UpdateStats(const std::string &); - - namespace Level - { - enum type_t { NONE=0, BASIC=1, ADVANCED=2, EXPERT=3 }; - - type_t FromMP2(const u8 byte); - - const char* String(u8 level); - } - - class Secondary : private std::pair - { - public: - - enum skill_t - { - UNKNOWN = 0, - PATHFINDING = 1, - ARCHERY = 2, - LOGISTICS = 3, - SCOUTING = 4, - DIPLOMACY = 5, - NAVIGATION = 6, - LEADERSHIP = 7, - WISDOM = 8, - MYSTICISM = 9, - LUCK = 10, - BALLISTICS = 11, - EAGLEEYE = 12, - NECROMANCY = 13, - ESTATES = 14 - }; - - Secondary(); - Secondary(const skill_t s, const Level::type_t t); - - void SetSkill(const skill_t s); - void SetLevel(const u8 level); - void NextLevel(void); - - Level::type_t Level(void) const; - skill_t Skill(void) const; - - bool isLevel(u8) const; - bool isSkill(u8) const; - - static skill_t Skill(const u8); - static skill_t FromMP2(const u8 byte); - static skill_t RandForWitchsHut(void); - static const char* String(const skill_t skill); - static const char* Description(const skill_t skill, const Level::type_t level); - static skill_t PriorityFromRace(const u8 race, const std::vector& exclude); - static void FillStandard(std::vector &); - static u8 GetWeightSkillFromRace(u8 race, u8 skill); - static void LoadDefaults(u8, std::vector &); - static u16 GetValues(skill_t, u8); - - /* index sprite from SECSKILL */ - static u8 GetIndexSprite1(const skill_t skill); - - /* index sprite from MINISS */ - static u8 GetIndexSprite2(const skill_t skill); - }; - - class Primary - { - public: - - enum skill_t - { - UNKNOWN = 0, - ATTACK = 1, - DEFENSE = 2, - POWER = 3, - KNOWLEDGE = 4 - }; - - enum type_t - { - UNDEFINED, - MONSTER, - CAPTAIN, - HEROES - }; - - Primary(); - virtual ~Primary(){}; - - virtual u8 GetAttack(void) const = 0; - virtual u8 GetDefense(void) const = 0; - virtual u8 GetPower(void) const = 0; - virtual u8 GetKnowledge(void) const = 0; - virtual s8 GetMorale(void) const = 0; - virtual s8 GetLuck(void) const = 0; - virtual Race::race_t GetRace(void) const = 0; - virtual u8 GetType(void) const = 0; - - static const char* String(const skill_t skill); - static skill_t FromLevelUp(const u8 race, const u8 level); - static void LoadDefaults(u8, Primary &, u8 &, u8 &); - - protected: - u8 attack; - u8 defense; - u8 power; - u8 knowledge; - }; - -} - -class SecondarySkillBar -{ -public: - SecondarySkillBar(); - - const Rect & GetArea(void) const; - u8 GetIndexFromCoord(const Point &); - - void SetSkills(const std::vector &); - void SetUseMiniSprite(void); - void SetPos(s16, s16); - void SetInterval(u8); - - void Redraw(void); - void QueueEventProcessing(void); - -private: - void CalcSize(void); - - Rect pos; - const std::vector *skills; - u8 interval; - bool use_mini_sprite; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/image/images_pack.h b/project/jni/application/fheroes2/src/fheroes2/image/images_pack.h deleted file mode 100644 index 0bcd80fd4..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/image/images_pack.h +++ /dev/null @@ -1,779 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2IMAGES_H -#define H2IMAGES_H - -#ifdef WITH_ZLIB -#include "zzlib.h" - -#define FH2_ICONS_WIDTH 32 -#define FH2_ICONS_HEIGHT 32 -#define FH2_ICONS_BPP 2 -#define FH2_ICONS_SIZE 560 - -static const unsigned char fh2_icons_pack[FH2_ICONS_SIZE] = { - 0x78, 0x9c, 0xcd, 0x94, 0x8d, 0x69, 0xeb, 0x30, 0x14, 0x85, 0x1b, 0x6f, 0x10, 0xdc, 0x09, 0x1e, - 0xe9, 0x04, 0x59, 0xc1, 0xd0, 0x09, 0x0c, 0x9d, 0xc0, 0x90, 0x09, 0x0c, 0x9a, 0xc0, 0xe0, 0x09, - 0x82, 0x3d, 0x81, 0xc9, 0x06, 0x26, 0x1b, 0xb8, 0xdd, 0x20, 0x2b, 0x04, 0xab, 0x96, 0x2c, 0xff, - 0x25, 0xee, 0x3d, 0x12, 0xe2, 0xe5, 0xb9, 0xc9, 0x4b, 0xd2, 0x42, 0x69, 0x2e, 0x09, 0x38, 0xe6, - 0x3b, 0xf7, 0xef, 0x48, 0x0f, 0x0f, 0xbf, 0xf9, 0x33, 0xe7, 0x73, 0xfe, 0x1d, 0x3a, 0xef, 0xf3, - 0xfe, 0x36, 0x85, 0x69, 0x26, 0x3c, 0x47, 0x4d, 0xde, 0xaf, 0xdb, 0xa8, 0x39, 0xf7, 0x6e, 0x4a, - 0x47, 0x8d, 0x2f, 0xf1, 0xbf, 0x8d, 0xa0, 0x06, 0x1d, 0x35, 0x59, 0x17, 0x35, 0x51, 0x13, 0xd4, - 0xa7, 0xef, 0x3c, 0x11, 0x35, 0x53, 0x3e, 0xa8, 0x91, 0x09, 0xb1, 0x6e, 0xb3, 0x0e, 0x75, 0x83, - 0x86, 0x8a, 0x7d, 0x32, 0xb5, 0x44, 0x4d, 0xa8, 0x10, 0xd3, 0x8a, 0x7c, 0x99, 0x75, 0xc5, 0x90, - 0xf7, 0xf8, 0x1a, 0x1d, 0x13, 0x8e, 0x28, 0x06, 0xd4, 0x10, 0xaa, 0xa0, 0xb6, 0x61, 0xea, 0x99, - 0xf2, 0xeb, 0xd6, 0xe6, 0x0c, 0x15, 0x72, 0x66, 0x5d, 0xa8, 0x40, 0x33, 0xb9, 0x3f, 0x9a, 0xbc, - 0x96, 0xcf, 0x7b, 0xf4, 0xfa, 0x2f, 0xbf, 0xac, 0xd0, 0xaf, 0x2b, 0x5d, 0xe9, 0x88, 0x99, 0x70, - 0xc4, 0x42, 0x3d, 0x29, 0xb7, 0x76, 0x04, 0xe3, 0x31, 0xc5, 0xfe, 0xb8, 0x3b, 0xd8, 0x08, 0x55, - 0xde, 0x7b, 0xe2, 0xf3, 0x04, 0xa1, 0xfb, 0xa4, 0x40, 0xcf, 0xc4, 0xaa, 0x8c, 0xf9, 0x42, 0x2d, - 0xd4, 0x86, 0xd8, 0x55, 0xc9, 0x88, 0x87, 0x0e, 0x68, 0x54, 0x89, 0x8d, 0x7c, 0xde, 0x9f, 0x2f, - 0x8b, 0x01, 0xfd, 0x42, 0x81, 0x71, 0x28, 0x3c, 0xb7, 0x5b, 0xa2, 0x18, 0x1f, 0x47, 0x46, 0xbf, - 0xbb, 0x43, 0xca, 0x13, 0x9d, 0x65, 0x3a, 0x3d, 0xdb, 0x01, 0x26, 0xec, 0x08, 0x57, 0xa2, 0x02, - 0x57, 0x32, 0x9e, 0x52, 0x0d, 0x29, 0x29, 0x8c, 0x63, 0xac, 0x79, 0xc4, 0xb9, 0xee, 0xad, 0x42, - 0xa8, 0x8a, 0x61, 0x59, 0xe9, 0x0e, 0x2a, 0xe8, 0xc4, 0x7c, 0xcb, 0x91, 0x13, 0x7c, 0xa2, 0x79, - 0x6c, 0xe2, 0x92, 0x23, 0xd1, 0x41, 0xde, 0x07, 0xb5, 0xee, 0xa0, 0x32, 0x15, 0x6c, 0x88, 0x4f, - 0xf5, 0xfc, 0x12, 0x8e, 0x29, 0x18, 0x4f, 0x5d, 0xe2, 0x3d, 0x81, 0xb7, 0x98, 0x3a, 0x2a, 0x40, - 0x7e, 0xf0, 0x5b, 0xca, 0x6d, 0xe7, 0x87, 0xd9, 0x4f, 0x77, 0x7f, 0x9a, 0x3f, 0x54, 0x51, 0x63, - 0x3a, 0x60, 0xfc, 0xa5, 0x5c, 0x95, 0xae, 0x4c, 0x49, 0x63, 0xa3, 0x59, 0x74, 0x00, 0x87, 0x9c, - 0xef, 0xde, 0x4e, 0x00, 0xfe, 0x71, 0x44, 0x4c, 0x34, 0x26, 0xe0, 0x92, 0x77, 0xde, 0x34, 0x8f, - 0x09, 0x62, 0x77, 0xeb, 0xf6, 0xf2, 0x79, 0x9c, 0xf3, 0x3f, 0xef, 0x70, 0xda, 0x9c, 0x23, 0xff, - 0xac, 0xc2, 0xee, 0x13, 0xfe, 0x5a, 0x6e, 0xf5, 0x0c, 0x51, 0x3d, 0x3c, 0x79, 0x9d, 0x5f, 0x56, - 0xe8, 0x7f, 0x56, 0x31, 0xfe, 0x58, 0x33, 0xe2, 0x41, 0x8f, 0x63, 0x31, 0x80, 0xbf, 0x5c, 0xbd, - 0x51, 0x30, 0xa7, 0x95, 0x3c, 0x40, 0xfc, 0xaa, 0x7c, 0xac, 0xe1, 0x9d, 0x37, 0xbd, 0x3d, 0x73, - 0x96, 0xff, 0x7f, 0x9b, 0x60, 0x86, 0x27, 0x15, 0x90, 0x8f, 0xf7, 0x47, 0xcc, 0x7e, 0xa3, 0x75, - 0xaf, 0x65, 0x3f, 0x55, 0xf0, 0x88, 0x7d, 0xa6, 0xfc, 0x09, 0x6d, 0x90, 0x71, 0x6c, 0x0d, 0xee, - 0xbe, 0x7e, 0x97, 0x59, 0xde, 0x97, 0x9e, 0x76, 0xb1, 0x71, 0x2e, 0x3a, 0x87, 0xe6, 0x2d, 0x77, - 0xa1, 0x51, 0x08, 0x95, 0xaf, 0xcf, 0x72, 0xde, 0xef, 0x0e, 0xb6, 0xa2, 0x5b, 0xef, 0x62, 0x9c, - 0x25, 0x6c, 0x0a, 0x0a, 0x38, 0x31, 0xb8, 0xd1, 0x96, 0xd5, 0x3d, 0x37, 0x39, 0xbc, 0x9c, 0x75, - 0xb8, 0x89, 0x8c, 0x63, 0xef, 0xa3, 0xff, 0xd6, 0x60, 0xee, 0xb3, 0xfb, 0x69, 0xab, 0x10, 0xd4, - 0xbe, 0xfc, 0x1a, 0x6d, 0x14, 0x4c, 0x7c, 0x8d, 0xfe, 0x99, 0xcf, 0x07, 0xc7, 0xe1, 0x9f, 0xa3, -}; - -#define SDL_LOGO_WIDTH 640 -#define SDL_LOGO_HEIGHT 480 -#define SDL_LOGO_BPP 2 -#define SDL_LOGO_SIZE 11143 - -static const unsigned char sdl_logo_data[SDL_LOGO_SIZE] = { - 0x78, 0x9c, 0xed, 0xdd, 0xeb, 0x99, 0xa2, 0xca, 0xc2, 0x86, 0xe1, 0x1f, 0x03, 0x8a, 0x9c, 0x7a, - 0x7f, 0x19, 0x0c, 0x3b, 0x83, 0x76, 0x32, 0x58, 0xae, 0x0c, 0x96, 0x1d, 0x82, 0x1d, 0x42, 0x1b, - 0x82, 0x86, 0xa0, 0x21, 0x68, 0x08, 0x6d, 0x08, 0x4d, 0x08, 0x6d, 0x08, 0xc3, 0xce, 0x60, 0xcd, - 0x67, 0x89, 0x08, 0x22, 0x20, 0x2a, 0xa5, 0x54, 0xf1, 0x5c, 0xf7, 0x9f, 0x39, 0x74, 0x2b, 0x20, - 0xbc, 0xd6, 0xb9, 0xfe, 0xbc, 0xfc, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28, 0x15, 0xf9, 0xcf, 0x3e, 0x02, - 0x00, 0x78, 0x1e, 0x32, 0x10, 0x40, 0x77, 0x45, 0x3e, 0x19, 0x08, 0xa0, 0xbb, 0x22, 0xff, 0x37, - 0x19, 0x08, 0xa0, 0xb3, 0xb6, 0x64, 0x20, 0x80, 0xce, 0x8a, 0xfc, 0xad, 0x47, 0x5d, 0x18, 0x40, - 0x57, 0x91, 0x81, 0x00, 0xba, 0x6c, 0xeb, 0x91, 0x81, 0x00, 0xba, 0x2a, 0xf2, 0xbf, 0xc9, 0x40, - 0x00, 0x9d, 0xb5, 0xf5, 0x42, 0x77, 0xeb, 0x3d, 0xfb, 0x28, 0x00, 0xe0, 0x19, 0x44, 0x29, 0x30, - 0x74, 0xe9, 0x15, 0x06, 0xd0, 0x4d, 0x71, 0x29, 0x90, 0x9a, 0x30, 0x80, 0x2e, 0x8a, 0xfc, 0x90, - 0x9a, 0xb0, 0x56, 0x42, 0x6f, 0xe3, 0xae, 0x9d, 0x85, 0x3d, 0x1d, 0xbc, 0x5b, 0x6f, 0xfd, 0xb7, - 0xfe, 0xb8, 0xf7, 0xcf, 0x99, 0xf1, 0xee, 0xdf, 0x27, 0xfd, 0x77, 0x6b, 0x3a, 0x98, 0x0f, 0x56, - 0xce, 0xa7, 0xc3, 0x1d, 0x80, 0xee, 0x12, 0xa5, 0xc0, 0xd0, 0xa5, 0x14, 0xa8, 0xaa, 0xad, 0xbf, - 0x71, 0x17, 0xf6, 0x87, 0x35, 0xea, 0xbd, 0x1a, 0x3f, 0xef, 0x10, 0x18, 0xa3, 0xde, 0xa4, 0x3f, - 0x1b, 0x2c, 0xed, 0x2f, 0x6a, 0x05, 0xe8, 0x90, 0x38, 0x01, 0xbf, 0xb9, 0xe7, 0x95, 0x12, 0xee, - 0x52, 0x6f, 0xd2, 0x1f, 0x99, 0xc1, 0x5d, 0xa9, 0x57, 0x96, 0x85, 0x43, 0x73, 0xdc, 0xfb, 0xb0, - 0x96, 0x76, 0xe8, 0x3e, 0xfb, 0x3c, 0x01, 0xd9, 0x76, 0xf5, 0x60, 0x57, 0xa0, 0x1e, 0xd4, 0x7e, - 0x5b, 0x6f, 0x61, 0xbf, 0xf5, 0x65, 0xa4, 0x5e, 0x69, 0xb9, 0xd0, 0x7c, 0x17, 0x49, 0xd8, 0xd8, - 0xf7, 0xe3, 0xb7, 0xf7, 0x61, 0x3d, 0xde, 0x6c, 0x57, 0xdb, 0xdf, 0xb1, 0x97, 0x3b, 0x9f, 0xce, - 0xc6, 0x15, 0xa3, 0xc0, 0x44, 0x39, 0x57, 0xb5, 0x6f, 0xfd, 0xc8, 0x6f, 0xfe, 0xda, 0x2c, 0xed, - 0x67, 0x9f, 0xd5, 0xf3, 0x6d, 0xbd, 0x8d, 0xbb, 0xb4, 0xd7, 0x8e, 0x6a, 0xf7, 0x43, 0x77, 0x84, - 0xde, 0x6c, 0x30, 0xea, 0x3d, 0x2e, 0xf9, 0x0a, 0xca, 0x84, 0xfd, 0xc5, 0xae, 0x76, 0x7c, 0xef, - 0x79, 0x7c, 0xba, 0xcf, 0x39, 0x83, 0xf3, 0x33, 0x12, 0xe7, 0x34, 0x34, 0x47, 0xbd, 0xf1, 0xae, - 0xe6, 0xff, 0x61, 0xcd, 0x07, 0xeb, 0x5d, 0x2e, 0x86, 0x2d, 0x2f, 0x03, 0x6c, 0xfd, 0xe6, 0xaf, - 0xc4, 0xb8, 0xff, 0xec, 0xb3, 0x6a, 0x83, 0x71, 0x4f, 0xdc, 0x13, 0x1f, 0x16, 0xa5, 0xc0, 0xb6, - 0xd9, 0xfa, 0x73, 0x7b, 0xd4, 0x7b, 0x76, 0x5e, 0xa4, 0xb9, 0x21, 0x72, 0xf0, 0xfb, 0xe6, 0xbb, - 0xa4, 0x2d, 0xf9, 0x57, 0x75, 0x86, 0xa3, 0xde, 0xc4, 0x12, 0xbd, 0x43, 0xa1, 0xb7, 0x6d, 0x59, - 0x79, 0x80, 0xfc, 0x93, 0x23, 0x3a, 0x5c, 0xd7, 0xa1, 0x49, 0x7f, 0x48, 0x9b, 0x7c, 0xb9, 0x93, - 0xfe, 0x7d, 0x3d, 0x1b, 0xf2, 0x32, 0x62, 0x6a, 0x6d, 0x6e, 0x28, 0x0d, 0xb6, 0x3f, 0xff, 0xb2, - 0x67, 0xf9, 0xba, 0xef, 0x17, 0x12, 0xf5, 0xff, 0x67, 0xdf, 0x09, 0x31, 0xf2, 0x4f, 0x96, 0x71, - 0x3f, 0x2e, 0xff, 0xd1, 0x16, 0xd8, 0x0e, 0xd1, 0xcb, 0xda, 0x69, 0x4f, 0xa9, 0xaf, 0x3c, 0x21, - 0x3e, 0x76, 0x29, 0x78, 0xcd, 0xf7, 0xa5, 0x4a, 0xf9, 0x77, 0x7a, 0xa6, 0x22, 0x07, 0x9f, 0xfd, - 0x5c, 0x90, 0x7f, 0xf2, 0x7c, 0xed, 0x5b, 0x3f, 0xe2, 0xfe, 0x60, 0x4a, 0x81, 0xcf, 0xb5, 0xb4, - 0x47, 0xe6, 0xb3, 0x9f, 0xf8, 0xfa, 0x86, 0xe6, 0xee, 0x7b, 0xb3, 0x66, 0x32, 0xa8, 0x9a, 0x7f, - 0xb1, 0x5d, 0xed, 0xbf, 0x37, 0x1f, 0x3c, 0xaf, 0x56, 0x4c, 0xfe, 0xc9, 0x97, 0xf4, 0x07, 0x53, - 0x0a, 0x7c, 0x8e, 0xb5, 0x33, 0x54, 0x28, 0xfb, 0x52, 0x43, 0x73, 0x61, 0x5f, 0x4e, 0x06, 0xb5, - 0xf3, 0x2f, 0x16, 0x18, 0x7f, 0xf7, 0x56, 0x4f, 0xe9, 0x2b, 0x24, 0xff, 0x1e, 0x21, 0x4d, 0x40, - 0x4a, 0x81, 0x8f, 0x15, 0xba, 0xcf, 0xeb, 0xe3, 0x6d, 0xc2, 0xab, 0xf1, 0x6e, 0x55, 0xf7, 0x11, - 0xeb, 0x90, 0x7f, 0x31, 0x51, 0xea, 0x7d, 0x74, 0x09, 0x81, 0xfc, 0x7b, 0x94, 0x34, 0x01, 0x29, - 0x05, 0x3e, 0x46, 0xe4, 0x4f, 0x1e, 0x38, 0xb2, 0x4f, 0xa6, 0x49, 0xc5, 0x13, 0xa5, 0x4f, 0xfe, - 0x09, 0x81, 0xf1, 0xd6, 0xbf, 0xa5, 0x17, 0xe8, 0x56, 0xe4, 0xdf, 0xe3, 0xa4, 0x2d, 0x81, 0xb7, - 0x8f, 0x76, 0x40, 0x5d, 0x2b, 0x45, 0x6b, 0xbd, 0x45, 0xfe, 0xe9, 0x95, 0x9f, 0xa7, 0x5e, 0xf9, - 0x27, 0x88, 0x11, 0x41, 0x8f, 0xca, 0x40, 0xf2, 0xef, 0x91, 0xd2, 0x04, 0xa4, 0x1e, 0x2c, 0xd3, - 0x76, 0x57, 0xf2, 0x7b, 0xf6, 0x53, 0xdc, 0xa4, 0x6e, 0xe5, 0x5f, 0xec, 0xad, 0xff, 0x88, 0xd9, - 0x82, 0xe4, 0xdf, 0x63, 0x6d, 0x7d, 0xea, 0xc1, 0xb2, 0x6d, 0x5c, 0x7d, 0x4a, 0x7e, 0xb1, 0x2e, - 0xe6, 0x5f, 0x3c, 0x16, 0x48, 0x76, 0x29, 0x81, 0xfc, 0x7b, 0xb4, 0x88, 0x04, 0x94, 0x6a, 0x36, - 0xd0, 0xa3, 0xcd, 0x2f, 0xab, 0x9b, 0xf9, 0x27, 0x04, 0x86, 0xdc, 0xd9, 0xb4, 0xe4, 0xdf, 0xe3, - 0x65, 0x13, 0x90, 0x7a, 0x70, 0x93, 0x22, 0xcd, 0xea, 0xbd, 0x89, 0xee, 0xe6, 0x5f, 0x3c, 0x42, - 0x50, 0x5e, 0x39, 0x81, 0xfc, 0x7b, 0x86, 0xd3, 0x04, 0x64, 0xdd, 0xfc, 0x66, 0x7c, 0x7b, 0x7f, - 0x69, 0x56, 0xef, 0x4d, 0x74, 0x39, 0xff, 0x84, 0xc0, 0x98, 0x0f, 0xe4, 0xdc, 0x33, 0xe4, 0xdf, - 0xb3, 0x88, 0xe4, 0xdb, 0xb8, 0x9f, 0xce, 0x86, 0x15, 0x83, 0x1b, 0x11, 0x6a, 0xd7, 0xea, 0x97, - 0xea, 0x7a, 0xfe, 0x09, 0xe3, 0xbe, 0x8c, 0xa7, 0x84, 0xfc, 0x7b, 0x1e, 0x31, 0x1f, 0xf5, 0xd5, - 0xdc, 0xcf, 0x75, 0x6a, 0xfd, 0x3a, 0x41, 0x6d, 0xb7, 0x71, 0xf5, 0x6b, 0xf5, 0x4b, 0x91, 0x7f, - 0x42, 0x60, 0xac, 0x9d, 0xa6, 0xef, 0x1b, 0xf2, 0xef, 0x59, 0x22, 0x3f, 0x9d, 0x91, 0x3a, 0xb5, - 0xbe, 0x68, 0x09, 0xbc, 0xc3, 0xc6, 0x6d, 0xe3, 0x9a, 0x2e, 0xcd, 0x21, 0xff, 0x62, 0xa2, 0x47, - 0xb8, 0xd9, 0x3b, 0x87, 0xfc, 0x7b, 0x96, 0x6f, 0x2f, 0x2d, 0xb1, 0x8c, 0x7b, 0x5f, 0x2e, 0x09, - 0x78, 0xab, 0x50, 0xeb, 0xb2, 0x9f, 0x40, 0xfe, 0xa5, 0x76, 0xf5, 0xe0, 0x06, 0x9f, 0x12, 0xf2, - 0xef, 0x59, 0xb6, 0x7e, 0x5a, 0x66, 0x99, 0xf4, 0x45, 0xfe, 0x09, 0xb4, 0x04, 0x5e, 0x2b, 0xf4, - 0xf4, 0x6d, 0xf7, 0x4b, 0x90, 0x7f, 0x59, 0x7f, 0x99, 0xcd, 0x3d, 0x25, 0xe4, 0xdf, 0xf3, 0x2c, - 0xec, 0xb8, 0xdc, 0x32, 0x34, 0xd7, 0x4e, 0x92, 0x7f, 0x24, 0xe0, 0x75, 0x22, 0x5f, 0xd7, 0x3e, - 0xdf, 0x2c, 0xf2, 0xef, 0xd4, 0xd0, 0x6c, 0x6a, 0x7e, 0x1c, 0xf9, 0xf7, 0x4c, 0x5b, 0x4f, 0xec, - 0x91, 0x20, 0x46, 0xc3, 0x6c, 0x0e, 0x44, 0x02, 0x32, 0x3b, 0xb8, 0xbe, 0x37, 0x2d, 0xc7, 0xfb, - 0xe5, 0x91, 0x7f, 0x79, 0x81, 0xf1, 0xd9, 0x48, 0x5f, 0x08, 0xf9, 0xd7, 0x0e, 0x69, 0x02, 0x0a, - 0xf4, 0x06, 0xd7, 0x33, 0x1b, 0x3c, 0xfb, 0x39, 0x7c, 0x0c, 0xf2, 0xef, 0x5c, 0x33, 0x33, 0x43, - 0xc8, 0xbf, 0xb6, 0xc8, 0x25, 0x20, 0x3b, 0xc5, 0x5e, 0xa4, 0xf7, 0x98, 0x97, 0x2c, 0xf2, 0xaf, - 0x48, 0x13, 0xe3, 0x61, 0xc8, 0xbf, 0xb6, 0x88, 0xfc, 0x2f, 0x12, 0xf0, 0x0a, 0xdd, 0x68, 0xf9, - 0x8b, 0x91, 0x7f, 0xc5, 0xee, 0x2f, 0x03, 0x92, 0x7f, 0xed, 0x11, 0xf9, 0x9b, 0x5c, 0x02, 0xfe, - 0xfb, 0xf4, 0x63, 0x6a, 0xaf, 0x69, 0x47, 0xea, 0xbe, 0x02, 0xf9, 0x57, 0x26, 0x30, 0xee, 0xeb, - 0x09, 0x21, 0xff, 0xda, 0xe4, 0xb7, 0x48, 0x40, 0x67, 0xef, 0x90, 0x80, 0x8c, 0x08, 0x2c, 0x16, - 0x7a, 0x5d, 0xa9, 0xfb, 0x0a, 0xe4, 0x5f, 0xb9, 0xd7, 0xbb, 0x12, 0x90, 0xfc, 0x6b, 0x97, 0xad, - 0x77, 0xc8, 0xbf, 0x83, 0x2f, 0x12, 0xb0, 0xd0, 0xf8, 0x29, 0xfd, 0xbe, 0x81, 0x31, 0x34, 0x47, - 0xbd, 0x71, 0x6f, 0xdc, 0xcf, 0x1a, 0xf5, 0x86, 0xa6, 0xdc, 0x34, 0x26, 0xff, 0xaa, 0x0c, 0xcd, - 0xdb, 0x47, 0x44, 0x93, 0x7f, 0x6d, 0x13, 0xe6, 0x12, 0x90, 0x32, 0xe0, 0xb9, 0x47, 0xf6, 0x7c, - 0x88, 0x1d, 0xbb, 0x3f, 0xac, 0xd5, 0xae, 0x44, 0x7e, 0xe9, 0x29, 0xdb, 0x7d, 0x77, 0xb9, 0x4b, - 0xfb, 0xc3, 0x1a, 0xf7, 0x9b, 0xce, 0x43, 0xf2, 0xaf, 0xda, 0xa8, 0x77, 0xeb, 0x33, 0x42, 0xfe, - 0xb5, 0x4f, 0xe8, 0x9e, 0x26, 0xe0, 0x75, 0xfb, 0x61, 0x77, 0xc1, 0xf8, 0x21, 0xfb, 0x98, 0x8b, - 0x1d, 0xba, 0x57, 0xce, 0x2d, 0x65, 0x8b, 0xc8, 0x17, 0x23, 0x3b, 0xa7, 0xd6, 0xaf, 0x86, 0x72, - 0x90, 0xfc, 0xbb, 0xa4, 0x6a, 0x87, 0xa8, 0x2a, 0xe4, 0x5f, 0x1b, 0x7d, 0xb9, 0xd4, 0x82, 0xcb, - 0x7d, 0x49, 0x7f, 0xe2, 0x83, 0x5d, 0x89, 0x62, 0x69, 0x37, 0x71, 0xcd, 0x23, 0x7f, 0xed, 0x4c, - 0xfa, 0xf7, 0xce, 0xd0, 0x23, 0xff, 0x2e, 0x9b, 0xdd, 0xb4, 0x42, 0x20, 0xf9, 0xd7, 0x46, 0x51, - 0xda, 0x0f, 0x72, 0x4c, 0xc0, 0x67, 0x1f, 0x53, 0x7b, 0xc8, 0x5e, 0xe3, 0x79, 0xdc, 0x6b, 0x7a, - 0xf7, 0x31, 0xf1, 0x79, 0xbe, 0x5b, 0xb7, 0x97, 0x05, 0x1f, 0x9d, 0x7f, 0x43, 0xf3, 0xb4, 0x85, - 0xf3, 0xa8, 0x37, 0x8a, 0x99, 0xc3, 0x3d, 0xb9, 0x9f, 0xc3, 0x75, 0x6e, 0xeb, 0x09, 0x26, 0xff, - 0xda, 0xe9, 0xb7, 0x9f, 0xab, 0x03, 0x3b, 0x8c, 0x07, 0x8c, 0x6d, 0x3d, 0x99, 0x6b, 0x5d, 0xfd, - 0xd5, 0xd8, 0xcc, 0xd2, 0x22, 0x6b, 0x67, 0x7c, 0xd3, 0x8e, 0xc4, 0x8f, 0xce, 0xbf, 0x6b, 0xca, - 0x52, 0x91, 0xd8, 0xd3, 0xcb, 0xdb, 0xb8, 0x6b, 0x67, 0x3e, 0x98, 0xf4, 0x9f, 0xb9, 0xdb, 0xfc, - 0xd0, 0xbc, 0xbe, 0xc4, 0x4e, 0xfe, 0xb5, 0x55, 0xdc, 0x13, 0xbc, 0xb6, 0x97, 0xf6, 0xda, 0xa6, - 0x0c, 0x98, 0x5a, 0xd8, 0xf2, 0x9e, 0xa0, 0x89, 0xf4, 0xfd, 0xc6, 0xc4, 0xba, 0x67, 0xd7, 0xef, - 0xd0, 0xd4, 0xe6, 0xfc, 0xcb, 0xdb, 0xee, 0xca, 0xba, 0x53, 0xeb, 0x39, 0x65, 0xc3, 0xeb, 0x5b, - 0x01, 0xc9, 0xbf, 0xf6, 0xda, 0x95, 0x16, 0x7a, 0xaf, 0xbb, 0x72, 0x7d, 0x60, 0xfc, 0xdd, 0x5b, - 0xda, 0x94, 0x01, 0x63, 0x23, 0x49, 0x7d, 0x1f, 0xc1, 0x5d, 0x4f, 0xfd, 0x75, 0xa2, 0x97, 0xa5, - 0x7d, 0x4d, 0x49, 0x49, 0xa5, 0xfc, 0x4b, 0x84, 0xee, 0x74, 0xf0, 0xe8, 0x14, 0x0c, 0x8c, 0xd5, - 0x95, 0xf3, 0x41, 0xc8, 0xbf, 0xb6, 0xda, 0x9e, 0xac, 0x6b, 0x27, 0x66, 0xfa, 0x90, 0x80, 0xe2, - 0x7e, 0x95, 0x55, 0xbf, 0x92, 0xb5, 0xc3, 0x4e, 0x39, 0xb1, 0xff, 0x41, 0xbd, 0x63, 0x53, 0x31, - 0xff, 0x04, 0xd1, 0xfb, 0x23, 0xeb, 0xfb, 0xaa, 0xd8, 0xeb, 0x95, 0x75, 0x60, 0xf2, 0xaf, 0xad, - 0xde, 0xad, 0xdc, 0x55, 0xed, 0xc5, 0xb5, 0xe0, 0x6e, 0xaf, 0x0f, 0xb8, 0x94, 0x54, 0xfb, 0x6d, - 0x7a, 0x5d, 0xf5, 0xba, 0x36, 0x6e, 0x9d, 0x72, 0xa0, 0xaa, 0xf9, 0x77, 0xcd, 0x39, 0x36, 0xe5, - 0xba, 0x3a, 0x30, 0xf9, 0xd7, 0x56, 0xf9, 0xba, 0xc3, 0xab, 0x99, 0xb4, 0x03, 0x76, 0x39, 0x01, - 0xe5, 0xf4, 0xfd, 0x8e, 0x7a, 0xd1, 0x13, 0xcf, 0x69, 0xed, 0x5c, 0xaa, 0x27, 0xaa, 0x9d, 0x7f, - 0xf5, 0xce, 0xb1, 0x29, 0xd7, 0xad, 0x0c, 0x48, 0xfe, 0xb5, 0x55, 0xfe, 0x7e, 0x19, 0x1e, 0xf3, - 0x6f, 0xe3, 0x74, 0x75, 0x34, 0x60, 0xf4, 0x22, 0x63, 0xcd, 0x97, 0xc0, 0x78, 0xfe, 0x7a, 0x8b, - 0x0b, 0xbb, 0x2a, 0x1f, 0xd4, 0xcf, 0x3f, 0xf1, 0xd9, 0x5d, 0xdf, 0xef, 0x73, 0x9b, 0xa1, 0x59, - 0xff, 0xa8, 0xc8, 0xbf, 0xb6, 0xca, 0xaf, 0x6f, 0x92, 0xd4, 0x7f, 0xbb, 0x9c, 0x80, 0x5b, 0x29, - 0xab, 0x1e, 0xdc, 0x3a, 0x77, 0xa0, 0xe1, 0x73, 0xf3, 0xf3, 0x2d, 0x1e, 0x29, 0x1d, 0xf2, 0x4f, - 0xd8, 0xd5, 0x84, 0x1f, 0x52, 0x0a, 0x5c, 0xd4, 0xee, 0x05, 0x21, 0xff, 0xda, 0x2a, 0xf2, 0xb3, - 0x2d, 0xc7, 0x43, 0x73, 0x65, 0x9f, 0x8e, 0x07, 0x7c, 0xf6, 0xf1, 0x3d, 0xc3, 0xda, 0x69, 0xfe, - 0x6e, 0xbd, 0x77, 0x05, 0xa5, 0x26, 0x89, 0x96, 0xb2, 0xa2, 0x63, 0xd4, 0x25, 0xff, 0x84, 0x8f, - 0x3b, 0xc6, 0x81, 0xd7, 0x55, 0x7f, 0x45, 0x04, 0xf2, 0xaf, 0xbd, 0x44, 0x8d, 0x41, 0xac, 0x2d, - 0x32, 0x32, 0x27, 0xfd, 0xb5, 0xcd, 0x78, 0xe8, 0x3f, 0x2f, 0x73, 0x09, 0x6b, 0xfe, 0xdd, 0x32, - 0x6a, 0x56, 0x9e, 0x68, 0x57, 0xee, 0x3f, 0xcf, 0x07, 0x9d, 0xf2, 0x4f, 0xf4, 0x61, 0xc9, 0x4f, - 0xc0, 0xba, 0xfd, 0x59, 0xe4, 0x5f, 0xdb, 0x89, 0xa7, 0x33, 0x3a, 0x9b, 0x0d, 0xb2, 0x4f, 0xc0, - 0xa7, 0xb7, 0x5a, 0x3d, 0xda, 0xa4, 0xb4, 0x86, 0x78, 0xc7, 0xdd, 0x5a, 0x91, 0x2d, 0xcf, 0x11, - 0x9e, 0xd5, 0x12, 0xf5, 0xca, 0x3f, 0x51, 0xce, 0x95, 0xdd, 0x1b, 0x12, 0x18, 0xf5, 0x4a, 0x80, - 0xe4, 0x9f, 0x1a, 0xb6, 0xde, 0xa7, 0x13, 0xcb, 0x26, 0x60, 0xd7, 0x7a, 0x82, 0x65, 0x8c, 0x25, - 0x9b, 0x3c, 0x69, 0xe4, 0x4b, 0x95, 0x28, 0xd7, 0x16, 0xa8, 0x5b, 0xfe, 0x3d, 0x62, 0xd7, 0xe6, - 0x7a, 0x25, 0x40, 0xf2, 0x4f, 0x15, 0x1b, 0xe7, 0xf3, 0x44, 0x17, 0xfb, 0x41, 0x64, 0x3c, 0x33, - 0xef, 0x2d, 0xcc, 0x3f, 0x61, 0x69, 0xa7, 0xf3, 0x9c, 0xf5, 0xcb, 0x3f, 0x31, 0x0f, 0x50, 0x6e, - 0x02, 0xee, 0x4a, 0x80, 0x35, 0x4a, 0x07, 0xe4, 0x9f, 0x2a, 0x22, 0xff, 0xd3, 0x39, 0xd7, 0xad, - 0x7e, 0x10, 0x19, 0xed, 0x46, 0x6d, 0xcd, 0x3f, 0xb1, 0xce, 0x57, 0x92, 0x10, 0x3a, 0xe6, 0x9f, - 0xfc, 0x3d, 0x0c, 0xa6, 0x35, 0x3e, 0x59, 0xf2, 0x4f, 0x1d, 0xa1, 0x5b, 0x94, 0x80, 0x5d, 0xea, - 0x07, 0x91, 0xf1, 0x94, 0xb4, 0xf9, 0x6e, 0xfd, 0xed, 0xaf, 0x1c, 0xa1, 0xaa, 0x87, 0x5a, 0xdd, - 0xfc, 0x13, 0xed, 0x80, 0x32, 0xd7, 0xf2, 0x09, 0x8c, 0xcb, 0xb5, 0x23, 0xf2, 0x4f, 0x25, 0x45, - 0xf9, 0xf7, 0xd9, 0x99, 0x56, 0xc0, 0x48, 0xc2, 0xbd, 0xfa, 0xd3, 0x18, 0x5d, 0x31, 0x5a, 0xb6, - 0x8d, 0x54, 0xce, 0x3f, 0x79, 0xf3, 0x19, 0x63, 0x97, 0xc7, 0x01, 0x92, 0x7f, 0x2a, 0xf9, 0xf6, - 0xd6, 0xce, 0xba, 0xb3, 0x75, 0x60, 0x19, 0xf7, 0x6a, 0xdd, 0x76, 0xa2, 0xf6, 0x52, 0x3b, 0xff, - 0xc4, 0x78, 0x40, 0x19, 0x9f, 0x6a, 0x6c, 0x74, 0xb1, 0x6f, 0x9f, 0xfc, 0x53, 0xcb, 0xc6, 0x59, - 0x1f, 0xa5, 0x09, 0xd8, 0x8d, 0x95, 0x01, 0xe5, 0xe4, 0xdf, 0x35, 0xb3, 0x05, 0xda, 0x48, 0xf5, - 0xfc, 0x3b, 0x1d, 0xe7, 0xdf, 0xac, 0xcb, 0x63, 0xdb, 0xc9, 0x3f, 0xb5, 0x6c, 0xbd, 0xb5, 0x73, - 0xaa, 0x3b, 0x75, 0x60, 0x59, 0xf9, 0x77, 0xcd, 0x7c, 0xd1, 0xf6, 0x51, 0x3d, 0xff, 0xe4, 0xf6, - 0x83, 0x5c, 0x9a, 0xdb, 0x48, 0xfe, 0xa9, 0x66, 0xe3, 0xe4, 0x13, 0x30, 0x4e, 0x41, 0xfd, 0x47, - 0xc2, 0xc8, 0xca, 0x3f, 0xb5, 0x4b, 0x80, 0xea, 0xe7, 0xdf, 0x9f, 0x97, 0xa9, 0xb4, 0x3a, 0x70, - 0x60, 0x54, 0xaf, 0xec, 0x43, 0xfe, 0xa9, 0x66, 0xeb, 0x17, 0xe5, 0xdf, 0xba, 0x13, 0x75, 0x60, - 0x59, 0x4f, 0xc9, 0xab, 0xa1, 0x6e, 0x2f, 0xba, 0x0e, 0xf9, 0x17, 0xf9, 0xf2, 0xc6, 0x02, 0xae, - 0x2a, 0x5b, 0xc7, 0xc9, 0x3f, 0xf5, 0x6c, 0xdc, 0xb5, 0xbd, 0x97, 0x4b, 0x40, 0xfd, 0xeb, 0xc0, - 0xb2, 0x9e, 0x91, 0xfd, 0x8c, 0x79, 0x45, 0xaf, 0x9e, 0x0e, 0xf9, 0x27, 0xb3, 0x1f, 0xb8, 0xba, - 0x06, 0x4c, 0xfe, 0xa9, 0x27, 0xf2, 0x0f, 0xf9, 0x97, 0x4b, 0xc1, 0x6b, 0xd6, 0x7d, 0x54, 0x93, - 0xcc, 0xf1, 0xb2, 0x43, 0x53, 0xcd, 0x12, 0xb4, 0x1e, 0xf9, 0xf7, 0xe7, 0x45, 0xd6, 0xca, 0x58, - 0x43, 0xf3, 0x77, 0x45, 0xcb, 0x10, 0xf9, 0xa7, 0x22, 0xb1, 0x2f, 0xdc, 0x99, 0x5d, 0x02, 0xaa, - 0x5b, 0x8b, 0xab, 0x47, 0xf6, 0x8c, 0x29, 0x15, 0xdb, 0x01, 0x75, 0xc9, 0x3f, 0x19, 0x6b, 0x9b, - 0xc5, 0xd6, 0x15, 0xe5, 0x02, 0xf2, 0x4f, 0x45, 0x5b, 0xaf, 0x20, 0xff, 0xf6, 0x19, 0xa8, 0x77, - 0x2f, 0xc8, 0x58, 0xfa, 0x5e, 0x3a, 0x7f, 0x99, 0x55, 0x4f, 0x4b, 0x1b, 0xe9, 0x92, 0x7f, 0x91, - 0xb4, 0x9d, 0xfd, 0xaa, 0x56, 0x42, 0x20, 0xff, 0xd4, 0x54, 0x58, 0x02, 0xdc, 0xef, 0x14, 0xfc, - 0xec, 0x23, 0x93, 0x49, 0xe6, 0x58, 0xd9, 0x44, 0x60, 0x8c, 0x7a, 0x4b, 0xfb, 0x99, 0xfb, 0x81, - 0x5c, 0x47, 0x97, 0xfc, 0x93, 0xb7, 0xb3, 0x73, 0xd5, 0xf8, 0x26, 0xf2, 0x4f, 0x4d, 0xa5, 0x25, - 0x40, 0x5b, 0xd5, 0x76, 0xfc, 0x3a, 0x64, 0xac, 0x7f, 0x5a, 0x2c, 0x30, 0xde, 0xad, 0x8d, 0xab, - 0x42, 0x0a, 0xea, 0x93, 0x7f, 0x91, 0xb4, 0xbd, 0x4d, 0xcb, 0x57, 0xca, 0x24, 0xff, 0x54, 0xb5, - 0x2e, 0x29, 0x01, 0xee, 0xea, 0xc0, 0x4f, 0x3f, 0x36, 0x79, 0xe7, 0x2c, 0xe7, 0xf9, 0x28, 0x16, - 0xec, 0x6a, 0xc3, 0xed, 0x4f, 0x41, 0x7d, 0xf2, 0x4f, 0xce, 0xfa, 0xb6, 0xc2, 0xb2, 0xb4, 0x5d, - 0x97, 0xfc, 0x53, 0x55, 0xe8, 0x96, 0x95, 0x00, 0xf5, 0xed, 0x05, 0x91, 0xb3, 0xff, 0xd1, 0x25, - 0x81, 0x31, 0xee, 0xcd, 0x07, 0xa1, 0xd7, 0xce, 0xb6, 0x55, 0x9d, 0xf2, 0x6f, 0x23, 0xe1, 0x5c, - 0x84, 0xf2, 0x31, 0x30, 0xe4, 0x9f, 0xaa, 0x22, 0x7f, 0x65, 0xcf, 0x07, 0x1f, 0xd6, 0xd4, 0x9a, - 0x0f, 0x56, 0xb9, 0x04, 0x6c, 0xe7, 0x93, 0xda, 0xc4, 0x39, 0x3f, 0x6a, 0x17, 0xd9, 0x73, 0x81, - 0x31, 0x34, 0xc7, 0xfd, 0xd9, 0x60, 0x57, 0x1e, 0x6c, 0xd5, 0xd5, 0xd5, 0x29, 0xff, 0x64, 0x7d, - 0xbe, 0xe5, 0xeb, 0x20, 0x90, 0x7f, 0xaa, 0x9a, 0x0f, 0x92, 0x7b, 0x25, 0x30, 0x46, 0xe6, 0xcc, - 0xca, 0xe6, 0x9f, 0x9a, 0x23, 0xd9, 0xea, 0x18, 0x4b, 0xd9, 0xff, 0xfc, 0x3a, 0xe2, 0x7a, 0x7f, - 0x58, 0x2b, 0x67, 0xeb, 0xb5, 0xa1, 0x66, 0xac, 0x53, 0xfe, 0xfd, 0x79, 0x29, 0xdf, 0x03, 0xf4, - 0xbe, 0x4f, 0xac, 0x6c, 0x37, 0x10, 0xf2, 0x4f, 0x45, 0x91, 0x7f, 0x9e, 0x03, 0xef, 0xfd, 0x2e, - 0x94, 0x00, 0x67, 0x0f, 0xeb, 0x01, 0xa9, 0xf3, 0x54, 0xfd, 0x65, 0x4e, 0xfa, 0x8b, 0x27, 0xb7, - 0x37, 0xe8, 0x95, 0x7f, 0xb2, 0x5a, 0x78, 0xcb, 0xd6, 0x81, 0x21, 0xff, 0x54, 0x54, 0x34, 0x5f, - 0x3c, 0x30, 0xb2, 0x65, 0xc0, 0xf6, 0xec, 0x69, 0xdb, 0x2c, 0x59, 0x2d, 0x44, 0xf7, 0x11, 0x63, - 0x66, 0x66, 0x83, 0x4f, 0xb7, 0xee, 0xae, 0xb3, 0x4d, 0xd2, 0x2b, 0xff, 0x64, 0xf5, 0x01, 0xcf, - 0x4b, 0xce, 0x88, 0xfc, 0x53, 0xcf, 0xb6, 0xe4, 0x1e, 0x19, 0x99, 0x5d, 0x28, 0x01, 0x3e, 0xa3, - 0x07, 0xa4, 0x2e, 0x91, 0x83, 0x1f, 0xd6, 0x63, 0x47, 0xa1, 0xeb, 0x95, 0x7f, 0x72, 0xf6, 0xf8, - 0x2b, 0xdf, 0xe5, 0x8f, 0xfc, 0x53, 0x4f, 0x59, 0x1d, 0x21, 0x30, 0xb2, 0xfd, 0x20, 0xba, 0x96, - 0x00, 0x27, 0x2d, 0x68, 0x01, 0xbc, 0x64, 0xdf, 0x22, 0xfb, 0xa0, 0x9e, 0x12, 0xdd, 0xf2, 0x4f, - 0x4e, 0x0b, 0x47, 0xd9, 0x18, 0x68, 0xf2, 0x4f, 0x3d, 0xab, 0xd2, 0x71, 0xf2, 0xcb, 0x0e, 0xf4, - 0x02, 0x3f, 0x76, 0x0c, 0xe0, 0x7d, 0x86, 0xe6, 0xa4, 0x2f, 0xbb, 0x34, 0xa8, 0x5b, 0xfe, 0xc9, - 0xf9, 0x7c, 0x03, 0xa3, 0xf8, 0xdd, 0xc8, 0x3f, 0xf5, 0x94, 0xb5, 0x81, 0x9d, 0x96, 0xff, 0x74, - 0x1d, 0x07, 0xf8, 0xcc, 0x31, 0x30, 0xb7, 0x09, 0x76, 0x4f, 0xc4, 0xd2, 0x96, 0xd5, 0x36, 0xa8, - 0x5b, 0xfe, 0xc9, 0x1a, 0xe3, 0x59, 0x3c, 0x2f, 0x8a, 0xfc, 0x53, 0x51, 0x71, 0x02, 0x8c, 0x7b, - 0xf9, 0x71, 0x80, 0xcf, 0x3e, 0x4e, 0x39, 0xe4, 0x8c, 0x91, 0x90, 0xed, 0xd5, 0x1c, 0xf7, 0x65, - 0xcc, 0xcd, 0xd1, 0x2d, 0xff, 0x64, 0x7d, 0xbf, 0x15, 0xb7, 0x07, 0x91, 0x7f, 0x2a, 0x5a, 0x39, - 0xe7, 0xdf, 0x91, 0xaf, 0xc6, 0x62, 0xb0, 0xb2, 0x13, 0x3a, 0x97, 0x00, 0x43, 0x4f, 0xc6, 0xf3, - 0xf1, 0x18, 0x81, 0x31, 0xb1, 0x9a, 0x6d, 0x99, 0xd5, 0x2d, 0xff, 0x64, 0xad, 0xf2, 0x53, 0xbc, - 0x0e, 0x34, 0xf9, 0xa7, 0xa6, 0xa5, 0x7d, 0x9a, 0x80, 0x43, 0x73, 0x9e, 0x49, 0xbf, 0x63, 0x0a, - 0x6a, 0xba, 0x1a, 0x8c, 0xfc, 0x75, 0xb0, 0x64, 0x12, 0xbd, 0xc4, 0x8b, 0xc6, 0x5a, 0x67, 0xf5, - 0xcb, 0x3f, 0x39, 0xe5, 0xfb, 0xe2, 0x73, 0x22, 0xff, 0x54, 0x15, 0x7a, 0x1f, 0x96, 0xa8, 0x29, - 0x04, 0xfb, 0x56, 0xf6, 0x45, 0x41, 0xfa, 0x09, 0x7a, 0xae, 0x06, 0xb3, 0x71, 0xdb, 0x3c, 0x0a, - 0xa6, 0x9e, 0xc0, 0xf8, 0xb0, 0x9a, 0xf8, 0x74, 0xf4, 0xcb, 0x3f, 0x39, 0xeb, 0x60, 0xbd, 0x17, - 0x8e, 0x80, 0x21, 0xff, 0xd4, 0xb7, 0x2e, 0x4c, 0xbe, 0x98, 0xae, 0xeb, 0x01, 0xaa, 0x5d, 0x02, - 0x4c, 0xbc, 0xee, 0x6a, 0xc3, 0xf7, 0x66, 0xa0, 0x7e, 0xf9, 0x27, 0xa7, 0x07, 0xf8, 0xad, 0x30, - 0x95, 0xc8, 0x3f, 0xf5, 0x6d, 0x9c, 0xa5, 0x2d, 0x14, 0x27, 0xa0, 0x9e, 0xa3, 0x60, 0x42, 0x0d, - 0x4a, 0x80, 0xb1, 0x7d, 0x39, 0xf0, 0x8e, 0xcf, 0x48, 0xbf, 0xfc, 0x0b, 0xa5, 0xcc, 0xf1, 0xf9, - 0xa7, 0x70, 0x0d, 0x04, 0xf2, 0x4f, 0x7d, 0x5b, 0x2f, 0xce, 0xbf, 0xc4, 0x69, 0xfe, 0xe9, 0xd9, - 0x07, 0xa2, 0xc6, 0x38, 0xe8, 0xba, 0x86, 0xe6, 0xed, 0x89, 0xa3, 0x5f, 0xfe, 0xc9, 0xd9, 0xe7, - 0x79, 0x54, 0x38, 0x02, 0x9a, 0xfc, 0x53, 0x5f, 0xe4, 0x9f, 0xe6, 0xdf, 0x69, 0x0e, 0xea, 0xda, - 0x07, 0xa2, 0xde, 0x38, 0xc0, 0x6a, 0xc3, 0x1b, 0x77, 0x1e, 0xd1, 0x2f, 0xff, 0xe4, 0xec, 0x73, - 0x3a, 0x34, 0x8b, 0x6a, 0x42, 0xe4, 0x9f, 0x0e, 0x56, 0x85, 0xf9, 0x97, 0xa4, 0x60, 0xd5, 0xfe, - 0x7f, 0x2a, 0x53, 0x69, 0x26, 0x48, 0x1d, 0x62, 0xcd, 0xfd, 0xeb, 0x5b, 0x2b, 0x74, 0xcc, 0x3f, - 0x19, 0x6d, 0x1b, 0xe4, 0x9f, 0xbe, 0x92, 0x16, 0xc0, 0x62, 0xfa, 0xae, 0x06, 0xa8, 0xe6, 0x48, - 0xe8, 0x2a, 0x43, 0xf3, 0xda, 0xd1, 0x81, 0x3a, 0xe6, 0x9f, 0x8c, 0x92, 0xfd, 0xab, 0x59, 0xd4, - 0xca, 0x4a, 0xfe, 0xe9, 0x20, 0x74, 0x97, 0x83, 0x9d, 0xd2, 0x12, 0xe0, 0xb3, 0x8f, 0x4f, 0x96, - 0xc8, 0x97, 0xb5, 0x67, 0xe2, 0xf3, 0x04, 0x57, 0xa6, 0x0f, 0xf9, 0x57, 0xf7, 0xba, 0x16, 0xf5, - 0xb4, 0x93, 0x7f, 0x3a, 0xd8, 0xfa, 0xfb, 0xfc, 0x1b, 0x94, 0xa5, 0xa0, 0x9e, 0x7d, 0xc0, 0xf1, - 0x99, 0xeb, 0xd5, 0x0a, 0x18, 0x7b, 0xeb, 0xd7, 0xff, 0xc4, 0x74, 0xcc, 0x3f, 0x19, 0xdf, 0x6a, - 0xe4, 0x9f, 0xbe, 0xc4, 0x5e, 0x20, 0x99, 0x04, 0x3c, 0xcb, 0x41, 0x7d, 0x6b, 0xc0, 0x62, 0x2c, - 0xf4, 0x6b, 0xe3, 0x77, 0xf0, 0xf3, 0x8d, 0x7a, 0x75, 0xc7, 0xc4, 0x90, 0x7f, 0xf5, 0x90, 0x7f, - 0x3a, 0x5b, 0x9f, 0xe7, 0x5f, 0x26, 0x05, 0x75, 0x5d, 0x09, 0x21, 0xa6, 0xc3, 0x6c, 0x90, 0x73, - 0x43, 0xb3, 0x7c, 0xd7, 0xda, 0x2c, 0xf2, 0xaf, 0x1e, 0xf2, 0x4f, 0x67, 0x1b, 0xa7, 0x24, 0xff, - 0x0e, 0x29, 0xa8, 0x6f, 0x0d, 0x58, 0x58, 0x17, 0xac, 0x07, 0xa1, 0xbe, 0xa1, 0x59, 0x67, 0x6e, - 0x08, 0xf9, 0x57, 0x0f, 0xf9, 0xa7, 0xb3, 0x43, 0x0f, 0x48, 0x29, 0x5d, 0x47, 0x41, 0x1f, 0xcf, - 0xdf, 0xd3, 0xb1, 0x1d, 0xb0, 0x4e, 0x02, 0x92, 0x7f, 0xf5, 0x90, 0x7f, 0x3a, 0xdb, 0x7a, 0xd5, - 0xf9, 0xf7, 0xa9, 0xe9, 0x28, 0xe8, 0xec, 0x15, 0xd0, 0xaf, 0x2f, 0x58, 0xcc, 0x5a, 0xb8, 0x54, - 0x72, 0x27, 0xff, 0xea, 0x21, 0xff, 0x74, 0xf6, 0xdb, 0xaf, 0xce, 0xbf, 0xa5, 0xd6, 0x2d, 0x80, - 0xb1, 0xe8, 0x65, 0xd2, 0xd7, 0xaf, 0x1e, 0x3c, 0xee, 0x55, 0xaf, 0x99, 0xaa, 0x65, 0xfe, 0x31, - 0xfe, 0x05, 0x57, 0x89, 0x2e, 0xe5, 0xdf, 0x40, 0xef, 0x16, 0xc0, 0x44, 0x7e, 0x5d, 0x44, 0x1d, - 0x4c, 0x2b, 0xd3, 0x48, 0xc7, 0xfc, 0x63, 0xfc, 0x1f, 0xae, 0x75, 0x29, 0xff, 0x74, 0x6f, 0x01, - 0x4c, 0x7c, 0x7b, 0x7a, 0xac, 0x8d, 0x95, 0x55, 0x35, 0x27, 0x44, 0xc7, 0xfc, 0x93, 0x31, 0xa2, - 0x89, 0xf9, 0x6f, 0x7a, 0x5b, 0x96, 0x8d, 0x80, 0xe9, 0x4c, 0x0b, 0x60, 0x6a, 0xa1, 0x59, 0x29, - 0xf0, 0xaf, 0x8a, 0x56, 0x40, 0x1d, 0xf3, 0x8f, 0xf9, 0xbf, 0xb8, 0x56, 0xe9, 0x08, 0xc0, 0x03, - 0xbd, 0xc7, 0x00, 0xe6, 0x45, 0xfe, 0xc4, 0xd2, 0x29, 0x03, 0x3f, 0x4a, 0xf6, 0xef, 0xd6, 0x31, - 0xff, 0x22, 0x29, 0xeb, 0x5f, 0xed, 0xbe, 0x43, 0x0a, 0xde, 0x8b, 0xfc, 0xd3, 0xc5, 0x67, 0xf5, - 0x08, 0xc0, 0xce, 0xb4, 0x00, 0xa6, 0x42, 0x57, 0x9f, 0x9a, 0x70, 0x71, 0xeb, 0xd5, 0xfe, 0x73, - 0xd7, 0x2e, 0xff, 0xb6, 0x52, 0xf6, 0xb7, 0x1a, 0xb1, 0xfe, 0xa9, 0xd6, 0x36, 0xce, 0x62, 0x10, - 0x2b, 0xcb, 0x3f, 0x3d, 0xf7, 0x02, 0xa9, 0xf6, 0xe5, 0x8e, 0x35, 0xe9, 0x13, 0x9e, 0x94, 0x3c, - 0x55, 0xfa, 0xe5, 0x5f, 0xd9, 0xfe, 0xd6, 0xf7, 0x19, 0x93, 0x7f, 0x5a, 0xfb, 0x72, 0x93, 0xfc, - 0x2b, 0xcb, 0xc1, 0xae, 0xf4, 0x80, 0xe4, 0x6d, 0xb4, 0xc8, 0xc0, 0xc0, 0x28, 0x9e, 0x0f, 0xa7, - 0x5f, 0xfe, 0xc9, 0x59, 0xd7, 0xb1, 0xf8, 0xfb, 0x83, 0xfc, 0xd3, 0x45, 0x78, 0x96, 0x7f, 0xf9, - 0x14, 0xd4, 0x75, 0x2f, 0xa4, 0x3a, 0xb6, 0x87, 0xdd, 0xf2, 0x54, 0x56, 0xbc, 0x83, 0x99, 0x7e, - 0xf9, 0x37, 0x1f, 0xc8, 0xb8, 0x7a, 0xc5, 0x2d, 0xa8, 0xe4, 0x9f, 0x2e, 0xca, 0xf2, 0x2f, 0xcd, - 0x41, 0x7d, 0xd7, 0x01, 0xac, 0x47, 0xec, 0x13, 0xa0, 0xf2, 0x1c, 0x91, 0xc0, 0x28, 0x6a, 0xc1, - 0xd5, 0x2f, 0xff, 0x26, 0x52, 0x56, 0xb5, 0x2d, 0x9e, 0x01, 0x40, 0xfe, 0xe9, 0x22, 0xf4, 0xaa, - 0xf3, 0x4f, 0x24, 0xe0, 0xb3, 0x8f, 0xb1, 0x0d, 0x42, 0x6f, 0x36, 0x18, 0x99, 0x6a, 0xd6, 0x87, - 0x17, 0x05, 0xcf, 0xb0, 0x7e, 0xf9, 0x27, 0xa7, 0xd7, 0xaa, 0x78, 0xfc, 0x17, 0xf9, 0xa7, 0x8b, - 0xed, 0xc5, 0xfc, 0x5b, 0x74, 0xae, 0x07, 0xb8, 0x4c, 0xb4, 0x2b, 0x2d, 0x4f, 0x07, 0xea, 0xd5, - 0x87, 0x8b, 0xda, 0xf0, 0x75, 0xcb, 0x3f, 0x59, 0xfb, 0x5a, 0x15, 0xb7, 0x9e, 0x92, 0x7f, 0xba, - 0xa8, 0x93, 0x7f, 0x5d, 0xec, 0x01, 0xae, 0x12, 0x7a, 0xf3, 0xc1, 0xb8, 0xa7, 0xce, 0xfa, 0xa9, - 0x45, 0xa3, 0x60, 0x74, 0xcb, 0xbf, 0x6f, 0x4f, 0x46, 0xd9, 0x3c, 0x30, 0x8a, 0xdf, 0x8d, 0xfc, - 0xd3, 0x43, 0xe4, 0x6f, 0xdc, 0x99, 0x35, 0xb7, 0xaa, 0xf3, 0xef, 0x9b, 0xfc, 0x2b, 0xb0, 0xf5, - 0xd7, 0x8e, 0x2a, 0xbd, 0x23, 0xe7, 0xad, 0x58, 0xba, 0xe5, 0x9f, 0x9c, 0xde, 0xdf, 0x61, 0xe1, - 0xee, 0xbf, 0xe4, 0x9f, 0xfa, 0xb6, 0xfe, 0x6c, 0x30, 0xea, 0x0d, 0xcd, 0x60, 0xf7, 0x1d, 0x37, - 0x34, 0x46, 0xe6, 0x7b, 0x7f, 0x5e, 0x9a, 0x7f, 0x5d, 0x1d, 0x01, 0x53, 0xcf, 0xd6, 0x5f, 0x39, - 0xef, 0xd6, 0xa8, 0xd7, 0xe6, 0xb6, 0xc1, 0xf3, 0x67, 0x4b, 0xb7, 0xfc, 0x9b, 0x4a, 0xe9, 0xfd, - 0x28, 0x1b, 0x3d, 0x49, 0xfe, 0xa9, 0x6d, 0x3e, 0x38, 0x7f, 0x5a, 0x87, 0xe6, 0xd4, 0x2a, 0xce, - 0xc0, 0x2e, 0x8f, 0x80, 0xa9, 0x6f, 0xbb, 0x2b, 0x4b, 0x8b, 0x7a, 0x71, 0x1b, 0x73, 0xf0, 0xbc, - 0x1e, 0xa7, 0x5b, 0xfe, 0xc9, 0x58, 0xfb, 0xea, 0xa7, 0x31, 0x2f, 0x39, 0x23, 0xf2, 0x4f, 0x65, - 0x65, 0xeb, 0xdd, 0xbd, 0x1a, 0x22, 0x01, 0x85, 0xd3, 0xfc, 0xeb, 0xd2, 0x1a, 0x08, 0x4d, 0x08, - 0x3d, 0x51, 0x33, 0x1e, 0xb5, 0xaa, 0x85, 0x30, 0xdf, 0x8e, 0xaf, 0x57, 0xfe, 0xc9, 0x99, 0xfb, - 0xfb, 0xd3, 0xf8, 0x2c, 0xa9, 0xf9, 0x90, 0x7f, 0xea, 0xfa, 0xa8, 0xa8, 0x29, 0x04, 0xc6, 0xec, - 0x90, 0x80, 0xd9, 0x1c, 0xec, 0xd6, 0x1a, 0x08, 0xcd, 0x39, 0x94, 0x08, 0x5b, 0x31, 0x8b, 0x64, - 0x9d, 0xfb, 0x0e, 0xd3, 0x2b, 0xff, 0xe4, 0xb4, 0xfe, 0x05, 0x46, 0xd9, 0x6e, 0x7a, 0xe4, 0x9f, - 0xaa, 0xc2, 0x0b, 0xbb, 0x9e, 0x8d, 0x7a, 0xd9, 0xfc, 0x8b, 0x75, 0x7d, 0x04, 0xf4, 0xfd, 0x42, - 0x6f, 0x61, 0xbf, 0xf5, 0x87, 0x4f, 0x1c, 0x3f, 0x38, 0xcd, 0xcd, 0x63, 0xd0, 0x2b, 0xff, 0x26, - 0x7d, 0x19, 0xd7, 0xac, 0x78, 0xed, 0x03, 0x81, 0xfc, 0x53, 0xd5, 0xfb, 0x85, 0x76, 0xe2, 0x7c, - 0x09, 0x50, 0xe8, 0xc2, 0x2a, 0xf8, 0x8f, 0x10, 0xf9, 0x71, 0x0e, 0x3e, 0x23, 0x05, 0xf3, 0x4f, - 0x97, 0x4e, 0xf9, 0x27, 0x6b, 0xec, 0x5f, 0xf1, 0xcc, 0x41, 0x81, 0xfc, 0x53, 0xd5, 0xe5, 0x3b, - 0x45, 0xf4, 0x04, 0xe7, 0xf2, 0x8f, 0x19, 0x20, 0x0d, 0xdb, 0xb8, 0x8f, 0x1e, 0x39, 0x93, 0x2f, - 0xcb, 0xe8, 0x94, 0x7f, 0x72, 0x6a, 0xbf, 0xe7, 0x6d, 0x06, 0x29, 0xf2, 0x4f, 0x55, 0x97, 0x3f, - 0x87, 0xb7, 0xb3, 0x1a, 0x30, 0xf9, 0x27, 0x43, 0xe4, 0xaf, 0x9d, 0xc7, 0xad, 0x34, 0x98, 0x5f, - 0xc7, 0x58, 0xa7, 0xfc, 0x93, 0x53, 0xfb, 0xfd, 0x59, 0xda, 0xfa, 0x47, 0xfe, 0xa9, 0xeb, 0xf2, - 0xe7, 0x40, 0xfe, 0x3d, 0xd2, 0xa3, 0x56, 0xd9, 0xca, 0xb7, 0xe5, 0xeb, 0x93, 0x7f, 0x91, 0x2f, - 0xe7, 0xfa, 0x95, 0x8d, 0x7d, 0x16, 0xc8, 0x3f, 0x55, 0xd5, 0xaa, 0xff, 0x5a, 0x73, 0x8b, 0xfc, - 0x7b, 0x9c, 0xb5, 0x23, 0xbf, 0x2e, 0x9c, 0x9f, 0x03, 0xa7, 0x4f, 0xfe, 0xc9, 0x59, 0xf7, 0xaa, - 0x7a, 0xff, 0x3c, 0xf2, 0x4f, 0x55, 0x55, 0xa3, 0x5f, 0x84, 0x7d, 0xff, 0x47, 0xd6, 0x7e, 0x14, - 0x4c, 0xf5, 0x5e, 0xb2, 0xb8, 0x57, 0xb4, 0xfb, 0x5c, 0x64, 0x97, 0x02, 0x43, 0x2d, 0xf3, 0x4f, - 0x56, 0xdf, 0x47, 0x50, 0xb9, 0x7b, 0x1e, 0xf9, 0xa7, 0xaa, 0xad, 0x57, 0x3d, 0x2a, 0x77, 0xdc, - 0x9b, 0x5b, 0x79, 0x8b, 0xc1, 0xbf, 0x4f, 0x3f, 0x6e, 0xfd, 0xad, 0x1d, 0xb9, 0x09, 0x78, 0x3a, - 0x96, 0x57, 0x97, 0xfc, 0x5b, 0xd9, 0x72, 0xae, 0xd6, 0xb0, 0x70, 0xdf, 0xa3, 0x04, 0xf9, 0xa7, - 0xae, 0x45, 0xc5, 0x1d, 0x33, 0x34, 0x67, 0x67, 0xe9, 0x47, 0xfe, 0x3d, 0x4a, 0xe8, 0xca, 0xac, - 0x07, 0xeb, 0x99, 0x7f, 0xb2, 0xae, 0x58, 0xf9, 0xce, 0x79, 0x02, 0xf9, 0xa7, 0xb2, 0x59, 0xc1, - 0xec, 0x5f, 0x61, 0x3f, 0x03, 0xb8, 0x00, 0xed, 0x7f, 0x8f, 0xb2, 0xb9, 0x30, 0x3a, 0xfd, 0x1e, - 0xab, 0x93, 0xd1, 0x1c, 0x7a, 0xe4, 0x5f, 0xd5, 0x77, 0xf9, 0x7d, 0xaa, 0x6a, 0xbf, 0xe4, 0x9f, - 0xea, 0x36, 0x67, 0x25, 0x8d, 0xc0, 0x18, 0xf5, 0x8a, 0xca, 0x7e, 0xe4, 0xdf, 0x63, 0xc9, 0x7b, - 0xa2, 0x4f, 0x47, 0xb1, 0xeb, 0x90, 0x7f, 0x5b, 0x49, 0x6d, 0x7f, 0xd5, 0x7d, 0xbf, 0xf1, 0x3b, - 0x37, 0xff, 0x9e, 0xe4, 0xdf, 0x63, 0x89, 0x31, 0xb8, 0x23, 0x73, 0xb8, 0x33, 0x32, 0xc7, 0xbd, - 0xe2, 0x92, 0x1f, 0xf9, 0xf7, 0x68, 0xff, 0xbe, 0xc8, 0xda, 0x6b, 0x44, 0xbf, 0xfc, 0xbb, 0xd4, - 0x97, 0x27, 0xef, 0x4c, 0xc8, 0x3f, 0x3d, 0x2c, 0xed, 0xb2, 0x32, 0xdf, 0x49, 0xfe, 0x31, 0xff, - 0xed, 0x81, 0x64, 0xcd, 0x66, 0xd0, 0xad, 0xfd, 0x4f, 0xce, 0x7e, 0xbf, 0x42, 0xf9, 0xae, 0xf1, - 0x09, 0xf2, 0x4f, 0x0f, 0x8b, 0xc1, 0xe5, 0xf4, 0x9b, 0x5b, 0x2a, 0xaf, 0x7f, 0xf0, 0xdb, 0x1f, - 0xf7, 0xfe, 0xd9, 0x19, 0xf7, 0xaa, 0x5b, 0x74, 0xda, 0x44, 0x4e, 0x1b, 0xa0, 0x5e, 0xf9, 0x17, - 0xf9, 0x72, 0x56, 0xfc, 0x13, 0xde, 0x2e, 0x26, 0x11, 0xf9, 0xa7, 0x83, 0xc8, 0xaf, 0x93, 0x7e, - 0x73, 0x4b, 0xe5, 0xf5, 0xaf, 0xb6, 0xc7, 0x7d, 0x21, 0x82, 0xc2, 0x7d, 0xd0, 0xda, 0xe8, 0x4d, - 0xca, 0x7c, 0xae, 0x50, 0xab, 0xfc, 0x93, 0x35, 0xe7, 0x4d, 0xb8, 0xfc, 0x4d, 0x49, 0xfe, 0xe9, - 0x20, 0x74, 0x67, 0x56, 0xac, 0x3a, 0xff, 0x54, 0x5e, 0xff, 0x74, 0x9b, 0xd9, 0x17, 0x27, 0xb8, - 0x30, 0xaa, 0xa1, 0x2d, 0x66, 0x12, 0x66, 0x34, 0xe8, 0x35, 0xff, 0x63, 0x29, 0xad, 0x97, 0xa8, - 0x6a, 0xd5, 0xab, 0x14, 0xf9, 0xa7, 0x83, 0x8d, 0x93, 0xe4, 0x5f, 0x75, 0x0a, 0xaa, 0xbc, 0xfe, - 0xfd, 0x36, 0xb7, 0x2f, 0xd8, 0xa8, 0x57, 0xbc, 0xa3, 0x61, 0x9b, 0xc8, 0x78, 0xba, 0x75, 0x9a, - 0xff, 0xfb, 0x29, 0x75, 0xa4, 0x78, 0xf9, 0xaa, 0x2f, 0x29, 0xf2, 0x4f, 0x07, 0xcb, 0xc1, 0x69, - 0xfe, 0x95, 0xe5, 0xa0, 0xca, 0xfb, 0x1f, 0xe5, 0xf3, 0xef, 0xa7, 0xf1, 0x6a, 0xd6, 0xb9, 0xc3, - 0x9f, 0x49, 0x46, 0x0f, 0x88, 0x3e, 0xeb, 0xbf, 0x84, 0x9e, 0xcc, 0x51, 0xe2, 0xa3, 0xca, 0x79, - 0x1f, 0x09, 0xf2, 0x4f, 0x07, 0xc5, 0xe9, 0x77, 0x9e, 0x82, 0x2a, 0xef, 0xff, 0x7b, 0x9e, 0x7f, - 0xc2, 0xc4, 0x6a, 0xf3, 0x9e, 0xee, 0x2b, 0x09, 0xf9, 0xa7, 0xcb, 0xfa, 0x7f, 0x72, 0xd3, 0xaf, - 0x68, 0xa7, 0xd0, 0x22, 0xe4, 0x9f, 0xfa, 0xb6, 0x5e, 0x75, 0xfe, 0xa5, 0x39, 0xd8, 0xe6, 0xac, - 0xb8, 0x7c, 0x96, 0xc5, 0x75, 0xa5, 0x91, 0xd9, 0xde, 0xfe, 0x60, 0x19, 0x63, 0xa0, 0xf3, 0x7d, - 0x9a, 0x6a, 0xe6, 0xdf, 0x56, 0x72, 0xfa, 0x5d, 0x1a, 0xf7, 0x7c, 0x3c, 0x0e, 0xf2, 0x4f, 0x79, - 0xf9, 0xd6, 0xbf, 0x72, 0xcf, 0x3e, 0xd2, 0x7b, 0x94, 0xe5, 0x9f, 0xf0, 0xd1, 0xd2, 0x64, 0x9f, - 0x4a, 0xe8, 0xff, 0xc8, 0x67, 0x93, 0x8a, 0xf9, 0x77, 0x3e, 0x6b, 0xa9, 0x59, 0x41, 0xad, 0xb6, - 0x3f, 0x81, 0xfc, 0x53, 0x5f, 0x59, 0xeb, 0xdf, 0x59, 0xf9, 0x4f, 0xe9, 0xd9, 0x1f, 0x55, 0xf9, - 0x27, 0xbe, 0xef, 0xdb, 0xd8, 0x16, 0x28, 0x63, 0x55, 0x68, 0xf5, 0xf7, 0x7f, 0x93, 0xbd, 0x3e, - 0x8e, 0x58, 0xfb, 0xa8, 0xee, 0xb1, 0x90, 0x7f, 0xaa, 0x13, 0x63, 0xff, 0xea, 0xe5, 0x9f, 0xca, - 0xa3, 0x9f, 0x2f, 0xe5, 0x5f, 0x7c, 0xdf, 0x7d, 0xb7, 0xaa, 0x7d, 0x53, 0xce, 0x7a, 0xc6, 0xf9, - 0x36, 0x5c, 0xd5, 0xf2, 0x6f, 0x2a, 0x7d, 0x7d, 0xc4, 0xc0, 0xa8, 0xdf, 0xcf, 0x47, 0xfe, 0xa9, - 0x2e, 0x1d, 0xfb, 0x77, 0x89, 0xca, 0xa3, 0x5f, 0xea, 0xe4, 0x5f, 0xbc, 0xef, 0x7b, 0x7b, 0x6a, - 0xc2, 0x32, 0x46, 0xbf, 0xbc, 0x1a, 0xf9, 0x77, 0x51, 0x29, 0xff, 0xb6, 0xde, 0x23, 0xf6, 0x49, - 0x99, 0x5c, 0x91, 0x3f, 0xe4, 0x9f, 0xea, 0xd6, 0x76, 0xdd, 0xfc, 0x53, 0x79, 0xf4, 0x4b, 0xbd, - 0xfc, 0x13, 0x5e, 0x8d, 0xb9, 0xdd, 0x86, 0x0c, 0x94, 0x33, 0xaf, 0x6b, 0x72, 0xd6, 0x86, 0xab, - 0x4a, 0xfe, 0xfd, 0xfb, 0xb2, 0xb0, 0x1f, 0xb1, 0x3f, 0xca, 0xd0, 0x2c, 0xdf, 0xed, 0xe8, 0x1c, - 0xf9, 0xa7, 0xba, 0xba, 0xb5, 0xdf, 0x59, 0x8b, 0x4a, 0x46, 0xb7, 0xa8, 0x9b, 0x7f, 0xf1, 0x33, - 0xf0, 0xfc, 0x95, 0x1e, 0xe4, 0xec, 0x66, 0x71, 0x7e, 0x5e, 0x6a, 0xe4, 0xdf, 0xc6, 0x95, 0xb5, - 0x1a, 0x4e, 0xde, 0x75, 0x73, 0x23, 0xc9, 0x3f, 0xb5, 0xd5, 0x1d, 0xfb, 0xa2, 0x7a, 0xef, 0xc7, - 0x75, 0xf9, 0x27, 0x0c, 0xcd, 0xc5, 0x13, 0xcb, 0x81, 0x72, 0xd6, 0x3f, 0xcd, 0xcf, 0xfd, 0x10, - 0xda, 0x9f, 0x7f, 0xe1, 0x83, 0x76, 0xc6, 0x13, 0xea, 0xcc, 0x79, 0x3b, 0xb9, 0xab, 0xc8, 0x3f, - 0xa5, 0xd5, 0xaf, 0xfd, 0x3e, 0xbf, 0x44, 0x74, 0x9f, 0x6b, 0xf3, 0x4f, 0x18, 0x9a, 0xb3, 0xc1, - 0x35, 0xb5, 0xa1, 0xa6, 0x7c, 0x49, 0x1a, 0xdf, 0x51, 0xd4, 0xaf, 0xd9, 0xee, 0xfc, 0x7b, 0xd4, - 0xae, 0xa0, 0xb1, 0x57, 0xe3, 0xda, 0x39, 0x91, 0xe4, 0x9f, 0xda, 0xe6, 0x83, 0x69, 0x27, 0x7a, - 0x3f, 0x6e, 0xcb, 0x3f, 0x21, 0x30, 0x26, 0xfd, 0xc7, 0x8e, 0x90, 0x96, 0x37, 0xab, 0xb5, 0xe8, - 0x3b, 0xac, 0xad, 0xf9, 0x17, 0x7a, 0xf3, 0x81, 0xfc, 0xdd, 0x40, 0x4f, 0x5d, 0xbf, 0x2e, 0x10, - 0xf9, 0xa7, 0xb2, 0x6f, 0x6f, 0x6a, 0xa5, 0xaa, 0xf3, 0x4f, 0xe5, 0xb9, 0x6f, 0xc2, 0xad, 0xf9, - 0x27, 0x88, 0x3d, 0x01, 0xe6, 0x0f, 0x2a, 0x09, 0x96, 0xed, 0xc9, 0x72, 0xbf, 0xc0, 0x28, 0xaa, - 0xcf, 0xb7, 0x2d, 0xff, 0x22, 0x7f, 0xe3, 0x4e, 0xad, 0x51, 0xef, 0x71, 0xa5, 0xbe, 0xc4, 0xb5, - 0x75, 0xdf, 0xfd, 0x5d, 0x45, 0xfe, 0x29, 0x6c, 0x65, 0x67, 0xf3, 0xaf, 0x3a, 0x05, 0x9f, 0x7d, - 0xac, 0xf7, 0xba, 0x27, 0xff, 0x62, 0xc1, 0xae, 0xfe, 0xb8, 0xb4, 0x65, 0xa6, 0xe0, 0x97, 0xd4, - 0x56, 0xfe, 0xf7, 0xc2, 0xcf, 0x50, 0x56, 0xfe, 0x45, 0xc5, 0xfc, 0xd8, 0xd6, 0xdf, 0x7a, 0xc2, - 0xb7, 0x17, 0x7a, 0x9f, 0xee, 0xda, 0x59, 0xda, 0xf3, 0xc1, 0x6c, 0x30, 0xee, 0x3f, 0xba, 0xc4, - 0x97, 0x1a, 0x9a, 0xb7, 0x7c, 0xc3, 0x93, 0x7f, 0x2a, 0x3b, 0x4f, 0xbf, 0xb2, 0x1c, 0x54, 0x7f, - 0xe7, 0x8f, 0xfb, 0xf3, 0x2f, 0x76, 0x48, 0xc1, 0xc6, 0x4b, 0xc3, 0xa1, 0xf7, 0x2e, 0x75, 0x64, - 0x6f, 0x60, 0x7c, 0x15, 0xd6, 0xe2, 0x65, 0xe4, 0xdf, 0xd0, 0x1c, 0xf5, 0xfe, 0x32, 0x8b, 0x0c, - 0x0f, 0x02, 0x23, 0x26, 0xef, 0x7c, 0xaf, 0x75, 0xdb, 0xfc, 0x1f, 0x19, 0xf9, 0xf7, 0x6a, 0xfc, - 0xd3, 0x6b, 0x87, 0x6b, 0x46, 0x42, 0xaa, 0x27, 0x74, 0xab, 0xf2, 0xef, 0x34, 0x05, 0x55, 0x6f, - 0xfd, 0x6b, 0x2e, 0xff, 0x12, 0x43, 0xf3, 0xc3, 0x5a, 0x3b, 0x4d, 0x94, 0x06, 0x23, 0x7f, 0xed, - 0x8c, 0x25, 0xae, 0x62, 0x1c, 0x2b, 0x2b, 0x55, 0xc8, 0xc8, 0x3f, 0xf5, 0x4c, 0x6f, 0xac, 0xdf, - 0xc8, 0xc8, 0xbf, 0xf6, 0xf8, 0xab, 0xd6, 0x1a, 0x60, 0xaa, 0x5a, 0x0c, 0x2e, 0xe7, 0x5f, 0x92, - 0x82, 0xaa, 0xb7, 0xfe, 0x35, 0x9f, 0x7f, 0x31, 0xd1, 0x32, 0xf8, 0x6e, 0xad, 0xec, 0x5b, 0xc6, - 0x86, 0x47, 0x2f, 0x1b, 0x77, 0x61, 0x3f, 0xaa, 0xce, 0x57, 0xd6, 0x87, 0x43, 0xfe, 0x89, 0x7e, - 0xf1, 0x5b, 0x9f, 0x73, 0xf2, 0x4f, 0x55, 0x5b, 0xaf, 0x6e, 0xfa, 0x89, 0x1d, 0x31, 0x9f, 0x7d, - 0xb4, 0x4d, 0x9c, 0xaf, 0xdc, 0xda, 0x56, 0xb0, 0x2b, 0x11, 0x4e, 0xfa, 0xb3, 0xc1, 0xc2, 0x5e, - 0x3b, 0xdf, 0xa2, 0x6d, 0x4b, 0xb4, 0x73, 0x9d, 0xb4, 0x7c, 0x89, 0x36, 0xaf, 0xd0, 0x5b, 0x3b, - 0x0b, 0x7b, 0x6a, 0x89, 0xd4, 0x7b, 0x64, 0xed, 0xaf, 0x7c, 0x46, 0x3f, 0xf9, 0x97, 0x5f, 0x11, - 0xf6, 0xaa, 0xbb, 0x8a, 0xfc, 0x53, 0x54, 0x51, 0xdf, 0x47, 0x19, 0x95, 0xf7, 0x3d, 0x4a, 0xc8, - 0xce, 0xbf, 0x53, 0x81, 0xf1, 0x6a, 0x0e, 0x73, 0x2d, 0x5f, 0xaf, 0x4f, 0x6b, 0xef, 0x2a, 0x6b, - 0xfb, 0x13, 0xba, 0x9e, 0x7f, 0xaf, 0xe6, 0x3d, 0xf3, 0x3a, 0xc9, 0x3f, 0x35, 0x45, 0x7e, 0xfd, - 0xf4, 0x9b, 0x2a, 0x3e, 0xf3, 0x37, 0xf6, 0xd8, 0xfc, 0x6b, 0x97, 0xaa, 0xdd, 0x9e, 0xba, 0x9d, - 0x7f, 0x41, 0x8d, 0x3d, 0xde, 0x2a, 0xef, 0x2a, 0xf2, 0x4f, 0x49, 0x9f, 0x4e, 0xfd, 0xf4, 0x53, - 0x7f, 0xec, 0x8b, 0xd0, 0xdd, 0xfc, 0x7b, 0x2d, 0x1c, 0xf7, 0x77, 0xbc, 0x13, 0x3a, 0x9c, 0x7f, - 0x41, 0xcd, 0x55, 0xee, 0x2b, 0xee, 0x2a, 0xf2, 0x4f, 0x41, 0xd1, 0xcb, 0xfc, 0x8a, 0xd2, 0x9f, - 0xda, 0xeb, 0xfe, 0x25, 0xba, 0x9a, 0x7f, 0x97, 0xd6, 0x32, 0xee, 0x6e, 0xfe, 0xdd, 0x9f, 0x7e, - 0xe4, 0x9f, 0x0a, 0xb6, 0xfe, 0xdc, 0x1e, 0xf7, 0x5f, 0x0f, 0x9f, 0xf9, 0xa8, 0xf7, 0x61, 0x2d, - 0x06, 0x1f, 0xfd, 0x69, 0xac, 0x23, 0xb5, 0xdf, 0xee, 0xe6, 0xdf, 0xf9, 0x8a, 0x57, 0xa7, 0xba, - 0x9a, 0x7f, 0x81, 0xd1, 0xc4, 0x8a, 0x1e, 0xe4, 0x5f, 0xbb, 0x45, 0xfe, 0x87, 0xf5, 0x5a, 0xf0, - 0xd9, 0x0f, 0xcd, 0x49, 0x6f, 0xda, 0xcf, 0xa8, 0xe8, 0xfb, 0xfd, 0xf7, 0xe9, 0x67, 0xd1, 0x84, - 0x6e, 0xe6, 0xdf, 0xe5, 0xbe, 0xcd, 0x6e, 0xe6, 0x5f, 0x13, 0x65, 0xbf, 0xfd, 0x5d, 0x45, 0xfe, - 0xb5, 0xd8, 0xa7, 0x53, 0x3e, 0xb6, 0x6c, 0x57, 0x12, 0x34, 0x3f, 0xfa, 0xd3, 0x3c, 0x2d, 0xfb, - 0x7e, 0x85, 0x2e, 0xe6, 0xdf, 0x6b, 0x45, 0xbf, 0xef, 0xf1, 0x1e, 0xe9, 0x60, 0xfe, 0xed, 0xca, - 0x7e, 0x0d, 0xdd, 0xd5, 0xe4, 0x5f, 0x7b, 0x5d, 0xde, 0x27, 0x66, 0x58, 0x94, 0x80, 0xb9, 0x14, - 0x54, 0x7f, 0xe4, 0x73, 0xac, 0x7b, 0xf9, 0x57, 0x6f, 0x17, 0xb3, 0xee, 0xe5, 0x5f, 0xfd, 0xdd, - 0xdd, 0x6a, 0xdc, 0x55, 0xe4, 0x5f, 0x4b, 0xd5, 0x5b, 0x41, 0x73, 0x64, 0x16, 0xe6, 0xdf, 0x91, - 0x0e, 0x23, 0x9f, 0x63, 0xdd, 0xcb, 0xbf, 0x7a, 0xab, 0xb0, 0x74, 0x2d, 0xff, 0x86, 0x8d, 0xee, - 0xf7, 0x4c, 0xfe, 0xb5, 0x55, 0xdd, 0x95, 0x44, 0x72, 0xed, 0x80, 0x39, 0xed, 0xdd, 0x1b, 0xfc, - 0x5a, 0x5d, 0xcb, 0xbf, 0xba, 0x6b, 0x50, 0x75, 0x2b, 0xff, 0x46, 0xbd, 0x66, 0xd7, 0xef, 0x21, - 0xff, 0xda, 0x69, 0xe5, 0xd4, 0x3d, 0xc7, 0xd2, 0x3a, 0xf0, 0x8e, 0xea, 0x7b, 0x7e, 0x64, 0x75, - 0x2b, 0xff, 0x2e, 0xf5, 0xfa, 0xa6, 0xba, 0x94, 0x7f, 0x93, 0x7e, 0xd3, 0xf7, 0x33, 0xf9, 0xd7, - 0x4e, 0xf5, 0xd7, 0x13, 0x11, 0xeb, 0x1b, 0x97, 0xe5, 0x9f, 0x2e, 0x7d, 0x1f, 0x42, 0x97, 0xf2, - 0xaf, 0x6a, 0xbe, 0x47, 0x5e, 0x57, 0xf2, 0xef, 0xf5, 0x86, 0xd5, 0x9d, 0x6b, 0xdc, 0x55, 0xe4, - 0x5f, 0x0b, 0x45, 0xfe, 0x35, 0x6b, 0x8a, 0x8c, 0x4b, 0x6b, 0xc0, 0xfa, 0x94, 0xfe, 0xba, 0x93, - 0x7f, 0x81, 0x31, 0xbd, 0x6a, 0x5c, 0x5b, 0x37, 0xf2, 0x6f, 0x64, 0x5e, 0xbb, 0xb3, 0x47, 0xcd, - 0xbb, 0x8a, 0xfc, 0x6b, 0xa1, 0xeb, 0x9e, 0x75, 0x31, 0x0e, 0xa6, 0xa8, 0x0e, 0xac, 0xfe, 0x9a, - 0xa7, 0xb7, 0x5f, 0x13, 0x55, 0x5d, 0x3f, 0xae, 0x4d, 0xff, 0xfc, 0x0b, 0xa4, 0xed, 0xc7, 0x4e, - 0xfe, 0xb5, 0xd3, 0x2d, 0xf9, 0x97, 0x48, 0xf3, 0x4f, 0x97, 0x91, 0x2f, 0xb7, 0x5c, 0x13, 0x35, - 0xbd, 0xde, 0x30, 0xb2, 0x43, 0xf7, 0xfc, 0x1b, 0xf5, 0x2e, 0x8f, 0x81, 0xbc, 0xe3, 0xae, 0x22, - 0xff, 0x5a, 0xe8, 0x9e, 0xfc, 0x4b, 0x52, 0x70, 0xa1, 0x55, 0xe9, 0xaf, 0x0b, 0xf9, 0x37, 0xea, - 0xdd, 0xf2, 0x8d, 0xa5, 0x73, 0xfe, 0x89, 0x3d, 0x9c, 0x25, 0xdf, 0x55, 0xe4, 0x5f, 0x0b, 0x5d, - 0xdb, 0xfe, 0x77, 0x9e, 0x7f, 0x1f, 0x7d, 0x39, 0xed, 0x25, 0xcf, 0xa3, 0x7b, 0xfe, 0x7d, 0xdc, - 0xd8, 0x57, 0xaf, 0x6b, 0xfe, 0x05, 0xc6, 0xbb, 0x25, 0x7f, 0xc7, 0x3e, 0xf2, 0xaf, 0x9d, 0x26, - 0xd6, 0x15, 0xf7, 0x49, 0x41, 0xfa, 0x35, 0x31, 0x37, 0xbc, 0x5d, 0xb6, 0x57, 0x7d, 0x27, 0xa8, - 0x65, 0x68, 0xde, 0x3e, 0xa3, 0x41, 0xc7, 0xfc, 0x0b, 0x8c, 0xb7, 0xfe, 0xf7, 0x43, 0xbe, 0xbf, - 0xc9, 0xbf, 0x76, 0x0a, 0x6b, 0xcd, 0xfe, 0x10, 0x8a, 0x6b, 0xbf, 0xba, 0x95, 0xfe, 0x84, 0xad, - 0xff, 0xf8, 0x1d, 0xb5, 0x1f, 0x61, 0xd2, 0xbf, 0xa7, 0x9c, 0xa3, 0x5b, 0xfe, 0x05, 0xc6, 0xb8, - 0xff, 0xb8, 0x15, 0x8b, 0xc8, 0xbf, 0xb6, 0x9a, 0xd4, 0x1a, 0x01, 0x58, 0x5c, 0xfa, 0xd3, 0xad, - 0xed, 0x2f, 0x4b, 0xec, 0xb5, 0xa6, 0x4f, 0x4d, 0x78, 0x74, 0xf7, 0x6c, 0x2e, 0x9d, 0xf2, 0xef, - 0xd5, 0x98, 0x58, 0x8f, 0xfd, 0xe6, 0x26, 0xff, 0xda, 0x2a, 0xf2, 0x47, 0x17, 0xcb, 0x3a, 0x41, - 0x49, 0xdb, 0x9f, 0x5e, 0x3d, 0xbf, 0xe7, 0x42, 0x6f, 0xa6, 0x41, 0x49, 0x50, 0xac, 0x62, 0x72, - 0xff, 0x08, 0x4d, 0x5d, 0xf2, 0x6f, 0x68, 0xce, 0x06, 0xf2, 0xdb, 0xfb, 0xf2, 0xc8, 0xbf, 0xf6, - 0xda, 0x7a, 0x97, 0x9e, 0xf1, 0xbf, 0x0b, 0xd3, 0x4f, 0xaf, 0x71, 0x7f, 0xe5, 0x36, 0xee, 0xe4, - 0x41, 0x7b, 0x4f, 0x36, 0xef, 0x75, 0xf7, 0xb4, 0x37, 0x33, 0x3a, 0x5d, 0xfd, 0xfc, 0x1b, 0x9a, - 0x13, 0xeb, 0x59, 0xf3, 0xd4, 0xc9, 0xbf, 0x36, 0x8b, 0xfc, 0xf2, 0x5a, 0x70, 0x60, 0xbc, 0x15, - 0xa6, 0xdf, 0xf4, 0xae, 0xd6, 0x24, 0xd5, 0x44, 0xfe, 0xd2, 0x56, 0xad, 0x3e, 0x2c, 0xc6, 0xf3, - 0x36, 0x57, 0x42, 0x57, 0x39, 0xff, 0xc4, 0xdc, 0xcd, 0xb5, 0xf3, 0xfb, 0x89, 0xf7, 0x2b, 0xf9, - 0xd7, 0x6e, 0x6b, 0x7b, 0xdc, 0x1b, 0x16, 0xdc, 0x37, 0x23, 0xb3, 0xa8, 0xdd, 0x4f, 0xd0, 0x69, - 0xce, 0x6f, 0x5d, 0x71, 0x0a, 0xbe, 0x2a, 0x50, 0x16, 0xfc, 0xcb, 0x6c, 0xa2, 0xce, 0x9b, 0xa5, - 0x62, 0xfe, 0x0d, 0xcd, 0x71, 0x6f, 0x36, 0x68, 0xc3, 0xda, 0x44, 0xe4, 0x5f, 0x9b, 0x85, 0x6e, - 0x9c, 0x69, 0x93, 0xfe, 0xb8, 0x37, 0x32, 0x87, 0x7b, 0x23, 0xb3, 0xb8, 0xdc, 0x77, 0x28, 0xfd, - 0x59, 0x6a, 0x9f, 0xf1, 0x3d, 0xb6, 0xfe, 0xca, 0x99, 0xb4, 0xb6, 0x2c, 0x28, 0xfa, 0x35, 0xd7, - 0x4e, 0xf3, 0x9f, 0x8e, 0x3a, 0xf9, 0xb7, 0xdf, 0xb5, 0xc1, 0x5a, 0xd8, 0x5f, 0x6e, 0x7b, 0xe6, - 0xa5, 0x93, 0x7f, 0xed, 0x25, 0xf6, 0xf8, 0x2d, 0x4f, 0xba, 0x62, 0x9b, 0xc6, 0x56, 0xc6, 0x55, - 0xd7, 0xc6, 0x9d, 0x5a, 0xa3, 0x5e, 0x7b, 0x72, 0x50, 0xf4, 0x52, 0x2d, 0x1a, 0x2e, 0xf5, 0xa5, - 0xda, 0x9b, 0x7f, 0x22, 0xef, 0x46, 0xbd, 0x71, 0xff, 0x63, 0x97, 0x79, 0x9f, 0x4e, 0x3b, 0x47, - 0x64, 0x91, 0x7f, 0xed, 0x25, 0x76, 0x79, 0xbb, 0x8e, 0x7e, 0xa3, 0x9e, 0x6f, 0xb7, 0xf5, 0x76, - 0xa5, 0x41, 0xeb, 0xb9, 0xfd, 0x23, 0x71, 0xf2, 0xc9, 0xed, 0x8d, 0x6f, 0x4b, 0xfe, 0xbd, 0x1e, - 0xd3, 0x6e, 0x36, 0x58, 0xda, 0x6b, 0xe7, 0xdb, 0xdb, 0x7a, 0xed, 0x29, 0xe7, 0x95, 0xde, 0x25, - 0xe4, 0x5f, 0x4b, 0xad, 0x9d, 0x6b, 0xd3, 0x4f, 0xff, 0x71, 0x2f, 0xb7, 0x10, 0x39, 0xf8, 0xfe, - 0xe0, 0xf2, 0xe0, 0xeb, 0x2e, 0x09, 0xa6, 0x83, 0x4f, 0x09, 0xb5, 0xdd, 0x73, 0xbf, 0x77, 0xb5, - 0xfe, 0xc7, 0x5b, 0x3b, 0x1b, 0xc1, 0x0d, 0xbd, 0xd0, 0xdb, 0xfa, 0xea, 0x3e, 0x65, 0x62, 0xa5, - 0x61, 0x7d, 0x7d, 0x2a, 0x5b, 0x1b, 0x4c, 0x5a, 0xfe, 0xae, 0xd1, 0xc5, 0x9e, 0x8f, 0xfa, 0xb6, - 0xfe, 0x97, 0x3b, 0xb7, 0x3f, 0xa4, 0x26, 0xe1, 0xd0, 0x9c, 0xf4, 0xe7, 0xf6, 0xc6, 0xed, 0x52, - 0x0f, 0x3c, 0xd0, 0xb4, 0x5b, 0x5a, 0xfe, 0x66, 0x1d, 0xee, 0xf9, 0xb8, 0xd6, 0xd6, 0xdf, 0xb8, - 0x2b, 0x67, 0x36, 0xd8, 0xf7, 0x2b, 0xf5, 0x86, 0xe6, 0xab, 0x71, 0x4b, 0x26, 0xee, 0xdb, 0xb7, - 0xcc, 0x71, 0x6f, 0xd2, 0x9f, 0x0d, 0xd6, 0x2d, 0x6d, 0xdf, 0x02, 0xd4, 0x33, 0xbf, 0x3a, 0xfd, - 0xa8, 0xfb, 0xde, 0x2e, 0xf2, 0xb7, 0xfe, 0xd6, 0xfb, 0xf6, 0x36, 0xee, 0xda, 0x59, 0xda, 0x0b, - 0x7b, 0x3e, 0x98, 0x0f, 0x76, 0xdf, 0x3f, 0x05, 0x66, 0x03, 0xf1, 0x7f, 0xa2, 0x75, 0x6b, 0xe3, - 0xaa, 0xd1, 0xbe, 0x05, 0xa8, 0x66, 0x69, 0x5f, 0x9f, 0x7e, 0x2b, 0xea, 0xbe, 0x00, 0x94, 0x77, - 0x4b, 0xbf, 0x87, 0x3e, 0xbb, 0xfc, 0x02, 0xe8, 0xae, 0x5b, 0xfa, 0x3d, 0xa8, 0xfb, 0x02, 0x50, - 0xdf, 0xd6, 0xbb, 0x25, 0xfd, 0x6e, 0x5f, 0x3b, 0x13, 0x00, 0xda, 0xe1, 0x96, 0x5e, 0x5f, 0xc6, - 0x3c, 0x03, 0x50, 0x5f, 0xe4, 0xcf, 0x6e, 0x48, 0x3f, 0xbd, 0xf6, 0xf8, 0x05, 0xd0, 0x4d, 0xd7, - 0xcf, 0x76, 0x13, 0x1e, 0xb7, 0x52, 0x38, 0x00, 0xc8, 0xb1, 0xbc, 0x29, 0xfd, 0x68, 0xf9, 0x43, - 0x2a, 0xf2, 0x37, 0xce, 0xca, 0x5e, 0xd9, 0x6b, 0x27, 0xf9, 0x56, 0x8c, 0x7c, 0xb1, 0x6e, 0x90, - 0xd0, 0xd4, 0x5a, 0x53, 0x6b, 0x27, 0x7e, 0xbd, 0x6b, 0x77, 0x69, 0x2f, 0xb3, 0xf5, 0xe2, 0xd7, - 0x1b, 0x99, 0x6a, 0xd4, 0x63, 0x36, 0x6e, 0x7c, 0xb4, 0x1f, 0xd6, 0x9f, 0x97, 0xf9, 0x20, 0xfd, - 0x33, 0xee, 0xb1, 0xba, 0x61, 0xc4, 0x1f, 0x2d, 0x7f, 0x48, 0x6d, 0xdc, 0xbf, 0x7b, 0xff, 0xf9, - 0x91, 0x35, 0xee, 0xad, 0x9d, 0xc8, 0x0f, 0x8c, 0xf8, 0x6f, 0x4d, 0x7d, 0x53, 0x2e, 0x06, 0xf1, - 0xeb, 0x4d, 0x6b, 0x3e, 0xf3, 0x6f, 0xfd, 0xec, 0x31, 0xfd, 0xfc, 0x21, 0x56, 0xfe, 0x5b, 0x66, - 0xd6, 0xc2, 0x09, 0xdd, 0xe4, 0xff, 0x9a, 0x98, 0x33, 0x28, 0x46, 0xb1, 0x0b, 0x32, 0xae, 0x70, - 0x6c, 0xed, 0x24, 0x57, 0xf7, 0xcf, 0xcb, 0x7b, 0x3f, 0xfd, 0x73, 0x1d, 0x9b, 0x46, 0xcf, 0x55, - 0x1f, 0xeb, 0x9b, 0xd2, 0x6f, 0x76, 0xe3, 0x7e, 0xb1, 0xd0, 0xcf, 0x6c, 0x10, 0xfc, 0xf8, 0xcf, - 0x99, 0xa1, 0xd1, 0xb6, 0xfc, 0x4b, 0x8f, 0x2c, 0x39, 0x9e, 0x66, 0xf3, 0xef, 0x97, 0x19, 0xbf, - 0x96, 0xbc, 0x56, 0x21, 0xf2, 0xaf, 0x69, 0xb7, 0x8c, 0x77, 0x16, 0x18, 0xf3, 0x87, 0x58, 0xf2, - 0x4c, 0xfe, 0xe7, 0x47, 0xf0, 0x43, 0xd4, 0xc7, 0x86, 0x46, 0x70, 0x48, 0x19, 0xf1, 0x7f, 0xa2, - 0x46, 0xbc, 0xb2, 0x9b, 0x7a, 0xe2, 0x9a, 0xc9, 0x3f, 0x21, 0xae, 0xbd, 0x44, 0x7e, 0x7c, 0x7c, - 0x2b, 0xfb, 0x7f, 0x0d, 0x1c, 0xdd, 0x63, 0xf3, 0x2f, 0x74, 0xe3, 0x23, 0xaf, 0xdb, 0xb6, 0x40, - 0xfe, 0x9d, 0xfb, 0xbc, 0x31, 0xfd, 0xe8, 0xf7, 0x40, 0x62, 0x74, 0x78, 0xea, 0x7f, 0x99, 0xf1, - 0x1a, 0x0c, 0xd1, 0x4b, 0xe8, 0x4d, 0xad, 0x60, 0x9f, 0x7f, 0x4d, 0xbb, 0x35, 0xff, 0x46, 0xa6, - 0xa8, 0x97, 0x6e, 0x9c, 0xf7, 0x7e, 0x9a, 0xd5, 0xcd, 0xaf, 0x7f, 0xff, 0xd8, 0xfc, 0xbb, 0x16, - 0xf9, 0x97, 0xb7, 0xb9, 0x31, 0xfd, 0xd4, 0x5d, 0xd7, 0x0b, 0x4d, 0xdb, 0xfa, 0x49, 0xdd, 0xf7, - 0x74, 0xd7, 0xe7, 0xad, 0xf7, 0xde, 0x17, 0x6d, 0xf4, 0xf1, 0xca, 0x0d, 0xa2, 0xad, 0x24, 0xfd, - 0xf3, 0xc6, 0x1d, 0xf7, 0xe2, 0xa7, 0x38, 0x4e, 0x0a, 0xd1, 0xab, 0x21, 0x12, 0x29, 0xd9, 0x89, - 0x3d, 0x59, 0xef, 0x41, 0xb4, 0x4c, 0xff, 0xda, 0xff, 0x4f, 0xf2, 0x93, 0xf9, 0xfc, 0xdb, 0xb8, - 0xef, 0xfd, 0xe1, 0xbe, 0x8e, 0x2d, 0xf6, 0xe3, 0x3a, 0x4f, 0xb4, 0xb7, 0xb3, 0x3a, 0xe2, 0x97, - 0x9b, 0xd4, 0xc9, 0xe3, 0x7c, 0x8e, 0xdf, 0x49, 0xbc, 0xde, 0xc6, 0x8d, 0xff, 0x2c, 0xee, 0xee, - 0xad, 0x27, 0x8e, 0x56, 0xd4, 0x71, 0x44, 0x96, 0x1f, 0xde, 0x61, 0xdf, 0xa6, 0x99, 0xbe, 0xf6, - 0xda, 0x79, 0xeb, 0xfd, 0xd7, 0x88, 0x5f, 0x69, 0xd2, 0x5f, 0xec, 0x7e, 0x3e, 0xb9, 0x12, 0x93, - 0x7e, 0xfc, 0x4a, 0xc9, 0x19, 0x87, 0xde, 0xd6, 0x9b, 0xf4, 0x83, 0x7d, 0x0e, 0xc7, 0xcf, 0x4e, - 0xb8, 0xbb, 0x02, 0x3f, 0x7f, 0xfc, 0x14, 0xe7, 0x75, 0xac, 0x47, 0x45, 0xbe, 0xe8, 0xd1, 0x48, - 0xca, 0xd1, 0xe9, 0x8a, 0xdd, 0x91, 0xbf, 0x7b, 0x65, 0x23, 0xbe, 0x3e, 0x53, 0x2b, 0x3d, 0x9f, - 0xec, 0xf1, 0xae, 0x77, 0xc9, 0x9e, 0xa4, 0xaf, 0xf8, 0xed, 0x99, 0x75, 0x5e, 0x3f, 0x2b, 0xcb, - 0xbf, 0xed, 0xee, 0x0c, 0x47, 0x66, 0x7a, 0x55, 0x26, 0xfb, 0x55, 0xdc, 0xf7, 0xa3, 0x81, 0xf7, - 0x57, 0x26, 0x6d, 0xe7, 0x9a, 0x1d, 0xce, 0xe7, 0xbb, 0xf4, 0xba, 0x64, 0x3f, 0x6f, 0xb1, 0x0e, - 0xfa, 0xac, 0xc5, 0x7d, 0x04, 0xb7, 0x96, 0xfd, 0x9a, 0xea, 0x7b, 0x83, 0x0e, 0xd2, 0xfc, 0x2b, - 0xea, 0x43, 0x8d, 0x9f, 0xe7, 0xff, 0xfb, 0x21, 0x9e, 0xc6, 0xa4, 0x9c, 0x18, 0x27, 0xc1, 0xe1, - 0x59, 0x35, 0x44, 0x32, 0xa4, 0xb5, 0xd2, 0x91, 0x29, 0x9e, 0xbc, 0xe4, 0x6f, 0x6f, 0x99, 0x3e, - 0x95, 0xc0, 0x10, 0x09, 0x78, 0x9a, 0x7f, 0x53, 0xeb, 0xb4, 0xdd, 0x31, 0xf8, 0x91, 0x7f, 0xde, - 0xce, 0xf3, 0x6f, 0xf7, 0x1a, 0x76, 0xf2, 0xf3, 0xa1, 0x9b, 0xbc, 0x57, 0xf0, 0x23, 0xfb, 0xda, - 0x49, 0x7b, 0xe6, 0x66, 0x57, 0xc3, 0xcc, 0xb7, 0x6c, 0x4e, 0xfa, 0xf1, 0x59, 0x27, 0x67, 0x53, - 0x25, 0xf9, 0x99, 0xb7, 0x5e, 0x92, 0x2e, 0x71, 0xb9, 0x73, 0x96, 0x39, 0xee, 0xa1, 0x11, 0x27, - 0xd5, 0x97, 0x3b, 0x34, 0xf2, 0xbf, 0x2d, 0xae, 0xe7, 0xb7, 0x97, 0xff, 0xf7, 0xe4, 0x7c, 0xb2, - 0xd7, 0x62, 0xdc, 0xcb, 0xff, 0x44, 0x60, 0xe4, 0xf7, 0xa2, 0x28, 0xcb, 0xbf, 0xb4, 0xfd, 0x22, - 0xf1, 0xf3, 0x87, 0xf8, 0xee, 0x4a, 0x8e, 0x3e, 0x79, 0xde, 0xb7, 0xc7, 0x6b, 0x25, 0x5a, 0x0d, - 0x8a, 0xaf, 0x4b, 0xf2, 0x79, 0x6f, 0x9c, 0xb8, 0x3f, 0x4c, 0x46, 0x1d, 0xe0, 0x5a, 0x91, 0xbf, - 0x76, 0xc4, 0x8a, 0x4a, 0x62, 0x65, 0xcc, 0x74, 0x8d, 0xbe, 0x5b, 0xd3, 0x8f, 0x5e, 0x5f, 0x64, - 0x45, 0x2f, 0xc3, 0xcc, 0xb3, 0xfd, 0x77, 0x6f, 0x3e, 0xd8, 0x38, 0x69, 0x0e, 0x16, 0xe5, 0x5f, - 0xee, 0x39, 0xcd, 0xfd, 0x5d, 0xf4, 0x1a, 0x97, 0xa5, 0xc9, 0xe9, 0x33, 0x3f, 0x3b, 0x96, 0x85, - 0x56, 0xf6, 0x7c, 0x90, 0x24, 0xcc, 0x69, 0x19, 0xb0, 0x28, 0xff, 0xfe, 0xf7, 0x92, 0xbc, 0xa7, - 0xd8, 0x03, 0xf9, 0x3c, 0xff, 0xd2, 0x23, 0x7a, 0xef, 0xff, 0x3c, 0xbc, 0xf3, 0xd2, 0x5e, 0x0c, - 0x92, 0xf2, 0xd5, 0x7c, 0xf7, 0x5b, 0x43, 0x33, 0x49, 0x0a, 0xd1, 0xe2, 0x19, 0x14, 0x24, 0x54, - 0x36, 0xff, 0xaa, 0xcf, 0x58, 0x9c, 0xcb, 0xd6, 0x4b, 0xda, 0x4c, 0xe7, 0x83, 0x95, 0xfd, 0xf7, - 0xf1, 0x9b, 0x22, 0xad, 0x53, 0x5f, 0xce, 0xbf, 0xd3, 0xd6, 0x57, 0x91, 0x80, 0xa7, 0x9f, 0x54, - 0x55, 0xfe, 0x89, 0xd6, 0x8a, 0xfd, 0x99, 0x64, 0x3e, 0x87, 0xe4, 0xf5, 0x93, 0x6b, 0xb7, 0xb4, - 0x93, 0xa3, 0x5a, 0x3b, 0xc5, 0xd7, 0x25, 0xfd, 0x8c, 0x93, 0xd7, 0x79, 0x76, 0xfe, 0x85, 0xde, - 0xe9, 0x8e, 0x64, 0x81, 0x11, 0x97, 0xea, 0x6f, 0xed, 0xf5, 0x60, 0xa5, 0x17, 0xe4, 0x25, 0x75, - 0xb2, 0xd4, 0xd0, 0x78, 0x3f, 0xd4, 0x64, 0x8b, 0xf2, 0x4f, 0x8c, 0x06, 0x0c, 0xdd, 0xbf, 0x8f, - 0xcf, 0xf5, 0xa4, 0x1f, 0xba, 0x9b, 0x63, 0xe9, 0x47, 0xd4, 0x9d, 0x8e, 0xf9, 0x63, 0x7d, 0xed, - 0x7e, 0x32, 0x2d, 0x1f, 0x86, 0x6e, 0xfa, 0xcc, 0x27, 0x89, 0x91, 0x3c, 0x9d, 0x49, 0x29, 0xe6, - 0xed, 0xa4, 0x65, 0xac, 0x28, 0xff, 0xfe, 0x1c, 0x13, 0xfb, 0xad, 0x5f, 0x94, 0x7f, 0x22, 0x39, - 0xf6, 0x35, 0xd8, 0x43, 0x39, 0xf5, 0xbf, 0x46, 0x9c, 0xe7, 0x49, 0x49, 0x57, 0x64, 0x54, 0xf2, - 0x5b, 0x71, 0xbd, 0x4f, 0xd4, 0x5c, 0x83, 0x5d, 0x39, 0x29, 0x79, 0xdd, 0x95, 0x1d, 0x8f, 0x83, - 0x49, 0xca, 0xaf, 0xa2, 0xbf, 0x39, 0xf4, 0xd2, 0xb6, 0xc7, 0x71, 0x4f, 0x5c, 0x81, 0xf4, 0x7a, - 0xec, 0x8e, 0xb3, 0x17, 0xbf, 0x5e, 0x5c, 0xcb, 0x8f, 0xfc, 0x5f, 0x87, 0x7a, 0xf0, 0xec, 0x78, - 0x4c, 0xe2, 0x2a, 0x85, 0x6e, 0xb6, 0xcf, 0x37, 0x9b, 0x7f, 0x4b, 0xfb, 0xd3, 0x89, 0xaf, 0x78, - 0xb4, 0xcb, 0xb9, 0x24, 0x7d, 0x4e, 0xbf, 0x0b, 0xca, 0xf2, 0x2f, 0xf4, 0xc4, 0x1e, 0x31, 0x71, - 0xc9, 0x68, 0xeb, 0x27, 0x25, 0xc9, 0xc9, 0xf1, 0xda, 0xfc, 0xfc, 0x11, 0x9f, 0x7f, 0xf2, 0x3f, - 0x6b, 0x27, 0x3e, 0xcf, 0xf3, 0xeb, 0x92, 0xfd, 0x8e, 0xfb, 0x65, 0xc6, 0x2b, 0x56, 0x3e, 0xf3, - 0xce, 0x5c, 0xd8, 0xaf, 0x85, 0xab, 0xa4, 0xdf, 0x32, 0xcf, 0x57, 0x60, 0xcc, 0x0b, 0xce, 0xfd, - 0xaf, 0xb0, 0x64, 0x17, 0xfc, 0x10, 0xed, 0x52, 0xe7, 0xf9, 0x17, 0xff, 0x39, 0x7d, 0x1a, 0x87, - 0x87, 0xa7, 0x28, 0x79, 0xd2, 0xd3, 0x4c, 0xfa, 0xcf, 0x8f, 0xe4, 0x1d, 0x92, 0x5c, 0x59, 0x0c, - 0xd2, 0x67, 0x3e, 0xc9, 0xa0, 0xa4, 0xe5, 0x29, 0xf2, 0x93, 0xb6, 0xb8, 0xec, 0x3d, 0x5a, 0x9c, - 0x7f, 0xc9, 0xf1, 0x8e, 0x7b, 0x45, 0xf9, 0x17, 0xd7, 0xe4, 0x44, 0xeb, 0x78, 0xfc, 0xf7, 0xf4, - 0x19, 0xce, 0x97, 0x6e, 0xb2, 0x2d, 0x9e, 0xa1, 0x97, 0xa4, 0x56, 0xda, 0xff, 0x91, 0x24, 0x77, - 0x92, 0x92, 0xa7, 0xf9, 0xf3, 0xe9, 0x24, 0x57, 0x20, 0x9f, 0xe5, 0x7f, 0x5e, 0xde, 0xad, 0xd3, - 0x77, 0xca, 0xa7, 0x7c, 0x3e, 0xff, 0x12, 0x62, 0x2d, 0xdd, 0x6f, 0x2f, 0x39, 0xce, 0xd3, 0x51, - 0x47, 0x97, 0xfb, 0x3f, 0x76, 0xbf, 0xed, 0xcd, 0x33, 0xa5, 0xbe, 0x24, 0xbf, 0x45, 0x0d, 0x38, - 0x49, 0xb9, 0x5f, 0xe6, 0xda, 0x2e, 0xbb, 0x2e, 0xe1, 0xf1, 0x9d, 0xdb, 0xb0, 0xb7, 0xf2, 0xc2, - 0x2e, 0x5f, 0x39, 0x7d, 0x5c, 0xb1, 0x87, 0x6f, 0x99, 0xa9, 0xf5, 0x9b, 0xf4, 0x43, 0x81, 0xe8, - 0x65, 0x5e, 0x30, 0x02, 0x30, 0xd8, 0x25, 0x51, 0x79, 0xfe, 0x6d, 0xbd, 0xd3, 0xfc, 0x4b, 0x6a, - 0x57, 0x45, 0xf9, 0xf7, 0x71, 0x48, 0x83, 0xf7, 0x7e, 0xfa, 0xcc, 0x8f, 0x8f, 0x65, 0xab, 0x64, - 0x06, 0x47, 0x70, 0x48, 0x8c, 0xed, 0xc5, 0xfc, 0xfb, 0x75, 0x6c, 0x97, 0x2b, 0x6e, 0xff, 0x8b, - 0x7f, 0x2a, 0x49, 0xe4, 0xfc, 0x3b, 0xa4, 0xf2, 0x39, 0x52, 0x9d, 0x7f, 0x7f, 0x8e, 0xf5, 0xee, - 0xf8, 0xf7, 0xc2, 0xe3, 0x37, 0x40, 0x92, 0x84, 0x71, 0x0d, 0x36, 0xae, 0xc5, 0x9e, 0xbe, 0x53, - 0xf2, 0x0a, 0xe5, 0xf9, 0x17, 0xee, 0x7b, 0x31, 0x76, 0xb5, 0x5f, 0xe3, 0xfc, 0xb7, 0x62, 0xe5, - 0xf9, 0x17, 0xf9, 0x0b, 0x7b, 0xdc, 0x1b, 0xee, 0xea, 0xf1, 0xe9, 0x19, 0x8a, 0x77, 0xc8, 0xbe, - 0x5b, 0xf2, 0x67, 0xd1, 0x3a, 0x5a, 0x76, 0x5d, 0x36, 0xce, 0xe9, 0x67, 0xfc, 0x4c, 0xa1, 0x57, - 0xb5, 0xa7, 0x44, 0xb0, 0xab, 0xa1, 0x5c, 0x99, 0x7e, 0x8c, 0xf8, 0x43, 0xa5, 0x8d, 0x3b, 0x1b, - 0x8c, 0x0f, 0x3d, 0xa2, 0x49, 0xb9, 0xa1, 0x2a, 0xff, 0xfe, 0xaf, 0x76, 0xfe, 0xa5, 0x65, 0xc3, - 0xf4, 0x99, 0x2f, 0x6e, 0x17, 0xdb, 0xe7, 0x5f, 0xe6, 0x3e, 0x2d, 0xce, 0xbf, 0xe4, 0x79, 0x9d, - 0x5a, 0x55, 0xf9, 0xf7, 0x5e, 0x3a, 0x76, 0x30, 0xfd, 0x9d, 0x53, 0xb7, 0xe6, 0xdf, 0xd2, 0xae, - 0x7e, 0xa7, 0xff, 0x1c, 0xcf, 0xa9, 0x2c, 0xff, 0xce, 0xdb, 0x20, 0xea, 0xe7, 0x5f, 0x5a, 0x5f, - 0xce, 0x12, 0xef, 0x10, 0xf9, 0x49, 0x0f, 0xef, 0xf6, 0x58, 0x97, 0xcf, 0xd6, 0xe3, 0xcf, 0xdf, - 0xaf, 0x3d, 0xf9, 0xf7, 0xd6, 0xaf, 0xde, 0x3d, 0x67, 0x64, 0x92, 0x7e, 0x68, 0x9e, 0x18, 0x37, - 0x91, 0x3c, 0x0f, 0xa2, 0x44, 0xd2, 0x44, 0xfe, 0x4d, 0x0b, 0xca, 0x7f, 0x69, 0xdf, 0xea, 0xe9, - 0x1e, 0x29, 0x53, 0xeb, 0x52, 0xfd, 0x37, 0xed, 0xef, 0xdc, 0x38, 0x75, 0xf2, 0x6f, 0x64, 0x9e, - 0xbe, 0x43, 0x92, 0x6a, 0xcd, 0xe7, 0xdf, 0xd0, 0x38, 0x7d, 0xa7, 0xf7, 0x63, 0x4f, 0x79, 0x75, - 0xfe, 0x25, 0xbf, 0x1f, 0xec, 0xae, 0xd0, 0xd2, 0xde, 0xb8, 0xbf, 0xae, 0xa8, 0xff, 0x26, 0x19, - 0x27, 0xce, 0x73, 0x3e, 0x58, 0x3b, 0xb3, 0x93, 0x5e, 0x8f, 0xa4, 0xe4, 0x9d, 0x94, 0xef, 0x45, - 0x5b, 0x65, 0xd9, 0x75, 0xf9, 0xb0, 0x92, 0x36, 0xcd, 0xe7, 0xe7, 0x9f, 0x98, 0x79, 0x54, 0x9d, - 0x7f, 0xaf, 0xc6, 0x35, 0xe9, 0xc7, 0x78, 0x67, 0x14, 0xdb, 0x7a, 0x7f, 0xf7, 0xf2, 0x77, 0xfb, - 0xb1, 0x7f, 0xb5, 0xa1, 0xfc, 0x4b, 0xb2, 0x6e, 0x9e, 0x69, 0xff, 0x4b, 0xb2, 0xa5, 0x7a, 0x34, - 0xd6, 0x79, 0xfe, 0x6d, 0x8f, 0xe3, 0x49, 0x7e, 0x65, 0xc6, 0xda, 0x14, 0xe5, 0x5f, 0xf2, 0xf7, - 0xf7, 0xfe, 0xe9, 0x6b, 0xa6, 0xc7, 0x97, 0xdf, 0x73, 0xef, 0x57, 0xae, 0xf5, 0xab, 0x6e, 0xfe, - 0x25, 0xc9, 0x24, 0xd2, 0xe5, 0xe4, 0x9d, 0x8e, 0x2d, 0x9f, 0xd5, 0xf5, 0xdf, 0xbf, 0x7b, 0xa7, - 0xd7, 0xe2, 0x9a, 0xf6, 0xbf, 0xe4, 0x15, 0x93, 0xf7, 0x4e, 0x3e, 0x87, 0xf8, 0x8a, 0x85, 0x5e, - 0x72, 0x7d, 0xd2, 0x77, 0x28, 0xbb, 0x2e, 0xe9, 0x3b, 0x3f, 0x3f, 0xff, 0x36, 0xee, 0xe5, 0xdd, - 0x13, 0x27, 0xa4, 0x1f, 0xee, 0x26, 0x72, 0xec, 0xbf, 0x86, 0x18, 0x13, 0x92, 0xfc, 0xcb, 0xe7, - 0xb1, 0x7c, 0x75, 0x5a, 0x1f, 0xba, 0x35, 0xff, 0xd2, 0xd7, 0xdb, 0xb8, 0xe7, 0x65, 0x9e, 0xd3, - 0x51, 0x87, 0xa1, 0x77, 0xfa, 0x54, 0x9e, 0xe6, 0x5f, 0xe4, 0xa7, 0x7d, 0xb4, 0x71, 0x3a, 0x54, - 0xe5, 0x5f, 0x92, 0x4f, 0xa7, 0x2d, 0x8a, 0x5b, 0x7f, 0xd2, 0x4f, 0x5e, 0x23, 0xfb, 0x5e, 0x53, - 0x2b, 0xf4, 0xf2, 0xe5, 0xae, 0xba, 0xf9, 0x97, 0xcc, 0x93, 0x0e, 0x7e, 0x64, 0xc7, 0xec, 0xfd, - 0x4f, 0x8c, 0x6f, 0x34, 0x4e, 0xf3, 0x3b, 0x3b, 0x26, 0xe5, 0xbc, 0x2d, 0x20, 0xc9, 0xdd, 0x6b, - 0xf2, 0x2f, 0x1d, 0xd5, 0x72, 0xfa, 0xf7, 0xe4, 0x1d, 0xb3, 0x7d, 0x5b, 0xf1, 0x95, 0x28, 0xbf, - 0x2e, 0xa7, 0xed, 0xbd, 0xcf, 0xf4, 0xe9, 0x34, 0x95, 0x7f, 0xa4, 0x1f, 0xaa, 0x24, 0x39, 0x96, - 0x8c, 0x78, 0x48, 0xdb, 0xe5, 0x44, 0xf9, 0xea, 0xbe, 0xfc, 0x13, 0x75, 0x5b, 0x31, 0x4f, 0x22, - 0x7d, 0xbd, 0xf4, 0x99, 0x4f, 0xeb, 0x6d, 0xa2, 0xfe, 0x18, 0x7a, 0xdf, 0xde, 0xca, 0x16, 0x6d, - 0x54, 0xa7, 0x65, 0xa8, 0xf2, 0xf9, 0xbf, 0x71, 0xca, 0x55, 0xe5, 0xdf, 0x9f, 0x97, 0xa4, 0x5c, - 0x15, 0x18, 0xb3, 0x41, 0xe8, 0x7e, 0x7b, 0x6b, 0x27, 0x9e, 0xe3, 0xb1, 0xb4, 0x7f, 0x1e, 0x8f, - 0x50, 0xec, 0x44, 0xba, 0xda, 0xb7, 0x73, 0x26, 0xb3, 0x5a, 0x92, 0x11, 0x3e, 0xf3, 0x41, 0x3a, - 0x62, 0x24, 0x7e, 0xbd, 0xb2, 0xfc, 0x4b, 0x6b, 0xf8, 0xc1, 0xee, 0xdd, 0xc5, 0x2b, 0x8a, 0xb9, - 0x13, 0x22, 0xfb, 0xd2, 0xb1, 0x3f, 0xe2, 0xea, 0xa6, 0x63, 0x86, 0x8a, 0xcb, 0x7f, 0xe3, 0x9e, - 0x18, 0x2f, 0xf4, 0x71, 0x6c, 0x7f, 0x28, 0xcb, 0xbf, 0x22, 0x81, 0x21, 0x46, 0xed, 0xa4, 0xdf, - 0x0f, 0xf9, 0x51, 0x7f, 0xd9, 0x8c, 0x2c, 0xbb, 0x2e, 0xed, 0xc9, 0xbf, 0x3a, 0xe5, 0xbf, 0x3a, - 0x3d, 0x20, 0xa4, 0x1f, 0xaa, 0xa5, 0xf9, 0x77, 0x6a, 0xb8, 0x9f, 0xaf, 0x71, 0x5f, 0xfe, 0x9d, - 0x3c, 0x9f, 0xfb, 0xd2, 0x4d, 0x36, 0xa3, 0xbe, 0x0a, 0xdb, 0xed, 0xeb, 0xe4, 0x5f, 0x3a, 0x4f, - 0xa4, 0x3a, 0xff, 0xb6, 0x85, 0x73, 0x2f, 0xc4, 0x73, 0x5e, 0xd4, 0x07, 0x90, 0x96, 0x4e, 0xd3, - 0x63, 0xa9, 0x9b, 0x7f, 0xbb, 0x4c, 0x29, 0xec, 0xcf, 0xd9, 0x38, 0xc5, 0x47, 0x50, 0xdc, 0xfe, - 0x97, 0x77, 0x4d, 0xfe, 0x15, 0xbd, 0xc3, 0xfe, 0x1a, 0xf8, 0xc1, 0xd9, 0xeb, 0x95, 0x5f, 0x97, - 0xb6, 0xe4, 0x5f, 0xf4, 0x52, 0xa7, 0xfd, 0x6f, 0x4a, 0xfa, 0xe1, 0x4e, 0x62, 0xec, 0xcb, 0xd0, - 0xf8, 0x79, 0xf2, 0x1c, 0x04, 0xfb, 0x14, 0x13, 0xff, 0x7b, 0x5f, 0xfe, 0x65, 0x66, 0x96, 0x18, - 0xf1, 0xbc, 0xd9, 0xfc, 0x98, 0x8f, 0x71, 0x2f, 0x3f, 0x03, 0xee, 0x74, 0x35, 0xd0, 0x7c, 0xfe, - 0x05, 0x86, 0x28, 0x47, 0xa5, 0x4f, 0x67, 0x75, 0xfe, 0x89, 0xff, 0xcf, 0xce, 0xd6, 0x8b, 0x7f, - 0x32, 0x4e, 0x06, 0x71, 0xd6, 0xd9, 0x7f, 0x1f, 0x1a, 0x62, 0x56, 0xec, 0xe9, 0xfb, 0x5d, 0x93, - 0x7f, 0x7f, 0x32, 0xb5, 0xdd, 0xe4, 0x9d, 0x46, 0xe6, 0xd6, 0x0b, 0x33, 0x59, 0xf3, 0xd6, 0x9b, - 0x17, 0xd6, 0x7f, 0xd3, 0x7e, 0x0a, 0xf1, 0x5b, 0xc9, 0x2c, 0xe2, 0xba, 0xf9, 0x97, 0xbe, 0xaf, - 0x98, 0x8f, 0x3c, 0x3f, 0xe9, 0xff, 0xc8, 0x5e, 0xc3, 0x6c, 0x7f, 0x4f, 0xf1, 0x75, 0x69, 0x4f, - 0xfe, 0x89, 0x11, 0x94, 0x17, 0xfa, 0x7f, 0x7b, 0xd3, 0x7e, 0xaa, 0x30, 0xfd, 0xac, 0x7c, 0xfb, - 0x2e, 0x50, 0x24, 0xda, 0xa5, 0xd9, 0xd2, 0x8e, 0xe7, 0xcb, 0xcf, 0x76, 0xa5, 0x91, 0xf4, 0xee, - 0xcf, 0xae, 0x08, 0x9a, 0x5f, 0x1d, 0x34, 0xfe, 0x5b, 0xf2, 0xb3, 0x91, 0x7f, 0xf8, 0xbb, 0x9f, - 0xe6, 0x9f, 0x98, 0x67, 0x2a, 0x5e, 0x73, 0x79, 0x5c, 0x3f, 0x2b, 0xf9, 0xa9, 0xcc, 0x0a, 0xa6, - 0xc7, 0x77, 0x16, 0xbd, 0x97, 0xf9, 0x91, 0x6d, 0xdb, 0xc3, 0xcf, 0x27, 0xce, 0x47, 0xfe, 0x7e, - 0x1f, 0x8f, 0xea, 0xfc, 0xb5, 0x93, 0xd7, 0x58, 0xda, 0xb3, 0xc3, 0xb9, 0xad, 0xec, 0x6c, 0x76, - 0x7e, 0x3a, 0xf1, 0x7c, 0xff, 0x59, 0x66, 0xce, 0xdf, 0xc6, 0x8d, 0xff, 0x6d, 0xba, 0xbf, 0x0e, - 0xa7, 0xaf, 0xf8, 0x5d, 0x79, 0x05, 0x92, 0x99, 0xaa, 0xc9, 0x6f, 0x87, 0xc7, 0x2b, 0xb3, 0xb4, - 0xc5, 0xbf, 0xc4, 0xab, 0x12, 0xa4, 0xbf, 0x73, 0x7a, 0xbc, 0x1b, 0x67, 0xba, 0xbf, 0x06, 0xe2, - 0x0c, 0x8f, 0xef, 0x5b, 0x72, 0xae, 0xa7, 0x92, 0xd5, 0x1e, 0x44, 0xcd, 0x3b, 0xfb, 0x39, 0x24, - 0xbf, 0x95, 0x8c, 0x7c, 0xc9, 0xaf, 0x33, 0x5d, 0x74, 0x5d, 0xe4, 0xaf, 0x00, 0x5b, 0xd7, 0xb7, - 0x57, 0x34, 0xf7, 0x23, 0xad, 0xfd, 0x7e, 0xf4, 0xa7, 0x05, 0xb2, 0xe9, 0xd7, 0x86, 0xb3, 0x40, - 0xf7, 0x9c, 0xf7, 0xff, 0xe2, 0x79, 0x92, 0xb9, 0x29, 0x81, 0xc4, 0x55, 0xbd, 0xe4, 0x10, 0x73, - 0xc2, 0x4b, 0xfb, 0x3e, 0x7a, 0x45, 0xe9, 0x97, 0x2a, 0x5a, 0x3f, 0x07, 0x78, 0x04, 0xf2, 0xaf, - 0x4d, 0x92, 0xfa, 0x70, 0x7e, 0x6c, 0x4e, 0xdb, 0xad, 0x77, 0xe5, 0x61, 0xb1, 0xee, 0x4e, 0x71, - 0xcf, 0x2f, 0xe9, 0x87, 0xb6, 0x22, 0xff, 0xda, 0x24, 0x9d, 0x7b, 0xfd, 0xec, 0x23, 0xa9, 0x2f, - 0xf2, 0x97, 0x83, 0xa9, 0x25, 0x7c, 0xf4, 0xc5, 0xea, 0x3c, 0x69, 0xf2, 0xbd, 0x1a, 0x7f, 0xf7, - 0x8a, 0x6b, 0xbe, 0xa9, 0xec, 0x58, 0x2e, 0xe0, 0xd1, 0xc8, 0xbf, 0xf6, 0x48, 0xfb, 0x4c, 0xd4, - 0xc9, 0x84, 0xad, 0x37, 0xb7, 0xa6, 0x19, 0x1f, 0xfd, 0x49, 0x7f, 0xdc, 0x13, 0x26, 0xfb, 0x76, - 0xbd, 0xea, 0xf4, 0x5b, 0x92, 0x7e, 0x00, 0x14, 0x25, 0xfa, 0x81, 0x6a, 0x3a, 0x4f, 0x3f, 0x6b, - 0xc5, 0xda, 0xce, 0x00, 0x94, 0x24, 0x7a, 0xca, 0x6b, 0xa7, 0x5f, 0x41, 0x0e, 0xb2, 0xaf, 0x07, - 0x00, 0x35, 0x7d, 0x7b, 0xb3, 0xeb, 0xb3, 0xef, 0x68, 0x66, 0xa9, 0xd6, 0xbf, 0x0d, 0x00, 0xb1, - 0xb5, 0x73, 0x5f, 0xfa, 0xd1, 0xe3, 0x0b, 0x40, 0x45, 0x5b, 0x6f, 0x31, 0xb8, 0x3d, 0xfb, 0xa6, - 0x16, 0x7d, 0x1e, 0x00, 0xd4, 0xb4, 0xd9, 0x95, 0xfc, 0x84, 0x5b, 0xd3, 0x8f, 0x3e, 0x0f, 0x00, - 0x2a, 0x12, 0x23, 0xfd, 0xe2, 0xf4, 0x4b, 0x5d, 0x57, 0xef, 0x6d, 0xc3, 0x4e, 0x25, 0x00, 0x70, - 0xad, 0x8d, 0x3b, 0xb7, 0xf2, 0xe9, 0x77, 0x4d, 0x0a, 0xce, 0x69, 0xf5, 0x03, 0xa0, 0xa0, 0xa2, - 0x92, 0xdf, 0x75, 0x39, 0x48, 0xab, 0x1f, 0x00, 0x15, 0x7d, 0x55, 0x94, 0xfc, 0xea, 0xe5, 0xe0, - 0x86, 0xb1, 0x7e, 0x00, 0x94, 0x23, 0x7a, 0x7b, 0xaf, 0xcb, 0xbe, 0x7c, 0x0e, 0xce, 0x07, 0xd4, - 0x7b, 0x01, 0xa8, 0xe7, 0xd3, 0xb9, 0xb6, 0xe4, 0x97, 0xb7, 0xb4, 0xa9, 0xf7, 0x02, 0x68, 0xab, - 0xc8, 0x17, 0xab, 0xe0, 0x9e, 0xff, 0x7b, 0xe8, 0xcd, 0xef, 0x28, 0xf9, 0xc5, 0xbe, 0xe8, 0xef, - 0x05, 0xd0, 0x4a, 0x91, 0x3f, 0x1b, 0x8c, 0x7b, 0x43, 0xf3, 0xd5, 0x18, 0x9a, 0x62, 0x2d, 0xfe, - 0x34, 0x05, 0x23, 0x7f, 0x6d, 0xdf, 0x9b, 0x7d, 0x0b, 0xea, 0xbd, 0x00, 0x5a, 0x6a, 0x69, 0xe7, - 0xd7, 0x2b, 0x0d, 0x8c, 0xd5, 0xbe, 0x9f, 0x62, 0x73, 0x77, 0xad, 0x77, 0x66, 0xb1, 0xba, 0x01, - 0x80, 0xb6, 0x2a, 0x5e, 0xaf, 0x3e, 0x30, 0xa6, 0xbb, 0x72, 0xdb, 0xbd, 0xe9, 0x47, 0x8f, 0x07, - 0x80, 0xf6, 0xfa, 0x74, 0xca, 0x77, 0xac, 0x7c, 0xef, 0xcf, 0xad, 0x04, 0x25, 0x3f, 0x00, 0xba, - 0x19, 0xf5, 0xca, 0x77, 0x6b, 0x1b, 0x9a, 0x33, 0x6b, 0x7e, 0x82, 0x92, 0x1f, 0x00, 0x5d, 0x84, - 0x5e, 0xd5, 0x5e, 0xbd, 0x62, 0xb7, 0xca, 0xb9, 0x55, 0xe4, 0x42, 0xf6, 0x51, 0xf2, 0x03, 0xd0, - 0x7a, 0x6b, 0xa7, 0x7a, 0xb7, 0xf2, 0x49, 0x49, 0xfe, 0x55, 0xe5, 0x20, 0xbd, 0xbd, 0x00, 0x54, - 0x70, 0x6f, 0xfe, 0xe5, 0x73, 0x70, 0xce, 0xba, 0x2e, 0x00, 0x14, 0xb1, 0x71, 0xab, 0xf3, 0xaf, - 0xac, 0xfe, 0x5b, 0x6c, 0xc5, 0x0c, 0x0f, 0x00, 0x0a, 0x29, 0xef, 0xfd, 0xfd, 0x69, 0x0c, 0x8d, - 0x7c, 0xff, 0x47, 0xb9, 0xc5, 0x20, 0xa4, 0xd6, 0xdb, 0x21, 0xff, 0x3e, 0xfd, 0x08, 0x80, 0xfb, - 0x88, 0xb9, 0x1d, 0xe3, 0x8a, 0xfe, 0xdf, 0x71, 0xaf, 0x6e, 0xfa, 0xb1, 0xaa, 0x4b, 0x17, 0x51, - 0xda, 0x87, 0xaa, 0xb6, 0xbb, 0xec, 0x9b, 0x0f, 0x76, 0xac, 0x91, 0x59, 0x9c, 0x7e, 0x23, 0xb3, - 0x5e, 0xf6, 0xad, 0xa9, 0xf5, 0x76, 0x56, 0x44, 0x06, 0x42, 0x39, 0xbf, 0xfd, 0xb5, 0xb3, 0x18, - 0xcc, 0x0f, 0x66, 0x85, 0x09, 0x38, 0x3a, 0x1b, 0xfb, 0x57, 0x64, 0x49, 0x5f, 0x6f, 0xe7, 0x45, - 0x85, 0x6b, 0x66, 0x00, 0x6d, 0xb4, 0xf5, 0x0e, 0xe5, 0xbe, 0x13, 0xef, 0xfd, 0xa1, 0x99, 0xb4, - 0x04, 0x06, 0xc6, 0xd0, 0x7c, 0xaf, 0xd1, 0xef, 0xb1, 0x18, 0xb0, 0x73, 0x2f, 0x62, 0x62, 0xe5, - 0xa0, 0x67, 0x1f, 0x03, 0x50, 0x4d, 0x64, 0xdf, 0xe2, 0x2c, 0xfb, 0x12, 0x53, 0xeb, 0xa3, 0xff, - 0xde, 0xff, 0xe8, 0x8b, 0xfd, 0x39, 0xe2, 0x9a, 0x71, 0x75, 0x8b, 0x1f, 0xdf, 0xfa, 0xc8, 0xda, - 0x7a, 0xd4, 0x05, 0xd0, 0x56, 0xa1, 0xbb, 0xdc, 0x65, 0x5f, 0x79, 0xfa, 0x55, 0xc8, 0x67, 0xdf, - 0x60, 0x4d, 0xf6, 0xa1, 0x90, 0xc8, 0x40, 0x7a, 0x86, 0xd1, 0x2e, 0x5f, 0x87, 0xec, 0x4b, 0xdd, - 0x90, 0x82, 0x83, 0x64, 0x8c, 0x1f, 0xdf, 0xf2, 0x28, 0xb7, 0xab, 0x09, 0xef, 0x32, 0x90, 0xef, - 0x47, 0xb4, 0x41, 0xe4, 0x6f, 0x9c, 0xd3, 0xe4, 0xbb, 0x27, 0x07, 0xc9, 0x3e, 0xd4, 0x41, 0x06, - 0xe2, 0xf9, 0xb6, 0xde, 0xda, 0x59, 0x56, 0x64, 0xdf, 0x75, 0x39, 0xb8, 0x24, 0xfb, 0x70, 0x05, - 0x32, 0x10, 0xcf, 0x13, 0x7a, 0x2b, 0xbb, 0x5e, 0xf2, 0xd5, 0xc9, 0xc1, 0x95, 0xfd, 0x4d, 0xf6, - 0xe1, 0x6a, 0x71, 0x06, 0xf2, 0xbd, 0x89, 0xe6, 0x6c, 0xdc, 0x85, 0x3d, 0x1b, 0x2c, 0xec, 0xb2, - 0x75, 0x06, 0x44, 0x8d, 0x37, 0xdf, 0xda, 0x77, 0x4f, 0x0e, 0x2e, 0xc9, 0x3e, 0xdc, 0x41, 0x64, - 0xe0, 0x37, 0x25, 0x41, 0x34, 0x60, 0xe5, 0x0c, 0x33, 0x23, 0x95, 0x87, 0xe6, 0xd2, 0x3e, 0xfd, - 0x7f, 0x31, 0xbe, 0x65, 0x39, 0xc8, 0xba, 0x2f, 0x05, 0xd7, 0xd4, 0x79, 0xd1, 0x00, 0x32, 0x10, - 0xf7, 0x9b, 0x9e, 0xed, 0xd3, 0x11, 0x18, 0x93, 0x7e, 0xfc, 0x7f, 0xbb, 0x52, 0x9f, 0xbb, 0xca, - 0x65, 0xdf, 0x7d, 0x39, 0x48, 0xf6, 0xa1, 0x59, 0x5b, 0x52, 0x10, 0x37, 0x5b, 0xd8, 0xc5, 0xb3, - 0x74, 0xa7, 0xd6, 0x79, 0xa9, 0xef, 0xbe, 0x1c, 0x5c, 0x0e, 0x3e, 0x9d, 0xdf, 0xdc, 0xa3, 0x90, - 0x20, 0x29, 0x09, 0x72, 0x7f, 0xe1, 0x1a, 0xd1, 0xcb, 0x6b, 0xe9, 0x1a, 0xf5, 0x33, 0xab, 0x6e, - 0xfa, 0xd5, 0x49, 0x41, 0xe6, 0x75, 0x40, 0xae, 0xa4, 0x57, 0x84, 0x92, 0x20, 0xea, 0xaa, 0x5a, - 0xa7, 0x79, 0xd2, 0xbf, 0x36, 0xff, 0x8a, 0x93, 0x70, 0x69, 0x7f, 0xb9, 0xd1, 0xd3, 0xcf, 0x14, - 0x5d, 0x90, 0x66, 0x20, 0x29, 0x88, 0xcb, 0x66, 0x83, 0xaa, 0x55, 0xfa, 0x6e, 0xcf, 0xbf, 0x24, - 0x05, 0x97, 0x36, 0x6b, 0x19, 0xe0, 0xb1, 0xfe, 0x7d, 0x49, 0x33, 0x90, 0xfa, 0x30, 0xaa, 0xcc, - 0x25, 0xe6, 0xdf, 0xa7, 0x43, 0x4f, 0x07, 0x9e, 0x85, 0x92, 0x20, 0x2e, 0x5b, 0x96, 0xf4, 0x7e, - 0xdc, 0x59, 0xff, 0x15, 0x35, 0x5e, 0xee, 0x39, 0x3c, 0x59, 0x36, 0x03, 0xf3, 0x29, 0xc8, 0xea, - 0x82, 0x5d, 0x26, 0xea, 0x08, 0x1b, 0x47, 0x8c, 0x6c, 0x29, 0xef, 0xff, 0x98, 0xdf, 0x94, 0x7d, - 0x6b, 0xc6, 0x35, 0xa3, 0x55, 0x8a, 0x52, 0x70, 0xed, 0x0c, 0xcd, 0xa1, 0xc9, 0x6e, 0xd2, 0x5d, - 0x24, 0x92, 0x6f, 0x6d, 0xef, 0xb2, 0x6f, 0xef, 0xbd, 0x5f, 0xbc, 0x53, 0xd1, 0xae, 0xf4, 0x77, - 0xf8, 0x89, 0xfa, 0xd9, 0xb7, 0x61, 0x7c, 0x0b, 0x5a, 0xe9, 0x34, 0x03, 0x43, 0x2f, 0x5e, 0x99, - 0x7c, 0xdc, 0x7b, 0xf6, 0x71, 0xe1, 0x71, 0x22, 0xff, 0x7b, 0x5f, 0xe6, 0x3b, 0xb5, 0xb4, 0x27, - 0x67, 0x09, 0x18, 0x88, 0xb6, 0x3f, 0xfb, 0x4c, 0x65, 0xa9, 0x8f, 0x5d, 0xda, 0xd0, 0x76, 0x69, - 0x0a, 0xbe, 0xf7, 0xe3, 0x31, 0xae, 0xd4, 0x81, 0xbb, 0x20, 0xf2, 0x43, 0xf7, 0x73, 0x5f, 0xe6, - 0x2b, 0x36, 0x3d, 0xd9, 0xa9, 0x63, 0x68, 0x4e, 0xad, 0x82, 0xf4, 0x2b, 0x4b, 0x41, 0x9b, 0x91, - 0x7d, 0x50, 0x87, 0x58, 0x51, 0x5f, 0x24, 0xe0, 0xca, 0x5e, 0x3b, 0xf4, 0x8f, 0xe8, 0x4d, 0x7c, - 0xdf, 0x89, 0xba, 0x6e, 0x79, 0xf2, 0xa5, 0x16, 0xfb, 0x75, 0xea, 0x3f, 0x2c, 0xb1, 0x32, 0x41, - 0x2d, 0x83, 0xd5, 0x2e, 0xf9, 0xe8, 0xe1, 0x85, 0x8a, 0x4e, 0xeb, 0xc3, 0xa4, 0xa0, 0x6e, 0x44, - 0x89, 0x2f, 0x4e, 0xbe, 0x53, 0x97, 0x73, 0x30, 0xad, 0x17, 0x57, 0xd9, 0xd5, 0x77, 0xe9, 0xe1, - 0x85, 0xe2, 0x8a, 0x52, 0x90, 0x1c, 0x6c, 0xaf, 0xfd, 0xe7, 0x55, 0xf9, 0xe9, 0xec, 0x4b, 0x7c, - 0xee, 0x79, 0xee, 0x35, 0x97, 0x83, 0x24, 0x1f, 0xf4, 0x52, 0x96, 0x82, 0xdc, 0xe5, 0x6d, 0xf2, - 0xe5, 0xbe, 0xed, 0xf7, 0x92, 0x7c, 0x35, 0x47, 0xbd, 0xd5, 0x59, 0xbf, 0xbd, 0xf8, 0x0c, 0xbf, - 0xf6, 0x6d, 0x7c, 0xd7, 0xb9, 0x26, 0x05, 0x49, 0x3e, 0xe8, 0xab, 0x38, 0x05, 0xc9, 0xc1, 0x76, - 0x58, 0xd8, 0xa7, 0x7d, 0xb4, 0x6f, 0xc7, 0xf5, 0xa9, 0xb6, 0x5e, 0xe8, 0xae, 0xaf, 0xce, 0xbd, - 0xeb, 0x72, 0x90, 0xe4, 0x43, 0x37, 0x94, 0xa5, 0x20, 0x39, 0xf8, 0x4c, 0x1b, 0xf7, 0x7c, 0x8c, - 0xde, 0x87, 0x55, 0xdc, 0xc2, 0xd7, 0x6c, 0x0a, 0x92, 0x7c, 0xe8, 0x9e, 0xf2, 0x14, 0x14, 0xed, - 0x4f, 0xe7, 0xcf, 0xc3, 0xd2, 0x9e, 0x0e, 0xca, 0xd6, 0x4d, 0xc7, 0xfd, 0xc6, 0xbd, 0xa2, 0xf9, - 0x19, 0xcb, 0x46, 0xb3, 0xef, 0x34, 0x07, 0xd7, 0xf6, 0xa7, 0x43, 0xf2, 0xa1, 0xcb, 0x2a, 0x53, - 0x30, 0x53, 0x22, 0x7c, 0xb7, 0xe2, 0xe7, 0x91, 0xd9, 0x24, 0xb2, 0x14, 0xcf, 0xd0, 0x98, 0x0d, - 0xe4, 0xa4, 0x9f, 0x18, 0xd5, 0x42, 0xf2, 0x01, 0x82, 0x48, 0xb9, 0xaa, 0x14, 0xdc, 0xb8, 0xc9, - 0xde, 0x11, 0x1f, 0xd6, 0xb3, 0x8f, 0x55, 0x2f, 0x71, 0xdb, 0xde, 0xae, 0x8e, 0xeb, 0x94, 0xe6, - 0x9f, 0x73, 0x7f, 0xcb, 0x5f, 0x86, 0xf3, 0xe5, 0x32, 0x9e, 0x0f, 0x28, 0x52, 0x96, 0x82, 0xa1, - 0x17, 0xd7, 0xce, 0xc4, 0x7c, 0x79, 0x5a, 0x09, 0xef, 0x77, 0x48, 0xbd, 0x5d, 0xee, 0x7d, 0x1e, - 0x65, 0x77, 0x27, 0x3a, 0xa9, 0xff, 0x3a, 0x19, 0x77, 0x24, 0x1f, 0x75, 0x5d, 0xa0, 0x8e, 0xa2, - 0xd2, 0x60, 0xe8, 0x4e, 0x2d, 0x31, 0x5b, 0xfe, 0xfb, 0xe4, 0x5f, 0x7f, 0xef, 0x7e, 0x92, 0x55, - 0x7f, 0xeb, 0x89, 0x77, 0x2f, 0x08, 0x4f, 0x32, 0x2f, 0x6b, 0x6a, 0x9d, 0x97, 0x00, 0xc7, 0xbd, - 0x93, 0xf4, 0xbb, 0x29, 0x07, 0x37, 0xbb, 0xdc, 0xa3, 0xc4, 0x07, 0x5c, 0x2b, 0x99, 0x45, 0x57, - 0xcf, 0x3e, 0x0b, 0x3b, 0x50, 0xbe, 0xd8, 0x7a, 0xb3, 0xc1, 0xa4, 0xff, 0x6e, 0xad, 0x6b, 0xb4, - 0x84, 0xee, 0xcb, 0x79, 0xfb, 0xcc, 0x3b, 0x97, 0xcf, 0xbf, 0xb5, 0xf3, 0xd6, 0x3f, 0x4d, 0xbf, - 0x5f, 0xe6, 0xda, 0x2e, 0xc9, 0xbf, 0x5a, 0x29, 0xb8, 0x71, 0x69, 0xe3, 0x03, 0xee, 0x75, 0xa9, - 0x8f, 0x24, 0xeb, 0xdb, 0xfb, 0x3e, 0xf6, 0x9b, 0x54, 0x97, 0x0c, 0x23, 0x7f, 0x3a, 0x18, 0x9a, - 0xe3, 0xfe, 0x97, 0x52, 0x7d, 0xca, 0xcb, 0xcc, 0x18, 0xbd, 0x51, 0x2f, 0x9f, 0x2e, 0xff, 0x1e, - 0xae, 0x55, 0xe8, 0x7e, 0x15, 0x66, 0xde, 0xa5, 0x1c, 0x9c, 0x5a, 0x7f, 0x99, 0xc1, 0xbe, 0xde, - 0x3b, 0x34, 0x27, 0x7d, 0x51, 0x67, 0x4d, 0xb2, 0xb1, 0x7e, 0x0e, 0x7e, 0xee, 0x5e, 0xf3, 0x9b, - 0xdc, 0x03, 0x1a, 0x56, 0x3f, 0x07, 0xbf, 0x8f, 0xd2, 0xf1, 0x34, 0xf9, 0x27, 0x72, 0xd4, 0x4b, - 0xda, 0xb8, 0x64, 0xec, 0x1e, 0x21, 0xa7, 0x2c, 0x9a, 0x1f, 0xa3, 0xf7, 0xd6, 0x8f, 0xdb, 0x0a, - 0x44, 0x19, 0x2f, 0x6e, 0xcf, 0xbb, 0x55, 0x9a, 0x74, 0x4b, 0x5b, 0xec, 0xa8, 0x91, 0x66, 0x5f, - 0xb6, 0x84, 0x58, 0x8d, 0xf2, 0x1e, 0x20, 0x5f, 0xe4, 0xff, 0xae, 0x99, 0x84, 0xdf, 0x27, 0xc2, - 0xbd, 0x38, 0x13, 0x37, 0x99, 0x3d, 0xc9, 0xa6, 0x83, 0x66, 0x8f, 0x6f, 0xe3, 0xfe, 0x65, 0xc6, - 0xe5, 0xb3, 0x66, 0x93, 0x35, 0xf2, 0x27, 0xb9, 0x1a, 0xaa, 0xe8, 0x9f, 0xb8, 0x3d, 0xf3, 0x2e, - 0x97, 0x07, 0xcb, 0xa4, 0x99, 0x27, 0x4a, 0x7b, 0x21, 0xb9, 0x07, 0x3c, 0xdc, 0xa5, 0x51, 0x33, - 0x55, 0x39, 0x98, 0x2d, 0x49, 0x89, 0x5d, 0xb8, 0xb3, 0x6d, 0x88, 0xf7, 0x95, 0xdd, 0x42, 0x2f, - 0x5d, 0xed, 0x7d, 0x68, 0xde, 0xd2, 0xf2, 0x1f, 0xbd, 0xc4, 0xc7, 0x90, 0xf4, 0xfc, 0xc4, 0x76, - 0xa5, 0x3b, 0x77, 0x74, 0xd6, 0x47, 0x3b, 0x1f, 0x34, 0x9d, 0x7f, 0x75, 0x53, 0x70, 0x9f, 0x7b, - 0x9d, 0x68, 0x71, 0x05, 0xda, 0xad, 0x6e, 0x12, 0x66, 0x53, 0xf0, 0xe3, 0xd0, 0xdf, 0x39, 0xea, - 0x6d, 0xdc, 0xb8, 0x64, 0x98, 0x24, 0xcd, 0xa9, 0x6c, 0x8f, 0xf3, 0xae, 0xdc, 0x79, 0x4c, 0xc8, - 0x23, 0x91, 0x57, 0x99, 0x63, 0xf9, 0xb0, 0x4e, 0xc7, 0xcf, 0x9d, 0xfd, 0xfc, 0xde, 0xef, 0x4c, - 0xdf, 0xce, 0xf7, 0xe1, 0x9d, 0xbf, 0x72, 0x36, 0x67, 0xf2, 0x3d, 0x14, 0x81, 0xb1, 0x6a, 0xbc, - 0xfc, 0x57, 0x95, 0x83, 0xbb, 0x7f, 0x71, 0x29, 0xed, 0x01, 0x6d, 0x55, 0x27, 0x09, 0x93, 0x52, - 0xe0, 0xda, 0x99, 0x5a, 0x8b, 0x41, 0x98, 0xa4, 0x5f, 0xaa, 0x30, 0x07, 0xeb, 0x3a, 0xad, 0xa3, - 0x4e, 0xfa, 0xf5, 0x7f, 0x33, 0x9f, 0x7f, 0xe7, 0x39, 0xb8, 0xcc, 0xad, 0x50, 0x30, 0xee, 0xc9, - 0x4d, 0xbf, 0x23, 0x52, 0x0f, 0x50, 0xca, 0xe5, 0x24, 0xfc, 0x2e, 0x6c, 0x1f, 0xbc, 0x37, 0x07, - 0xe7, 0x83, 0x20, 0x53, 0x3e, 0x5b, 0xd8, 0xd7, 0xbf, 0x42, 0x55, 0x0e, 0xce, 0x8f, 0x7b, 0xa9, - 0x05, 0xc6, 0xdf, 0x22, 0xfd, 0xd2, 0x74, 0x94, 0x92, 0x79, 0xd4, 0x70, 0x01, 0xd5, 0x55, 0x67, - 0x61, 0xd3, 0x29, 0x98, 0x96, 0x00, 0xdf, 0xad, 0xdb, 0xcb, 0x91, 0x65, 0x29, 0x28, 0x4a, 0xad, - 0x93, 0xfe, 0x7b, 0x7f, 0x31, 0x38, 0x49, 0xbf, 0x86, 0x52, 0x90, 0xcc, 0x03, 0x74, 0x56, 0x9e, - 0x85, 0xcd, 0xe5, 0xe0, 0xda, 0x9e, 0x5a, 0x33, 0x6b, 0xed, 0xdc, 0x9e, 0x7e, 0x97, 0x93, 0xb0, - 0x20, 0xfb, 0x6e, 0xc8, 0xc1, 0xaf, 0xfd, 0x3b, 0x90, 0x79, 0x40, 0x17, 0x1d, 0xfa, 0x22, 0xea, - 0xa7, 0xe0, 0x9d, 0xad, 0x83, 0xcd, 0x97, 0x07, 0xaf, 0xce, 0x41, 0x37, 0xee, 0xd3, 0xe9, 0xc6, - 0x6c, 0x19, 0x00, 0x75, 0x1d, 0xc6, 0x9d, 0xf8, 0xe7, 0x59, 0xa8, 0x66, 0x0e, 0x7e, 0x1d, 0x7e, - 0x67, 0xdf, 0x87, 0xcd, 0x5c, 0x69, 0x00, 0x57, 0x49, 0xc6, 0xab, 0x1c, 0x47, 0xaa, 0xb4, 0x3a, - 0x05, 0x8f, 0x59, 0xe7, 0xdd, 0x3b, 0x8a, 0x11, 0x00, 0xca, 0x64, 0xc6, 0xf1, 0xe5, 0xea, 0xce, - 0x8f, 0xc8, 0xc4, 0x64, 0x4c, 0x62, 0x32, 0x5e, 0xfb, 0xd9, 0x57, 0x03, 0x00, 0xb2, 0xfe, 0x7d, - 0x29, 0x1d, 0xf7, 0x1c, 0x3b, 0xeb, 0x7f, 0x29, 0x1e, 0x29, 0x4d, 0x9d, 0x15, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd0, - 0x76, 0xff, 0x0f, 0x2c, 0xaf, 0x34, 0xc9, -}; - -#endif - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/color.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/color.cpp deleted file mode 100644 index 5a374064d..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/color.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "color.h" - -const char* Color::String(u8 color) -{ - const char* str_color[] = { _("Blue"), _("Green"), _("Red"), _("Yellow"), _("Orange"), _("Purple"), _("Gray"), "Unknown" }; - - switch(color) - { - case Color::BLUE: return str_color[0]; - case Color::GREEN: return str_color[1]; - case Color::RED: return str_color[2]; - case Color::YELLOW: return str_color[3]; - case Color::ORANGE: return str_color[4]; - case Color::PURPLE: return str_color[5]; - case Color::GRAY: return str_color[6]; - } - - return str_color[7]; -} - -u8 Color::GetIndex(color_t color) -{ - switch(color) - { - case BLUE: return 0; - case GREEN: return 1; - case RED: return 2; - case YELLOW: return 3; - case ORANGE: return 4; - case PURPLE: return 5; - default: break; - } - - // GRAY - return 6; -} - -u8 Color::Count(u8 colors) -{ - const std::bitset<8> bset(colors); - return bset.count(); -} - -Color::color_t Color::GetFromIndex(u8 index) -{ - switch(index) - { - case 0: return BLUE; - case 1: return GREEN; - case 2: return RED; - case 3: return YELLOW; - case 4: return ORANGE; - case 5: return PURPLE; - default: break; - } - - return GRAY; -} - -Color::color_t Color::Get(u8 index) -{ - switch(index) - { - case BLUE: return BLUE; - case GREEN: return GREEN; - case RED: return RED; - case YELLOW: return YELLOW; - case ORANGE: return ORANGE; - case PURPLE: return PURPLE; - default: break; - } - - return GRAY; -} - -u8 Color::GetFirst(u8 colors) -{ - Color::color_t color = Color::BLUE; - for(; color != Color::GRAY; ++color) if(color & colors) return color; - - return 0; -} - -const char* Barrier::Color(u8 val) -{ - switch(val) - { - case 0x01: return _("Aqua"); - case 0x02: return _("Blue"); - case 0x04: return _("Brown"); - case 0x08: return _("Gold"); - case 0x10: return _("Green"); - case 0x20: return _("Orange"); - case 0x40: return _("Purple"); - case 0x80: return _("Red"); - default: break; - } - - return "None"; -} - -Barrier::color_t Barrier::FromMP2(u8 val) -{ - switch(val) - { - case 0: return AQUA; - case 8: return BLUE; - case 16:return BROWN; - case 24:return GOLD; - case 32:return GREEN; - case 40:return ORANGE; - case 48:return PURPLE; - case 56:return RED; - default: break; - } - - return NONE; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/color.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/color.h deleted file mode 100644 index 5f72cf09c..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/color.h +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2COLOR_H -#define H2COLOR_H - -#include -#include "gamedefs.h" - -namespace Barrier -{ - enum color_t - { - NONE = 0x00, - AQUA = 0x01, - BLUE = 0x02, - BROWN = 0x04, - GOLD = 0x08, - GREEN = 0x10, - ORANGE = 0x20, - PURPLE = 0x40, - RED = 0x80 - }; - - const char* Color(u8); - color_t FromMP2(u8); -} - -namespace Color -{ - enum color_t - { - NONE = 0x00, - BLUE = 0x01, - GREEN = 0x02, - RED = 0x04, - YELLOW = 0x08, - ORANGE = 0x10, - PURPLE = 0x20, - GRAY = 0x40 - }; - - inline color_t& operator++ (color_t& color){ return color = ( GRAY == color ? BLUE : color_t(color << 1)); } - inline color_t& operator-- (color_t& color){ return color = ( BLUE == color ? GRAY : color_t(color >> 1)); } - - const char* String(u8); - - u8 Count(u8); - u8 GetIndex(color_t); - color_t GetFromIndex(u8); - u8 GetFirst(u8); - color_t Get(u8); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/kingdom.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/kingdom.cpp deleted file mode 100644 index d1735342b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/kingdom.cpp +++ /dev/null @@ -1,630 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include - -#include "settings.h" -#include "castle.h" -#include "heroes.h" -#include "difficulty.h" -#include "gameevent.h" -#include "profit.h" -#include "world.h" -#include "visit.h" -#include "battle2.h" -#include "kingdom.h" - -u8 Kingdom::max_heroes = 8; - -cost_t Kingdom::starting_resource[] = { - { 10000, 30, 10, 30, 10, 10, 10 }, - { 7500, 20, 5, 20, 5, 5, 5 }, - { 5000, 10, 2, 10, 2, 2, 2 }, - { 2500, 5, 0, 5, 0, 0, 0 }, - { 0, 0, 0, 0, 0, 0, 0 }, - // ai resource - { 10000, 30, 10, 30, 10, 10, 10 }, -}; - -bool HeroesStrongestArmy(const Heroes* h1, const Heroes* h2) -{ - return h1 && h2 && h2->GetArmy().StrongerEnemyArmy(h1->GetArmy()); -} - -#ifdef WITH_XML -#include "xmlccwrap.h" - -void Kingdom::UpdateStartingResource(const TiXmlElement* xml_resource) -{ - const TiXmlElement* xml_difficult; - const char* ai_always = xml_resource->Attribute("ai_always"); - const char* level; - - level = "easy"; - if(NULL != (xml_difficult = xml_resource->FirstChildElement(level))) - { - LoadCostFromXMLElement(Kingdom::starting_resource[0], *xml_difficult); - if(ai_always && 0 == std::strcmp(ai_always, level)) LoadCostFromXMLElement(Kingdom::starting_resource[5], *xml_difficult); - } - - level = "normal"; - if(NULL != (xml_difficult = xml_resource->FirstChildElement(level))) - { - LoadCostFromXMLElement(Kingdom::starting_resource[1], *xml_difficult); - if(ai_always && 0 == std::strcmp(ai_always, level)) LoadCostFromXMLElement(Kingdom::starting_resource[5], *xml_difficult); - } - - level = "hard"; - if(NULL != (xml_difficult = xml_resource->FirstChildElement(level))) - { - LoadCostFromXMLElement(Kingdom::starting_resource[2], *xml_difficult); - if(ai_always && 0 == std::strcmp(ai_always, level)) LoadCostFromXMLElement(Kingdom::starting_resource[5], *xml_difficult); - } - - level = "expert"; - if(NULL != (xml_difficult = xml_resource->FirstChildElement(level))) - { - LoadCostFromXMLElement(Kingdom::starting_resource[3], *xml_difficult); - if(ai_always && 0 == std::strcmp(ai_always, level)) LoadCostFromXMLElement(Kingdom::starting_resource[5], *xml_difficult); - } - - level = "impossible"; - if(NULL != (xml_difficult = xml_resource->FirstChildElement(level))) - { - LoadCostFromXMLElement(Kingdom::starting_resource[4], *xml_difficult); - if(ai_always && 0 == std::strcmp(ai_always, level)) LoadCostFromXMLElement(Kingdom::starting_resource[5], *xml_difficult); - } -} -#endif - -Kingdom::Kingdom() -{ -} - -Kingdom::Kingdom(const Color::color_t cl) : color(cl), control(Game::AI), flags(0), lost_town_days(0), ai_capital(NULL), visited_tents_colors(0) -{ - const Settings & conf = Settings::Get(); - - lost_town_days = Game::GetLostTownDays() + 1; - - // set play - if(conf.KingdomColors(color)) SetModes(PLAY); - - heroes.reserve(GetMaxHeroes()); - castles.reserve(15); - - // set control - if(color & conf.PlayersColors()) - switch(Settings::Get().GameType()) - { - default: control = Game::LOCAL; break; -#ifdef WITH_NET - case Game::NETWORK: control = (color == conf.MyColor() ? Game::LOCAL : Game::REMOTE); break; -#endif - } - - UpdateStartingResource(); -} - -void Kingdom::UpdateStartingResource(void) -{ - cost_t* sres = NULL; - - switch(Settings::Get().GameDifficulty()) - { - case Difficulty::EASY: sres = &starting_resource[0]; break; - case Difficulty::NORMAL: sres = &starting_resource[1]; break; - case Difficulty::HARD: sres = &starting_resource[2]; break; - case Difficulty::EXPERT: sres = &starting_resource[3]; break; - case Difficulty::IMPOSSIBLE: sres = &starting_resource[4]; break; - default: break; - } - - if(Game::AI == control) sres = &starting_resource[5]; - if(sres) PaymentLoadCost(resource, *sres); -} - -void Kingdom::SetModes(flags_t f) -{ - flags |= f; -} - -void Kingdom::ResetModes(flags_t f) -{ - flags &= ~f; -} - -bool Kingdom::Modes(flags_t f) const -{ - return flags & f; -} - -bool Kingdom::isLoss(void) const -{ - return castles.empty() && heroes.empty(); -} - -void Kingdom::LossPostActions(void) -{ - if(Modes(PLAY)) - { - ResetModes(PLAY); - if(heroes.size()) - { - std::for_each(heroes.begin(), heroes.end(), std::bind2nd(std::mem_fun(&Heroes::SetFreeman), static_cast(Battle2::RESULT_LOSS))); - heroes.clear(); - } - if(castles.size()) castles.clear(); - world.KingdomLoss(color); - } -} - -void Kingdom::ActionBeforeTurn(void) -{ - // rescan heroes path - std::for_each(heroes.begin(), heroes.end(), std::mem_fun(&Heroes::RescanPath)); -} - -void Kingdom::ActionNewDay(void) -{ - Settings::Get().SetCurrentColor(color); - - if(isLoss() || 0 == lost_town_days) - { - LossPostActions(); - return; - } - - // modes - ResetModes(IDENTIFYHERO); - - // check lost town - if(castles.empty()) --lost_town_days; - - // skip incomes for first day - if(1 < world.CountDay()) - { - // castle New Day - std::for_each(castles.begin(), castles.end(), std::mem_fun(&Castle::ActionNewDay)); - - // heroes New Day - std::for_each(heroes.begin(), heroes.end(), std::mem_fun(&Heroes::ActionNewDay)); - - // captured object - resource += ProfitConditions::FromMine(Resource::WOOD) * world.CountCapturedObject(MP2::OBJ_SAWMILL, color); - resource += ProfitConditions::FromMine(Resource::ORE) * world.CountCapturedMines(Resource::ORE, color); - resource += ProfitConditions::FromMine(Resource::MERCURY) * world.CountCapturedObject(MP2::OBJ_ALCHEMYLAB, color); - resource += ProfitConditions::FromMine(Resource::SULFUR) * world.CountCapturedMines(Resource::SULFUR, color); - resource += ProfitConditions::FromMine(Resource::CRYSTAL) * world.CountCapturedMines(Resource::CRYSTAL, color); - resource += ProfitConditions::FromMine(Resource::GEMS) * world.CountCapturedMines(Resource::GEMS, color); - resource += ProfitConditions::FromMine(Resource::GOLD) * world.CountCapturedMines(Resource::GOLD, color); - - // funds - std::vector::const_iterator itc = castles.begin(); - for(; itc != castles.end(); ++itc) if(*itc) - { - const Castle & castle = **itc; - - // castle or town profit - resource += ProfitConditions::FromBuilding((castle.isCastle() ? BUILD_CASTLE : BUILD_TENT), 0); - - // statue - if(castle.isBuild(BUILD_STATUE)) - resource += ProfitConditions::FromBuilding(BUILD_STATUE, 0); - - // dungeon for warlock - if(castle.isBuild(BUILD_SPEC) && Race::WRLK == castle.GetRace()) - resource += ProfitConditions::FromBuilding(BUILD_SPEC, Race::WRLK); - } - } - - // check event day - std::vector events; - events.reserve(5); - world.GetEventDay(color, events); - std::vector::const_iterator it1 = events.begin(); - std::vector::const_iterator it2 = events.end(); - - for(; it1 != it2; ++it1) if(*it1) AddFundsResource((*it1)->GetResource()); - - // remove day visit object - visit_object.remove_if(Visit::isDayLife); -} - -void Kingdom::ActionNewWeek(void) -{ - // skip first day - if(1 < world.CountDay()) - { - // castle New Week - std::for_each(castles.begin(), castles.end(), std::mem_fun(&Castle::ActionNewWeek)); - - // heroes New Week - std::for_each(heroes.begin(), heroes.end(), std::mem_fun(&Heroes::ActionNewWeek)); - - // debug an gift - if(IS_DEVEL() && Game::LOCAL == Control()) - { - DEBUG(DBG_GAME , DBG_INFO, "Kingdom::ActionNewWeek: for the best debugging, God has sent you a gift."); - - resource.wood += 20; - resource.ore += 20; - resource.sulfur += 10; - resource.crystal += 10; - resource.gems += 10; - resource.mercury += 10; - resource.gold += 5000; - } - } - - // remove week visit object - visit_object.remove_if(Visit::isWeekLife); - - UpdateRecruits(); -} - -void Kingdom::ActionNewMonth(void) -{ - // skip first day - if(1 < world.CountDay()) - { - // castle New Month - std::for_each(castles.begin(), castles.end(), std::mem_fun(&Castle::ActionNewMonth)); - - // heroes New Month - std::for_each(heroes.begin(), heroes.end(), std::mem_fun(&Heroes::ActionNewMonth)); - } - - // remove week visit object - visit_object.remove_if(Visit::isMonthLife); -} - -void Kingdom::AddHeroes(const Heroes *hero) -{ - if(hero && heroes.end() == std::find(heroes.begin(), heroes.end(), hero)) - heroes.push_back(const_cast(hero)); -} - -void Kingdom::RemoveHeroes(const Heroes *hero) -{ - if(hero && heroes.size()) - heroes.erase(std::find(heroes.begin(), heroes.end(), hero)); - - if(isLoss()) LossPostActions(); -} - -void Kingdom::AddCastle(const Castle *castle) -{ - if(castle && castles.end() == std::find(castles.begin(), castles.end(), castle)) - castles.push_back(const_cast(castle)); - - lost_town_days = Game::GetLostTownDays() + 1; -} - -void Kingdom::RemoveCastle(const Castle *castle) -{ - if(castle && castles.size()) - castles.erase(std::find(castles.begin(), castles.end(), castle)); - - if(ai_capital == castle) - { - const_cast(castle)->ResetModes(Castle::CAPITAL); - ai_capital = NULL; - } - - if(isLoss()) LossPostActions(); -} - -u8 Kingdom::GetCountCastle(void) const -{ - return std::count_if(castles.begin(), castles.end(), Castle::PredicateIsCastle); -} - -u8 Kingdom::GetCountTown(void) const -{ - return std::count_if(castles.begin(), castles.end(), Castle::PredicateIsTown); -} - -u8 Kingdom::GetCountMarketplace(void) const -{ - return std::count_if(castles.begin(), castles.end(), Castle::PredicateIsBuildMarketplace); -} - -u8 Kingdom::GetCountNecromancyShrineBuild(void) const -{ - return std::count_if(castles.begin(), castles.end(), std::mem_fun(&Castle::isNecromancyShrineBuild)); -} - -u8 Kingdom::GetCountBuilding(u32 build) const -{ - return std::count_if(castles.begin(), castles.end(), std::bind2nd(std::mem_fun(&Castle::isBuild), build)); -} - -Race::race_t Kingdom::GetRace(void) const -{ - return Settings::Get().KingdomRace(color); -} - -bool Kingdom::AllowPayment(const Resource::funds_t & funds) const -{ - return funds > resource ? false : true; -} - -/* is visited cell */ -bool Kingdom::isVisited(const Maps::Tiles & tile) const -{ - return isVisited(tile.GetIndex(), tile.GetObject()); -} - -bool Kingdom::isVisited(s32 index, u8 object) const -{ - std::list::const_iterator it = std::find_if(visit_object.begin(), visit_object.end(), std::bind2nd(std::mem_fun_ref(&IndexObject::isIndex), index)); - return visit_object.end() != it && (*it).isObject(object); -} - -/* return true if object visited */ -bool Kingdom::isVisited(const u8 object) const -{ - return visit_object.end() != std::find_if(visit_object.begin(), visit_object.end(), std::bind2nd(std::mem_fun_ref(&IndexObject::isObject), object)); -} - -u16 Kingdom::CountVisitedObjects(const MP2::object_t object) const -{ - return std::count_if(visit_object.begin(), visit_object.end(), std::bind2nd(std::mem_fun_ref(&IndexObject::isObject), object)); -} - -/* set visited cell */ -void Kingdom::SetVisited(const s32 index, const MP2::object_t object) -{ - if(!isVisited(index, object) && object != MP2::OBJ_ZERO) visit_object.push_front(IndexObject(index, object)); -} - -bool Kingdom::HeroesMayStillMove(void) const -{ - return heroes.end() != std::find_if(heroes.begin(), heroes.end(), std::mem_fun(&Heroes::MayStillMove)); -} - -void Kingdom::Dump(void) const -{ - world.DateDump(); - std::cout << "Kingdom::Dump: " << "color: " << Color::String(color) << - ", resource: " << - "ore(" << resource.ore << ")," << - "wood(" << resource.wood << ")," << - "mercury(" << resource.mercury << ")," << - "sulfur(" << resource.sulfur << ")," << - "crystal(" << resource.crystal << ")," << - "gems(" << resource.gems << ")," << - "gold(" << resource.gold << ")" << std::endl; -} - -u8 Kingdom::GetCountCapital(void) const -{ - return std::count_if(castles.begin(), castles.end(), Castle::PredicateIsCapital); -} - -void Kingdom::AddFundsResource(const Resource::funds_t & funds) -{ - resource = resource + funds; - - if(0 > resource.wood) resource.wood = 0; - if(0 > resource.mercury) resource.mercury = 0; - if(0 > resource.ore) resource.ore = 0; - if(0 > resource.sulfur) resource.sulfur = 0; - if(0 > resource.crystal) resource.crystal = 0; - if(0 > resource.gems) resource.gems = 0; - if(0 > resource.gold) resource.gold = 0; -} - -void Kingdom::OddFundsResource(const Resource::funds_t & funds) -{ - resource = resource - funds; - - if(0 > resource.wood) resource.wood = 0; - if(0 > resource.mercury) resource.mercury = 0; - if(0 > resource.ore) resource.ore = 0; - if(0 > resource.sulfur) resource.sulfur = 0; - if(0 > resource.crystal) resource.crystal = 0; - if(0 > resource.gems) resource.gems = 0; - if(0 > resource.gold) resource.gold = 0; -} - -u8 Kingdom::GetLostTownDays(void) const -{ - return lost_town_days; -} - -Recruits & Kingdom::GetRecruits(void) -{ - // update hero1 - if(Heroes::UNKNOWN == recruits.GetID1() || (recruits.GetHero1() && !recruits.GetHero1()->isFreeman())) - recruits.SetHero1(world.GetFreemanHeroes(GetRace())); - - // update hero2 - if(Heroes::UNKNOWN == recruits.GetID2() || (recruits.GetHero2() && !recruits.GetHero2()->isFreeman())) - recruits.SetHero2(world.GetFreemanHeroes()); - - if(recruits.GetID1() == recruits.GetID2()) world.UpdateRecruits(recruits); - - return recruits; -} - -void Kingdom::UpdateRecruits(void) -{ - recruits.SetHero1(world.GetFreemanHeroes(GetRace())); - recruits.SetHero2(world.GetFreemanHeroes()); - - if(recruits.GetID1() == recruits.GetID2()) world.UpdateRecruits(recruits); -} - -const Puzzle & Kingdom::PuzzleMaps(void) const -{ - return puzzle_maps; -} - -Puzzle & Kingdom::PuzzleMaps(void) -{ - return puzzle_maps; -} - -void Kingdom::SetVisitTravelersTent(u8 col) -{ - visited_tents_colors |= col; -} - -bool Kingdom::IsVisitTravelersTent(u8 col) const -{ - return visited_tents_colors & col; -} - -bool Kingdom::AllowRecruitHero(bool check_payment, u8 level) const -{ - return (heroes.size() < GetMaxHeroes()) && (!check_payment || AllowPayment(PaymentConditions::RecruitHero(level))); -} - -void Kingdom::ApplyPlayWithStartingHero(void) -{ - if(isPlay() && castles.size()) - { - // get first castle - std::vector::const_iterator it = std::find_if(castles.begin(), castles.end(), std::mem_fun(&Castle::isCastle)); - if(it == castles.end()) it = castles.begin(); - - // check manual set hero (castle position + point(0, 1))? - const Point & cp = (*it)->GetCenter(); - if(world.GetTiles(cp.x, cp.y + 1).GetObject() == MP2::OBJ_HEROES) - { - Heroes *hero = world.GetHeroes((cp.y + 1) * world.w() + cp.x); - // and move manual set hero to castle - if(hero && hero->GetColor() == GetColor()) - { - hero->SetFreeman(0); - hero->Recruit(**it); - } - } - else - if(Settings::Get().GameStartWithHeroes()) - { - Heroes *hero = world.GetFreemanHeroes((*it)->GetRace()); - if(hero && AllowRecruitHero(false, 0)) hero->Recruit(**it); - } - } -} - -void Kingdom::SetMaxHeroes(u8 max) -{ - max_heroes = max; -} - -u8 Kingdom::GetMaxHeroes(void) -{ - return max_heroes; -} - -void Kingdom::HeroesActionNewPosition(void) -{ - // Heroes::ActionNewPosition: can ramove elements from heroes vector. - size_t size = heroes.size(); - std::vector::iterator it = heroes.begin(); - - while(it != heroes.end()) - { - (**it).ActionNewPosition(); - - if(size != heroes.size()) - size = heroes.size(); - else - ++it; - } -} - -u32 Kingdom::GetIncome(void) -{ - Resource::funds_t resource; - - // captured object - //resource += ProfitConditions::FromMine(Resource::WOOD) * world.CountCapturedObject(MP2::OBJ_SAWMILL, color); - //resource += ProfitConditions::FromMine(Resource::ORE) * world.CountCapturedMines(Resource::ORE, color); - //resource += ProfitConditions::FromMine(Resource::MERCURY) * world.CountCapturedObject(MP2::OBJ_ALCHEMYLAB, color); - //resource += ProfitConditions::FromMine(Resource::SULFUR) * world.CountCapturedMines(Resource::SULFUR, color); - //resource += ProfitConditions::FromMine(Resource::CRYSTAL) * world.CountCapturedMines(Resource::CRYSTAL, color); - //resource += ProfitConditions::FromMine(Resource::GEMS) * world.CountCapturedMines(Resource::GEMS, color); - resource += ProfitConditions::FromMine(Resource::GOLD) * world.CountCapturedMines(Resource::GOLD, color); - - std::vector::const_iterator itc = castles.begin(); - for(; itc != castles.end(); ++itc) if(*itc) - { - const Castle & castle = **itc; - - // castle or town profit - resource += ProfitConditions::FromBuilding((castle.isCastle() ? BUILD_CASTLE : BUILD_TENT), 0); - - // statue - if(castle.isBuild(BUILD_STATUE)) - resource += ProfitConditions::FromBuilding(BUILD_STATUE, 0); - - // dungeon for warlock - if(castle.isBuild(BUILD_SPEC) && Race::WRLK == castle.GetRace()) - resource += ProfitConditions::FromBuilding(BUILD_SPEC, Race::WRLK); - } - - std::vector::const_iterator ith = heroes.begin(); - for(; ith != heroes.end(); ++ith) if(*ith) - { - if((**ith).HasArtifact(Artifact::GOLDEN_GOOSE)) resource += ProfitConditions::FromArtifact(Artifact::GOLDEN_GOOSE); - if((**ith).HasArtifact(Artifact::ENDLESS_SACK_GOLD)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_SACK_GOLD); - if((**ith).HasArtifact(Artifact::ENDLESS_BAG_GOLD)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_BAG_GOLD); - if((**ith).HasArtifact(Artifact::ENDLESS_PURSE_GOLD)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_PURSE_GOLD); - //if((**ith).HasArtifact(Artifact::ENDLESS_POUCH_SULFUR)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_POUCH_SULFUR); - //if((**ith).HasArtifact(Artifact::ENDLESS_VIAL_MERCURY)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_VIAL_MERCURY); - //if((**ith).HasArtifact(Artifact::ENDLESS_POUCH_GEMS)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_POUCH_GEMS); - //if((**ith).HasArtifact(Artifact::ENDLESS_CORD_WOOD)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_CORD_WOOD); - //if((**ith).HasArtifact(Artifact::ENDLESS_CART_ORE)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_CART_ORE); - //if((**ith).HasArtifact(Artifact::ENDLESS_POUCH_CRYSTAL)) resource += ProfitConditions::FromArtifact(Artifact::ENDLESS_POUCH_CRYSTAL); - - // estates skill bonus - resource.gold += (**ith).GetSecondaryValues(Skill::Secondary::ESTATES); - - if((**ith).HasArtifact(Artifact::TAX_LIEN)) resource.gold -= 250; - } - - return resource.gold; -} - -const Heroes* Kingdom::GetBestHero(void) const -{ - return heroes.size() ? *std::max_element(heroes.begin(), heroes.end(), HeroesStrongestArmy) : NULL; -} - -u32 Kingdom::GetArmiesStrength(void) const -{ - double res = 0; - - std::vector::const_iterator ith = heroes.begin(); - for(; ith != heroes.end(); ++ith) if(*ith) res += (**ith).GetArmy().GetStrength(); - - std::vector::const_iterator itc = castles.begin(); - for(; itc != castles.end(); ++itc) if(*itc) res += (**itc).GetArmy().GetStrength(); - - return static_cast(res); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/kingdom.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/kingdom.h deleted file mode 100644 index fae9a738a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/kingdom.h +++ /dev/null @@ -1,174 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2KINGDOM_H -#define H2KINGDOM_H - -#include -#include -#include "race.h" -#include "color.h" -#include "payment.h" -#include "puzzle.h" -#include "game.h" -#include "mp2.h" -#include "pairs.h" -#include "game_io.h" -#include "heroes_recruits.h" - -class Castle; -class Heroes; - -class Kingdom -{ -public: - enum flags_t - { - PLAY = 0x0001, - IDENTIFYHERO = 0x0002 - }; - - Kingdom(); - Kingdom(const Color::color_t cl); - - void SetModes(flags_t); - void ResetModes(flags_t); - bool Modes(flags_t) const; - - Game::control_t Control(void) const{ return control; } - void SetControl(const Game::control_t con) { control = con; } - void UpdateStartingResource(void); - bool isPlay(void) const{ return Modes(PLAY); } - bool isLoss(void) const; - bool AllowPayment(const Resource::funds_t & funds) const; - bool AllowRecruitHero(bool check_payment, u8 level) const; - - Color::color_t GetColor(void) const{ return color; } - Race::race_t GetRace(void) const; - - const Resource::funds_t & GetFundsResource(void) const{ return resource; } - u16 GetFundsWood(void) const{ return resource.wood; } - u16 GetFundsMercury(void) const{ return resource.mercury; } - u16 GetFundsOre(void) const{ return resource.ore; } - u16 GetFundsSulfur(void) const{ return resource.sulfur; } - u16 GetFundsCrystal(void) const{ return resource.crystal; } - u16 GetFundsGems(void) const{ return resource.gems; } - u32 GetFundsGold(void) const{ return resource.gold; } - - u32 GetIncome(void); - const Heroes* GetBestHero(void) const; - u32 GetArmiesStrength(void) const; - - void AddFundsResource(const Resource::funds_t & funds); - void OddFundsResource(const Resource::funds_t & funds); - - u8 GetCountCastle(void) const; - u8 GetCountTown(void) const; - u8 GetCountMarketplace(void) const; - u8 GetCountCapital(void) const; - u8 GetLostTownDays(void) const; - u8 GetCountNecromancyShrineBuild(void) const; - u8 GetCountBuilding(u32) const; - - Recruits & GetRecruits(void); - - const std::vector & GetHeroes(void) const{ return heroes; } - const std::vector & GetCastles(void) const{ return castles; } - - std::vector & GetHeroes(void) { return heroes; } - std::vector & GetCastles(void) { return castles; } - - void AddHeroes(const Heroes *hero); - void RemoveHeroes(const Heroes *hero); - void ApplyPlayWithStartingHero(void); - void HeroesActionNewPosition(void); - - void AddCastle(const Castle *castle); - void RemoveCastle(const Castle *castle); - - void AITurns(void); - void ActionBeforeTurn(void); - void ActionNewDay(void); - void ActionNewWeek(void); - void ActionNewMonth(void); - - void SetVisited(const s32 index, const MP2::object_t object = MP2::OBJ_ZERO); - u16 CountVisitedObjects(const MP2::object_t) const; - bool isVisited(const u8 object) const; - bool isVisited(const Maps::Tiles &) const; - bool isVisited(s32, u8) const; - - bool HeroesMayStillMove(void) const; - - const Puzzle & PuzzleMaps(void) const; - Puzzle & PuzzleMaps(void); - - void SetVisitTravelersTent(u8); - bool IsVisitTravelersTent(u8) const; - - void Dump(void) const; - -#ifdef WITH_XML - static void UpdateStartingResource(const TiXmlElement*); -#endif - - static void SetMaxHeroes(u8); - static u8 GetMaxHeroes(void); - -private: - friend class Game::IO; - - void UpdateRecruits(void); - void LossPostActions(void); - - void AICastlesTurns(void); - void AIHeroesTurns(Heroes &); - void AIHeroesNoGUITurns(Heroes &); - void AIHeroesGetTask(Heroes &); - void AIHeroesPrepareTask(Heroes &); - void AIDumpCacheObjects(const IndexDistance &) const; - - Color::color_t color; - Game::control_t control; - Resource::funds_t resource; - - u16 flags; - u8 lost_town_days; - - std::vector castles; - std::vector heroes; - - Recruits recruits; - - Castle *ai_capital; - std::map ai_objects; - - std::list visit_object; - - Puzzle puzzle_maps; - u8 visited_tents_colors; - - static cost_t starting_resource[]; - - static u8 max_heroes; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/kingdom_ai.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/kingdom_ai.cpp deleted file mode 100644 index 4b65f1405..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/kingdom_ai.cpp +++ /dev/null @@ -1,522 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "game.h" -#include "cursor.h" -#include "engine.h" -#include "game_interface.h" -#include "interface_gamearea.h" -#include "heroes.h" -#include "castle.h" -#include "world.h" -#include "settings.h" -#include "kingdom.h" -#include "agg.h" - -#define HERO_MAX_SHEDULED_TASK 7 - -void Kingdom::AIDumpCacheObjects(const IndexDistance & id) const -{ - std::map::const_iterator it = ai_objects.find(id.first); - if(it != ai_objects.end()) - DEBUG(DBG_AI , DBG_TRACE, "AIDumpCacheObjects: " << MP2::StringObject((*it).second) << ", maps index: " << id.first << ", dist: " << id.second); -} - -void Kingdom::AITurns(void) -{ - if(isLoss() || color == Color::GRAY) - { - LossPostActions(); - return; - } - - if(! Settings::Get().MusicMIDI()) AGG::PlayMusic(MUS::COMPUTER); - - Interface::StatusWindow *status = Interface::NoGUI() ? NULL : &Interface::StatusWindow::Get(); - - // turn indicator - if(status) status->RedrawTurnProgress(0); - - // scan map - ai_objects.clear(); - world.StoreActionObject(GetColor(), ai_objects); - DEBUG(DBG_AI , DBG_INFO, "Kingdom::AITurns: " << Color::String(color) << ", size cache objects: " << ai_objects.size()); - - // set capital - if(NULL == ai_capital && castles.size()) - { - std::vector::iterator it = std::find_if(castles.begin(), castles.end(), Castle::PredicateIsCastle); - - if(castles.end() != it) - { - if(*it) - { - ai_capital = *it; - ai_capital->SetModes(Castle::CAPITAL); - } - } - else - // first town - { - ai_capital = castles.front(); - ai_capital->SetModes(Castle::CAPITAL); - } - } - - // turn indicator - if(status) status->RedrawTurnProgress(1); - - // castle AI turn - AICastlesTurns(); - - const u8 maxhero = Maps::XLARGE > world.w() ? (Maps::LARGE > world.w() ? 3 : 2) : 4; - - // buy hero in capital - if((heroes.empty() || heroes.size() < maxhero) && - ai_capital && ai_capital->isCastle()) - { - Recruits & rec = GetRecruits(); - - if(rec.GetHero1()) ai_capital->RecruitHero(rec.GetHero1()); - else - if(rec.GetHero2()) ai_capital->RecruitHero(rec.GetHero2()); - } - - // update roles - if(heroes.size()) - { - std::for_each(heroes.begin(), heroes.end(), std::mem_fun(&Heroes::ResetStupidFlag)); - std::for_each(heroes.begin(), heroes.end(), std::bind2nd(std::mem_fun(&Heroes::SetModes), Heroes::SCOUTER)); - heroes.front()->SetModes(Heroes::HUNTER); - } - - // turn indicator - if(status) status->RedrawTurnProgress(2); - - // heroes turns - std::vector::const_iterator ith1 = heroes.begin(); - std::vector::const_iterator ith2 = heroes.end(); - - for(; ith1 != ith2; ++ith1) if(*ith1) - { - Heroes & hero = **ith1; - - while(hero.MayStillMove()) - { - // turn indicator - if(status) status->RedrawTurnProgress(3); - //if(status) status->RedrawTurnProgress(4); - - // get task for heroes - AIHeroesGetTask(hero); - - // turn indicator - if(status) status->RedrawTurnProgress(5); - //if(status) status->RedrawTurnProgress(6); - - // heroes AI turn - if(Interface::NoGUI()) - AIHeroesNoGUITurns(hero); - else - AIHeroesTurns(hero); - - // turn indicator - if(status) status->RedrawTurnProgress(7); - //if(status) status->RedrawTurnProgress(8); - } - } - - // turn indicator - if(status) status->RedrawTurnProgress(9); - - DEBUG(DBG_AI , DBG_INFO, "Kingdom::AITurns: " << Color::String(color) << " moved"); -} - -void Kingdom::AICastlesTurns(void) -{ - std::vector::const_iterator itc1 = castles.begin(); - std::vector::const_iterator itc2 = castles.end(); - - for(; itc1 != itc2; ++itc1) if(*itc1) - { - Castle & castle = **itc1; - const s8 range = Game::GetViewDistance(castle.isCastle() ? Game::VIEW_CASTLE : Game::VIEW_TOWN); - bool defense = false; - - // find enemy hero - for(s8 y = -range; y <= range && !defense; ++y) - for(s8 x = -range; x <= range && !defense; ++x) - { - if(!y && !x) continue; - - if(Maps::isValidAbsPoint(castle.GetCenter().x + x, castle.GetCenter().y + y)) - { - const Maps::Tiles & tile = world.GetTiles(Maps::GetIndexFromAbsPoint(castle.GetCenter().x + x, castle.GetCenter().y + y)); - const Heroes* hero = NULL; - - if(MP2::OBJ_HEROES == tile.GetObject() && NULL != (hero = world.GetHeroes(tile.GetIndex())) && GetColor() != hero->GetColor()) - defense = true; - } - } - - defense ? castle.AIDefense() : castle.AIDevelopment(); - } -} - -void Kingdom::AIHeroesTurns(Heroes &hero) -{ - if(hero.GetPath().isValid()) hero.SetMove(true); - else return; - - const Settings & conf = Settings::Get(); - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - Interface::Basic & I = Interface::Basic::Get(); - - cursor.Hide(); - - if(0 != conf.AIMoveSpeed() && hero.isShow(Settings::Get().MyColor())) - { - cursor.Hide(); - I.gameArea.Center(hero.GetCenter()); - I.Redraw(REDRAW_GAMEAREA); - cursor.Show(); - display.Flip(); - } - - bool hide_move = (0 == conf.AIMoveSpeed()) || - (! IS_DEVEL() && !hero.isShow(Settings::Get().MyColor())); - - while(LocalEvent::Get().HandleEvents()) - { - if(hero.isFreeman() || !hero.isEnableMove()) break; - - if(hide_move) - { - hero.Move(true); - } - else - if(Game::AnimateInfrequent(Game::CURRENT_AI_DELAY)) - { - cursor.Hide(); - hero.Move(); - - I.gameArea.Center(hero.GetCenter()); - I.Redraw(REDRAW_GAMEAREA); - cursor.Show(); - display.Flip(); - } - - if(Game::AnimateInfrequent(Game::MAPS_DELAY)) - { - Maps::IncreaseAnimationTicket(); - cursor.Hide(); - I.Redraw(REDRAW_GAMEAREA); - cursor.Show(); - display.Flip(); - } - } - - // 0.2 sec delay for show enemy hero position - if(!hero.isFreeman() && !hide_move) DELAY(200); -} - -void Kingdom::AIHeroesNoGUITurns(Heroes &hero) -{ - if(hero.GetPath().isValid()) hero.SetMove(true); - else return; - - while(1) - { - if(hero.isFreeman() || !hero.isEnableMove()) break; - - hero.Move(true); - - DELAY(10); - } -} - -void Kingdom::AIHeroesGetTask(Heroes & hero) -{ - std::deque & task = hero.GetAITasks(); - - std::vector results; - results.reserve(5); - - // patrol task - if(hero.Modes(Heroes::PATROL)) - { - // goto patrol center - if(hero.GetCenterPatrol() != hero.GetCenter() && - hero.GetPath().Calculate(Maps::GetIndexFromAbsPoint(hero.GetCenterPatrol()))) - return; - - // scan enemy hero - if(Maps::ScanDistanceObject(Maps::GetIndexFromAbsPoint(hero.GetCenterPatrol()), - MP2::OBJ_HEROES, hero.GetSquarePatrol(), results)) - { - std::vector::const_iterator it = results.begin(); - for(; it != results.end(); ++it) - { - const Heroes* enemy = world.GetHeroes(*it); - if(enemy && !Settings::Get().IsUnions(enemy->GetColor(), hero.GetColor())) - { - if(hero.GetPath().Calculate(enemy->GetIndex())) - return; - } - } - } - - hero.SetModes(Heroes::STUPID); - return; - } - - // primary target - if(Maps::isValidAbsIndex(hero.GetPrimaryTarget())) - { - if(hero.GetIndex() == hero.GetPrimaryTarget()) - hero.SetPrimaryTarget(-1); - else - if(hero.GetPrimaryTarget() != hero.GetPath().GetDestinationIndex() && - !hero.GetPath().Calculate(hero.GetPrimaryTarget())) - { - DEBUG(DBG_AI , DBG_INFO, "AI::HeroesTask: " << Color::String(color) << - ", Hero " << hero.GetName() << ": path unknown, primary target reset"); - - hero.SetPrimaryTarget(-1); - } - - if(hero.GetPath().isValid()) return; - } - - // scan heroes and castle - if(Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_CASTLE, hero.GetScoute(), results) || - Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_HEROES, hero.GetScoute(), results)) - { - std::vector::const_iterator it = results.begin(); - - for(; it != results.end(); ++it) - if(hero.AIPriorityObject(*it) && - hero.GetPath().Calculate(*it)) - { - DEBUG(DBG_AI , DBG_INFO, "AI::HeroesTask: " << Color::String(color) << - ", Hero " << hero.GetName() << ": set primary target: " << - MP2::StringObject(world.GetTiles(*it).GetObject()) << "(" << *it << ")"); - - hero.SetPrimaryTarget(*it); - return; - } - } - - // check destination - if(hero.GetPath().isValid()) - { - if(!hero.AIValidObject(hero.GetPath().GetDestinationIndex())) - hero.GetPath().Reset(); - else - if(hero.GetPath().size() < 5) - { - DEBUG(DBG_AI , DBG_INFO, "AI::HeroesTask: " << Color::String(color) << - ", Hero " << hero.GetName() << ": continue" << " short"); - - return; - } - } - - // scan 2x2 pickup objects - if(Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_ARTIFACT, 2, results) || - Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_RESOURCE, 2, results) || - Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_CAMPFIRE, 2, results) || - Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_TREASURECHEST, 2, results) || - // scan 3x3 capture objects - Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_SAWMILL, 3, results) || - Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_MINES, 3, results) || - Maps::ScanDistanceObject(hero.GetIndex(), MP2::OBJ_ALCHEMYLAB, 3, results)) - { - std::vector::const_iterator it = results.begin(); - for(; it != results.end(); ++it) - if(hero.AIPriorityObject(*it) && - hero.GetPath().Calculate(*it)) - { - ai_objects.erase(*it); - - DEBUG(DBG_AI , DBG_INFO, "AI::HeroesTask: " << Color::String(color) << - ", Hero " << hero.GetName() << ": find object: " << - MP2::StringObject(world.GetTiles(*it).GetObject()) << "(" << *it << ")"); - - return; - } - } - - if(hero.GetPath().isValid()) - { - DEBUG(DBG_AI , DBG_INFO, "AI::HeroesTask: " << Color::String(color) << - ", Hero " << hero.GetName() << ": continue"); - - return; - } - - // get task from kingdom - if(task.empty()) AIHeroesPrepareTask(hero); - - // random shuffle - if(1 < task.size()) - std::random_shuffle(task.begin(), task.begin() + (2 < task.size() ? 2 : 1)); - - // find passable index - while(task.size()) - { - const s32 & index = task.front(); - - if(hero.GetPath().Calculate(index)) break; - - DEBUG(DBG_AI , DBG_INFO, "AI::HeroesTask: " << Color::String(color) << - ", Hero " << hero.GetName() << " say: unable get object: " << - MP2::StringObject(world.GetTiles(index).GetObject()) << ", index: " << - index << ", remove task..."); - - task.pop_front(); - } - - // success - if(task.size()) - { - const s32 & index = task.front(); - - DEBUG(DBG_AI , DBG_INFO, "AI::HeroesTask: " << Color::String(color) << - ", Hero " << hero.GetName() << " say: go to object: " << - MP2::StringObject(world.GetTiles(index).GetObject()) << ", index: " << index); - - ai_objects.erase(index); - task.pop_front(); - - if(IS_DEBUG(DBG_AI, DBG_TRACE)) hero.GetPath().Dump(); - } - else - { - hero.GetPath().Reset(); - DEBUG(DBG_AI , DBG_INFO, "AI::HeroesTask: " << Color::String(color) << - ", Hero " << hero.GetName() << " say: unknown task., help my please.."); - - hero.SetModes(Heroes::STUPID); - } -} - -void Kingdom::AIHeroesPrepareTask(Heroes & hero) -{ - if(hero.GetPath().isValid()) return; - - std::deque & task = hero.GetAITasks(); - - Castle *castle = hero.inCastle(); - - DEBUG(DBG_AI , DBG_INFO, "Kingdom::AIHeroesTask: " << Color::String(color) << - ", hero: " << hero.GetName() << ", task prepare"); - - // if hero in castle - if(castle) - { - castle->RecruitAllMonster(); - hero.GetArmy().UpgradeTroops(*castle); - - // recruit army - if(hero.Modes(Heroes::HUNTER)) - hero.GetArmy().JoinStrongestFromArmy(castle->GetArmy()); - else - if(hero.Modes(Heroes::SCOUTER)) - hero.GetArmy().KeepOnlyWeakestTroops(castle->GetArmy()); - } - - // load minimal distance tasks - std::vector objs; - objs.reserve(ai_objects.size()); - - for(std::map::const_iterator - it = ai_objects.begin(); it != ai_objects.end(); ++it) - { - if(hero.isShipMaster()) - { - if(MP2::isGroundObject((*it).second)) continue; - - // check previous positions - if(MP2::OBJ_COAST == (*it).second && - hero.isVisited(world.GetTiles((*it).first))) continue; - } - else - { - if(MP2::isWaterObject((*it).second)) continue; - } - - objs.push_back(IndexDistance((*it).first, - Maps::GetApproximateDistance(hero.GetIndex(), (*it).first))); - } - - std::sort(objs.begin(), objs.end(), IndexDistance::Shortest); - - for(std::vector::const_iterator - it = objs.begin(); it != objs.end(); ++it) - { - if(task.size() >= HERO_MAX_SHEDULED_TASK) break; - - if(hero.AIValidObject((*it).first) && - hero.GetPath().Calculate((*it).first)) - { - s32 pos = 0; - - // path dangerous - if(u16 around = hero.GetPath().isUnderProtection(pos)) - { - bool skip = false; - for(Direction::vector_t - dir = Direction::TOP_LEFT; dir < Direction::CENTER && !skip; ++dir) if(around & dir) - { - const s32 dst = Maps::GetDirectionIndex(pos, dir); - Army::army_t enemy; - enemy.FromGuardian(world.GetTiles(dst)); - if(enemy.isValid() && enemy.StrongerEnemyArmy(hero.GetArmy())) skip = true; - } - if(skip) continue; - } - - DEBUG(DBG_AI , DBG_INFO, "Kingdom::AIHeroesTask: " << Color::String(color) << - ", hero: " << hero.GetName() << ", added tasks: " << - MP2::StringObject(ai_objects[(*it).first]) << ", index: " << (*it).first << - ", distance: " << (*it).second); - - task.push_back((*it).first); - ai_objects.erase((*it).first); - } - else - { - DEBUG(DBG_AI , DBG_TRACE, "Kingdom::AIHeroesTask: " << Color::String(color) << - ", hero: " << hero.GetName() << ", impossible: " << - MP2::StringObject(ai_objects[(*it).first]) << ", index: " << (*it).first << - ", distance: " << (*it).second); - } - } - - if(task.empty()) - hero.AIRescueWhereMove(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/luck.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/luck.cpp deleted file mode 100644 index eab5a9688..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/luck.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "luck.h" - -const char* Luck::String(s8 luck) -{ - const char* str_luck[] = { "Unknown", _("luck|Cursed"), _("luck|Awful"), _("luck|Bad"), _("luck|Normal"), _("luck|Good"), _("luck|Great"), _("luck|Irish") }; - - switch(luck) - { - case Luck::CURSED: return str_luck[1]; - case Luck::AWFUL: return str_luck[2]; - case Luck::BAD: return str_luck[3]; - case Luck::NORMAL: return str_luck[4]; - case Luck::GOOD: return str_luck[5]; - case Luck::GREAT: return str_luck[6]; - case Luck::IRISH: return str_luck[7]; - default: break; - } - - return str_luck[0]; -} - -const char* Luck::Description(s8 luck) -{ - const char* str_desc_luck[] = { "Unknown", - _("Bad luck sometimes falls on your armies in combat, causing their attacks to only do half damage."), - _("Neutral luck means your armies will never get lucky or unlucky attacks on the enemy."), - _("Good luck sometimes lets your armies get lucky attacks (double strength) in combat.") }; - - switch(luck) - { - case Luck::CURSED: - case Luck::AWFUL: - case Luck::BAD: return str_desc_luck[1]; - case Luck::NORMAL: return str_desc_luck[2]; - case Luck::GOOD: - case Luck::GREAT: - case Luck::IRISH: return str_desc_luck[3]; - default: break; - } - - return str_desc_luck[0]; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/luck.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/luck.h deleted file mode 100644 index 6354a0c58..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/luck.h +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2LUCK_H -#define H2LUCK_H - -#include -#include "gamedefs.h" - -namespace Luck -{ - enum luck_t - { - UNKNOWN = -4, - CURSED = -3, - AWFUL = -2, - BAD = -1, - NORMAL = 0, - GOOD = 1, - GREAT = 2, - IRISH = 3 - }; - - const char* String(s8); - const char* Description(s8); - - inline luck_t & operator++ (luck_t & luck){ return luck = IRISH == luck ? IRISH : luck_t(luck + 1); } - inline luck_t & operator-- (luck_t & luck){ return luck = CURSED == luck ? CURSED : luck_t(luck - 1); } -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/morale.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/morale.cpp deleted file mode 100644 index c9885570d..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/morale.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "morale.h" - -const char* Morale::String(s8 morale) -{ - const char* str_morale[] = { "Unknown", _("morale|Treason"), _("morale|Awful"), _("morale|Poor"), _("morale|Normal"), _("morale|Good"), _("morale|Great"), _("morale|Blood!") }; - - switch(morale) - { - case Morale::TREASON: return str_morale[1]; - case Morale::AWFUL: return str_morale[2]; - case Morale::POOR: return str_morale[3]; - case Morale::NORMAL: return str_morale[4]; - case Morale::GOOD: return str_morale[5]; - case Morale::GREAT: return str_morale[6]; - case Morale::BLOOD: return str_morale[7]; - default: break; - } - - return str_morale[0]; -} - -const char* Morale::Description(s8 morale) -{ - const char* str_desc_morale[] = { "Unknown", - _("Bad morale may cause your armies to freeze in combat."), - _("Neutral morale means your armies will never be blessed with extra attacks or freeze in combat."), - _("Good morale may give your armies extra attacks in combat.") }; - - switch(morale) - { - case Morale::TREASON: - case Morale::AWFUL: - case Morale::POOR: return str_desc_morale[1]; - case Morale::NORMAL: return str_desc_morale[2]; - case Morale::GOOD: - case Morale::GREAT: - case Morale::BLOOD: return str_desc_morale[3]; - default: break; - } - - return str_desc_morale[0]; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/morale.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/morale.h deleted file mode 100644 index a4486752a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/morale.h +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2MORALE_H -#define H2MORALE_H - -#include "gamedefs.h" -#include - -namespace Morale -{ - enum morale_t - { - UNKNOWN = -4, - TREASON = -3, - AWFUL = -2, - POOR = -1, - NORMAL = 0, - GOOD = 1, - GREAT = 2, - BLOOD = 3 - }; - - const char* String(s8); - const char* Description(s8); - - inline morale_t & operator++ (morale_t & morale){ return morale = BLOOD == morale ? BLOOD : morale_t(morale + 1); } - inline morale_t & operator-- (morale_t & morale){ return morale = TREASON == morale ? TREASON : morale_t(morale - 1); } -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/payment.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/payment.cpp deleted file mode 100644 index d148ecc4f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/payment.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "castle.h" -#include "race.h" -#include "monster.h" -#include "buildinginfo.h" -#include "settings.h" -#include "payment.h" - -#ifdef WITH_XML -#include "xmlccwrap.h" -#endif - -struct paymentstats_t -{ - const char* id; - cost_t cost; -}; - -static paymentstats_t _payments[] = { - { "buy_boat", { 1000,10, 0, 0, 0, 0, 0 } }, - { "buy_spell_book", { 500, 0, 0, 0, 0, 0, 0 } }, - { "buy_spell_book_from_shrine1", { 1250, 0, 0, 0, 0, 0, 0 } }, - { "buy_spell_book_from_shrine2", { 1000, 0, 0, 0, 0, 0, 0 } }, - { "buy_spell_book_from_shrine3", { 750, 0, 0, 0, 0, 0, 0 } }, - { "recruit_hero", { 2500, 0, 0, 0, 0, 0, 0 } }, - { "recruit_level", { 500, 0, 0, 0, 0, 0, 0 } }, - - { NULL, { 0, 0, 0, 0, 0, 0, 0 } }, -}; - -void PaymentLoadCost(payment_t & payment, const cost_t & cost) -{ - payment.gold = cost.gold; - payment.wood = cost.wood; - payment.mercury = cost.mercury; - payment.ore = cost.ore; - payment.sulfur = cost.sulfur; - payment.crystal = cost.crystal; - payment.gems = cost.gems; -} - -#ifdef WITH_XML -void LoadCostFromXMLElement(cost_t & cost, const TiXmlElement & element) -{ - int value; - - element.Attribute("gold", &value); cost.gold = value; - element.Attribute("wood", &value); cost.wood = value; - element.Attribute("mercury", &value); cost.mercury = value; - element.Attribute("ore", &value); cost.ore = value; - element.Attribute("sulfur", &value); cost.sulfur = value; - element.Attribute("crystal", &value); cost.crystal = value; - element.Attribute("gems", &value); cost.gems = value; -} -#endif - -void PaymentConditions::UpdateCosts(const std::string & spec) -{ -#ifdef WITH_XML - // parse payments.xml - TiXmlDocument doc; - const TiXmlElement* xml_payments = NULL; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_payments = doc.FirstChildElement("payments"))) - { - paymentstats_t* ptr = &_payments[0]; - - while(ptr->id) - { - const TiXmlElement* xml_payment = xml_payments->FirstChildElement(ptr->id); - - if(xml_payment) - LoadCostFromXMLElement(ptr->cost, *xml_payment); - - ++ptr; - } - } - else - VERBOSE(spec << ": " << doc.ErrorDesc()); -#endif -} - -PaymentConditions::BuyMonster::BuyMonster(u8 monster) -{ - Monster::GetCost(monster, *this); -} - -PaymentConditions::UpgradeMonster::UpgradeMonster(u8 monster) -{ - Monster::GetUpgradeCost(monster, *this); -} - -PaymentConditions::BuyBuilding::BuyBuilding(u8 race, u32 build) -{ - BuildingInfo::GetCost(build, race, *this); -} - -PaymentConditions::BuyBoat::BuyBoat() -{ - paymentstats_t* ptr = &_payments[0]; - - while(ptr->id && std::strcmp("buy_boat", ptr->id)) ++ptr; - - if(ptr) PaymentLoadCost(*this, ptr->cost); -} - -PaymentConditions::BuySpellBook::BuySpellBook(u8 shrine) -{ - paymentstats_t* ptr = &_payments[0]; - const char* skey = NULL; - - switch(shrine) - { - case 1: skey = "buy_spell_book_from_shrine1"; break; - case 2: skey = "buy_spell_book_from_shrine2"; break; - case 3: skey = "buy_spell_book_from_shrine3"; break; - default: skey = "buy_spell_book"; break; - } - - while(ptr->id && std::strcmp(skey, ptr->id)) ++ptr; - - if(ptr) PaymentLoadCost(*this, ptr->cost); -} - -PaymentConditions::RecruitHero::RecruitHero(u8 level) -{ - paymentstats_t* ptr = &_payments[0]; - while(ptr->id && std::strcmp("recruit_hero", ptr->id)) ++ptr; - if(ptr) PaymentLoadCost(*this, ptr->cost); - - // level price - if(Settings::Get().ExtHeroRecruitCostDependedFromLevel()) - { - ptr = &_payments[0]; - while(ptr->id && std::strcmp("recruit_level", ptr->id)) ++ptr; - if(ptr && 1 < level) - { - if(ptr->cost.gold) gold += (level - 1) * ptr->cost.gold; - if(ptr->cost.wood) wood += (level - 1) * ptr->cost.wood; - if(ptr->cost.mercury) mercury += (level - 1) * ptr->cost.mercury; - if(ptr->cost.ore) ore += (level - 1) * ptr->cost.ore; - if(ptr->cost.sulfur) sulfur += (level - 1) * ptr->cost.sulfur; - if(ptr->cost.crystal) crystal += (level - 1) * ptr->cost.crystal; - if(ptr->cost.gems) gems += (level - 1) * ptr->cost.gems; - } - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/payment.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/payment.h deleted file mode 100644 index 069e24ecf..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/payment.h +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2PAYMENT_H -#define H2PAYMENT_H - -#include "resource.h" - -struct cost_t -{ - u16 gold; - u8 wood; - u8 mercury; - u8 ore; - u8 sulfur; - u8 crystal; - u8 gems; -}; - -typedef Resource::funds_t payment_t; -void PaymentLoadCost(payment_t &, const cost_t &); -#ifdef WITH_XML -struct TiXmlElement; -void LoadCostFromXMLElement(cost_t &, const TiXmlElement &); -#endif - -namespace PaymentConditions -{ - class BuyBuilding : public payment_t - { - public: - BuyBuilding(u8 race, u32 build); - }; - - class BuyMonster : public payment_t - { - public: - BuyMonster(u8 monster); - }; - - class UpgradeMonster : public payment_t - { - public: - UpgradeMonster(u8 monster); - }; - - class BuyBoat : public payment_t - { - public: - BuyBoat(); - }; - - class BuySpellBook : public payment_t - { - public: - BuySpellBook(u8 shrine = 0); - }; - - class RecruitHero : public payment_t - { - public: - RecruitHero(u8 level); - }; - - void UpdateCosts(const std::string &); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/profit.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/profit.cpp deleted file mode 100644 index b455f012a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/profit.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "castle.h" -#include "artifact.h" -#include "skill.h" -#include "settings.h" -#include "profit.h" - -#ifdef WITH_XML -#include "xmlccwrap.h" -#endif - -struct profitstats_t -{ - const char* id; - cost_t cost; -}; - -static profitstats_t _profits[] = { - { "castle", {1000, 0, 0, 0, 0, 0, 0 } }, - { "town", { 250, 0, 0, 0, 0, 0, 0 } }, - { "statue", { 250, 0, 0, 0, 0, 0, 0 } }, - { "dungeon", { 500, 0, 0, 0, 0, 0, 0 } }, - - { "sawmill", { 0, 2, 0, 0, 0, 0, 0 } }, - { "alchemylab", { 0, 0, 1, 0, 0, 0, 0 } }, - { "mine_ore", { 0, 0, 0, 2, 0, 0, 0 } }, - { "mine_sulfur", { 0, 0, 0, 0, 1, 0, 0 } }, - { "mine_crystal", { 0, 0, 0, 0, 0, 1, 0 } }, - { "mine_gems", { 0, 0, 0, 0, 0, 0, 1 } }, - { "mine_gold", {1000, 0, 0, 0, 0, 0, 0 } }, - - { "ultimate_golden_goose", {10000, 0, 0, 0, 0, 0, 0 } }, - { "endless_sack_gold", {1000, 0, 0, 0, 0, 0, 0 } }, - { "endless_bag_gold", { 750, 0, 0, 0, 0, 0, 0 } }, - { "endless_purse_gold", { 500, 0, 0, 0, 0, 0, 0 } }, - { "endless_cord_wood", { 0, 2, 0, 0, 0, 0, 0 } }, - { "endless_vial_mercury", { 0, 0, 1, 0, 0, 0, 0 } }, - { "endless_cart_ore", { 0, 0, 0, 2, 0, 0, 0 } }, - { "endless_pouch_sulfur", { 0, 0, 0, 0, 1, 0, 0 } }, - { "endless_pouch_crystal", { 0, 0, 0, 0, 0, 1, 0 } }, - { "endless_pouch_gems", { 0, 0, 0, 0, 0, 0, 1 } }, - - { NULL, { 0, 0, 0, 0, 0, 0, 0 } }, -}; - -void ProfitConditions::UpdateCosts(const std::string & spec) -{ -#ifdef WITH_XML - // parse profits.xml - TiXmlDocument doc; - const TiXmlElement* xml_profits = NULL; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_profits = doc.FirstChildElement("profits"))) - { - profitstats_t* ptr = &_profits[0]; - - while(ptr->id) - { - const TiXmlElement* xml_profit = xml_profits->FirstChildElement(ptr->id); - - if(xml_profit) - LoadCostFromXMLElement(ptr->cost, *xml_profit); - - ++ptr; - } - } - else - VERBOSE(spec << ": " << doc.ErrorDesc()); -#endif -} - -ProfitConditions::FromBuilding::FromBuilding(u32 building, u8 race) -{ - const char* id = NULL; - - switch(building) - { - case BUILD_CASTLE: id = "castle"; break; - case BUILD_TENT: id = "town"; break; - case BUILD_STATUE: id = "statue"; break; - case BUILD_SPEC: if(race == Race::WRLK) id = "dungeon"; break; - default: break; - } - - profitstats_t* ptr = &_profits[0]; - while(ptr->id && id && std::strcmp(id, ptr->id)) ++ptr; - - if(ptr && id) PaymentLoadCost(*this, ptr->cost); -} - -ProfitConditions::FromArtifact::FromArtifact(u8 artifact) -{ - const char* id = NULL; - - switch(artifact) - { - case Artifact::GOLDEN_GOOSE: id = "ultimate_golden_goose"; break; - case Artifact::ENDLESS_SACK_GOLD: id = "endless_sack_gold"; break; - case Artifact::ENDLESS_BAG_GOLD: id = "endless_bag_gold"; break; - case Artifact::ENDLESS_PURSE_GOLD: id = "endless_purse_gold"; break; - case Artifact::ENDLESS_POUCH_SULFUR: id = "endless_pouch_sulfur"; break; - case Artifact::ENDLESS_VIAL_MERCURY: id = "endless_vial_mercury"; break; - case Artifact::ENDLESS_POUCH_GEMS: id = "endless_pouch_gems"; break; - case Artifact::ENDLESS_CORD_WOOD: id = "endless_cord_wood"; break; - case Artifact::ENDLESS_CART_ORE: id = "endless_cart_ore"; break; - case Artifact::ENDLESS_POUCH_CRYSTAL: id = "endless_pouch_crystal"; break; - default: break; - } - - profitstats_t* ptr = &_profits[0]; - while(ptr->id && id && std::strcmp(id, ptr->id)) ++ptr; - - if(ptr && id) PaymentLoadCost(*this, ptr->cost); -} - -ProfitConditions::FromMine::FromMine(u8 type) -{ - const char* id = NULL; - - switch(type) - { - case Resource::ORE: id = "mine_ore"; break; - case Resource::WOOD: id = "sawmill"; break; - case Resource::MERCURY: id = "alchemylab"; break; - case Resource::SULFUR: id = "mine_sulfur"; break; - case Resource::CRYSTAL: id = "mine_crystal"; break; - case Resource::GEMS: id = "mine_gems"; break; - case Resource::GOLD: id = "mine_gold"; break; - default: break; - } - - profitstats_t* ptr = &_profits[0]; - while(ptr->id && id && std::strcmp(id, ptr->id)) ++ptr; - - if(ptr && id) PaymentLoadCost(*this, ptr->cost); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/profit.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/profit.h deleted file mode 100644 index 557f508ad..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/profit.h +++ /dev/null @@ -1,51 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2PROFIT_H -#define H2PROFIT_H - -#include "payment.h" - -namespace ProfitConditions -{ - class FromBuilding : public payment_t - { - public: - FromBuilding(u32, u8); - }; - - class FromArtifact : public payment_t - { - public: - FromArtifact(u8); - }; - - class FromMine : public payment_t - { - public: - FromMine(u8); - }; - - void UpdateCosts(const std::string &); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/puzzle.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/puzzle.cpp deleted file mode 100644 index b56b5fdf8..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/puzzle.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "cursor.h" -#include "settings.h" -#include "agg.h" -#include "button.h" -#include "game_interface.h" -#include "interface_gamearea.h" -#include "interface_radar.h" -#include "world.h" -#include "puzzle.h" - -bool ClosedTilesExists(const Puzzle &, const u8*, const u8*); -void ZoneOpenRandomTiles(Puzzle &, u8 &, const u8*, const u8*); -void ShowStandardDialog(const Puzzle &, const Surface &); -void ShowExtendedDialog(const Puzzle &, const Surface &); -void PuzzlesDraw(const Puzzle &, const Surface &, s16, s16); - -Puzzle::Puzzle() -{ -} - -Puzzle & Puzzle::operator= (const char* str) -{ - while(str && *str) - { - *this <<= 1; - if(*str == 0x31) set(0); - ++str; - } - - return *this; -} - -void Puzzle::Update(u8 open_obelisk, u8 total_obelisk) -{ - u8 open_puzzle = open_obelisk * PUZZLETILES / total_obelisk; - u8 need_puzzle = open_puzzle > count() ? open_puzzle - count() : 0; - - const u8 zone1_index[] = { 0, 1, 2, 3, 4, 5, 6, 11, 12, 17, 18, 23, 24, 29, 30, 35, 36, 41, 42, 43, 44, 45, 46, 47 }; - const u8 zone2_index[] = { 7, 8, 9, 10, 13, 16, 19, 22, 25, 28, 31, 34, 37, 38, 39, 40 }; - const u8 zone3_index[] = { 14, 15, 32, 33 }; - const u8 zone4_index[] = { 20, 21, 26, 27 }; - - if(need_puzzle && ClosedTilesExists(*this, &zone1_index[0], &zone1_index[23])) - ZoneOpenRandomTiles(*this, need_puzzle, &zone1_index[0], &zone1_index[23]); - - if(need_puzzle && ClosedTilesExists(*this, &zone2_index[0], &zone2_index[15])) - ZoneOpenRandomTiles(*this, need_puzzle, &zone2_index[0], &zone2_index[15]); - - if(need_puzzle && ClosedTilesExists(*this, &zone3_index[0], &zone3_index[3])) - ZoneOpenRandomTiles(*this, need_puzzle, &zone3_index[0], &zone3_index[3]); - - if(need_puzzle && ClosedTilesExists(*this, &zone4_index[0], &zone4_index[3])) - ZoneOpenRandomTiles(*this, need_puzzle, &zone4_index[0], &zone4_index[3]); -} - -void Puzzle::ShowMapsDialog(void) const -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - Cursor::themes_t old_cursor = cursor.Themes(); - - if(! Settings::Get().MusicMIDI()) AGG::PlayMusic(MUS::PUZZLE); - - const Surface & sf = world.GetPuzzleSurface(); - - cursor.Hide(); - - if(display.w() == 640 && display.h() == 480 && !Settings::Get().HideInterface()) - ShowStandardDialog(*this, sf); - else - ShowExtendedDialog(*this, sf); - - cursor.SetThemes(old_cursor); -} - -bool ClosedTilesExists(const Puzzle & pzl, const u8* it1, const u8* it2) -{ - while(it1 && it2 && it1 <= it2) if(! pzl.test(*it1++)) return true; - return false; -} - -void ZoneOpenRandomTiles(Puzzle & pzl, u8 & opens, const u8* it1, const u8* it2) -{ - std::vector values; - values.reserve(25); - const u8* it = NULL; - - while(opens) - { - values.clear(); - it = it1; - while(it && it2 && it <= it2){ if(! pzl.test(*it)) values.push_back(*it); ++it; } - if(values.empty()) break; - pzl.set(*Rand::Get(values)); - --opens; - } -} - -void ShowStandardDialog(const Puzzle & pzl, const Surface & sf) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - - const Rect & radar_pos = Interface::Radar::Get().GetArea(); - bool evil_interface = Settings::Get().EvilInterface(); - - Background back(BORDERWIDTH, BORDERWIDTH, sf.w(), sf.h()); - back.Save(); - - display.Blit(AGG::GetICN((evil_interface ? ICN::EVIWPUZL : ICN::VIEWPUZL), 0), radar_pos); - display.Blit(sf, BORDERWIDTH, BORDERWIDTH); - - Point dst_pt(radar_pos.x + 32, radar_pos.y + radar_pos.h - 37); - Button buttonExit(dst_pt, (evil_interface ? ICN::LGNDXTRE : ICN::LGNDXTRA), 4, 5); - - buttonExit.Draw(); - PuzzlesDraw(pzl, sf, BORDERWIDTH, BORDERWIDTH); - - cursor.SetThemes(Cursor::POINTER); - cursor.Show(); - display.Flip(); - LocalEvent & le = LocalEvent::Get(); - - while(le.HandleEvents()) - { - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) break; - } - - Interface::Basic::Get().SetRedraw(REDRAW_RADAR); - - cursor.Hide(); - back.Restore(); -} - -void ShowExtendedDialog(const Puzzle & pzl, const Surface & sf) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - bool evil_interface = Settings::Get().EvilInterface(); - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - BORDERWIDTH * 2 - sf.w()) / 2, - (display.h() - sf.h() - BORDERWIDTH * 2 - 32) / 2, - sf.w(), - sf.h() + (Settings::Get().QVGA() ? 25 : 32)); - frameborder.Redraw(); - - if(evil_interface) - display.FillRect(80, 80, 80, frameborder.GetArea()); - else - display.FillRect(128, 64, 32, frameborder.GetArea()); - display.Blit(sf, frameborder.GetArea()); - - Button buttonExit(frameborder.GetArea().x + sf.w() / 2 - 40, - frameborder.GetArea().y + sf.h() + (Settings::Get().QVGA() ? 0 : 5), - (evil_interface ? ICN::LGNDXTRE : ICN::LGNDXTRA), 4, 5); - - buttonExit.Draw(); - PuzzlesDraw(pzl, sf, frameborder.GetArea().x, frameborder.GetArea().y); - - cursor.SetThemes(Cursor::POINTER); - cursor.Show(); - display.Flip(); - LocalEvent & le = LocalEvent::Get(); - - while(le.HandleEvents()) - { - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - if(le.MouseClickLeft(buttonExit) || HotKeyCloseWindow) break; - if(Settings::Get().QVGA() && le.MouseClickLeft(frameborder.GetArea())) break; - } -} - -void PuzzlesDraw(const Puzzle & pzl, const Surface & sf, s16 dstx, s16 dsty) -{ - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - - // show all for debug - if(IS_DEVEL()) return; - - u8 alpha = 250; - LocalEvent & le = LocalEvent::Get(); - - while(le.HandleEvents() && 0 < alpha) - { - if(Game::AnimateInfrequent(Game::PUZZLE_FADE_DELAY)) - { - cursor.Hide(); - display.Blit(sf, dstx, dsty); - for(size_t ii = 0; ii < pzl.size(); ++ii) - { - const Sprite & piece = AGG::GetICN(ICN::PUZZLE, ii); - if(pzl.test(ii)) - { - Surface fade(piece.w(), piece.h()); - fade.SetColorKey(); - fade.Blit(piece); - fade.SetAlpha(alpha); - if(Settings::Get().QVGA()) - display.Blit(fade, dstx + 8 + piece.x() - BORDERWIDTH, dsty + 8 + piece.y() - BORDERWIDTH); - else - display.Blit(fade, dstx + piece.x() - BORDERWIDTH, dsty + piece.y() - BORDERWIDTH); - } - else - { - if(Settings::Get().QVGA()) - display.Blit(piece, dstx + 8 + piece.x() - BORDERWIDTH, dsty + 8 + piece.y() - BORDERWIDTH); - else - display.Blit(piece, dstx + piece.x() - BORDERWIDTH, dsty + piece.y() - BORDERWIDTH); - } - } - cursor.Show(); - display.Flip(); - alpha -= 10; - } - } - cursor.Hide(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/puzzle.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/puzzle.h deleted file mode 100644 index 0cf3fe273..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/puzzle.h +++ /dev/null @@ -1,41 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2PUZZLE_H -#define H2PUZZLE_H - -#include -#include "gamedefs.h" - -#define PUZZLETILES 48 - -class Puzzle : public std::bitset -{ -public: - Puzzle(); - Puzzle & operator= (const char*); - - void Update(u8, u8); - void ShowMapsDialog(void) const; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/race.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/race.cpp deleted file mode 100644 index fc89786b5..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/race.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "engine.h" -#include "gamedefs.h" -#include "race.h" - -const char* Race::String(u8 race) -{ - const char* str_race[] = { _("Knight"), _("Barbarian"), _("Sorceress"), - _("Warlock"), _("Wizard"), _("Necromancer"), _("Multi"), "Random", "Neutral" }; - - switch(race) - { - case Race::KNGT: return str_race[0]; - case Race::BARB: return str_race[1]; - case Race::SORC: return str_race[2]; - case Race::WRLK: return str_race[3]; - case Race::WZRD: return str_race[4]; - case Race::NECR: return str_race[5]; - case Race::MULT: return str_race[6]; - case Race::RAND: return str_race[7]; - case Race::BOMG: return str_race[8]; - default: break; - } - - return str_race[8]; -} - -Race::race_t Race::Rand(void) -{ - switch(Rand::Get(1, 6)){ - case 1: return Race::KNGT; - case 2: return Race::BARB; - case 3: return Race::SORC; - case 4: return Race::WRLK; - case 5: return Race::WZRD; - default: break; - } - - return Race::NECR; -} - -Race::race_t Race::Get(u8 index) -{ - switch(index) - { - case KNGT: return KNGT; - case BARB: return BARB; - case SORC: return SORC; - case WRLK: return WRLK; - case WZRD: return WZRD; - case NECR: return NECR; - case MULT: return MULT; - case RAND: return RAND; - default: break; - } - - return Race::BOMG; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/race.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/race.h deleted file mode 100644 index 24e2d4091..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/race.h +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2RACE_H -#define H2RACE_H - -#include -#include "gamedefs.h" - -namespace Race -{ - enum race_t - { - KNGT = 0x01, - BARB = 0x02, - SORC = 0x04, - WRLK = 0x08, - WZRD = 0x10, - NECR = 0x20, - MULT = 0x40, - RAND = 0x80, - BOMG = 0x00, - ALL = KNGT | BARB | SORC | WRLK | WZRD | NECR - }; - - const char* String(u8); - race_t Rand(void); - race_t Get(u8); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/speed.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/speed.cpp deleted file mode 100644 index 57864a126..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/speed.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "speed.h" - -const char* Speed::String(u8 speed) -{ - const char* str_speed[] = { _("speed|Standing"), _("speed|Crawling"), _("speed|Very Slow"), _("speed|Slow"), _("speed|Average"), _("speed|Fast"), - _("speed|Very Fast"), _("speed|Ultra Fast"), _("speed|Blazing"), _("speed|Instant"), "Unknown" }; - - switch(speed) - { - case STANDING: return str_speed[0]; - case CRAWLING: return str_speed[1]; - case VERYSLOW: return str_speed[2]; - case SLOW: return str_speed[3]; - case AVERAGE: return str_speed[4]; - case FAST: return str_speed[5]; - case VERYFAST: return str_speed[6]; - case ULTRAFAST: return str_speed[7]; - case BLAZING: return str_speed[8]; - case INSTANT: return str_speed[9]; - default: break; - } - - return str_speed[10]; -} - -Speed::speed_t Speed::GetOriginalSlow(u8 speed) -{ - switch(speed) - { - case CRAWLING: - case VERYSLOW: return CRAWLING; - case SLOW: - case AVERAGE: return VERYSLOW; - case FAST: - case VERYFAST: return SLOW; - case ULTRAFAST: - case BLAZING: return AVERAGE; - case INSTANT: return FAST; - default: break; - } - - return STANDING; -} - -Speed::speed_t Speed::GetOriginalFast(u8 speed) -{ - switch(speed) - { - case CRAWLING: return SLOW; - case VERYSLOW: return AVERAGE; - case SLOW: return FAST; - case AVERAGE: return VERYFAST; - case FAST: return ULTRAFAST; - case VERYFAST: return BLAZING; - case ULTRAFAST: - case BLAZING: - case INSTANT: return INSTANT; - default: break; - } - - return STANDING; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/speed.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/speed.h deleted file mode 100644 index 3d9d052bf..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/speed.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2SPEED_H -#define H2SPEED_H - -#include -#include "gamedefs.h" - -namespace Speed -{ - enum speed_t - { - STANDING = 0, - CRAWLING = 1, - VERYSLOW = 2, - SLOW = 3, - AVERAGE = 4, - FAST = 5, - VERYFAST = 6, - ULTRAFAST = 7, - BLAZING = 8, - INSTANT = 9 - }; - - const char* String(u8 speed); - - speed_t GetOriginalSlow(u8); - speed_t GetOriginalFast(u8); - - inline speed_t& operator++ (speed_t& speed){ return speed = ( INSTANT == speed ? INSTANT : speed_t(speed + 1)); } - inline speed_t& operator-- (speed_t& speed){ return speed = ( CRAWLING == speed ? CRAWLING : speed_t(speed - 1)); } -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/week.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/week.cpp deleted file mode 100644 index 44b7655a1..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/week.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "engine.h" -#include "gamedefs.h" -#include "week.h" - -const char* Week::GetString(type_t type) -{ - const char* str_name[] = { "Unnamed", _("week|PLAGUE"), - _("week|Ant"), _("week|Grasshopper"), _("week|Dragonfly"), _("week|Spider"), _("week|Butterfly"), _("week|Bumblebee"), - _("week|Locust"), _("week|Earthworm"), _("week|Hornet"), _("week|Beetle"), _("week|Squirrel"), _("week|Rabbit"), - _("week|Gopher"), _("week|Badger"), _("week|Eagle"), _("week|Weasel"), _("week|Raven"), _("week|Mongoose"), _("week|Aardvark"), - _("week|Lizard"), _("week|Tortoise"), _("week|Hedgehog"), _("week|Condor"), "Monsters HII" }; - - switch(type) - { - case PLAGUE: return str_name[1]; - case ANT: return str_name[2]; - case GRASSHOPPER: return str_name[3]; - case DRAGONFLY: return str_name[4]; - case SPIDER: return str_name[5]; - case BUTTERFLY: return str_name[6]; - case BUMBLEBEE: return str_name[7]; - case LOCUST: return str_name[8]; - case EARTHWORM: return str_name[9]; - case HORNET: return str_name[10]; - case BEETLE: return str_name[11]; - case SQUIRREL: return str_name[12]; - case RABBIT: return str_name[13]; - case GOPHER: return str_name[14]; - case BADGER: return str_name[15]; - case EAGLE: return str_name[16]; - case WEASEL: return str_name[17]; - case RAVEN: return str_name[18]; - case MONGOOSE: return str_name[19]; - case AARDVARK: return str_name[20]; - case LIZARD: return str_name[21]; - case TORTOISE: return str_name[22]; - case HEDGEHOG: return str_name[23]; - case CONDOR: return str_name[24]; - case MONSTERS: return str_name[25]; - default: break; - } - - return str_name[0]; -} - -Week::type_t Week::WeekRand(void) -{ - switch(Rand::Get(2, 24)) - { - case 2: return ANT; - case 3: return GRASSHOPPER; - case 4: return DRAGONFLY; - case 5: return SPIDER; - case 6: return BUTTERFLY; - case 7: return BUMBLEBEE; - case 8: return LOCUST; - case 9: return EARTHWORM; - case 10: return HORNET; - case 11: return BEETLE; - case 12: return SQUIRREL; - case 13: return RABBIT; - case 14: return GOPHER; - case 15: return BADGER; - case 16: return EAGLE; - case 17: return WEASEL; - case 18: return RAVEN; - case 19: return MONGOOSE; - case 20: return AARDVARK; - case 21: return LIZARD; - case 22: return TORTOISE; - case 23: return HEDGEHOG; - case 24: return CONDOR; - default: break; - } - - return UNNAMED; -} - -Week::type_t Week::MonthRand(void) -{ - switch(Rand::Get(1, 24)) - { - case 1: return PLAGUE; - case 2: return ANT; - case 3: return GRASSHOPPER; - case 4: return DRAGONFLY; - case 5: return SPIDER; - case 6: return BUTTERFLY; - case 7: return BUMBLEBEE; - case 8: return LOCUST; - case 9: return EARTHWORM; - case 10: return HORNET; - case 11: return BEETLE; - case 12: return SQUIRREL; - case 13: return RABBIT; - case 14: return GOPHER; - case 15: return BADGER; - case 16: return EAGLE; - case 17: return WEASEL; - case 18: return RAVEN; - case 19: return MONGOOSE; - case 20: return AARDVARK; - case 21: return LIZARD; - case 22: return TORTOISE; - case 23: return HEDGEHOG; - case 24: return CONDOR; - default: break; - } - - return UNNAMED; -} - -Week::type_t Week::Get(u8 index) -{ - return index > CONDOR ? UNNAMED : static_cast(index); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/week.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/week.h deleted file mode 100644 index 0d7443c25..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/week.h +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2WEEK_H -#define H2WEEK_H - -#include - -namespace Week -{ - enum type_t - { - UNNAMED, - PLAGUE, - ANT, - GRASSHOPPER, - DRAGONFLY, - SPIDER, - BUTTERFLY, - BUMBLEBEE, - LOCUST, - EARTHWORM, - HORNET, - BEETLE, - SQUIRREL, - RABBIT, - GOPHER, - BADGER, - EAGLE, - WEASEL, - RAVEN, - MONGOOSE, - AARDVARK, - LIZARD, - TORTOISE, - HEDGEHOG, - CONDOR, - - MONSTERS // week of monsters game - }; - - const char* GetString(type_t type); - type_t WeekRand(void); - type_t MonthRand(void); - type_t Get(u8); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/world.cpp b/project/jni/application/fheroes2/src/fheroes2/kingdom/world.cpp deleted file mode 100644 index 5d8a29c7b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/world.cpp +++ /dev/null @@ -1,2012 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "agg.h" -#include "artifact.h" -#include "resource.h" -#include "settings.h" -#include "kingdom.h" -#include "heroes.h" -#include "castle.h" -#include "gameevent.h" -#include "mp2.h" -#include "text.h" -#include "pairs.h" -#include "algorithm.h" -#include "game_over.h" -#include "interface_gamearea.h" -#include "world.h" - -bool PredicateHeroesIsFreeman(const Heroes *h) -{ - return h && h->isFreeman(); -} - -World & world = World::Get(); - -u32 World::uniq0 = 0; - -World & World::Get(void) -{ - static World insideWorld; - - return insideWorld; -} - -void World::Defaults(void) -{ - // playing kingdom - vec_kingdoms.resize(KINGDOMMAX + 1); - vec_kingdoms[0] = new Kingdom(Color::BLUE); - vec_kingdoms[1] = new Kingdom(Color::GREEN); - vec_kingdoms[2] = new Kingdom(Color::RED); - vec_kingdoms[3] = new Kingdom(Color::YELLOW); - vec_kingdoms[4] = new Kingdom(Color::ORANGE); - vec_kingdoms[5] = new Kingdom(Color::PURPLE); - vec_kingdoms[6] = new Kingdom(Color::GRAY); - - // initialize all heroes - vec_heroes.resize(HEROESMAXCOUNT + 2); - vec_heroes[0] = new Heroes(Heroes::LORDKILBURN, Race::KNGT); - vec_heroes[1] = new Heroes(Heroes::SIRGALLANTH, Race::KNGT); - vec_heroes[2] = new Heroes(Heroes::ECTOR, Race::KNGT); - vec_heroes[3] = new Heroes(Heroes::GVENNETH, Race::KNGT); - vec_heroes[4] = new Heroes(Heroes::TYRO, Race::KNGT); - vec_heroes[5] = new Heroes(Heroes::AMBROSE, Race::KNGT); - vec_heroes[6] = new Heroes(Heroes::RUBY, Race::KNGT); - vec_heroes[7] = new Heroes(Heroes::MAXIMUS, Race::KNGT); - vec_heroes[8] = new Heroes(Heroes::DIMITRY, Race::KNGT); - - vec_heroes[9] = new Heroes(Heroes::THUNDAX, Race::BARB); - vec_heroes[10] = new Heroes(Heroes::FINEOUS, Race::BARB); - vec_heroes[11] = new Heroes(Heroes::JOJOSH, Race::BARB); - vec_heroes[12] = new Heroes(Heroes::CRAGHACK, Race::BARB); - vec_heroes[13] = new Heroes(Heroes::JEZEBEL, Race::BARB); - vec_heroes[14] = new Heroes(Heroes::JACLYN, Race::BARB); - vec_heroes[15] = new Heroes(Heroes::ERGON, Race::BARB); - vec_heroes[16] = new Heroes(Heroes::TSABU, Race::BARB); - vec_heroes[17] = new Heroes(Heroes::ATLAS, Race::BARB); - - vec_heroes[18] = new Heroes(Heroes::ASTRA, Race::SORC); - vec_heroes[19] = new Heroes(Heroes::NATASHA, Race::SORC); - vec_heroes[20] = new Heroes(Heroes::TROYAN, Race::SORC); - vec_heroes[21] = new Heroes(Heroes::VATAWNA, Race::SORC); - vec_heroes[22] = new Heroes(Heroes::REBECCA, Race::SORC); - vec_heroes[23] = new Heroes(Heroes::GEM, Race::SORC); - vec_heroes[24] = new Heroes(Heroes::ARIEL, Race::SORC); - vec_heroes[25] = new Heroes(Heroes::CARLAWN, Race::SORC); - vec_heroes[26] = new Heroes(Heroes::LUNA, Race::SORC); - - vec_heroes[27] = new Heroes(Heroes::ARIE, Race::WRLK); - vec_heroes[28] = new Heroes(Heroes::ALAMAR, Race::WRLK); - vec_heroes[29] = new Heroes(Heroes::VESPER, Race::WRLK); - vec_heroes[30] = new Heroes(Heroes::CRODO, Race::WRLK); - vec_heroes[31] = new Heroes(Heroes::BAROK, Race::WRLK); - vec_heroes[32] = new Heroes(Heroes::KASTORE, Race::WRLK); - vec_heroes[33] = new Heroes(Heroes::AGAR, Race::WRLK); - vec_heroes[34] = new Heroes(Heroes::FALAGAR, Race::WRLK); - vec_heroes[35] = new Heroes(Heroes::WRATHMONT, Race::WRLK); - - vec_heroes[36] = new Heroes(Heroes::MYRA, Race::WZRD); - vec_heroes[37] = new Heroes(Heroes::FLINT, Race::WZRD); - vec_heroes[38] = new Heroes(Heroes::DAWN, Race::WZRD); - vec_heroes[39] = new Heroes(Heroes::HALON, Race::WZRD); - vec_heroes[40] = new Heroes(Heroes::MYRINI, Race::WZRD); - vec_heroes[41] = new Heroes(Heroes::WILFREY, Race::WZRD); - vec_heroes[42] = new Heroes(Heroes::SARAKIN, Race::WZRD); - vec_heroes[43] = new Heroes(Heroes::KALINDRA, Race::WZRD); - vec_heroes[44] = new Heroes(Heroes::MANDIGAL, Race::WZRD); - - vec_heroes[45] = new Heroes(Heroes::ZOM, Race::NECR); - vec_heroes[46] = new Heroes(Heroes::DARLANA, Race::NECR); - vec_heroes[47] = new Heroes(Heroes::ZAM, Race::NECR); - vec_heroes[48] = new Heroes(Heroes::RANLOO, Race::NECR); - vec_heroes[49] = new Heroes(Heroes::CHARITY, Race::NECR); - vec_heroes[50] = new Heroes(Heroes::RIALDO, Race::NECR); - vec_heroes[51] = new Heroes(Heroes::ROXANA, Race::NECR); - vec_heroes[52] = new Heroes(Heroes::SANDRO, Race::NECR); - vec_heroes[53] = new Heroes(Heroes::CELIA, Race::NECR); - - vec_heroes[54] = new Heroes(Heroes::ROLAND, Race::WZRD); - vec_heroes[55] = new Heroes(Heroes::CORLAGON, Race::KNGT); - vec_heroes[56] = new Heroes(Heroes::ELIZA, Race::SORC); - vec_heroes[57] = new Heroes(Heroes::ARCHIBALD, Race::WRLK); - vec_heroes[58] = new Heroes(Heroes::HALTON, Race::KNGT); - vec_heroes[59] = new Heroes(Heroes::BAX, Race::NECR); - - if(Settings::Get().PriceLoyaltyVersion()) - { - vec_heroes[60] = new Heroes(Heroes::SOLMYR, Race::WZRD); - vec_heroes[61] = new Heroes(Heroes::DAINWIN, Race::WRLK); - vec_heroes[62] = new Heroes(Heroes::MOG, Race::NECR); - vec_heroes[63] = new Heroes(Heroes::UNCLEIVAN, Race::BARB); - vec_heroes[64] = new Heroes(Heroes::JOSEPH, Race::KNGT); - vec_heroes[65] = new Heroes(Heroes::GALLAVANT, Race::KNGT); - vec_heroes[66] = new Heroes(Heroes::ELDERIAN, Race::WRLK); - vec_heroes[67] = new Heroes(Heroes::CEALLACH, Race::KNGT); - vec_heroes[68] = new Heroes(Heroes::DRAKONIA, Race::WZRD); - vec_heroes[69] = new Heroes(Heroes::MARTINE, Race::SORC); - vec_heroes[70] = new Heroes(Heroes::JARKONAS, Race::BARB); - vec_heroes[71] = IS_DEVEL() ? new Heroes(Heroes::SANDYSANDY, Race::WRLK) : new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[72] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - } - else - { - vec_heroes[60] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[61] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[62] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[63] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[64] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[65] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[66] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[67] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[68] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[69] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[70] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[71] = IS_DEVEL() ? new Heroes(Heroes::SANDYSANDY, Race::WRLK) : new Heroes(Heroes::UNKNOWN, Race::KNGT); - vec_heroes[72] = new Heroes(Heroes::UNKNOWN, Race::KNGT); - } -} - -/* new maps */ -void World::NewMaps(const u16 sw, const u16 sh) -{ - Reset(); - Defaults(); - - width = sw; - height = sh; - - AGG::PreloadObject(TIL::GROUND32); - - vec_tiles.resize(width * height); - - // init all tiles - for(int ii = 0; ii < width * height; ++ii) - { - MP2::mp2tile_t mp2tile; - - mp2tile.tileIndex = Rand::Get(16, 19); // index sprite ground, see ground32.til - mp2tile.objectName1 = 0; // object sprite level 1 - mp2tile.indexName1 = 0xff; // index sprite level 1 - mp2tile.quantity1 = 0; - mp2tile.quantity2 = 0; - mp2tile.objectName2 = 0; // object sprite level 2 - mp2tile.indexName2 = 0xff; // index sprite level 2 - mp2tile.shape = Rand::Get(0, 3); // shape reflect % 4, 0 none, 1 vertical, 2 horizontal, 3 any - mp2tile.generalObject = MP2::OBJ_ZERO; - mp2tile.indexAddon = 0; - mp2tile.uniqNumber1 = 0; - mp2tile.uniqNumber2 = 0; - - vec_tiles[ii] = new Maps::Tiles(ii, mp2tile); - } -} - -/* load maps */ -void World::LoadMaps(const std::string &filename) -{ - Reset(); - Defaults(); - - std::ifstream fd(filename.c_str(), std::ios::binary); - if(!fd.is_open()) Error::Except("World::LoadMaps: file not found ", filename.c_str()); - - AGG::PreloadObject(TIL::GROUND32); - - u8 byte8; - u16 byte16; - u32 byte32; - std::vector vec_object; // index maps for OBJ_CASTLE, OBJ_HEROES, OBJ_SIGN, OBJ_BOTTLE, OBJ_EVENT - vec_object.reserve(100); - - // endof - fd.seekg(0, std::ios_base::end); - const u32 endof_mp2 = fd.tellg(); - - // read uniq - fd.seekg(endof_mp2 - sizeof(u32), std::ios_base::beg); - fd.read(reinterpret_cast(&uniq0), sizeof(u32)); - SwapLE32(uniq0); - - // offset data - fd.seekg(MP2OFFSETDATA - 2 * sizeof(u32), std::ios_base::beg); - - // width - fd.read(reinterpret_cast(&byte32), sizeof(u32)); - SwapLE32(byte32); - - switch(byte32) - { - case Maps::SMALL: width = Maps::SMALL; break; - case Maps::MEDIUM: width = Maps::MEDIUM; break; - case Maps::LARGE: width = Maps::LARGE; break; - case Maps::XLARGE: width = Maps::XLARGE; break; - default: width = Maps::ZERO; break; - } - height = width; - - // height - fd.read(reinterpret_cast(&byte32), sizeof(u32)); - SwapLE32(byte32); - - if(byte32 != static_cast(height)) DEBUG(DBG_GAME , DBG_WARN, "World::World: maps size mismatch!"); - - // seek to ADDONS block - fd.ignore(width * height * SIZEOFMP2TILE); - - // count mp2addon_t - fd.read(reinterpret_cast(&byte32), sizeof(u32)); - SwapLE32(byte32); - - // read all addons - std::vector vec_mp2addons(byte32); - - for(unsigned int ii = 0; ii < byte32; ++ii) - { - MP2::mp2addon_t & mp2addon = vec_mp2addons[ii]; - - fd.read(reinterpret_cast(&mp2addon.indexAddon), sizeof(u16)); - SwapLE16(mp2addon.indexAddon); - - fd.read(reinterpret_cast(&byte8), 1); - mp2addon.objectNameN1 = byte8 * 2; - - fd.read(reinterpret_cast(&byte8), 1); - mp2addon.indexNameN1 = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2addon.quantityN = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2addon.objectNameN2 = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2addon.indexNameN2 = byte8; - - fd.read(reinterpret_cast(&mp2addon.uniqNumberN1), sizeof(u32)); - SwapLE32(mp2addon.uniqNumberN1); - - fd.read(reinterpret_cast(&mp2addon.uniqNumberN2), sizeof(u32)); - SwapLE32(mp2addon.uniqNumberN2); - } - - const u32 endof_addons = fd.tellg(); - - DEBUG(DBG_GAME , DBG_INFO, "World::World: read all tiles addons, tellg: " << endof_addons); - - // offset data - fd.seekg(MP2OFFSETDATA, std::ios_base::beg); - - vec_tiles.resize(width * height, NULL); - - // read all tiles - for(int ii = 0; ii < width * height; ++ii) - { - MP2::mp2tile_t mp2tile; - - // byte16 - fd.read(reinterpret_cast(&mp2tile.tileIndex), sizeof(u16)); - SwapLE16(mp2tile.tileIndex); - - fd.read(reinterpret_cast(&byte8), 1); - mp2tile.objectName1 = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2tile.indexName1 = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2tile.quantity1 = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2tile.quantity2 = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2tile.objectName2 = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2tile.indexName2 = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2tile.shape = byte8; - - fd.read(reinterpret_cast(&byte8), 1); - mp2tile.generalObject = byte8; - - switch(mp2tile.generalObject) - { - case MP2::OBJ_RNDTOWN: - case MP2::OBJ_RNDCASTLE: - case MP2::OBJ_CASTLE: - case MP2::OBJ_HEROES: - case MP2::OBJ_SIGN: - case MP2::OBJ_BOTTLE: - case MP2::OBJ_EVENT: - case MP2::OBJ_SPHINX: - case MP2::OBJ_JAIL: - vec_object.push_back(ii); - break; - default: - break; - } - - // offset first addon - fd.read(reinterpret_cast(&byte16), sizeof(u16)); - SwapLE16(byte16); - - // byte32 - fd.read(reinterpret_cast(&mp2tile.uniqNumber1), sizeof(u32)); - SwapLE32(mp2tile.uniqNumber1); - - // byte32 - fd.read(reinterpret_cast(&mp2tile.uniqNumber2), sizeof(u32)); - SwapLE32(mp2tile.uniqNumber2); - - Maps::Tiles * tile = new Maps::Tiles(ii, mp2tile); - - // load all addon for current tils - while(byte16) - { - if(vec_mp2addons.size() <= byte16){ DEBUG(DBG_GAME , DBG_WARN, "World::World: index addons out of range!"); break; } - - (*tile).AddonsPushLevel1(vec_mp2addons[byte16]); - (*tile).AddonsPushLevel2(vec_mp2addons[byte16]); - - byte16 = vec_mp2addons[byte16].indexAddon; - } - - (*tile).AddonsSort(); - - vec_tiles[ii] = tile; - } - - DEBUG(DBG_GAME , DBG_INFO, "World::World: read all tiles, tellg: " << fd.tellg()); - - // after addons - fd.seekg(endof_addons, std::ios_base::beg); - - // cood castles - // 72 x 3 byte (cx, cy, id) - for(u8 ii = 0; ii < 72; ++ii) - { - u8 cx, cy, id; - - fd.read(reinterpret_cast(&cx), 1); - fd.read(reinterpret_cast(&cy), 1); - fd.read(reinterpret_cast(&id), 1); - - // empty block - if(0xFF == cx && 0xFF == cy) continue; - - switch(id) - { - case 0x00: // tower: knight - case 0x80: // castle: knight - vec_castles.push_back(new Castle(cx, cy, Race::KNGT)); break; - - case 0x01: // tower: barbarian - case 0x81: // castle: barbarian - vec_castles.push_back(new Castle(cx, cy, Race::BARB)); break; - - case 0x02: // tower: sorceress - case 0x82: // castle: sorceress - vec_castles.push_back(new Castle(cx, cy, Race::SORC)); break; - - case 0x03: // tower: warlock - case 0x83: // castle: warlock - vec_castles.push_back(new Castle(cx, cy, Race::WRLK)); break; - - case 0x04: // tower: wizard - case 0x84: // castle: wizard - vec_castles.push_back(new Castle(cx, cy, Race::WZRD)); break; - - case 0x05: // tower: necromancer - case 0x85: // castle: necromancer - vec_castles.push_back(new Castle(cx, cy, Race::NECR)); break; - - case 0x06: // tower: random - case 0x86: // castle: random - vec_castles.push_back(new Castle(cx, cy, Race::BOMG)); break; - - default: - DEBUG(DBG_GAME , DBG_WARN, "World::World: castle block, unknown id: " << static_cast(id) << ", maps index: " << cx + cy * w()); - break; - } - // preload in to capture objects cache - map_captureobj[Maps::GetIndexFromAbsPoint(cx, cy)] = ObjectColor(MP2::OBJ_CASTLE, Color::GRAY); - } - - DEBUG(DBG_GAME , DBG_INFO, "World::World: read coord castles, tellg: " << fd.tellg()); - fd.seekg(endof_addons + (72 * 3), std::ios_base::beg); - - // cood resource kingdoms - // 144 x 3 byte (cx, cy, id) - for(u16 ii = 0; ii < 144; ++ii) - { - u8 cx, cy, id; - - fd.read(reinterpret_cast(&cx), 1); - fd.read(reinterpret_cast(&cy), 1); - fd.read(reinterpret_cast(&id), 1); - - // empty block - if(0xFF == cx && 0xFF == cy) continue; - - switch(id) - { - // mines: wood - case 0x00: - map_captureobj[Maps::GetIndexFromAbsPoint(cx, cy)] = ObjectColor(MP2::OBJ_SAWMILL, Color::GRAY); - break; - // mines: mercury - case 0x01: - map_captureobj[Maps::GetIndexFromAbsPoint(cx, cy)] = ObjectColor(MP2::OBJ_ALCHEMYLAB, Color::GRAY); - break; - // mines: ore - case 0x02: - // mines: sulfur - case 0x03: - // mines: crystal - case 0x04: - // mines: gems - case 0x05: - // mines: gold - case 0x06: - map_captureobj[Maps::GetIndexFromAbsPoint(cx, cy)] = ObjectColor(MP2::OBJ_MINES, Color::GRAY); - break; - // lighthouse - case 0x64: - map_captureobj[Maps::GetIndexFromAbsPoint(cx, cy)] = ObjectColor(MP2::OBJ_LIGHTHOUSE, Color::GRAY); - break; - // dragon city - case 0x65: - map_captureobj[Maps::GetIndexFromAbsPoint(cx, cy)] = ObjectColor(MP2::OBJ_DRAGONCITY, Color::GRAY); - break; - // abandoned mines - case 0x67: - map_captureobj[Maps::GetIndexFromAbsPoint(cx, cy)] = ObjectColor(MP2::OBJ_ABANDONEDMINE, Color::GRAY); - break; - default: - DEBUG(DBG_GAME , DBG_WARN, "World::World: kingdom block, unknown id: " << static_cast(id) << ", maps index: " << cx + cy * w()); - break; - } - } - - DEBUG(DBG_GAME , DBG_INFO, "World::World: read coord other resource, tellg: " << fd.tellg()); - fd.seekg(endof_addons + (72 * 3) + (144 * 3), std::ios_base::beg); - - // unknown byte - fd.read(reinterpret_cast(&byte8), 1); - DEBUG(DBG_GAME , DBG_TRACE, "World::World: dump unknown byte: 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(byte8)); - - // count final mp2 blocks - u16 countblock = 0; - while(1) - { - u8 l = 0; - u8 h = 0; - - // debug endof mp2 - //if(endof_mp2 < fd.tellg()) Error::Except("World::World: ", "read maps: out of range."); - - fd.read(reinterpret_cast(&l), 1); - fd.read(reinterpret_cast(&h), 1); - - DEBUG(DBG_GAME , DBG_TRACE, "World::World: dump final block: 0x" << std::setw(2) << std::setfill('0') << std::hex << static_cast(l) << \ - std::setw(2) << std::setfill('0') << std::hex << static_cast(h)); - - if(0 == h && 0 == l) break; - else - { - countblock = 256 * h + l - 1; - } - } - - //DEBUG(DBG_GAME , DBG_INFO, "World::World: read find final mp2 blocks, tellg: " << fd.tellg()); - - // castle or heroes or (events, rumors, etc) - for(u16 ii = 0; ii < countblock; ++ii) - { - // debug - //if(endof_mp2 < fd.tellg()) Error::Except("World::World: ", "read maps: out of range."); - - // size block - u16 sizeblock; - fd.read(reinterpret_cast(&sizeblock), sizeof(u16)); - SwapLE16(sizeblock); - - u8 *pblock = new u8[sizeblock]; - - // read block - fd.read(reinterpret_cast(pblock), sizeblock); - - std::vector::const_iterator it_index = vec_object.begin(); - bool findobject = false; - - while(it_index != vec_object.end()) - { - const Maps::Tiles & tile = *vec_tiles.at(*it_index); - - // orders(quantity2, quantity1) - u16 orders = (tile.GetQuantity2() ? tile.GetQuantity2() : 0); - orders <<= 8; - orders |= static_cast(tile.GetQuantity1()); - - if(orders && !(orders % 0x08) && (ii + 1 == orders / 0x08)){ findobject = true; break; } - - ++it_index; - } - - if(findobject) - { - Maps::Tiles & tile = *vec_tiles.at(*it_index); - const Maps::TilesAddon *addon = NULL; - - switch(tile.GetObject()) - { - case MP2::OBJ_CASTLE: - // add castle - if(SIZEOFMP2CASTLE != sizeblock) - { - DEBUG(DBG_GAME , DBG_WARN, "World::World: read castle: incorrect size block. " << sizeblock); - } - else - { - Castle *castle = GetCastle(*it_index); - if(castle) - { - castle->LoadFromMP2(pblock); - Maps::MinimizeAreaForCastle(castle->GetCenter()); - map_captureobj[tile.GetIndex()].second = castle->GetColor(); - } - else - { - DEBUG(DBG_GAME , DBG_WARN, "World::World: load castle: not found, index: " << *it_index); - } - } - break; - case MP2::OBJ_RNDTOWN: - case MP2::OBJ_RNDCASTLE: - // add rnd castle - if(SIZEOFMP2CASTLE != sizeblock) - { - DEBUG(DBG_GAME , DBG_WARN, "World::World: read castle: incorrect size block. " << sizeblock); - } - else - { - Castle *castle = GetCastle(*it_index); - if(castle) - { - castle->LoadFromMP2(pblock); - Maps::UpdateRNDSpriteForCastle(castle->GetCenter(), castle->GetRace(), castle->isCastle()); - Maps::MinimizeAreaForCastle(castle->GetCenter()); - map_captureobj[tile.GetIndex()].second = castle->GetColor(); - } - else - { - DEBUG(DBG_GAME , DBG_WARN, "World::World: load castle: not found, index: " << *it_index); - } - } - break; - case MP2::OBJ_JAIL: - // add jail - if(SIZEOFMP2HEROES != sizeblock) - { - DEBUG(DBG_GAME , DBG_WARN, "World::World: read heroes: incorrect size block. " << sizeblock); - } - else - { - Race::race_t race = Race::KNGT; - switch(pblock[0x3c]) - { - case 1: race = Race::BARB; break; - case 2: race = Race::SORC; break; - case 3: race = Race::WRLK; break; - case 4: race = Race::WZRD; break; - case 5: race = Race::NECR; break; - default: break; - } - - Heroes* hero = GetFreemanHeroes(race); - - if(hero) - { - hero->LoadFromMP2(*it_index, pblock, Color::GRAY, hero->GetRace()); - hero->SetModes(Heroes::JAIL); - } - } - break; - case MP2::OBJ_HEROES: - // add heroes - if(SIZEOFMP2HEROES != sizeblock) - { - DEBUG(DBG_GAME , DBG_WARN, "World::World: read heroes: incorrect size block. " << sizeblock); - } - else - if(NULL != (addon = tile.FindMiniHero())) - { - // calculate color - const u8 index_name = addon->index; - Color::color_t color = Color::GRAY; - - if( 7 > index_name) - color = Color::BLUE; - else - if(14 > index_name) - color = Color::GREEN; - else - if(21 > index_name) - color = Color::RED; - else - if(28 > index_name) - color = Color::YELLOW; - else - if(35 > index_name) - color = Color::ORANGE; - else - color = Color::PURPLE; - - Kingdom & kingdom = GetKingdom(color); - - // caclulate race - Race::race_t race = Race::BOMG; - switch(index_name % 7) - { - case 0: race = Race::KNGT; break; - case 1: race = Race::BARB; break; - case 2: race = Race::SORC; break; - case 3: race = Race::WRLK; break; - case 4: race = Race::WZRD; break; - case 5: race = Race::NECR; break; - case 6: race = (Color::GRAY != color ? Settings::Get().KingdomRace(color) : Race::Rand()); break; - } - - // check heroes max count - if(kingdom.AllowRecruitHero(false, 0)) - { - const Heroes * hero = NULL; - - hero = (pblock[17] && - pblock[18] < Heroes::BAX && - static_cast(pblock[18]) < vec_heroes.size() && - vec_heroes.at(pblock[18])->isFreeman() ? - vec_heroes[pblock[18]] : GetFreemanHeroes(race)); - - if(hero) - { - Heroes* herow = const_cast(hero); - herow->LoadFromMP2(*it_index, pblock, color, race); - kingdom.AddHeroes(herow); - } - } - else - { - DEBUG(DBG_GAME , DBG_WARN, "World::LoadMaps: load heroes maximum"); - } - } - break; - case MP2::OBJ_SIGN: - case MP2::OBJ_BOTTLE: - // add sign or buttle - if(SIZEOFMP2SIGN - 1 < sizeblock && 0x01 == pblock[0]) - map_sign[*it_index] = std::string(_(reinterpret_cast(&pblock[9]))); - break; - case MP2::OBJ_EVENT: - // add event maps - if(SIZEOFMP2EVENT - 1 < sizeblock && 0x01 == pblock[0]) - vec_eventsmap.push_back(new GameEvent::Coord(*it_index, pblock)); - break; - case MP2::OBJ_SPHINX: - // add riddle sphinx - if(SIZEOFMP2RIDDLE - 1 < sizeblock && 0x00 == pblock[0]) - vec_riddles.push_back(new GameEvent::Riddle(*it_index, pblock)); - break; - default: - break; - } - } - // other events - else - if(0x00 == pblock[0]) - { - // add event day - if(SIZEOFMP2EVENT - 1 < sizeblock && 1 == pblock[42]) - vec_eventsday.push_back(new GameEvent::Day(pblock)); - - // add rumors - else if(SIZEOFMP2RUMOR - 1 < sizeblock) - { - if(pblock[8]) - { - vec_rumors.push_back(_(reinterpret_cast(&pblock[8]))); - DEBUG(DBG_GAME , DBG_INFO, "add Rumors: " << vec_rumors.back()); - } - } - } - // debug - else - { - DEBUG(DBG_GAME , DBG_WARN, "World::World: read maps: unknown block addons, size: " << sizeblock); - } - - delete [] pblock; - } - - // last rumors - vec_rumors.push_back(_("You can load the newest version of game from a site:\n http://sf.net/projects/fheroes2")); - vec_rumors.push_back(_("This game is now in beta development version. ;)")); - - // close mp2 - fd.close(); - - // modify other objects - const s32 vec_size = vec_tiles.size(); - - for(s32 ii = 0; ii < vec_size; ++ii) - { - Maps::Tiles & tile = *vec_tiles[ii]; - const Maps::TilesAddon *addon = NULL; - - // fix loyalty version objects - if(Settings::Get().PriceLoyaltyVersion()) tile.FixLoyaltyVersion(); - - // - switch(tile.GetObject()) - { - case MP2::OBJ_WITCHSHUT: - case MP2::OBJ_SHRINE1: - case MP2::OBJ_SHRINE2: - case MP2::OBJ_SHRINE3: - tile.UpdateQuantity(); - break; - - case MP2::OBJ_STONELIGHTS: - tile.UpdateStoneLightsSprite(); - break; - - case MP2::OBJ_FOUNTAIN: - tile.UpdateFountainSprite(); - break; - - case MP2::OBJ_EVENT: - // remove event sprite - if(NULL != (addon = tile.FindEvent())) - { - tile.Remove(addon->uniq); - } - break; - - case MP2::OBJ_BOAT: - // remove small sprite boat - if(NULL != (addon = tile.FindBoat())) - { - tile.Remove(addon->uniq); - } - break; - - case MP2::OBJ_RNDULTIMATEARTIFACT: - // remove ultimate artifact sprite - if(NULL != (addon = tile.FindUltimateArtifact())) - { - tile.SetQuantity1(Artifact::FromIndexSprite(addon->index)); - tile.Remove(addon->uniq); - tile.SetObject(MP2::OBJ_ZERO); - ultimate_artifact = ii; - } - break; - - case MP2::OBJ_RNDARTIFACT: - case MP2::OBJ_RNDARTIFACT1: - case MP2::OBJ_RNDARTIFACT2: - case MP2::OBJ_RNDARTIFACT3: - // modify rnd artifact sprite - tile.UpdateRNDArtifactSprite(); - tile.UpdateQuantity(); - break; - - case MP2::OBJ_RNDRESOURCE: - // modify rnd resource sprite - tile.UpdateRNDResourceSprite(); - tile.UpdateQuantity(); - break; - - case MP2::OBJ_TREASURECHEST: - if(Maps::Ground::WATER == tile.GetGround()) - tile.SetObject(MP2::OBJ_WATERCHEST); - else - tile.UpdateTreasureChestSprite(); - tile.UpdateQuantity(); - break; - - case MP2::OBJ_ARTIFACT: - case MP2::OBJ_RESOURCE: - case MP2::OBJ_MAGICGARDEN: - case MP2::OBJ_WATERWHEEL: - case MP2::OBJ_WINDMILL: - case MP2::OBJ_WAGON: - case MP2::OBJ_SKELETON: - case MP2::OBJ_LEANTO: - case MP2::OBJ_CAMPFIRE: - case MP2::OBJ_FLOTSAM: - case MP2::OBJ_SHIPWRECKSURVIROR: - case MP2::OBJ_DERELICTSHIP: - case MP2::OBJ_SHIPWRECK: - case MP2::OBJ_GRAVEYARD: - case MP2::OBJ_PYRAMID: - case MP2::OBJ_DAEMONCAVE: - case MP2::OBJ_ABANDONEDMINE: - case MP2::OBJ_TREEKNOWLEDGE: - case MP2::OBJ_BARRIER: - case MP2::OBJ_TRAVELLERTENT: - tile.UpdateQuantity(); - break; - - case MP2::OBJ_MONSTER: - case MP2::OBJ_RNDMONSTER: - case MP2::OBJ_RNDMONSTER1: - case MP2::OBJ_RNDMONSTER2: - case MP2::OBJ_RNDMONSTER3: - case MP2::OBJ_RNDMONSTER4: - // modify rnd monster sprite - tile.UpdateMonsterInfo(); - break; - - // join dwelling - case MP2::OBJ_ANCIENTLAMP: - tile.SetCountMonster(Monster(Monster::FromObject(tile.GetObject())).GetRNDSize(true)); - break; - - case MP2::OBJ_WATCHTOWER: - case MP2::OBJ_EXCAVATION: - case MP2::OBJ_CAVE: - case MP2::OBJ_TREEHOUSE: - case MP2::OBJ_ARCHERHOUSE: - case MP2::OBJ_GOBLINHUT: - case MP2::OBJ_DWARFCOTT: - case MP2::OBJ_HALFLINGHOLE: - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_THATCHEDHUT: - // recruit dwelling - case MP2::OBJ_RUINS: - case MP2::OBJ_TREECITY: - case MP2::OBJ_WAGONCAMP: - case MP2::OBJ_DESERTTENT: - case MP2::OBJ_TROLLBRIDGE: - case MP2::OBJ_DRAGONCITY: - case MP2::OBJ_CITYDEAD: - case MP2::OBJ_WATERALTAR: - case MP2::OBJ_AIRALTAR: - case MP2::OBJ_FIREALTAR: - case MP2::OBJ_EARTHALTAR: - case MP2::OBJ_BARROWMOUNDS: - tile.SetCountMonster(0); - break; - - // - default: - break; - } - } - - // sort castles to kingdoms - std::vector::const_iterator itc1 = vec_castles.begin(); - std::vector::const_iterator itc2 = vec_castles.end(); - for(; itc1 != itc2; ++itc1) - if(*itc1) GetKingdom((*itc1)->GetColor()).AddCastle(*itc1); - - // play with hero - std::for_each(vec_kingdoms.begin(), vec_kingdoms.end(), std::mem_fun(&Kingdom::ApplyPlayWithStartingHero)); - - // play with debug hero - if(IS_DEVEL()) - { - // get first castle position - Kingdom & kingdom = GetMyKingdom(); - - if(kingdom.GetCastles().size()) - { - const Castle* castle = kingdom.GetCastles().front(); - Heroes* hero = vec_heroes[Heroes::SANDYSANDY]; - - if(hero) - { - const Point & cp = castle->GetCenter(); - hero->Recruit(castle->GetColor(), Point(cp.x, cp.y + 1)); - } - } - } - - // generate position for ultimate - if(-1 == ultimate_artifact) - { - std::vector pools; - pools.reserve(vec_tiles.size()); - - for(u16 ii = 0; ii < vec_tiles.size(); ++ii) - { - const Maps::Tiles & tile = *vec_tiles[ii]; - const u16 x = tile.GetIndex() % width; - const u16 y = tile.GetIndex() / width; - if(Maps::Ground::WATER != tile.GetGround() && tile.GoodForUltimateArtifact() && x > 5 && x < width - 5 && y > 5 && y < height - 5) pools.push_back(tile.GetIndex()); - } - - if(pools.size()) - { - const s32 pos = *Rand::Get(pools); - ultimate_artifact = pos; - vec_tiles[pos]->SetQuantity1(Artifact::RandUltimate()); - } - } - - if(Maps::isValidAbsIndex(ultimate_artifact)) - Interface::GameArea::GenerateUltimateArtifactAreaSurface(ultimate_artifact, puzzle_surface); - - // update wins, loss conditions - if(GameOver::WINS_HERO & Settings::Get().ConditionWins()) - { - const Heroes* hero = GetHeroes(Settings::Get().WinsMapsIndexObject()); - heroes_cond_wins = hero ? hero->GetID() : Heroes::UNKNOWN; - } - if(GameOver::LOSS_HERO & Settings::Get().ConditionLoss()) - { - const Heroes* hero = GetHeroes(Settings::Get().LossMapsIndexObject()); - heroes_cond_loss = hero ? hero->GetID() : Heroes::UNKNOWN; - } - - DEBUG(DBG_GAME , DBG_INFO, "World::LoadMaps: end load."); -} - -/* get human kindom */ -Kingdom & World::GetMyKingdom(void) -{ return GetKingdom(Settings::Get().MyColor()); } - -const Kingdom & World::GetMyKingdom(void) const -{ return GetKingdom(Settings::Get().MyColor()); } - -/* get kingdom */ -Kingdom & World::GetKingdom(u8 color) -{ - switch(color) - { - case Color::BLUE: return *vec_kingdoms[0]; - case Color::GREEN: return *vec_kingdoms[1]; - case Color::RED: return *vec_kingdoms[2]; - case Color::YELLOW: return *vec_kingdoms[3]; - case Color::ORANGE: return *vec_kingdoms[4]; - case Color::PURPLE: return *vec_kingdoms[5]; - case Color::GRAY: return *vec_kingdoms[6]; - } - - DEBUG(DBG_GAME , DBG_WARN, "World::GetKingdom: return Color::GRAY."); - - return *vec_kingdoms[6]; -} - -const Kingdom & World::GetKingdom(u8 color) const -{ - switch(color) - { - case Color::BLUE: return *vec_kingdoms[0]; - case Color::GREEN: return *vec_kingdoms[1]; - case Color::RED: return *vec_kingdoms[2]; - case Color::YELLOW: return *vec_kingdoms[3]; - case Color::ORANGE: return *vec_kingdoms[4]; - case Color::PURPLE: return *vec_kingdoms[5]; - case Color::GRAY: return *vec_kingdoms[6]; - } - - DEBUG(DBG_GAME , DBG_WARN, "World::GetKingdom: return Color::GRAY."); - - return *vec_kingdoms[6]; -} - -/* get castle from index maps */ -Castle * World::GetCastle(s32 maps_index) -{ - return GetCastle(maps_index % width, maps_index / height); -} - -const Castle * World::GetCastle(s32 maps_index) const -{ - return GetCastle(maps_index % width, maps_index / height); -} - -/* get castle from coord maps */ -Castle * World::GetCastle(u16 ax, u16 ay) const -{ - std::vector::const_iterator it1 = vec_castles.begin(); - std::vector::const_iterator it2 = vec_castles.end(); - - for(; it1 != it2; ++it1) - if(*it1 && (*it1)->ContainCoord(ax, ay)) return *it1; - - DEBUG(DBG_GAME, DBG_TRACE, "World::GetCastle: " << "return NULL pointer" << ", x: " << ax << ", y: " << ay); - - return NULL; -} - -Heroes * World::GetHeroes(Heroes::heroes_t id) -{ - return vec_heroes[id]; -} - -const Heroes * World::GetHeroes(Heroes::heroes_t id) const -{ - return vec_heroes[id]; -} - -/* get heroes from index maps */ -Heroes * World::GetHeroes(s32 maps_index) -{ - return GetHeroes(maps_index % width, maps_index / height); -} - -const Heroes * World::GetHeroes(s32 maps_index) const -{ - return GetHeroes(maps_index % width, maps_index / height); -} - -/* get heroes from coord maps */ -Heroes * World::GetHeroes(u16 ax, u16 ay) const -{ - std::vector::const_iterator it1 = vec_heroes.begin(); - std::vector::const_iterator it2 = vec_heroes.end(); - - for(; it1 != it2; ++it1) - if(*it1 && (*it1)->GetCenter().x == ax && (*it1)->GetCenter().y == ay) return *it1; - - DEBUG(DBG_GAME, DBG_TRACE, "World::GetHeroes: " << "return NULL pointer" << ", x: " << ax << ", y: " << ay); - - return NULL; -} - -/* new day */ -void World::NewDay(void) -{ - ++day; - - if(BeginWeek()) - { - ++week; - if(BeginMonth()) ++month; - } - - // action new day - for(u8 ii = 0; ii < vec_kingdoms.size(); ++ii) if((*vec_kingdoms[ii]).isPlay()) (*vec_kingdoms[ii]).ActionNewDay(); - - // action new week - if(BeginWeek()) - { - NewWeek(); - for(u8 ii = 0; ii < vec_kingdoms.size(); ++ii) if((*vec_kingdoms[ii]).isPlay()) (*vec_kingdoms[ii]).ActionNewWeek(); - } - - // action new month - if(BeginMonth()) - { - NewMonth(); - for(u8 ii = 0; ii < vec_kingdoms.size(); ++ii) if((*vec_kingdoms[ii]).isPlay()) (*vec_kingdoms[ii]).ActionNewMonth(); - } -} - -void World::NewWeek(void) -{ - UpdateDwellingPopulation(); - - if(1 < week) UpdateMonsterPopulation(); - - // update week object - std::vector::const_iterator it1 = vec_tiles.begin(); - std::vector::const_iterator it2 = vec_tiles.end(); - - for(; it1 != it2; ++it1) - if(*it1 && MP2::isWeekLife((*it1)->GetObject())) (*it1)->UpdateQuantity(); - - // update week type - week_name = BeginMonth() ? Week::MonthRand() : Week::WeekRand(); - - // added army for gray castle - std::vector::const_iterator itc = vec_castles.begin(); - for(; itc != vec_castles.end(); ++itc) if(*itc && Color::GRAY == (*itc)->GetColor()) (*itc)->AIJoinRNDArmy(); - - // TODO:: action for week type: PLAGUE and MONSTERS -} - -void World::NewMonth(void) -{ -} - -void World::Reset(void) -{ - // maps tiles - if(vec_tiles.size()) - { - std::vector::const_iterator it = vec_tiles.begin(); - - for(; it != vec_tiles.end(); ++it) delete *it; - } - vec_tiles.clear(); - - // kingdoms - if(vec_kingdoms.size()) - { - std::vector::const_iterator it = vec_kingdoms.begin(); - - for(; it != vec_kingdoms.end(); ++it) delete *it; - } - vec_kingdoms.clear(); - - // event day - if(vec_eventsday.size()) - { - std::vector::const_iterator it = vec_eventsday.begin(); - - for(; it != vec_eventsday.end(); ++it) delete *it; - } - vec_eventsday.clear(); - - // event maps - if(vec_eventsmap.size()) - { - std::vector::const_iterator it = vec_eventsmap.begin(); - - for(; it != vec_eventsmap.end(); ++it) delete *it; - } - vec_eventsmap.clear(); - - // riddle - if(vec_riddles.size()) - { - std::vector::const_iterator it = vec_riddles.begin(); - - for(; it != vec_riddles.end(); ++it) delete *it; - } - vec_riddles.clear(); - - // rumors - vec_rumors.clear(); - - // castles - if(vec_castles.size()) - { - std::vector::const_iterator it = vec_castles.begin(); - - for(; it != vec_castles.end(); ++it) delete *it; - } - vec_castles.clear(); - - // heroes - if(vec_heroes.size()) - { - std::vector::const_iterator it = vec_heroes.begin(); - - for(; it != vec_heroes.end(); ++it) delete *it; - } - vec_heroes.clear(); - - // extra - map_sign.clear(); - map_captureobj.clear(); - - ultimate_artifact = -1; - Surface::FreeSurface(puzzle_surface); - - day = 0; - week = 0; - month = 0; - - week_name = Week::TORTOISE; - - heroes_cond_wins = Heroes::UNKNOWN; - heroes_cond_loss = Heroes::UNKNOWN; - - // reserve memory - vec_eventsday.reserve(6); - vec_eventsmap.reserve(6); - vec_riddles.reserve(10); - vec_rumors.reserve(10); - vec_castles.reserve(MAXCASTLES); - vec_kingdoms.reserve(KINGDOMMAX); - vec_heroes.reserve(HEROESMAXCOUNT + 2); -} - -Heroes* World::GetFreemanHeroes(Race::race_t rc) const -{ - u8 min = 0; - u8 max = 0; - - switch(rc) - { - case Race::KNGT: - min = 0; - max = 8; - break; - - case Race::BARB: - min = 9; - max = 17; - break; - - case Race::SORC: - min = 18; - max = 26; - break; - - case Race::WRLK: - min = 27; - max = 35; - break; - - case Race::WZRD: - min = 36; - max = 44; - break; - - case Race::NECR: - min = 45; - max = 53; - break; - - default: - min = 0; - max = 53; - break; - } - - std::vector freeman_heroes; - freeman_heroes.reserve(HEROESMAXCOUNT); - - // find freeman in race - if(Race::BOMG != rc) - for(u8 ii = min; ii <= max; ++ii) - if((*vec_heroes[ii]).isFreeman()) freeman_heroes.push_back(ii); - - // not found, find other race - if(Race::BOMG == rc || freeman_heroes.empty()) - for(u8 ii = 0; ii <= 53; ++ii) - if((*vec_heroes[ii]).isFreeman()) freeman_heroes.push_back(ii); - - // not found, all heroes busy - if(freeman_heroes.empty()) - { - DEBUG(DBG_GAME , DBG_WARN, "World::GetFreemanHeroes: freeman not found, all heroes busy."); - - return NULL; - } - - return vec_heroes.at(*Rand::Get(freeman_heroes)); -} - -const std::string & World::GetRumors(void) -{ - return vec_rumors[Rand::Get(vec_rumors.size() - 1)]; -} - -/* return random teleport destination */ -s32 World::NextTeleport(const s32 index) const -{ - std::vector vec_teleports; - - vec_teleports.reserve(10); - GetObjectIndexes(vec_teleports, MP2::OBJ_STONELIGHTS, false); - - if(2 > vec_teleports.size()) - { - DEBUG(DBG_GAME , DBG_WARN, "World::NextTeleport: is empty."); - return index; - } - - const u8 type = GetTiles(index).GetQuantity1(); - - std::vector v; - v.reserve(vec_teleports.size()); - - for(std::vector::const_iterator itv = vec_teleports.begin(); itv != vec_teleports.end(); ++itv) - if(type == GetTiles(*itv).GetQuantity1()) v.push_back(*itv); - - if(v.empty()) DEBUG(DBG_GAME , DBG_WARN, "World::NextTeleport: not found."); - - return v.size() ? *Rand::Get(v) : index; -} - -/* return random whirlpools destination */ -s32 World::NextWhirlpool(const s32 index) -{ - std::vector whilrpools; - std::vector::const_iterator itv; - - whilrpools.reserve(40); - GetObjectIndexes(whilrpools, MP2::OBJ_WHIRLPOOL, false); - - std::map > uniq_whirlpools; - - for(itv = whilrpools.begin(); itv != whilrpools.end(); ++itv) - { - const Maps::TilesAddon* addon = GetTiles(*itv).FindWhirlpools(); - if(addon) uniq_whirlpools[addon->uniq].push_back(*itv); - } - whilrpools.clear(); - - if(2 > uniq_whirlpools.size()) - { - DEBUG(DBG_GAME , DBG_WARN, "World::NextWhirlpool: is empty."); - return index; - } - - const Maps::TilesAddon* addon = GetTiles(index).FindWhirlpools(); - std::vector uniqs; - uniqs.reserve(uniq_whirlpools.size()); - - if(addon) - { - std::map >::const_iterator it1 = uniq_whirlpools.begin(); - std::map >::const_iterator it2 = uniq_whirlpools.end(); - for(; it1 != it2; ++it1) - { - const u32 & uniq = (*it1).first; - if(uniq == addon->uniq) continue; - uniqs.push_back(uniq); - } - } - - std::vector & dest = uniq_whirlpools[*Rand::Get(uniqs)]; - uniqs.clear(); - - if(dest.empty()) DEBUG(DBG_GAME , DBG_WARN, "World::NextWhirlpool: is full."); - - return dest.size() ? *Rand::Get(dest) : index; -} - -/* return message from sign */ -const std::string & World::MessageSign(const s32 index) -{ - return map_sign[index]; -} - -/* return count captured object */ -u16 World::CountCapturedObject(const MP2::object_t obj, const Color::color_t col) const -{ - std::map::const_iterator it1 = map_captureobj.begin(); - std::map::const_iterator it2 = map_captureobj.end(); - - u16 result = 0; - for(; it1 != it2; ++it1) if((*it1).second.isObject(obj) && (*it1).second.isColor(col)) ++result; - - return result; -} - -/* return count captured mines */ -u16 World::CountCapturedMines(const Resource::resource_t res, const Color::color_t col) const -{ - std::map::const_iterator it1 = map_captureobj.begin(); - std::map::const_iterator it2 = map_captureobj.end(); - - u16 result = 0; - - for(; it1 != it2; ++it1) - if((*it1).second.isObject(MP2::OBJ_MINES) || (*it1).second.isObject(MP2::OBJ_HEROES)) - { - // scan for find mines - const Maps::TilesAddon * addon = GetTiles((*it1).first).FindMines(); - - if(addon) - { - // index sprite EXTRAOVR - if(0 == addon->index && Resource::ORE == res && (*it1).second.isColor(col)) ++result; - else - if(1 == addon->index && Resource::SULFUR == res && (*it1).second.isColor(col)) ++result; - else - if(2 == addon->index && Resource::CRYSTAL == res && (*it1).second.isColor(col)) ++result; - else - if(3 == addon->index && Resource::GEMS == res && (*it1).second.isColor(col)) ++result; - else - if(4 == addon->index && Resource::GOLD == res && (*it1).second.isColor(col)) ++result; - } - } - - return result; -} - -/* capture object */ -void World::CaptureObject(const s32 index, const Color::color_t col) -{ - MP2::object_t obj = GetTiles(index).GetObject(); - - if(MP2::OBJ_HEROES == obj) - { - const Heroes * hero = GetHeroes(index); - if(NULL == hero) return; - - obj = hero->GetUnderObject(); - } - - map_captureobj[index].first = obj; - map_captureobj[index].second = col; - - if(MP2::OBJ_CASTLE == obj) - { - Castle *castle = GetCastle(index); - if(castle) castle->ChangeColor(col); - } - - GetTiles(index).CaptureFlags32(obj, col); -} - -/* return color captured object */ -Color::color_t World::ColorCapturedObject(const s32 index) const -{ - std::map::const_iterator it1 = map_captureobj.begin(); - std::map::const_iterator it2 = map_captureobj.end(); - - for(; it1 != it2; ++it1) if((*it1).first == index) return (*it1).second.second; - - return Color::GRAY; -} - -void World::ClearFog(const u8 color) -{ - // clear abroad castles - if(vec_castles.size()) - { - std::vector::const_iterator it1 = vec_castles.begin(); - std::vector::const_iterator it2 = vec_castles.end(); - - for(; it1 != it2; ++it1) if(*it1 && color & (**it1).GetColor()) (**it1).Scoute(); - } - - // clear abroad heroes - if(vec_heroes.size()) - { - std::vector::const_iterator it1 = vec_heroes.begin(); - std::vector::const_iterator it2 = vec_heroes.end(); - - for(; it1 != it2; ++it1) if(*it1 && color & (**it1).GetColor()) (**it1).Scoute(); - } - - // clear abroad objects - std::map::const_iterator it1 = map_captureobj.begin(); - std::map::const_iterator it2 = map_captureobj.end(); - - for(; it1 != it2; ++it1) - if(color & (*it1).second.second) - { - u8 scoute = 0; - - switch((*it1).second.first) - { - case MP2::OBJ_MINES: - case MP2::OBJ_ALCHEMYLAB: - case MP2::OBJ_SAWMILL: scoute = 2; break; - - case MP2::OBJ_LIGHTHOUSE: scoute = 4; break; // FIXME: scoute and lighthouse - - default: break; - } - - if(scoute) Maps::ClearFog((*it1).first, scoute, color); - } -} - -/* update population monster in dwelling */ -void World::UpdateDwellingPopulation(void) -{ - std::vector::iterator it1 = vec_tiles.begin(); - std::vector::const_iterator it2 = vec_tiles.end(); - for(; it1 != it2; ++it1) - { - Maps::Tiles & tile = **it1; - MP2::object_t obj = tile.GetObject(); - float count = 0; - - if(obj == MP2::OBJ_HEROES) - { - const Heroes* hero = world.GetHeroes(tile.GetIndex()); - if(hero) obj = hero->GetUnderObject(); - } - - switch(obj) - { - // join monsters - case MP2::OBJ_HALFLINGHOLE: - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_THATCHEDHUT: - case MP2::OBJ_EXCAVATION: - case MP2::OBJ_CAVE: - case MP2::OBJ_TREEHOUSE: - case MP2::OBJ_GOBLINHUT: - { - const Monster m(Monster::FromObject(obj)); - count = m.GetRNDSize(true) * 3 / 2; - break; - } - - case MP2::OBJ_TREECITY: - { - const Monster m(Monster::FromObject(obj)); - count = 2 * m.GetRNDSize(true); - break; - } - - case MP2::OBJ_WATCHTOWER: - case MP2::OBJ_ARCHERHOUSE: - case MP2::OBJ_DWARFCOTT: - // - case MP2::OBJ_RUINS: - case MP2::OBJ_WAGONCAMP: - case MP2::OBJ_DESERTTENT: - case MP2::OBJ_WATERALTAR: - case MP2::OBJ_AIRALTAR: - case MP2::OBJ_FIREALTAR: - case MP2::OBJ_EARTHALTAR: - case MP2::OBJ_BARROWMOUNDS: - { - const Monster m(Monster::FromObject(obj)); - count = m.GetRNDSize(true); - break; - } - - case MP2::OBJ_TROLLBRIDGE: - case MP2::OBJ_CITYDEAD: - { - const Monster m(Monster::FromObject(obj)); - count = m.GetRNDSize(true); - break; - } - - case MP2::OBJ_DRAGONCITY: - count = 1; - break; - - default: break; - } - - if(week == 1) - count = count * 3 / 2; - else - // check guardians beaten - switch(obj) - { - case MP2::OBJ_TROLLBRIDGE: - case MP2::OBJ_CITYDEAD: - case MP2::OBJ_DRAGONCITY: - if(0 == tile.GetQuantity4()) count = 0; - break; - - default: break; - } - - if(count) tile.SetCountMonster(tile.GetCountMonster() + static_cast(count)); - } -} - -void World::UpdateMonsterPopulation(void) -{ - std::vector::const_iterator it1 = vec_tiles.begin(); - std::vector::const_iterator it2 = vec_tiles.end(); - - for(; it1 != it2; ++it1) if(*it1 && MP2::OBJ_MONSTER == (*it1)->GetObject()) - { - Maps::Tiles & tile = **it1; - const Army::Troop troop(tile); - - if(0 == troop.GetCount()) - tile.SetCountMonster(troop.GetRNDSize(false)); - else - tile.SetCountMonster(troop.GetCount() * 8 / 7); - } -} - -Artifact::artifact_t World::GetUltimateArtifact(void) const -{ - return Maps::isValidAbsIndex(ultimate_artifact) ? Artifact::FromInt(vec_tiles[ultimate_artifact]->GetQuantity1()) : Artifact::UNKNOWN; -} - -bool World::DiggingForUltimateArtifact(const Point & center) -{ - Maps::Tiles & tile = GetTiles(center); - - // puts hole sprite - u8 obj = 0; - u8 idx = 0; - - switch(tile.GetGround()) - { - case Maps::Ground::WASTELAND: obj = 0xE4; idx = 70; break; // ICN::OBJNCRCK - case Maps::Ground::DIRT: obj = 0xE0; idx = 140; break; // ICN::OBJNDIRT - case Maps::Ground::DESERT: obj = 0xDC; idx = 68; break; // ICN::OBJNDSRT - case Maps::Ground::LAVA: obj = 0xD8; idx = 26; break; // ICN::OBJNLAVA - case Maps::Ground::GRASS: - default: obj = 0xC0; idx = 9; break; // ICN::OBJNGRA2 - } - tile.AddonsPushLevel1(Maps::TilesAddon(0, GetUniq(), obj, idx)); - - return ultimate_artifact == tile.GetIndex(); -} - -void World::ActionForMagellanMaps(u8 color) -{ - std::vector::const_iterator it1 = vec_tiles.begin(); - std::vector::const_iterator it2 = vec_tiles.end(); - - for(; it1 != it2; ++it1) if(*it1 && Maps::Ground::WATER == (*it1)->GetGround()) (*it1)->ClearFog(color); -} - -s32 World::GetNearestObject(const s32 center, const MP2::object_t obj) -{ - if(!Maps::isValidAbsIndex(center)) return -1; - - s32 res = -1; - s32 min = -1; - - std::vector::const_iterator it1 = vec_tiles.begin(); - std::vector::const_iterator it2 = vec_tiles.end(); - - for(; it1 != it2; ++it1) if(*it1 && obj == (*it1)->GetObject()) - { - const u16 min2 = Maps::GetApproximateDistance(center, (*it1)->GetIndex()); - if(min2 < min) - { - min = min2; - res = (*it1)->GetIndex(); - } - } - - return res; -} - -void World::GetEventDay(const Color::color_t c, std::vector & v) const -{ - if(vec_eventsday.size()) - { - std::vector::const_iterator it1 = vec_eventsday.begin(); - std::vector::const_iterator it2 = vec_eventsday.end(); - - for(; it1 != it2; ++it1) if(*it1) - { - const GameEvent::Day & event = **it1; - const u16 today = day; - const u16 first = event.GetFirst(); - const u16 sequent = event.GetSubsequent(); - - if((first == today || - (sequent && (first < today && 0 == ((today - first) % sequent)))) && - (c & event.GetColors())) v.push_back(*it1); - } - } -} - -const GameEvent::Coord* World::GetEventMaps(const Color::color_t c, const s32 index) const -{ - if(vec_eventsmap.size()) - { - std::vector::const_iterator it1 = vec_eventsmap.begin(); - std::vector::const_iterator it2 = vec_eventsmap.end(); - - for(; it1 != it2; ++it1) - if(*it1 && (*it1)->GetIndex() == index && (c & (*it1)->GetColors())) return *it1; - } - - return NULL; -} - -void World::StoreActionObject(const u8 color, std::map & store) -{ - std::vector::const_iterator it1 = vec_tiles.begin(); - std::vector::const_iterator it2 = vec_tiles.end(); - - for(; it1 != it2; ++it1) if(*it1) - { - const Maps::Tiles & tile = **it1; - if(tile.isFog(color)) continue; - - if(MP2::isGroundObject(tile.GetObject()) || MP2::isWaterObject(tile.GetObject()) || MP2::OBJ_HEROES == tile.GetObject()) - { - // if quantity object is empty - if(MP2::isQuantityObject(tile.GetObject()) && !tile.ValidQuantity()) continue; - - // skip for meeting heroes - if(MP2::OBJ_HEROES == tile.GetObject()) - { - const Heroes* hero = GetHeroes(tile.GetIndex()); - if(hero && color == hero->GetColor()) continue; - } - - // check: is visited objects - switch(tile.GetObject()) - { - case MP2::OBJ_MAGELLANMAPS: - case MP2::OBJ_OBSERVATIONTOWER: - if(world.GetKingdom(color).isVisited(tile)) continue; - break; - - default: break; - } - - store[tile.GetIndex()] = tile.GetObject(); - } - } -} - -void World::DateDump(void) const -{ - std::cout << "World::Date: month: " << static_cast(GetMonth()) << ", week " << static_cast(GetWeek()) << ", day: " << static_cast(GetDay()) << std::endl; -} - -u16 World::CountObeliskOnMaps(void) -{ - std::vector::const_iterator it1 = vec_tiles.begin(); - std::vector::const_iterator it2 = vec_tiles.end(); - u16 res = 0; - - for(; it1 != it2; ++it1) if(*it1) - { - switch((*it1)->GetObject()) - { - case MP2::OBJ_OBELISK: ++res; break; - case MP2::OBJ_HEROES: - { - const Heroes* hero = GetHeroes((*it1)->GetIndex()); - if(hero && MP2::OBJ_OBELISK == hero->GetUnderObject()) ++res; - break; - } - default: break; - } - } - - return res ? res : 6; -} - -void World::KingdomLoss(const Color::color_t color) -{ - // castles - std::vector::iterator itc1 = vec_castles.begin(); - std::vector::const_iterator itc2 = vec_castles.end(); - for(; itc1 != itc2; ++itc1) if(*itc1 && (*itc1)->GetColor() == color) (*itc1)->ChangeColor(color); - - // capture object - std::map::iterator it1 = map_captureobj.begin(); - std::map::const_iterator it2 = map_captureobj.end(); - for(; it1 != it2; ++it1) - { - ObjectColor & pair = (*it1).second; - if(pair.isColor(color)) - { - pair.second = Color::GRAY; - GetTiles((*it1).first).CaptureFlags32(pair.first, Color::GRAY); - } - } -} - -Heroes* World::FromJail(s32 index) -{ - std::vector::iterator ith1 = vec_heroes.begin(); - std::vector::const_iterator ith2 = vec_heroes.end(); - for(; ith1 != ith2; ++ith1) if(*ith1 && (*ith1)->Modes(Heroes::JAIL) && index == (*ith1)->GetIndex()) return *ith1; - - return NULL; -} - -void World::ActionToEyeMagi(const Color::color_t color) const -{ - std::vector vec_eyes; - vec_eyes.reserve(10); - GetObjectIndexes(vec_eyes, MP2::OBJ_EYEMAGI, true); - - if(vec_eyes.size()) - { - std::vector::const_iterator it1 = vec_eyes.begin(); - std::vector::const_iterator it2 = vec_eyes.end(); - - for(; it1 != it2; ++it1) Maps::ClearFog(*it1, Game::GetViewDistance(Game::VIEW_MAGI_EYES), color); - } -} - -GameEvent::Riddle* World::GetSphinx(const s32 index) const -{ - std::vector::const_iterator it1 = vec_riddles.begin(); - std::vector::const_iterator it2 = vec_riddles.end(); - - for(; it1 != it2; ++it1) if(*it1 && (*it1)->GetIndex() == index) return *it1; - - return NULL; -} - -void World::GetObjectIndexes(std::vector & v, MP2::object_t obj, bool check_hero) const -{ - std::vector::const_iterator it1 = vec_tiles.begin(); - std::vector::const_iterator it2 = vec_tiles.end(); - - for(; it1 != it2; ++it1) - if(*it1 && obj == (*it1)->GetObject()) v.push_back((*it1)->GetIndex()); - else - if(check_hero && *it1 && MP2::OBJ_HEROES == (*it1)->GetObject()) - { - const Heroes* hero = GetHeroes((*it1)->GetIndex()); - if(hero && obj == hero->GetUnderObject()) v.push_back((*it1)->GetIndex()); - } -} - -void World::UpdateRecruits(Recruits & recruits) const -{ - if(2 < std::count_if(vec_heroes.begin(), vec_heroes.end(), PredicateHeroesIsFreeman)) - while(recruits.GetID1() == recruits.GetID2()) recruits.SetHero2(GetFreemanHeroes()); - else - recruits.SetHero2(NULL); -} - -const Heroes* World::GetHeroesCondWins(void) const -{ - return GetHeroes(heroes_cond_wins); -} - -const Heroes* World::GetHeroesCondLoss(void) const -{ - return GetHeroes(heroes_cond_loss); -} - -bool World::CheckKingdomNormalVictory(const Kingdom & kingdom) const -{ - return !kingdom.isLoss() && - 1 == std::count_if(&vec_kingdoms[0], &vec_kingdoms[6], std::not1(std::mem_fun(&Kingdom::isLoss))); -} - -bool WorldCheckKingdomLossWins(const Kingdom* kingdom) -{ - if(kingdom) - switch(world.CheckKingdomWins(*kingdom)) - { - case GameOver::WINS_ALL: - case GameOver::WINS_TOWN: - case GameOver::WINS_HERO: - case GameOver::COND_NONE: - return false; - - default: - return true; - } - - return false; -} - -u16 World::CheckKingdomWins(const Kingdom & kingdom) const -{ - const Settings & conf = Settings::Get(); - - if((conf.ConditionWins() & GameOver::WINS_ALL) && CheckKingdomNormalVictory(kingdom)) - return GameOver::WINS_ALL; - else - if(conf.ConditionWins() & GameOver::WINS_TOWN) - { - const Castle *town = GetCastle(conf.WinsMapsIndexObject()); - - // check comp also wins - if(Game::AI == kingdom.Control() && !conf.WinsCompAlsoWins()) - return GameOver::COND_NONE; - else - if(town && town->GetColor() == kingdom.GetColor()) - return GameOver::WINS_TOWN; - } - else - if(conf.ConditionWins() & GameOver::WINS_HERO) - { - const Heroes *hero = GetHeroesCondWins(); - if(hero && Heroes::UNKNOWN != heroes_cond_wins && - hero->isFreeman() && - hero->GetKillerColor() == kingdom.GetColor()) - return GameOver::WINS_HERO; - } - else - if(conf.ConditionWins() & GameOver::WINS_ARTIFACT) - { - if(conf.WinsFindUltimateArtifact()) - { - std::vector::const_iterator beg = kingdom.GetHeroes().begin(); - std::vector::const_iterator end = kingdom.GetHeroes().end(); - if(end != std::find_if(beg, end, std::mem_fun(&Heroes::HasUltimateArtifact))) - return GameOver::WINS_ARTIFACT; - } - else - { - const Artifact::artifact_t art = conf.WinsFindArtifact(); - std::vector::const_iterator beg = kingdom.GetHeroes().begin(); - std::vector::const_iterator end = kingdom.GetHeroes().end(); - if(end != std::find_if(beg, end, std::bind2nd(std::mem_fun(&Heroes::HasArtifact), art))) - return GameOver::WINS_ARTIFACT; - } - } - else - if(conf.ConditionWins() & GameOver::WINS_SIDE) - { - u8 side1 = conf.GetUnions(kingdom.GetColor()); - u8 side2 = conf.KingdomColors() & ~side1; - u8 loss = 0; - - for(Color::color_t cl = Color::BLUE; cl < Color::GRAY; ++cl) - if(world.GetKingdom(cl).isLoss()) loss |= cl; - - if(side2 == (loss & side2)) - return GameOver::WINS_SIDE; - } - else - if(conf.ConditionWins() & GameOver::WINS_GOLD) - { - // check comp also wins - if(Game::AI == kingdom.Control() && !conf.WinsCompAlsoWins()) - return GameOver::COND_NONE; - else - if(kingdom.GetFundsGold() >= conf.WinsAccumulateGold()) - return GameOver::WINS_GOLD; - } - - return GameOver::COND_NONE; -} - -u16 World::CheckKingdomLoss(const Kingdom & kingdom) const -{ - const Settings & conf = Settings::Get(); - - // if other wins return false (skip for alianse) - if(!(conf.ConditionWins() & GameOver::WINS_SIDE)) - { - std::vector::const_iterator it = std::find_if(vec_kingdoms.begin(), vec_kingdoms.end(), WorldCheckKingdomLossWins); - if(vec_kingdoms.end() != it && *it && (*it)->GetColor() != kingdom.GetColor()) - return CheckKingdomWins(**it); - } - - if(conf.ConditionLoss() & GameOver::LOSS_ALL) - { - if(kingdom.isLoss()) - return GameOver::LOSS_ALL; - } - else - if(conf.ConditionLoss() & GameOver::LOSS_TOWN) - { - const Castle *town = GetCastle(conf.LossMapsIndexObject()); - if(town && town->GetColor() != kingdom.GetColor()) - return GameOver::LOSS_TOWN; - } - else - if(conf.ConditionLoss() & GameOver::LOSS_HERO) - { - const Heroes *hero = GetHeroesCondLoss(); - if(hero && Heroes::UNKNOWN != heroes_cond_loss && - hero->isFreeman() && - hero->GetKillerColor() != kingdom.GetColor()) - return GameOver::LOSS_HERO; - } - else - if(conf.ConditionLoss() & GameOver::LOSS_TIME) - { - if(CountDay() > conf.LossCountDays()) - return GameOver::LOSS_TIME; - } - - return GameOver::COND_NONE; -} - -const Surface & World::GetPuzzleSurface(void) const -{ - return puzzle_surface; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/kingdom/world.h b/project/jni/application/fheroes2/src/fheroes2/kingdom/world.h deleted file mode 100644 index bca743fbd..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/kingdom/world.h +++ /dev/null @@ -1,193 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2WORLD_H -#define H2WORLD_H - -#include -#include -#include -#include "gamedefs.h" -#include "maps.h" -#include "race.h" -#include "maps_tiles.h" -#include "heroes.h" -#include "week.h" -#include "color.h" -#include "sprite.h" -#include "game_io.h" - -class Heroes; -class Castle; -class Kingdom; -class Recruits; -class Radar; - -namespace GameEvent -{ - class Day; - class Coord; - class Riddle; -} - -class World : protected Size -{ -public: - ~World(){ Reset(); } - - void LoadMaps(const std::string &filename); - void NewMaps(const u16 sw, const u16 sh); - - static World & Get(void); - - u16 w(void){ return width; } - u16 h(void){ return height; } - - const Maps::Tiles & GetTiles(const Point & pt) const{ return GetTiles(pt.y * width + pt.x); } - const Maps::Tiles & GetTiles(u16 ax, u16 ay) const{ return GetTiles(ay * width + ax); } - const Maps::Tiles & GetTiles(s32 index) const{ return *vec_tiles.at(index); } - Maps::Tiles & GetTiles(const Point & pt) { return GetTiles(pt.y * width + pt.x); } - Maps::Tiles & GetTiles(u16 ax, u16 ay) { return GetTiles(ay * width + ax); } - Maps::Tiles & GetTiles(s32 index){ return *vec_tiles.at(index); } - - Kingdom & GetMyKingdom(void); - Kingdom & GetKingdom(u8 color); - const Kingdom & GetMyKingdom(void) const; - const Kingdom & GetKingdom(u8 color) const; - void KingdomLoss(const Color::color_t); - - const Castle * GetCastle(s32 maps_index) const; - Castle * GetCastle(s32 maps_index); - Castle * GetCastle(u16 ax, u16 ay) const; - - const Heroes * GetHeroes(Heroes::heroes_t) const; - const Heroes * GetHeroes(s32 maps_index) const; - Heroes * GetHeroes(Heroes::heroes_t); - Heroes * GetHeroes(s32 maps_index); - Heroes * GetHeroes(u16 ax, u16 ay) const; - Heroes * FromJail(s32); - const Heroes * GetHeroesCondWins(void) const; - const Heroes * GetHeroesCondLoss(void) const; - - const Surface & GetPuzzleSurface(void) const; - Artifact::artifact_t GetUltimateArtifact(void) const; - bool DiggingForUltimateArtifact(const Point & center); - void ActionForMagellanMaps(u8 color); - - u8 GetDay(void) const{ return LastDay() ? DAYOFWEEK : day % DAYOFWEEK; } - u8 GetWeek(void) const{ return LastWeek() ? WEEKOFMONTH : week % WEEKOFMONTH; } - u8 GetMonth(void) const{ return month; } - u16 CountDay(void) const{ return day; } - u16 CountWeek(void) const{ return week; } - bool BeginWeek(void) const{ return 1 == (day % DAYOFWEEK); } - bool BeginMonth(void) const{ return 1 == (week % WEEKOFMONTH) && BeginWeek(); } - bool LastDay(void) const{ return (0 == (day % DAYOFWEEK)); } - bool LastWeek(void) const{ return (0 == (week % WEEKOFMONTH)); } - Week::type_t GetWeekType(void) const{ return week_name; } - void DateDump(void) const; - - void NewDay(void); - void NewWeek(void); - void NewMonth(void); - - const std::string & GetRumors(void); - - s32 NextTeleport(const s32 index) const; - s32 NextWhirlpool(const s32 index); - - const std::string & MessageSign(const s32 index); - - s32 GetNearestObject(const s32 center, const MP2::object_t obj); - void CaptureObject(const s32 index, const Color::color_t col); - u16 CountCapturedObject(const MP2::object_t obj, const Color::color_t col) const; - u16 CountCapturedMines(const Resource::resource_t res, const Color::color_t col) const; - Color::color_t ColorCapturedObject(const s32 index) const; - void StoreActionObject(const u8 color, std::map & store); - - void ActionToEyeMagi(const Color::color_t) const; - - u16 CountObeliskOnMaps(void); - - void ClearFog(const u8 color); - - u16 CheckKingdomWins(const Kingdom &) const; - u16 CheckKingdomLoss(const Kingdom &) const; - - void GetEventDay(const Color::color_t, std::vector &) const; - const GameEvent::Coord* GetEventMaps(const Color::color_t c, const s32 index) const; - GameEvent::Riddle* GetSphinx(const s32 index) const; - - Heroes* GetFreemanHeroes(Race::race_t rc = Race::BOMG) const; - void UpdateRecruits(Recruits &) const; - - static u32 GetUniq(void){ return ++uniq0; }; - -protected: - void UpdateDwellingPopulation(void); - void UpdateMonsterPopulation(void); - void GetObjectIndexes(std::vector &, MP2::object_t, bool) const; - bool CheckKingdomNormalVictory(const Kingdom &) const; - -private: - World() : Size(0, 0), width(Size::w), height(Size::h) {}; - void Defaults(void); - void Reset(void); - -private: - friend class Radar; - friend class Game::IO; - - std::vector vec_tiles; - std::vector vec_kingdoms; - std::vector vec_eventsday; - std::vector vec_eventsmap; - std::vector vec_riddles; - std::vector vec_rumors; - std::vector vec_castles; - std::vector vec_heroes; - - std::map map_sign; - - // index, object, color - std::map map_captureobj; - - s32 ultimate_artifact; - - u16 & width; - u16 & height; - - u16 day; - u16 week; - u8 month; - - Week::type_t week_name; - - Heroes::heroes_t heroes_cond_wins; - Heroes::heroes_t heroes_cond_loss; - - Surface puzzle_surface; - - static u32 uniq0; -}; - -extern World & world; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/ground.cpp b/project/jni/application/fheroes2/src/fheroes2/maps/ground.cpp deleted file mode 100644 index 6e0aa24e3..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/ground.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "maps_tiles.h" -#include "direction.h" -#include "world.h" -#include "ground.h" - -const char* Maps::Ground::String(u16 ground) -{ - const char* str_ground[] = { _("Desert"), _("Snow"), _("Swamp"), _("Wasteland"), _("Beach"), - _("Lava"), _("Dirt"), _("Grass"), _("Water"), "Unknown" }; - - switch(ground) - { - case DESERT: return str_ground[0]; - case SNOW: return str_ground[1]; - case SWAMP: return str_ground[2]; - case WASTELAND: return str_ground[3]; - case BEACH: return str_ground[4]; - case LAVA: return str_ground[5]; - case DIRT: return str_ground[6]; - case GRASS: return str_ground[7]; - case WATER: return str_ground[8]; - default: break; - } - - return str_ground[8]; -} - -u16 Maps::Ground::GetBasePenalty(const s32 index, const u8 pathfinding) -{ - const Maps::Tiles & tile = world.GetTiles(index); - - // none basc advd expr - // Desert 2.00 1.75 1.50 1.00 - // Snow 1.75 1.50 1.25 1.00 - // Swamp 1.75 1.50 1.25 1.00 - // Cracked 1.25 1.00 1.00 1.00 - // Beach 1.25 1.00 1.00 1.00 - // Lava 1.00 1.00 1.00 1.00 - // Dirt 1.00 1.00 1.00 1.00 - // Grass 1.00 1.00 1.00 1.00 - // Water 1.00 1.00 1.00 1.00 - // Road 0.75 0.75 0.75 0.75 - - // if(tile.isRoad(direct)) need fix isRoad(Direction::vector_t) - - - if(tile.isRoad()) - return 75; - else - switch(tile.GetGround()) - { - case DESERT: - { - u16 fee = Skill::Secondary::GetValues(Skill::Secondary::PATHFINDING, pathfinding); - if(fee > 100) fee = 100; - - const u8 extra = 100; - return 100 + extra - (extra * fee / 100); - } - - case SNOW: - case SWAMP: - { - u16 fee = Skill::Secondary::GetValues(Skill::Secondary::PATHFINDING, pathfinding); - - const u8 extra = 75; - return 100 + extra - (extra * fee / 100); - } - - case WASTELAND: - case BEACH: - return (Skill::Level::NONE == pathfinding ? 125 : 100); - - default: break; - } - - return 100; -} - -u16 Maps::Ground::GetPenalty(const s32 index, const Direction::vector_t direct, const u8 pathfinding) -{ - if(Direction::UNKNOWN == direct) return MAXU16; - - u16 result = GetBasePenalty(index, pathfinding); - - switch(direct) - { - case Direction::TOP_RIGHT: - case Direction::BOTTOM_RIGHT: - case Direction::BOTTOM_LEFT: - case Direction::TOP_LEFT: result = static_cast(1.44 * result); break; - - default: break; - } - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/ground.h b/project/jni/application/fheroes2/src/fheroes2/maps/ground.h deleted file mode 100644 index 8ef063a26..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/ground.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2MAPSGROUND_H -#define H2MAPSGROUND_H - -#include -#include "gamedefs.h" -#include "direction.h" -#include "skill.h" - -namespace Maps -{ - class Tiles; - - namespace Ground - { - enum ground_t - { - UNKNOWN = 0x0000, - DESERT = 0x0001, - SNOW = 0x0002, - SWAMP = 0x0004, - WASTELAND = 0x0008, - BEACH = 0x0010, - LAVA = 0x0020, - DIRT = 0x0040, - GRASS = 0x0080, - WATER = 0x0100 - }; - - const char* String(u16); - u16 GetBasePenalty(const s32 index, const u8 pathfinding); - u16 GetPenalty(const s32 index, const Direction::vector_t direct, const u8 pathfinding); - } -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/maps.cpp b/project/jni/application/fheroes2/src/fheroes2/maps/maps.cpp deleted file mode 100644 index b084cb7d2..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/maps.cpp +++ /dev/null @@ -1,473 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "world.h" -#include "settings.h" -#include "maps.h" -#include "kingdom.h" -#include "maps_tiles.h" - -namespace Maps -{ - static u32 animation_ticket = 0; -} - -const char* Maps::SizeString(u16 s) -{ - const char* mapsize[] = { "Unknown", _("maps|Small"), _("maps|Medium"), _("maps|Large"), _("maps|Extra Large"), "size256", "size320" }; - - switch(s) - { - case SMALL: return mapsize[1]; - case MEDIUM: return mapsize[2]; - case LARGE: return mapsize[3]; - case XLARGE: return mapsize[4]; - case XLARGE2: return mapsize[5]; - case XLARGE3: return mapsize[6]; - default: break; - } - - return mapsize[0]; -} - -const char* Maps::GetMinesName(u8 type) -{ - switch(type) - { - case Resource::ORE: return _("Ore Mine"); - case Resource::SULFUR: return _("Sulfur Mine"); - case Resource::CRYSTAL: return _("Crystal Mine"); - case Resource::GEMS: return _("Gems Mine"); - case Resource::GOLD: return _("Gold Mine"); - default: break; - } - - return _("Mine"); -} - -u32 Maps::AnimationTicket(void) -{ - return animation_ticket; -} - -void Maps::IncreaseAnimationTicket(void) -{ - ++animation_ticket; -} - -s32 Maps::GetDirectionIndex(s32 from, Direction::vector_t vector) -{ - switch(vector) - { - case Direction::TOP: return from - world.w(); - case Direction::TOP_RIGHT: return from - world.w() + 1; - case Direction::RIGHT: return from + 1; - case Direction::BOTTOM_RIGHT: return from + world.w() + 1; - case Direction::BOTTOM: return from + world.w(); - case Direction::BOTTOM_LEFT: return from + world.w() - 1; - case Direction::LEFT: return from - 1; - case Direction::TOP_LEFT: return from - world.w() - 1; - default: break; - } - - return -1; -} - -// check bound -bool Maps::isValidDirection(s32 from, Direction::vector_t vector) -{ - switch(vector) - { - case Direction::TOP: return (!(from < world.w())); - case Direction::TOP_RIGHT: return (!(from < world.w()) && (world.w() - 1 > (from % world.w()))); - case Direction::RIGHT: return (world.w() - 1 > (from % world.w())); - case Direction::BOTTOM_RIGHT: return ((from < world.w() * (world.h() - 1)) && (world.w() - 1 > (from % world.w()))); - case Direction::BOTTOM: return (from < world.w() * (world.h() - 1)); - case Direction::BOTTOM_LEFT: return ((from < world.w() * (world.h() - 1)) && (from % world.w())); - case Direction::LEFT: return (from % world.w()); - case Direction::TOP_LEFT: return (!(from < world.w()) && (from % world.w())); - default: break; - } - - return false; -} - -bool Maps::isValidAbsPoint(const Point & pt) -{ - return isValidAbsPoint(pt.x, pt.y); -} - -bool Maps::isValidAbsIndex(s32 i) -{ - return 0 <= i && i < world.w() * world.h(); -} - -bool Maps::isValidAbsPoint(s16 x, s16 y) -{ - return 0 <= x && world.w() > x && 0 <= y && world.h() > y; -} - -/* convert maps point to index maps */ -s32 Maps::GetIndexFromAbsPoint(const Point & mp) -{ - return GetIndexFromAbsPoint(mp.x, mp.y); -} - -s32 Maps::GetIndexFromAbsPoint(s16 px, s16 py) -{ - s32 res = py * world.w() + px; - - if(px < 0 || py < 0) - { - VERBOSE("Maps::GetIndexFromAbsPoint: return " << res); - } - - return res; -} - -u16 Maps::GetDirectionAroundGround(const s32 center, const u16 ground) -{ - if(0 == ground || !isValidAbsIndex(center)) return 0; - - u16 result = 0; - - for(Direction::vector_t direct = Direction::TOP_LEFT; direct != Direction::CENTER; ++direct) - if(!isValidDirection(center, direct)) - result |= direct; - else - if(ground & world.GetTiles(GetDirectionIndex(center, direct)).GetGround()) result |= direct; - - return result; -} - -u8 Maps::GetCountAroundGround(const s32 center, const u16 ground) -{ - if(0 == ground || !isValidAbsIndex(center)) return 0; - - u8 result = 0; - - for(Direction::vector_t direct = Direction::TOP_LEFT; direct != Direction::CENTER; ++direct) - if(!isValidDirection(center, direct)) - ++result; - else - if(ground & world.GetTiles(GetDirectionIndex(center, direct)).GetGround()) ++result; - - return result; -} - -u16 Maps::GetMaxGroundAround(const s32 center) -{ - if(!isValidAbsIndex(center)) return 0; - - std::vector grounds(9, 0); - u16 result = 0; - - for(Direction::vector_t direct = Direction::TOP_LEFT; direct != Direction::CENTER; ++direct) - { - const Maps::Tiles & tile = (isValidDirection(center, direct) ? - world.GetTiles(GetDirectionIndex(center, direct)) : world.GetTiles(center)); - - switch(tile.GetGround()) - { - case Maps::Ground::DESERT: ++grounds[0]; break; - case Maps::Ground::SNOW: ++grounds[1]; break; - case Maps::Ground::SWAMP: ++grounds[2]; break; - case Maps::Ground::WASTELAND:++grounds[3]; break; - case Maps::Ground::BEACH: ++grounds[4]; break; - case Maps::Ground::LAVA: ++grounds[5]; break; - case Maps::Ground::DIRT: ++grounds[6]; break; - case Maps::Ground::GRASS: ++grounds[7]; break; - case Maps::Ground::WATER: ++grounds[8]; break; - default: break; - } - } - - const u8 max = *std::max_element(grounds.begin(), grounds.end()); - - if(max == grounds[0]) result |= Maps::Ground::DESERT; - if(max == grounds[1]) result |= Maps::Ground::SNOW; - if(max == grounds[2]) result |= Maps::Ground::SWAMP; - if(max == grounds[3]) result |= Maps::Ground::WASTELAND; - if(max == grounds[4]) result |= Maps::Ground::BEACH; - if(max == grounds[5]) result |= Maps::Ground::LAVA; - if(max == grounds[6]) result |= Maps::Ground::DIRT; - if(max == grounds[7]) result |= Maps::Ground::GRASS; - if(max == grounds[8]) result |= Maps::Ground::WATER; - - return result; -} - -void Maps::ClearFog(s32 index, u8 scoute, const u8 color) -{ - if(0 == scoute || !isValidAbsIndex(index)) return; - const Point center(index % world.w(), index / world.w()); - - // AI advantage - if(Game::AI == world.GetKingdom(color).Control()) - { - switch(Settings::Get().GameDifficulty()) - { - case Difficulty::NORMAL: scoute += 2; break; - case Difficulty::HARD: scoute += 3; break; - case Difficulty::EXPERT: scoute += 4; break; - case Difficulty::IMPOSSIBLE:scoute += 6; break; - default: break; - } - } - - for(s16 y = center.y - scoute; y <= center.y + scoute; ++y) - for(s16 x = center.x - scoute; x <= center.x + scoute; ++x) - if(isValidAbsPoint(x, y) && (scoute + scoute / 2) >= std::abs(x - center.x) + std::abs(y - center.y)) - world.GetTiles(GetIndexFromAbsPoint(x, y)).ClearFog(color); -} - -u16 Maps::ScanAroundObject(const s32 center, const u8 obj, const u16 exclude) -{ - if(!isValidAbsIndex(center)) return 0; - - u16 result = 0; - - for(Direction::vector_t dir = Direction::TOP_LEFT; dir < Direction::CENTER; ++dir) - { - if((exclude & dir) || !isValidDirection(center, dir)) continue; - if(obj == world.GetTiles(GetDirectionIndex(center, dir)).GetObject()) result |= dir; - } - - return result; -} - -bool Maps::ScanDistanceObject(const s32 center, const u8 obj, const u16 dist, std::vector & results) -{ - if(!isValidAbsIndex(center)) return false; - if(results.size()) results.clear(); - - const s16 cx = center % world.w(); - const s16 cy = center / world.w(); - - // from center to abroad - for(u16 ii = 1; ii <= dist; ++ii) - { - const s16 tx = cx - ii; - const s16 ty = cy - ii; - - const s16 mx = tx + 2 * ii; - const s16 my = ty + 2 * ii; - - for(s16 iy = ty; iy <= my; ++iy) - for(s16 ix = tx; ix <= mx; ++ix) - { - if(ty < iy && iy < my && tx < ix && ix < mx) continue; - - const s32 index = GetIndexFromAbsPoint(ix, iy); - - if(isValidAbsIndex(index) && - obj == world.GetTiles(index).GetObject()) - results.push_back(index); - } - } - - return results.size(); -} - -u16 Maps::GetApproximateDistance(const s32 index1, const s32 index2) -{ - return std::max(std::abs((index1 % world.w()) - (index2 % world.w())), - std::abs((index1 / world.w()) - (index2 / world.w()))); -} - - -void Maps::MinimizeAreaForCastle(const Point & center) -{ - // reset castle ID - for(s8 yy = -3; yy < 2; ++yy) - for(s8 xx = -2; xx < 3; ++xx) - { - Maps::Tiles & tile = world.GetTiles((center.y + yy) * world.h() + center.x + xx); - - if(MP2::OBJN_RNDCASTLE == tile.GetObject() || - MP2::OBJN_RNDTOWN == tile.GetObject() || - MP2::OBJN_CASTLE == tile.GetObject()) tile.SetObject(MP2::OBJ_ZERO); - } - - // set minimum area castle ID - for(s8 yy = -1; yy < 1; ++yy) - for(s8 xx = -2; xx < 3; ++xx) - { - Maps::Tiles & tile = world.GetTiles((center.y + yy) * world.h() + center.x + xx); - - // skip angle - if(yy == -1 && (xx == -2 || xx == 2)) continue; - - tile.SetObject(MP2::OBJN_CASTLE); - } - - // restore center ID - world.GetTiles(center).SetObject(MP2::OBJ_CASTLE); -} - -/* correct sprites for RND castles */ -void Maps::UpdateRNDSpriteForCastle(const Point & center, u8 race, bool castle) -{ -/* -castle size: T and B - sprite, S - shadow, XX - center - - T0 - S1S1T1T1T1T1T1 - S2S2S2T2T2T2T2T2 - S3S3B1B1XXB1B1 - S4B2B2 B2B2 -*/ - std::vector coords; - coords.reserve(21); - - // T0 - if(castle) coords.push_back(GetIndexFromAbsPoint(center.x, center.y - 3)); - // T1 - coords.push_back(GetIndexFromAbsPoint(center.x - 2, center.y - 2)); - coords.push_back(GetIndexFromAbsPoint(center.x - 1, center.y - 2)); - coords.push_back(GetIndexFromAbsPoint(center.x, center.y - 2)); - coords.push_back(GetIndexFromAbsPoint(center.x + 1, center.y - 2)); - coords.push_back(GetIndexFromAbsPoint(center.x + 2, center.y - 2)); - // T2 - coords.push_back(GetIndexFromAbsPoint(center.x - 2, center.y - 1)); - coords.push_back(GetIndexFromAbsPoint(center.x - 1, center.y - 1)); - coords.push_back(GetIndexFromAbsPoint(center.x, center.y - 1)); - coords.push_back(GetIndexFromAbsPoint(center.x + 1, center.y - 1)); - coords.push_back(GetIndexFromAbsPoint(center.x + 2, center.y - 1)); - // B1 - coords.push_back(GetIndexFromAbsPoint(center.x - 2, center.y)); - coords.push_back(GetIndexFromAbsPoint(center.x - 1, center.y)); - coords.push_back(GetIndexFromAbsPoint(center.x, center.y)); - coords.push_back(GetIndexFromAbsPoint(center.x + 1, center.y)); - coords.push_back(GetIndexFromAbsPoint(center.x + 2, center.y)); - // B2 - coords.push_back(GetIndexFromAbsPoint(center.x - 2, center.y + 1)); - coords.push_back(GetIndexFromAbsPoint(center.x - 1, center.y + 1)); - coords.push_back(GetIndexFromAbsPoint(center.x, center.y + 1)); - coords.push_back(GetIndexFromAbsPoint(center.x + 1, center.y + 1)); - coords.push_back(GetIndexFromAbsPoint(center.x + 2, center.y + 1)); - - Maps::Tiles & tile_center = world.GetTiles(center); - - // correct only RND town and castle - switch(tile_center.GetObject()) - { - case MP2::OBJ_RNDTOWN: - case MP2::OBJ_RNDCASTLE: - break; - - default: - DEBUG(DBG_GAME , DBG_WARN, "Maps::UpdateRNDSpriteForCastle: correct only RND town and castle. index: " << GetIndexFromAbsPoint(center.x, center.y)); - return; - } - - // modify all rnd sprites - std::vector::const_iterator it1 = coords.begin(); - std::vector::const_iterator it2 = coords.end(); - - for(; it1 != it2; ++it1) if(isValidAbsIndex(*it1)) - { - Maps::TilesAddon *addon = world.GetTiles(*it1).FindRNDCastle(); - if(addon) - { - addon->object -= 12; - - switch(race) - { - case Race::KNGT: break; - case Race::BARB: addon->index += 32; break; - case Race::SORC: addon->index += 64; break; - case Race::WRLK: addon->index += 96; break; - case Race::WZRD: addon->index += 128; break; - case Race::NECR: addon->index += 160; break; - default: break; - } - } - } -} - -void Maps::UpdateSpritesFromTownToCastle(const Point & center) -{ - // correct area maps sprites - std::vector coords; - coords.reserve(15); - - // T1 - coords.push_back(GetIndexFromAbsPoint(center.x - 2, center.y - 2)); - coords.push_back(GetIndexFromAbsPoint(center.x - 1, center.y - 2)); - coords.push_back(GetIndexFromAbsPoint(center.x, center.y - 2)); - coords.push_back(GetIndexFromAbsPoint(center.x + 1, center.y - 2)); - coords.push_back(GetIndexFromAbsPoint(center.x + 2, center.y - 2)); - // T2 - coords.push_back(GetIndexFromAbsPoint(center.x - 2, center.y - 1)); - coords.push_back(GetIndexFromAbsPoint(center.x - 1, center.y - 1)); - coords.push_back(GetIndexFromAbsPoint(center.x, center.y - 1)); - coords.push_back(GetIndexFromAbsPoint(center.x + 1, center.y - 1)); - coords.push_back(GetIndexFromAbsPoint(center.x + 2, center.y - 1)); - // B1 - coords.push_back(GetIndexFromAbsPoint(center.x - 2, center.y)); - coords.push_back(GetIndexFromAbsPoint(center.x - 1, center.y)); - coords.push_back(GetIndexFromAbsPoint(center.x, center.y)); - coords.push_back(GetIndexFromAbsPoint(center.x + 1, center.y)); - coords.push_back(GetIndexFromAbsPoint(center.x + 2, center.y)); - - // modify all town sprites - std::vector::const_iterator it1 = coords.begin(); - std::vector::const_iterator it2 = coords.end(); - for(; it1 != it2; ++it1) if(isValidAbsIndex(*it1)) - { - TilesAddon *addon = world.GetTiles(*it1).FindCastle(); - if(addon) addon->index -= 16; - } - - // T0 - if(isValidAbsIndex(GetIndexFromAbsPoint(center.x, center.y - 3) && isValidAbsIndex(GetIndexFromAbsPoint(center.x, center.y - 2)))) - { - TilesAddon *addon = world.GetTiles(GetIndexFromAbsPoint(center.x, center.y - 2)).FindCastle(); - if(addon) - world.GetTiles(GetIndexFromAbsPoint(center.x, center.y - 3)).AddonsPushLevel2(TilesAddon(addon->level, addon->uniq, addon->object, addon->index - 3)); - } -} - -u16 Maps::TileUnderProtection(const s32 center) -{ - if(!isValidAbsIndex(center) || Ground::WATER == world.GetTiles(center).GetGround()) return 0; - - u16 result = 0; - const u16 dst_around = Maps::ScanAroundObject(center, MP2::OBJ_MONSTER); - const u8 obj = MP2::OBJ_HEROES == world.GetTiles(center).GetObject() && world.GetHeroes(center) ? - world.GetHeroes(center)->GetUnderObject() : world.GetTiles(center).GetObject(); - - for(Direction::vector_t dir = Direction::TOP_LEFT; dir < Direction::CENTER; ++dir) if(dst_around & dir) - { - if((Direction::TOP | Direction::TOP_LEFT | Direction::TOP_RIGHT) & dir) - { - if(! MP2::isGroundObject(obj)) result |= dir; - } - else - result |= dir; - } - - return result; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/maps.h b/project/jni/application/fheroes2/src/fheroes2/maps/maps.h deleted file mode 100644 index 20207b08a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/maps.h +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2MAPS_H -#define H2MAPS_H - -#include "gamedefs.h" -#include "direction.h" - -#define TILEWIDTH 32 - -class Point; -class Castle; - -namespace Maps -{ - enum mapsize_t - { - ZERO = 0, - SMALL = 36, - MEDIUM = 72, - LARGE = 108, - XLARGE = 144, - XLARGE2 = 256, - XLARGE3 = 320 - }; - - const char* SizeString(u16); - const char* GetMinesName(u8); - - s32 GetDirectionIndex(s32 from, Direction::vector_t vector); - bool isValidDirection(s32 from, Direction::vector_t vector); - - bool isValidAbsIndex(s32); - bool isValidAbsPoint(const Point & pt); - bool isValidAbsPoint(s16 x, s16 y); - - s32 GetIndexFromAbsPoint(const Point & mp); - s32 GetIndexFromAbsPoint(s16 px, s16 py); - - u32 AnimationTicket(void); - void IncreaseAnimationTicket(void); - - u16 GetDirectionAroundGround(const s32 center, const u16 ground); - u8 GetCountAroundGround(const s32 center, const u16 ground); - u16 GetMaxGroundAround(const s32 center); - - u16 ScanAroundObject(const s32 center, const u8 obj, const u16 exclude = 0); - bool ScanDistanceObject(const s32 center, const u8 obj, const u16 dist, std::vector &); - u16 TileUnderProtection(const s32 center); - - void ClearFog(s32 center, u8 scoute, const u8 color); - u16 GetApproximateDistance(const s32 index1, const s32 index2); - - - void UpdateRNDSpriteForCastle(const Point & center, u8 race, bool castle); - void UpdateSpritesFromTownToCastle(const Point & center); - void MinimizeAreaForCastle(const Point & center); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/maps_fileinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/maps/maps_fileinfo.cpp deleted file mode 100644 index 36855f263..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/maps_fileinfo.cpp +++ /dev/null @@ -1,521 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include -#include "difficulty.h" -#include "color.h" -#include "race.h" -#include "world.h" -#include "settings.h" -#include "dir.h" -#include "maps_fileinfo.h" - -#define LENGTHNAME 16 -#define LENGTHDESCRIPTION 143 - -template -bool AlphabeticalCompare(const std::basic_string & lhs, const std::basic_string & rhs) -{ - return std::use_facet< std::collate< CharType > >( std::locale() ).compare( lhs.data(), lhs.data() + lhs.size(), - rhs.data(), rhs.data() + rhs.size() ) == -1; -} - -Race::race_t ByteToRace(u8 byte) -{ - switch(byte) - { - case 0x00: return Race::KNGT; - case 0x01: return Race::BARB; - case 0x02: return Race::SORC; - case 0x03: return Race::WRLK; - case 0x04: return Race::WZRD; - case 0x05: return Race::NECR; - case 0x06: return Race::MULT; - case 0x07: return Race::RAND; - - default: break; - } - - return Race::BOMG; -} - -Maps::FileInfo::FileInfo() : difficulty(Difficulty::EASY), - kingdom_colors(0), human_colors(0), computer_colors(0), rnd_races(0), localtime(0), with_heroes(false) -{ - for(u8 ii = 0; ii < KINGDOMMAX; ++ii) - { - races[ii] = Race::BOMG; - unions[ii] = Color::GetFromIndex(ii); - } -} - -bool Maps::FileInfo::ReadSAV(const std::string & filename) -{ - return Game::LoadSAV2FileInfo(filename, *this); -} - -bool Maps::FileInfo::ReadMP2(const std::string & filename) -{ - if(filename.empty()) return false; - - std::ifstream fd(filename.c_str(), std::ios::binary); - - if(!fd.is_open()) - { - DEBUG(DBG_GAME , DBG_WARN, "Maps::FileInfo::ReadMP2: file not found " << filename); - return false; - } - - file = filename; - kingdom_colors = 0; - human_colors = 0; - computer_colors = 0; - rnd_races = 0; - localtime = 0; - - u8 byte8; - u16 byte16; - u32 byte32; - - // magic byte - fd.read(reinterpret_cast(&byte32), sizeof(byte32)); - SwapLE32(byte32); - - if(byte32 != 0x0000005C) - { - DEBUG(DBG_GAME , DBG_WARN, "Maps::FileInfo::ReadMP2: incorrect maps file " << filename); - fd.close(); - return false; - } - - // level - fd.read(reinterpret_cast(&byte16), sizeof(byte16)); - SwapLE16(byte16); - - switch(byte16) - { - case 0x00: - difficulty = Difficulty::EASY; - break; - - case 0x01: - difficulty = Difficulty::NORMAL; - break; - - case 0x02: - difficulty = Difficulty::HARD; - break; - - case 0x03: - difficulty = Difficulty::EXPERT; - break; - - default: - DEBUG(DBG_GAME , DBG_WARN, "Maps::FileInfo::ReadMP2: incorrect difficulty, maps: " << filename << ". Load EASY default."); - break; - } - - // width - fd.read(reinterpret_cast(&byte8), 1); - size_w = byte8; - - // height - fd.read(reinterpret_cast(&byte8), 1); - size_h = byte8; - - // kingdom color blue - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) kingdom_colors |= Color::BLUE; - - // kingdom color green - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) kingdom_colors |= Color::GREEN; - - // kingdom color red - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) kingdom_colors |= Color::RED; - - // kingdom color yellow - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) kingdom_colors |= Color::YELLOW; - - // kingdom color orange - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) kingdom_colors |= Color::ORANGE; - - // kingdom color purple - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) kingdom_colors |= Color::PURPLE; - - // allow color blue - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) human_colors |= Color::BLUE; - - // allow color green - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) human_colors |= Color::GREEN; - - // allow color red - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) human_colors |= Color::RED; - - // allow color yellow - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) human_colors |= Color::YELLOW; - - // allow color orange - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) human_colors |= Color::ORANGE; - - // allow color purple - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) human_colors |= Color::PURPLE; - - // rnd color blue - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) computer_colors |= Color::BLUE; - - // rnd color green - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) computer_colors |= Color::GREEN; - - // rnd color red - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) computer_colors |= Color::RED; - - // rnd color yellow - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) computer_colors |= Color::YELLOW; - - // rnd color orange - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) computer_colors |= Color::ORANGE; - - // rnd color purple - fd.read(reinterpret_cast(&byte8), 1); - if(byte8) computer_colors |= Color::PURPLE; - - // kingdom count - // fd.seekg(0x1A, std::ios_base::beg); - // fd.read(&byte8, 1); - - // wins - fd.seekg(0x1D, std::ios_base::beg); - fd.read(reinterpret_cast(&byte8), 1); - conditions_wins = byte8; - - // data wins - fd.read(reinterpret_cast(&byte8), 1); - wins1 = byte8; - // data wins - fd.read(reinterpret_cast(&byte8), 1); - wins2 = byte8; - // data wins - fd.read(reinterpret_cast(&byte16), 2); - SwapLE16(byte16); - wins3 = byte16; - // data wins - fd.seekg(0x2c, std::ios_base::beg); - fd.read(reinterpret_cast(&byte16), 2); - SwapLE16(byte16); - wins4 = byte16; - - // loss - fd.seekg(0x22, std::ios_base::beg); - fd.read(reinterpret_cast(&byte8), 1); - conditions_loss = byte8; - // data loss - fd.read(reinterpret_cast(&byte16), 2); - SwapLE16(byte16); - loss1 = byte16; - // data loss - fd.seekg(0x2e, std::ios_base::beg); - fd.read(reinterpret_cast(&byte16), 2); - SwapLE16(byte16); - loss2 = byte16; - - // start with hero - fd.seekg(0x25, std::ios_base::beg); - fd.read(reinterpret_cast(&byte8), 1); - with_heroes = 0 == byte8; - - // race color - fd.read(reinterpret_cast(&byte8), 1); - races[0] = ByteToRace(byte8); - if(Race::RAND == races[0]) rnd_races |= Color::BLUE; - fd.read(reinterpret_cast(&byte8), 1); - races[1] = ByteToRace(byte8); - if(Race::RAND == races[1]) rnd_races |= Color::GREEN; - fd.read(reinterpret_cast(&byte8), 1); - races[2] = ByteToRace(byte8); - if(Race::RAND == races[2]) rnd_races |= Color::RED; - fd.read(reinterpret_cast(&byte8), 1); - races[3] = ByteToRace(byte8); - if(Race::RAND == races[3]) rnd_races |= Color::YELLOW; - fd.read(reinterpret_cast(&byte8), 1); - races[4] = ByteToRace(byte8); - if(Race::RAND == races[4]) rnd_races |= Color::ORANGE; - fd.read(reinterpret_cast(&byte8), 1); - races[5] = ByteToRace(byte8); - if(Race::RAND == races[5]) rnd_races |= Color::PURPLE; - - // name - char bufname[LENGTHNAME]; - fd.seekg(0x3A, std::ios_base::beg); - fd.read(bufname, LENGTHNAME); - bufname[LENGTHNAME - 1] = 0; - name = _(bufname); - - // description - char bufdescription[LENGTHDESCRIPTION]; - fd.seekg(0x76, std::ios_base::beg); - fd.read(bufdescription, LENGTHDESCRIPTION); - bufdescription[LENGTHDESCRIPTION - 1] = 0; - description = _(bufdescription); - - fd.close(); - - //fill unions - if(4 == conditions_wins) - { - u16 index = 0; - u8 side1 = 0; - u8 side2 = 0; - - for(Color::color_t cl = Color::BLUE; cl < Color::GRAY; ++cl, ++index) if(cl & kingdom_colors) - { - if(index < wins3) - side1 |= cl; - else - side2 |= cl; - } - - for(u8 ii = 0; ii < KINGDOMMAX; ++ii) - { - Color::color_t cl = Color::GetFromIndex(ii); - - if(side1 & cl) - unions[ii] = side1; - else - if(side2 & cl) - unions[ii] = side2; - else - unions[ii] = cl; - } - } - - return true; -} - -bool Maps::FileInfo::FileSorting(const FileInfo & fi1, const FileInfo & fi2) -{ - return AlphabeticalCompare(fi1.file, fi2.file); -} - -bool Maps::FileInfo::NameSorting(const FileInfo & fi1, const FileInfo & fi2) -{ - return AlphabeticalCompare(fi1.name, fi2.name); -} - -bool Maps::FileInfo::NameCompare(const FileInfo & fi1, const FileInfo & fi2) -{ - return fi1.name == fi2.name; -} - -u8 Maps::FileInfo::KingdomRace(u8 color) const -{ - switch(color) - { - case Color::BLUE: return races[0]; - case Color::GREEN: return races[1]; - case Color::RED: return races[2]; - case Color::YELLOW: return races[3]; - case Color::ORANGE: return races[4]; - case Color::PURPLE: return races[5]; - default: break; - } - return 0; -} - -u16 Maps::FileInfo::ConditionWins(void) const -{ - switch(conditions_wins) - { - case 0: return GameOver::WINS_ALL; - case 1: return wins2 ? GameOver::WINS_TOWN | GameOver::WINS_ALL : GameOver::WINS_TOWN; - case 2: return wins2 ? GameOver::WINS_HERO | GameOver::WINS_ALL : GameOver::WINS_HERO; - case 3: return wins2 ? GameOver::WINS_ARTIFACT | GameOver::WINS_ALL : GameOver::WINS_ARTIFACT; - case 4: return GameOver::WINS_SIDE; - case 5: return wins2 ? GameOver::WINS_GOLD | GameOver::WINS_ALL : GameOver::WINS_GOLD; - default: break; - } - - return GameOver::COND_NONE; -} - -u16 Maps::FileInfo::ConditionLoss(void) const -{ - switch(conditions_loss) - { - case 0: return GameOver::LOSS_ALL; - case 1: return GameOver::LOSS_TOWN; - case 2: return GameOver::LOSS_HERO; - case 3: return GameOver::LOSS_TIME; - default: break; - } - - return GameOver::COND_NONE; -} - -bool Maps::FileInfo::WinsCompAlsoWins(void) const -{ - return ((GameOver::WINS_TOWN | GameOver::WINS_GOLD) & ConditionWins()) && wins1; -} - -bool Maps::FileInfo::WinsAllowNormalVictory(void) const -{ - return ((GameOver::WINS_TOWN | GameOver::WINS_ARTIFACT | GameOver::WINS_GOLD) & ConditionWins()) && wins2; -} - -Artifact::artifact_t Maps::FileInfo::WinsFindArtifact(void) const -{ - return wins3 ? Artifact::FromInt(wins3 - 1) : Artifact::UNKNOWN; -} - -bool Maps::FileInfo::WinsFindUltimateArtifact(void) const -{ - return 0 == wins3; -} - -u32 Maps::FileInfo::WinsAccumulateGold(void) const -{ - return wins3 * 1000; -} - -u16 Maps::FileInfo::WinsSidePart(void) const -{ - // FIX:: Maps::FileInfo::ConditionSidePart - return wins3; -} - -u32 Maps::FileInfo::WinsMapsIndexObject(void) const -{ - return wins4 * world.w() + wins3; -} - -u32 Maps::FileInfo::LossMapsIndexObject(void) const -{ - return loss2 * world.w() + loss1; -} - -u16 Maps::FileInfo::LossCountDays(void) const -{ - return loss1; -} - -u8 Maps::FileInfo::HumanOnlyColors(void) const -{ - return human_colors & ~(human_colors & computer_colors); -} - -u8 Maps::FileInfo::ComputerOnlyColors(void) const -{ - return computer_colors & ~(human_colors & computer_colors); -} - -bool Maps::FileInfo::isAllowCountPlayers(u8 colors) const -{ - const u8 human_only = Color::Count(HumanOnlyColors()); - const u8 comp_human = Color::Count(human_colors & computer_colors); - - return human_only <= colors && colors <= human_only + comp_human; -} - -bool Maps::FileInfo::isMultiPlayerMap(void) const -{ - return 1 < Color::Count(HumanOnlyColors()); -} - -void Maps::FileInfo::Dump(void) const -{ - VERBOSE("Maps::FileInfo::Dump: " << "file: " << file << ", name: " << name << ", kingdom colors: " << static_cast(kingdom_colors) << \ - ", human colors: " << static_cast(human_colors) << ", computer colors: " << static_cast(computer_colors) << ", rnd races: " << \ - static_cast(rnd_races) << ", conditions wins: " << static_cast(conditions_wins) << ", wins1: " << static_cast(wins1) << \ - ", wins2: " << static_cast(wins2) << ", wins3: " << wins3 << ", wins4: " << wins4 << ", conditions loss: " << static_cast(conditions_loss) << \ - ", loss1: " << loss1 << ", loss2: " << loss2); -} - -bool PrepareMapsFileInfoList(MapsFileInfoList & lists, bool multi) -{ - const Settings & conf = Settings::Get(); - Dir dir; - - ListMapsDirectory::const_iterator it1 = conf.GetListMapsDirectory().begin(); - ListMapsDirectory::const_iterator it2 = conf.GetListMapsDirectory().end(); - - for(; it1 != it2; ++it1) - { - dir.Read(*it1, ".mp2", false); - dir.Read(conf.LocalPrefix() + SEPARATOR + *it1, ".mp2", false); - // loyality version - if(conf.PriceLoyaltyVersion()) - { - dir.Read(*it1, ".mx2", false); - dir.Read(conf.LocalPrefix() + SEPARATOR + *it1, ".mx2", false); - } - } - - if(dir.empty()) return false; - - dir.sort(); - dir.unique(); - - lists.reserve(dir.size()); - - for(Dir::const_iterator itd = dir.begin(); itd != dir.end(); ++itd) - { - Maps::FileInfo fi; - if(fi.ReadMP2(*itd)) lists.push_back(fi); - } - - std::sort(lists.begin(), lists.end(), Maps::FileInfo::NameSorting); - lists.resize(std::unique(lists.begin(), lists.end(), Maps::FileInfo::NameCompare) - lists.begin()); - - if(multi == false) - { - MapsFileInfoList::iterator it = std::remove_if(lists.begin(), lists.end(), std::mem_fun_ref(&Maps::FileInfo::isMultiPlayerMap)); - if(it != lists.begin()) lists.resize(std::distance(lists.begin(), it)); - } - - // set preferably count filter - if(conf.PreferablyCountPlayers()) - { - - MapsFileInfoList::iterator it = std::remove_if(lists.begin(), lists.end(), std::not1(std::bind2nd(std::mem_fun_ref(&Maps::FileInfo::isAllowCountPlayers), conf.PreferablyCountPlayers()))); - if(it != lists.begin()) lists.resize(std::distance(lists.begin(), it)); - } - - return lists.size(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/maps_fileinfo.h b/project/jni/application/fheroes2/src/fheroes2/maps/maps_fileinfo.h deleted file mode 100644 index 1046856aa..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/maps_fileinfo.h +++ /dev/null @@ -1,98 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2MAPSFILEINFO_H -#define H2MAPSFILEINFO_H - -#include -#include -#include "gamedefs.h" -#include "game_over.h" -#include "artifact.h" - -namespace Maps -{ - struct FileInfo - { - FileInfo(); - - bool ReadMP2(const std::string &); - bool ReadSAV(const std::string &); - - static bool NameSorting(const FileInfo &, const FileInfo &); - static bool FileSorting(const FileInfo &, const FileInfo &); - static bool NameCompare(const FileInfo &, const FileInfo &); - - bool isAllowCountPlayers(u8) const; - bool isMultiPlayerMap(void) const; - u8 HumanOnlyColors(void) const; - u8 ComputerOnlyColors(void) const; - - u8 KingdomRace(u8) const; - - u16 ConditionWins(void) const; - u16 ConditionLoss(void) const; - bool WinsCompAlsoWins(void) const; - bool WinsAllowNormalVictory(void) const; - Artifact::artifact_t WinsFindArtifact(void) const; - bool WinsFindUltimateArtifact(void) const; - u16 WinsSidePart(void) const; - u32 WinsAccumulateGold(void) const; - u32 WinsMapsIndexObject(void) const; - u32 LossMapsIndexObject(void) const; - u16 LossCountDays(void) const; - - void Dump(void) const; - - std::string file; - std::string name; - std::string description; - - u16 size_w; - u16 size_h; - u8 difficulty; - u8 races[KINGDOMMAX]; - u8 unions[KINGDOMMAX]; - - u8 kingdom_colors; - u8 human_colors; - u8 computer_colors; - u8 rnd_races; - u8 conditions_wins; - u8 wins1; - u8 wins2; - u16 wins3; - u16 wins4; - u8 conditions_loss; - u16 loss1; - u16 loss2; - - time_t localtime; - - bool with_heroes; - }; -} - -typedef std::vector MapsFileInfoList; - -bool PrepareMapsFileInfoList(MapsFileInfoList &, bool multi); - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/maps_tiles.cpp b/project/jni/application/fheroes2/src/fheroes2/maps/maps_tiles.cpp deleted file mode 100644 index d3b106a4a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/maps_tiles.cpp +++ /dev/null @@ -1,2507 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "agg.h" -#include "world.h" -#include "race.h" -#include "settings.h" -#include "heroes.h" -#include "castle.h" -#include "maps.h" -#include "interface_gamearea.h" -#include "game_focus.h" -#include "object.h" -#include "objxloc.h" -#include "monster.h" -#include "resource.h" -#include "maps_tiles.h" - -static u8 monster_animation_cicle[] = { 0, 1, 2, 1, 0, 3, 4, 5, 4, 3 }; - -Maps::TilesAddon::TilesAddon() : level(0), uniq(0), object(0), index(0) -{ -} - -Maps::TilesAddon::TilesAddon(u8 lv, u32 gid, u8 obj, u8 ii) : level(lv), uniq(gid), object(obj), index(ii) -{ -} - -Maps::TilesAddon & Maps::TilesAddon::operator= (const Maps::TilesAddon & ta) -{ - level = ta.level; - - object = ta.object; - - index = ta.index; - - uniq = ta.uniq; - - return *this; -} - -bool Maps::TilesAddon::PredicateSortRules1(const Maps::TilesAddon & ta1, const Maps::TilesAddon & ta2) -{ - return ((ta1.level % 4) > (ta2.level % 4)); -} - -bool Maps::TilesAddon::PredicateSortRules2(const Maps::TilesAddon & ta1, const Maps::TilesAddon & ta2) -{ - return ((ta1.level % 4) < (ta2.level % 4)); -} - -u16 Maps::TilesAddon::isRoad(const TilesAddon & ta) -{ - switch(MP2::GetICNObject(ta.object)) - { - // castle and tower (gate) - case ICN::OBJNTOWN: - return (13 == ta.index || - 29 == ta.index || - 45 == ta.index || - 61 == ta.index || - 77 == ta.index || - 93 == ta.index || - 109 == ta.index || - 125 == ta.index || - 141 == ta.index || - 157 == ta.index || - 173 == ta.index || - 189 == ta.index ? Direction::TOP | Direction::BOTTOM : 0); - - // castle lands (gate) - case ICN::OBJNTWBA: - return ( 7 == ta.index || - 17 == ta.index || - 27 == ta.index || - 37 == ta.index || - 47 == ta.index || - 57 == ta.index || - 67 == ta.index || - 77 == ta.index ? Direction::TOP | Direction::BOTTOM : 0); - - // from sprite road - case ICN::ROAD: - if(0 == ta.index || - 4 == ta.index || - 5 == ta.index || - 7 == ta.index || - 9 == ta.index || - 12 == ta.index || - 13 == ta.index || - 16 == ta.index || - 19 == ta.index || - 20 == ta.index || - 26 == ta.index) return Direction::TOP | Direction::BOTTOM; - else - if(2 == ta.index || - 21 == ta.index || - 28 == ta.index) return Direction::RIGHT | Direction::LEFT; - else - if(3 == ta.index || - 6 == ta.index || - 14 == ta.index) return Direction::TOP | Direction::BOTTOM | Direction::RIGHT | Direction::LEFT; - else - if(17 == ta.index || - 29 == ta.index) return Direction::TOP_LEFT | Direction::BOTTOM_RIGHT; - else - if(18 == ta.index || - 30 == ta.index) return Direction::TOP_RIGHT | Direction::BOTTOM_LEFT; - - default: - break; - } - - return 0; -} - -bool Maps::TilesAddon::isStream(const TilesAddon & ta) -{ - return ICN::STREAM == MP2::GetICNObject(ta.object); -} - -Maps::Tiles::Tiles(s32 index) : maps_index(index), tile_sprite_index(0), tile_sprite_shape(0), - mp2_object(0), quantity1(0), quantity2(0), fogs(0xFF), unused1(0), unused2(0), unused3(0) -{ -} - -Maps::Tiles::Tiles(s32 mi, const MP2::mp2tile_t & mp2tile) : maps_index(mi), tile_sprite_index(mp2tile.tileIndex), - tile_sprite_shape(mp2tile.shape), mp2_object(mp2tile.generalObject), quantity1(mp2tile.quantity1), quantity2(mp2tile.quantity2), - quantity3(0), quantity4(0), fogs(0xFF), unused1(0), unused2(0), unused3(0) -{ - AddonsPushLevel1(mp2tile); - AddonsPushLevel2(mp2tile); - - if(IS_DEVEL()) ClearFog(Settings::Get().MyColor()); -} - -void Maps::Tiles::SetTile(const u16 sprite_index, const u8 sh) -{ - tile_sprite_index = sprite_index; - tile_sprite_shape = sh; -} - -const Surface & Maps::Tiles::GetTileSurface(void) const -{ - return AGG::GetTIL(TIL::GROUND32, tile_sprite_index, tile_sprite_shape); -} - -void Maps::Tiles::AddonsPushLevel1(const MP2::mp2tile_t & mt) -{ - if(mt.objectName1 && mt.indexName1 < 0xFF) - addons_level1.push_back(TilesAddon(0, mt.uniqNumber1, mt.objectName1, mt.indexName1)); -} - -void Maps::Tiles::AddonsPushLevel1(const MP2::mp2addon_t & ma) -{ - if(ma.objectNameN1 && ma.indexNameN1 < 0xFF) - addons_level1.push_back(TilesAddon(ma.quantityN, ma.uniqNumberN1, ma.objectNameN1, ma.indexNameN1)); -} - -void Maps::Tiles::AddonsPushLevel1(const TilesAddon & ta) -{ - addons_level1.push_back(ta); -} - -void Maps::Tiles::AddonsPushLevel2(const MP2::mp2tile_t & mt) -{ - if(mt.objectName2 && mt.indexName2 < 0xFF) - addons_level2.push_back(TilesAddon(0, mt.uniqNumber2, mt.objectName2, mt.indexName2)); -} - -void Maps::Tiles::AddonsPushLevel2(const MP2::mp2addon_t & ma) -{ - if(ma.objectNameN2 && ma.indexNameN2 < 0xFF) - addons_level2.push_back(TilesAddon(ma.quantityN, ma.uniqNumberN2, ma.objectNameN2, ma.indexNameN2)); -} - -void Maps::Tiles::AddonsPushLevel2(const TilesAddon & ta) -{ - addons_level2.push_back(ta); -} - -void Maps::Tiles::AddonsSort(void) -{ - if(!addons_level1.empty()) addons_level1.sort(Maps::TilesAddon::PredicateSortRules1); - - if(!addons_level2.empty()) addons_level2.sort(Maps::TilesAddon::PredicateSortRules2); -} - -Maps::Ground::ground_t Maps::Tiles::GetGround(void) const -{ - // list grounds from GROUND32.TIL - if(30 > tile_sprite_index) - return Maps::Ground::WATER; - - else if(92 > tile_sprite_index) - return Maps::Ground::GRASS; - - else if(146 > tile_sprite_index) - return Maps::Ground::SNOW; - - else if(208 > tile_sprite_index) - return Maps::Ground::SWAMP; - - else if(262 > tile_sprite_index) - return Maps::Ground::LAVA; - - else if(321 > tile_sprite_index) - return Maps::Ground::DESERT; - - else if(361 > tile_sprite_index) - return Maps::Ground::DIRT; - - else if(415 > tile_sprite_index) - return Maps::Ground::WASTELAND; - - //else if(432 > tile_sprite_index) - - return Maps::Ground::BEACH; -} - -void Maps::Tiles::Remove(u32 uniq) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - while(it1 != it2) - if(uniq == (*it1).uniq) - it1 = addons_level1.erase(it1); - else - ++it1; - } - - if(!addons_level2.empty()) - { - std::list::iterator it1 = addons_level2.begin(); - std::list::const_iterator it2 = addons_level2.end(); - - while(it1 != it2) - if(uniq == (*it1).uniq) - it1 = addons_level2.erase(it1); - else - ++it1; - } -} - -void Maps::Tiles::RedrawTile(Surface & dst) const -{ - const Interface::GameArea & area = Interface::GameArea::Get(); - const Point mp(maps_index % world.w(), maps_index / world.w()); - - if(area.GetRectMaps() & mp) - area.BlitOnTile(dst, GetTileSurface(), 0, 0, mp); -} - -void Maps::Tiles::RedrawBottom(Surface & dst, const TilesAddon* skip) const -{ - const Interface::GameArea & area = Interface::GameArea::Get(); - const Point mp(maps_index % world.w(), maps_index / world.w()); - - if((area.GetRectMaps() & mp) && - !addons_level1.empty()) - { - std::list::const_iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - if(skip && skip == &(*it1)) continue; - - const u8 & object = (*it1).object; - const u8 & index = (*it1).index; - const ICN::icn_t icn = MP2::GetICNObject(object); - - if(ICN::UNKNOWN != icn && ICN::MINIHERO != icn && ICN::MONS32 != icn) - { - const Sprite & sprite = AGG::GetICN(icn, index); - area.BlitOnTile(dst, sprite, mp); - - // possible anime - if(const u16 anime_index = ICN::AnimationFrame(icn, index, Maps::AnimationTicket(), quantity2)) - { - const Sprite & anime_sprite = AGG::GetICN(icn, anime_index); - area.BlitOnTile(dst, anime_sprite, mp); - } - } - } - } -} - -void Maps::Tiles::RedrawObjects(Surface & dst) const -{ - switch(GetObject()) - { - // boat - case MP2::OBJ_BOAT: RedrawBoat(dst); break; - // monster - case MP2::OBJ_MONSTER: RedrawMonster(dst); break; - // - default: break; - } -} - -void Maps::Tiles::RedrawMonster(Surface & dst) const -{ - const Point mp(maps_index % world.w(), maps_index / world.w()); - const Interface::GameArea & area = Interface::GameArea::Get(); - s32 dst_index = -1; - - if(!(area.GetRectMaps() & mp)) return; - - // scan hero around - const u16 dst_around = Maps::ScanAroundObject(maps_index, MP2::OBJ_HEROES); - for(Direction::vector_t dir = Direction::TOP_LEFT; dir < Direction::CENTER; ++dir) if(dst_around & dir) - { - dst_index = Maps::GetDirectionIndex(maps_index, dir); - const Heroes* hero = world.GetHeroes(dst_index); - - if(!hero || - // skip bottom, bottom_right, bottom_left with ground objects - (((Direction::BOTTOM | Direction::BOTTOM_LEFT | Direction::BOTTOM_RIGHT) & dir) && MP2::isGroundObject(hero->GetUnderObject()))) - dst_index = -1; - else - break; - } - - // draw attack sprite - if(-1 != dst_index) - { - bool revert = false; - - switch(Direction::Get(maps_index, dst_index)) - { - case Direction::TOP_LEFT: - case Direction::LEFT: - case Direction::BOTTOM_LEFT: revert = true; - default: break; - } - - const Sprite & sprite_first = AGG::GetICN(ICN::MINIMON, Monster::GetSpriteIndex(quantity3) * 9 + (revert ? 8 : 7)); - area.BlitOnTile(dst, sprite_first, sprite_first.x() + 16, TILEWIDTH + sprite_first.y(), mp); - } - else - { - // draw first sprite - const Sprite & sprite_first = AGG::GetICN(ICN::MINIMON, Monster::GetSpriteIndex(quantity3) * 9); - area.BlitOnTile(dst, sprite_first, sprite_first.x() + 16, TILEWIDTH + sprite_first.y(), mp); - - // draw second sprite - const Sprite & sprite_next = AGG::GetICN(ICN::MINIMON, Monster::GetSpriteIndex(quantity3) * 9 + 1 + - monster_animation_cicle[ (Maps::AnimationTicket() + mp.x * mp.y) % (sizeof(monster_animation_cicle) / sizeof(monster_animation_cicle[0])) ]); - area.BlitOnTile(dst, sprite_next, sprite_next.x() + 16, TILEWIDTH + sprite_next.y(), mp); - } -} - -void Maps::Tiles::RedrawBoat(Surface & dst) const -{ - const Point mp(maps_index % world.w(), maps_index / world.w()); - const Interface::GameArea & area = Interface::GameArea::Get(); - - if(!(area.GetRectMaps() & mp)) return; - - if(Settings::Get().Editor()) - area.BlitOnTile(dst, AGG::GetICN(ICN::OBJNWAT2, 23), 0, 0, mp); - else - { - // FIXME: restore direction from Maps::Tiles - const Sprite & sprite = AGG::GetICN(ICN::BOAT32, 18); - area.BlitOnTile(dst, sprite, sprite.x(), TILEWIDTH + sprite.y(), mp); - } -} - -void Maps::Tiles::RedrawBottom4Hero(Surface & dst) const -{ - const Interface::GameArea & area = Interface::GameArea::Get(); - const Point mp(maps_index % world.w(), maps_index / world.w()); - - if((area.GetRectMaps() & mp) && - !addons_level1.empty()) - { - std::list::const_iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - const u8 & object = (*it1).object; - const u8 & index = (*it1).index; - const ICN::icn_t icn = MP2::GetICNObject(object); - - if(ICN::SkipBottomForRedrawHeroes(icn, index)) continue; - - if(ICN::UNKNOWN != icn && ICN::MINIHERO != icn && ICN::MONS32 != icn) - { - const Sprite & sprite = AGG::GetICN(icn, index); - area.BlitOnTile(dst, sprite, mp); - - // possible anime - if(const u16 anime_index = ICN::AnimationFrame(icn, index, Maps::AnimationTicket(), quantity2)) - { - const Sprite & anime_sprite = AGG::GetICN(icn, anime_index); - area.BlitOnTile(dst, anime_sprite, mp); - } - } - } - } -} - -void Maps::Tiles::RedrawTop(Surface & dst, const TilesAddon* skip) const -{ - const Interface::GameArea & area = Interface::GameArea::Get(); - const Point mp(maps_index % world.w(), maps_index / world.w()); - - if(!(area.GetRectMaps() & mp)) return; - - // fix for haut mine - if(MP2::OBJ_MINES == mp2_object) - { - if(quantity4 == Spell::HAUNT) - { - const Sprite & anime_sprite = AGG::GetICN(ICN::OBJNHAUN, Maps::AnimationTicket() % 15); - area.BlitOnTile(dst, anime_sprite, mp); - } - else - if(quantity4 >= Spell::SETEGUARDIAN && quantity4 <= Spell::SETWGUARDIAN) - { - const Sprite* mons = NULL; - switch(quantity4) - { - case Spell::SETAGUARDIAN: mons = &AGG::GetICN(ICN::MONS32, Monster::GetSpriteIndex(Monster::AIR_ELEMENT)); break; - case Spell::SETWGUARDIAN: mons = &AGG::GetICN(ICN::MONS32, Monster::GetSpriteIndex(Monster::WATER_ELEMENT)); break; - case Spell::SETEGUARDIAN: mons = &AGG::GetICN(ICN::MONS32, Monster::GetSpriteIndex(Monster::EARTH_ELEMENT)); break; - case Spell::SETFGUARDIAN: mons = &AGG::GetICN(ICN::MONS32, Monster::GetSpriteIndex(Monster::FIRE_ELEMENT)); break; - default: break; - } - if(mons) - area.BlitOnTile(dst, *mons, TILEWIDTH, 0, mp); - } - } - - if(!addons_level2.empty()) - { - std::list::const_iterator it1 = addons_level2.begin(); - std::list::const_iterator it2 = addons_level2.end(); - - for(; it1 != it2; ++it1) - { - if(skip && skip == &(*it1)) continue; - - const u8 & object = (*it1).object; - const u8 & index = (*it1).index; - const ICN::icn_t icn = MP2::GetICNObject(object); - - if(ICN::UNKNOWN != icn && ICN::MINIHERO != icn && ICN::MONS32 != icn) - { - const Sprite & sprite = AGG::GetICN(icn, index); - area.BlitOnTile(dst, sprite, mp); - - // possible anime - if(const u16 anime_index = ICN::AnimationFrame(icn, index, Maps::AnimationTicket())) - { - const Sprite & anime_sprite = AGG::GetICN(icn, anime_index); - area.BlitOnTile(dst, anime_sprite, mp); - } - } - } - } -} - -void Maps::Tiles::RedrawTop4Hero(Surface & dst, bool skip_ground) const -{ - const Interface::GameArea & area = Interface::GameArea::Get(); - const Point mp(maps_index % world.w(), maps_index / world.w()); - - if(!(area.GetRectMaps() & mp)) return; - - if(!addons_level2.empty()) - { - std::list::const_iterator it1 = addons_level2.begin(); - std::list::const_iterator it2 = addons_level2.end(); - - for(; it1 != it2; ++it1) - { - if(skip_ground && MP2::isGroundObject((*it1).object)) continue; - - const u8 & object = (*it1).object; - const u8 & index = (*it1).index; - const ICN::icn_t icn = MP2::GetICNObject(object); - - if(ICN::HighlyObjectSprite(icn, index)) - { - const Sprite & sprite = AGG::GetICN(icn, index); - area.BlitOnTile(dst, sprite, mp); - - // possible anime - if(const u16 anime_index = ICN::AnimationFrame(icn, index, Maps::AnimationTicket())) - { - const Sprite & anime_sprite = AGG::GetICN(icn, anime_index); - area.BlitOnTile(dst, anime_sprite, mp); - } - } - } - } -} - -Maps::TilesAddon * Maps::Tiles::FindAddonICN1(u16 icn1) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(icn1 == MP2::GetICNObject(addon.object)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindAddonICN2(u16 icn2) -{ - if(!addons_level2.empty()) - { - std::list::iterator it1 = addons_level2.begin(); - std::list::const_iterator it2 = addons_level2.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(icn2 == MP2::GetICNObject(addon.object)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindAddonLevel1(u32 uniq1) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(uniq1 == addon.uniq) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindAddonLevel2(u32 uniq2) -{ - if(!addons_level2.empty()) - { - std::list::iterator it1 = addons_level2.begin(); - std::list::const_iterator it2 = addons_level2.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(uniq2 == addon.uniq) return &addon; - } - } - - return NULL; -} - -void Maps::Tiles::DebugInfo(void) const -{ - std::list::const_iterator it1; - std::list::const_iterator it2; - - std::cout << std::endl << "----------------:--------" << std::endl; - - std::string value; - - String::AddInt(value, maps_index); - - std::cout << "maps index : " << value << std::endl; - - value.clear(); - - String::AddInt(value, tile_sprite_index); - - std::cout << "tile : " << value << std::endl; - - value.clear(); - - value = Ground::String(GetGround()); - if(isRoad()) value += ", (road)"; - std::cout << "ground : " << value << std::endl; - - value.clear(); - - value = isPassable() ? "true" : "false"; - std::cout << "passable : " << value << std::endl; - - value.clear(); - - String::AddInt(value, mp2_object); - value += ", (" + std::string(MP2::StringObject(mp2_object)) + ")"; - std::cout << "mp2 object : " << value << std::endl; - - value.clear(); - - String::AddInt(value, quantity1); - std::cout << "quantity 1 : " << value << std::endl; - - value.clear(); - - String::AddInt(value, quantity2); - std::cout << "quantity 2 : " << value << std::endl; - - value.clear(); - - String::AddInt(value, quantity3); - std::cout << "quantity 3 : " << value << std::endl; - - value.clear(); - - String::AddInt(value, quantity4); - std::cout << "quantity 4 : " << value << std::endl; - - value.clear(); - - if(!addons_level1.empty()) - { - it1 = addons_level1.begin(); - it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - const TilesAddon & addon = *it1; - - std::cout << "----------------1--------" << std::endl; - - value.clear(); - - String::AddInt(value, addon.object); - - std::cout << "object : " << value << " (" << ICN::GetString(MP2::GetICNObject(addon.object)) << ")" << std::endl; - - value.clear(); - - String::AddInt(value, addon.index); - - std::cout << "index : " << value << std::endl; - - value.clear(); - - String::AddInt(value, addon.uniq); - - std::cout << "uniq : " << value << std::endl; - - value.clear(); - - String::AddInt(value, addon.level); - - std::cout << "level : " << value << std::endl; - } - } - - if(!addons_level2.empty()) - { - it1 = addons_level2.begin(); - it2 = addons_level2.end(); - - for(; it1 != it2; ++it1) - { - const TilesAddon & addon = *it1; - - std::cout << "----------------2--------" << std::endl; - - value.clear(); - - String::AddInt(value, addon.object); - - std::cout << "object : " << value << " (" << ICN::GetString(MP2::GetICNObject(addon.object)) << ")" << std::endl; - - value.clear(); - - String::AddInt(value, addon.index); - - std::cout << "index : " << value << std::endl; - - value.clear(); - - String::AddInt(value, addon.uniq); - - std::cout << "uniq : " << value << std::endl; - - value.clear(); - - String::AddInt(value, addon.level); - - std::cout << "level : " << value << std::endl; - } - } - - std::cout << "----------------I--------" << std::endl; - - // extra obj info - switch(mp2_object) - { - // dwelling - case MP2::OBJ_RUINS: - case MP2::OBJ_TREECITY: - case MP2::OBJ_WAGONCAMP: - case MP2::OBJ_DESERTTENT: - case MP2::OBJ_TROLLBRIDGE: - case MP2::OBJ_DRAGONCITY: - case MP2::OBJ_CITYDEAD: - // - case MP2::OBJ_WATCHTOWER: - case MP2::OBJ_EXCAVATION: - case MP2::OBJ_CAVE: - case MP2::OBJ_TREEHOUSE: - case MP2::OBJ_ARCHERHOUSE: - case MP2::OBJ_GOBLINHUT: - case MP2::OBJ_DWARFCOTT: - case MP2::OBJ_HALFLINGHOLE: - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_THATCHEDHUT: - // - case MP2::OBJ_MONSTER: - std::cout << "count : " << GetCountMonster() << std::endl; - break; - - case MP2::OBJ_HEROES: - { - const Heroes *hero = world.GetHeroes(maps_index); - if(hero) hero->Dump(); - } - break; - - case MP2::OBJN_CASTLE: - case MP2::OBJ_CASTLE: - { - const Castle *castle = world.GetCastle(maps_index); - if(castle) castle->Dump(); - } - break; - - default: - { - const u16 dst_around = Maps::TileUnderProtection(maps_index); - if(dst_around) - { - std::cout << "protection : "; - for(Direction::vector_t dir = Direction::TOP_LEFT; dir < Direction::CENTER; ++dir) - if(dst_around & dir) - std::cout << Maps::GetDirectionIndex(maps_index, dir) << std::endl; - } - break; - } - } - - std::cout << "----------------:--------" << std::endl << std::endl; -} - -MP2::object_t Maps::Tiles::GetObject(void) const -{ - return static_cast(mp2_object); -} - -bool Maps::Tiles::GoodForUltimateArtifact(void) const -{ - return Ground::WATER != Maps::Tiles::GetGround() && isPassable(NULL, true); -} - -/* accept move */ -bool Maps::Tiles::isPassable(const Heroes *hero, bool skipfog) const -{ - if(!skipfog && isFog(Settings::Get().CurrentColor())) return false; - - if(hero) - { - if(hero->isShipMaster()) - { - if(Ground::WATER != Maps::Tiles::GetGround()) return false; - - switch(mp2_object) - { - case MP2::OBJ_BOAT: - case MP2::OBJ_HEROES: return false; - - default: break; - } - } - else - { - if(Ground::WATER == Maps::Tiles::GetGround()) return false; - - switch(mp2_object) - { - case MP2::OBJ_HEROES: return false; - - default: break; - } - } - } - - return Object::isPassable(addons_level1, maps_index); -} - -/* check road */ -bool Maps::Tiles::isRoad(const Direction::vector_t & direct) const -{ - switch(direct) - { - case Direction::UNKNOWN: - case Direction::CENTER: return addons_level1.end() != find_if(addons_level1.begin(), addons_level1.end(), TilesAddon::isRoad); - - default: break; - } - - if(!addons_level1.empty()) - { - std::list::const_iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) if(direct & TilesAddon::isRoad(*it1)) return true; - } - - return false; -} - -bool Maps::Tiles::isStream(void) const -{ - return addons_level1.end() != std::find_if(addons_level1.begin(), addons_level1.end(), TilesAddon::isStream); -} - -Maps::TilesAddon * Maps::Tiles::FindWaterResource(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNWATR - if(ICN::OBJNWATR == MP2::GetICNObject(addon.object) && - (0 == addon.index || // buttle - 19 == addon.index || // chest - 45 == addon.index || // flotsam - 111 == addon.index)) // surviror - return &addon; - } - } - - return NULL; -} - -const Maps::TilesAddon* Maps::Tiles::FindWhirlpools(void) const -{ - if(!addons_level1.empty()) - { - std::list::const_iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - const TilesAddon & addon = *it1; - - if(ICN::OBJNWATR == MP2::GetICNObject(addon.object) && (addon.index >= 202 && addon.index <= 225)) return &addon; - } - } - - return NULL; -} - -const Maps::TilesAddon* Maps::Tiles::FindStandingStones(void) const -{ - if(!addons_level1.empty()) - { - std::list::const_iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - const TilesAddon & addon = *it1; - - if(ICN::OBJNMULT == MP2::GetICNObject(addon.object) && (addon.index == 84 || addon.index == 85)) return &addon; - } - } - - return NULL; -} - -const Maps::TilesAddon* Maps::Tiles::FindArtesianSpring(void) const -{ - if(!addons_level1.empty()) - { - std::list::const_iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - const TilesAddon & addon = *it1; - - if(ICN::OBJNCRCK == MP2::GetICNObject(addon.object) && (addon.index == 3 || addon.index == 4)) return &addon; - } - } - - return NULL; -} - -const Maps::TilesAddon* Maps::Tiles::FindOasis(void) const -{ - if(!addons_level1.empty()) - { - std::list::const_iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - const TilesAddon & addon = *it1; - - if(ICN::OBJNDSRT == MP2::GetICNObject(addon.object) && (addon.index == 108 || addon.index == 109)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindResource(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNRSRC - if(ICN::OBJNRSRC == MP2::GetICNObject(addon.object) && (addon.index % 2)) return &addon; - else - // TREASURE - if(ICN::TREASURE == MP2::GetICNObject(addon.object)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindRNDResource(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNRSRC - if(ICN::OBJNRSRC == MP2::GetICNObject(addon.object) && 17 == addon.index) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindArtifact(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNARTI - if(ICN::OBJNARTI == MP2::GetICNObject(addon.object) && (addon.index % 2)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindRNDArtifact(const u8 level) -{ - u8 index = 0xA3; - - switch(level) - { - case MP2::OBJ_RNDARTIFACT1: index = 0xA7; break; - case MP2::OBJ_RNDARTIFACT2: index = 0xA9; break; - case MP2::OBJ_RNDARTIFACT3: index = 0xAB; break; - default: break; - } - - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNARTI - if(ICN::OBJNARTI == MP2::GetICNObject(addon.object) && index == addon.index) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindUltimateArtifact(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNARTI - if(ICN::OBJNARTI == MP2::GetICNObject(addon.object) && 0xA4 == addon.index) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindMiniHero(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // MINIHERO - if(ICN::MINIHERO == MP2::GetICNObject(addon.object)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindEvent(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNMUL2 - if(ICN::OBJNMUL2 == MP2::GetICNObject(addon.object) && 0xA3 == addon.index) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindBoat(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNWAT2 - if(ICN::OBJNWAT2 == MP2::GetICNObject(addon.object) && 0x17 == addon.index) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindCastle(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNTOWN - if(ICN::OBJNTOWN == MP2::GetICNObject(addon.object)) return &addon; - } - } - - if(!addons_level2.empty()) - { - std::list::iterator it1 = addons_level2.begin(); - std::list::const_iterator it2 = addons_level2.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNTOWN - if(ICN::OBJNTOWN == MP2::GetICNObject(addon.object)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindRNDCastle(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNTWRD - if(ICN::OBJNTWRD == MP2::GetICNObject(addon.object) && 32 > addon.index) return &addon; - } - } - - if(!addons_level2.empty()) - { - std::list::iterator it1 = addons_level2.begin(); - std::list::const_iterator it2 = addons_level2.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // OBJNTWRD - if(ICN::OBJNTWRD == MP2::GetICNObject(addon.object) && 32 > addon.index) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon* Maps::Tiles::FindFlags(void) -{ - Maps::TilesAddon* res = NULL; - - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // FLAG32 - //if(ICN::FLAG32 == MP2::GetICNObject(addon.object)) return &addon; - if(ICN::FLAG32 == MP2::GetICNObject(addon.object)) res = &addon; - } - } - - if(!addons_level2.empty()) - { - std::list::iterator it1 = addons_level2.begin(); - std::list::const_iterator it2 = addons_level2.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // FLAG32 - //if(ICN::FLAG32 == MP2::GetICNObject(addon.object)) return &addon; - if(ICN::FLAG32 == MP2::GetICNObject(addon.object)) res = &addon; - } - } - - return res; -} - -Maps::TilesAddon * Maps::Tiles::FindJail(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(ICN::X_LOC2 == MP2::GetICNObject(addon.object) && 0x09 == addon.index) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindBarrier(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(ICN::X_LOC3 == MP2::GetICNObject(addon.object) && - (60 == addon.index || - 66 == addon.index || - 72 == addon.index || - 78 == addon.index || - 84 == addon.index || - 90 == addon.index || - 96 == addon.index || - 102 == addon.index)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindRNDMonster(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // MONS32 - if(ICN::MONS32 == MP2::GetICNObject(addon.object) && - (0x41 < addon.index && 0x47 > addon.index)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindMonster(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // MONS32 - if(ICN::MONS32 == MP2::GetICNObject(addon.object)) return &addon; - } - } - - return NULL; -} - -Maps::TilesAddon * Maps::Tiles::FindCampFire(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - // MTNDSRT - if(ICN::OBJNDSRT == MP2::GetICNObject(addon.object) && 61 == addon.index) return &addon; - else - // OBJNMULT - if(ICN::OBJNMULT == MP2::GetICNObject(addon.object) && 131 == addon.index) return &addon; - else - // OBJNSNOW - if(ICN::OBJNSNOW == MP2::GetICNObject(addon.object) && 4 == addon.index) return &addon; - } - } - - return NULL; -} - -const Maps::TilesAddon * Maps::Tiles::FindMines(void) const -{ - if(!addons_level1.empty()) - { - std::list::const_iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - const TilesAddon & addon = *it1; - - // EXTRAOVR - if(ICN::EXTRAOVR == MP2::GetICNObject(addon.object)) return &addon; - } - } - - return NULL; -} - -/* ICN::FLAGS32 version */ -void Maps::Tiles::CaptureFlags32(const MP2::object_t obj, const Color::color_t col) -{ - u8 index = 0; - - switch(col) - { - case Color::BLUE: index = 0; break; - case Color::GREEN: index = 1; break; - case Color::RED: index = 2; break; - case Color::YELLOW: index = 3; break; - case Color::ORANGE: index = 4; break; - case Color::PURPLE: index = 5; break; - case Color::GRAY: index = 6; break; - - default: break; - } - - switch(obj) - { - case MP2::OBJ_MINES: index += 14; CorrectFlags32(index, true); break; - //case MP2::OBJ_DRAGONCITY: index += 35; CorrectFlags32(index); break; unused - case MP2::OBJ_LIGHTHOUSE: index += 42; CorrectFlags32(index, false); break; - - case MP2::OBJ_ALCHEMYLAB: - { - index += 21; - if(Maps::isValidDirection(maps_index, Direction::TOP)) - { - Maps::Tiles & tile = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::TOP)); - tile.CorrectFlags32(index, true); - } - } - break; - - case MP2::OBJ_SAWMILL: - { - index += 28; - if(Maps::isValidDirection(maps_index, Direction::TOP_RIGHT)) - { - Maps::Tiles & tile = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::TOP_RIGHT)); - tile.CorrectFlags32(index, true); - } - } - break; - - case MP2::OBJ_CASTLE: - { - index *= 2; - if(Maps::isValidDirection(maps_index, Direction::LEFT)) - { - Maps::Tiles & tile = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::LEFT)); - tile.CorrectFlags32(index, true); - } - - index += 1; - if(Maps::isValidDirection(maps_index, Direction::RIGHT)) - { - Maps::Tiles & tile = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::RIGHT)); - tile.CorrectFlags32(index, true); - } - } - break; - - default: return; - } -} - -/* correct flags, ICN::FLAGS32 vesion */ -void Maps::Tiles::CorrectFlags32(const u8 index, bool up) -{ - TilesAddon* taddon = FindFlags(); - - // replace flag - if(NULL != taddon) - taddon->index = index; - else - if(up) - // or new flag - addons_level2.push_back(TilesAddon(TilesAddon::UPPER, world.GetUniq(), 0x38, index)); - else - // or new flag - addons_level1.push_back(TilesAddon(TilesAddon::UPPER, world.GetUniq(), 0x38, index)); -} - -void Maps::Tiles::FixLoyaltyVersion(void) -{ - switch(mp2_object) - { - case MP2::OBJ_UNKNW_79: - case MP2::OBJ_UNKNW_7A: - case MP2::OBJ_UNKNW_F9: - case MP2::OBJ_UNKNW_FA: - { - std::list::iterator it1 = addons_level1.begin(); - std::list::const_iterator it2 = addons_level1.end(); - - // check level1 - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(ICN::X_LOC1 == MP2::GetICNObject(addon.object) || - ICN::X_LOC2 == MP2::GetICNObject(addon.object) || - ICN::X_LOC3 == MP2::GetICNObject(addon.object)) - { - const u8 newobj = ObjLoyalty::LearnObject(addon); - if(MP2::OBJ_ZERO != newobj) mp2_object = newobj; - return; - } - } - - it1 = addons_level2.begin(); - it2 = addons_level2.end(); - - // check level2 - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(ICN::X_LOC1 == MP2::GetICNObject(addon.object) || - ICN::X_LOC2 == MP2::GetICNObject(addon.object) || - ICN::X_LOC3 == MP2::GetICNObject(addon.object)) - { - const u8 newobj = ObjLoyalty::LearnObject(addon); - if(MP2::OBJ_ZERO != newobj) mp2_object = newobj; - return; - } - } - - DEBUG(DBG_GAME , DBG_WARN, "Maps::Tiles::FixLoyaltyVersion: index: " << maps_index); - - } break; - - default: break; - } -} - -u8 Maps::Tiles::GetMinesType(void) const -{ - const TilesAddon * taddon = FindMines(); - - if(taddon) switch(taddon->index) - { - case 0: return Resource::ORE; - case 1: return Resource::SULFUR; - case 2: return Resource::CRYSTAL; - case 3: return Resource::GEMS; - case 4: return Resource::GOLD; - default: break; - } - return 0; -} - -/* for few object need many resource */ -void Maps::Tiles::UpdateQuantity(void) -{ - const TilesAddon * addon = NULL; - - switch(mp2_object) - { - case MP2::OBJ_WITCHSHUT: - quantity1 = Skill::Secondary::RandForWitchsHut(); - break; - - case MP2::OBJ_SHRINE1: - quantity1 = Rand::Get(10) % 2 ? Spell::RandCombat(1) : Spell::RandAdventure(1); - break; - - case MP2::OBJ_SHRINE2: - quantity1 = Rand::Get(10) % 2 ? Spell::RandCombat(2) : Spell::RandAdventure(2); - break; - - case MP2::OBJ_SHRINE3: - quantity1 = Rand::Get(10) % 2 ? Spell::RandCombat(3) : Spell::RandAdventure(3); - break; - - case MP2::OBJ_SKELETON: - { - Rand::Queue percents(2); - // 80%: empty - percents.Push(0, 80); - // 20%: artifact 1 or 2 or 3 - percents.Push(1, 20); - - if(percents.Get()) - { - switch(Rand::Get(1, 3)) - { - case 1: quantity1 = Artifact::Rand1(); break; - case 2: quantity1 = Artifact::Rand2(); break; - case 3: quantity1 = Artifact::Rand3(); break; - default: break; - } - } - } - break; - - case MP2::OBJ_WAGON: - { - Rand::Queue percents(3); - // 20%: empty - percents.Push(0, 20); - // 10%: artifact 1 or 2 - percents.Push(1, 10); - // 50%: resource - percents.Push(2, 50); - - switch(percents.Get()) - { - case 1: - quantity1 = (1 == Rand::Get(1, 2) ? Artifact::Rand1() : Artifact::Rand2()); - break; - case 2: - quantity1 = Resource::Rand(); - quantity2 = Rand::Get(2, 5); - break; - default: break; - } - } - break; - - case MP2::OBJ_ARTIFACT: - // quantity1 - art, quantity2 - conditions for pickup: - // 1,2,3 - 2000g, 2500g+3res, 3000g+5res, - // 4,5 - need have skill wisard or leadership, - // 6 - 50 rogues, 7 - 1 gin, 8,9,10,11,12,13 - 1 monster level4, other - none - addon = FindArtifact(); - if(addon) - { - Artifact::artifact_t art = Artifact::FromIndexSprite(addon->index); - - if(Artifact::SPELL_SCROLL == art) - { - // spell from origin mp2 - Spell::spell_t spell = Spell::FromInt(1 + (quantity2 * 256 + quantity1) / 8); - quantity1 = art; - // always available - quantity2 = 15; - quantity3 = (spell == Spell::NONE ? Spell::FIREBALL : spell); - } - else - { - quantity1 = art; - // conditions: 70% empty - quantity2 = Rand::Get(1, 10) < 4 ? Rand::Get(1, 13) : 0; - // added resource - if(quantity2 == 2 || quantity2 == 3) - quantity4 = Resource::Rand(); - - if(Settings::Get().ExtNoRequirementsForArtifacts()) - quantity2 = 0; - } - } - break; - - case MP2::OBJ_RESOURCE: - addon = FindResource(); - if(addon) - { - quantity1 = Resource::FromIndexSprite(addon->index); - switch(quantity1) - { - case Resource::WOOD: - case Resource::ORE: - case Resource::GOLD: - quantity2 = Rand::Get(5, 10); - break; - default: - quantity2 = Rand::Get(3, 6); - break; - } - } - break; - - case MP2::OBJ_MAGICGARDEN: - // 5 gems or 500 gold - quantity1 = (Rand::Get(1) ? Resource::GEMS : Resource::GOLD); - quantity2 = 5; - break; - - case MP2::OBJ_WATERWHEEL: - // first week 500 gold, next week 100 gold - quantity1 = Resource::GOLD; - quantity2 = (world.CountDay() == 1 ? 5 : 10); - break; - - case MP2::OBJ_WINDMILL: - // 2 rnd resource - quantity1 = Resource::Rand(); - quantity2 = 2; - break; - - case MP2::OBJ_LEANTO: - // 1-4 rnd resource - quantity1 = Resource::Rand(); - quantity2 = Rand::Get(1, 4); - break; - - case MP2::OBJ_CAMPFIRE: - // 4-6 rnd resource and + 400-600 gold - quantity1 = Resource::Rand(); - quantity2 = Rand::Get(4, 6); - break; - - case MP2::OBJ_FLOTSAM: - { - Rand::Queue percents(3); - // 25%: empty - percents.Push(0, 25); - // 25%: 500 gold + 10 wood - percents.Push(1, 25); - // 25%: 200 gold + 5 wood - percents.Push(2, 25); - // 25%: 5 wood - percents.Push(3, 25); - - // variant - switch(percents.Get()) - { - case 1: quantity1 = 5; quantity2 = 10; break; - case 2: quantity1 = 2; quantity2 = 5; break; - case 3: quantity2 = 5; break; - default: break; - } - } - break; - - case MP2::OBJ_SHIPWRECKSURVIROR: - { - Rand::Queue percents(3); - // 55%: artifact 1 - percents.Push(1, 55); - // 30%: artifact 2 - percents.Push(1, 30); - // 15%: artifact 3 - percents.Push(1, 15); - - // variant - switch(percents.Get()) - { - case 1: quantity1 = Artifact::Rand1(); break; - case 2: quantity1 = Artifact::Rand2(); break; - case 3: quantity1 = Artifact::Rand3(); break; - default: break; - } - } - break; - - case MP2::OBJ_WATERCHEST: - { - Rand::Queue percents(3); - // 20% - empty - percents.Push(0, 20); - // 70% - 1500 gold - percents.Push(1, 70); - // 10% - 1000 gold + art - percents.Push(2, 10); - - // variant - switch(percents.Get()) - { - case 1: quantity2 = 15; break; - case 2: quantity2 = 10; quantity1 = Artifact::Rand1(); break; - default: break; - } - } - break; - - case MP2::OBJ_TREASURECHEST: - { - Rand::Queue percents(4); - // 31% - 2000 gold or 1500 exp - percents.Push(1, 31); - // 32% - 1500 gold or 1000 exp - percents.Push(2, 32); - // 32% - 1000 gold or 500 exp - percents.Push(3, 32); - // 5% - art - percents.Push(4, 5); - - // variant - switch(percents.Get()) - { - case 1: quantity2 = 20; break; - case 2: quantity2 = 15; break; - case 3: quantity2 = 10; break; - case 4: quantity1 = Artifact::Rand1(); break; - default: break; - } - } - break; - - case MP2::OBJ_DERELICTSHIP: - // 5000 gold - quantity2 = 50; - break; - - case MP2::OBJ_SHIPWRECK: - // variant: 10ghost(1000g), 15 ghost(2000g), 25ghost(5000g) or 50ghost(2000g+art) - switch(Rand::Get(1, 4)) - { - case 1: quantity2 = 10; break; - case 2: quantity2 = 15; break; - case 3: quantity2 = 25; break; - case 4: quantity1 = Artifact::Rand(); quantity2 = 50; break; - default: break; - } - break; - - case MP2::OBJ_GRAVEYARD: - // 1000 gold + art - quantity1 = Artifact::Rand(); - quantity2 = 10; - break; - - case MP2::OBJ_PYRAMID: - // random spell level 5 - quantity1 = (Rand::Get(1) ? Spell::RandCombat(5) : Spell::RandAdventure(5)); - quantity2 = 1; - break; - - case MP2::OBJ_DAEMONCAVE: - // 1000 exp or 1000 exp + 2500 gold or 1000 exp + art or (-2500 or remove hero) - quantity2 = Rand::Get(1, 4); - quantity1 = Artifact::Rand(); - break; - - // aband mines - case MP2::OBJ_ABANDONEDMINE: - SetCountMonster(Rand::Get(39, 45)); // I checked in Heroes II: min 3 x 13, and max 3 x 15 - quantity3 = Monster::GHOST; - if(! Settings::Get().ExtAbandonedMineRandom()) - quantity4 = Resource::GOLD; - else - switch(Rand::Get(1, 5)) - { - case 1: quantity4 = Resource::ORE; break; - case 2: quantity4 = Resource::SULFUR; break; - case 3: quantity4 = Resource::CRYSTAL; break; - case 4: quantity4 = Resource::GEMS; break; - default: quantity4 = Resource::GOLD; break; - } - break; - - case MP2::OBJ_TREEKNOWLEDGE: - // variant: 10 gems, 2000 gold or free - switch(Rand::Get(1, 3)) - { - case 1: - quantity2 = 10; - break; - case 2: - quantity2 = 20; - break; - default: break; - } - break; - - case MP2::OBJ_BARRIER: - case MP2::OBJ_TRAVELLERTENT: - quantity1 = Barrier::FromMP2(quantity1); - break; - - default: break; - } -} - -bool Maps::Tiles::ValidQuantity(void) const -{ - if(MP2::isQuantityObject(mp2_object)) - return quantity1 || quantity2; - - return false; -} - -bool Maps::Tiles::CheckEnemyGuardians(u8 color) const -{ - switch(mp2_object) - { - case MP2::OBJ_ARTIFACT: - return quantity1 > 5 || quantity1 < 14; - - case MP2::OBJ_DERELICTSHIP: - case MP2::OBJ_SHIPWRECK: - case MP2::OBJ_GRAVEYARD: - return quantity2; - - case MP2::OBJ_PYRAMID: - case MP2::OBJ_DAEMONCAVE: - return quantity2; - - case MP2::OBJ_MONSTER: - case MP2::OBJ_ABANDONEDMINE: - return GetCountMonster(); - - default: - break; - } - - if(color && - (MP2::isCaptureObject(mp2_object) || - (MP2::OBJ_HEROES == mp2_object && world.GetHeroes(maps_index) && - MP2::isCaptureObject(world.GetHeroes(maps_index)->GetUnderObject()))) && - color != world.ColorCapturedObject(maps_index)) - return quantity3 && GetCountMonster(); - - return false; -} - - -void Maps::Tiles::RemoveObjectSprite(void) -{ - const Maps::TilesAddon *addon = NULL; - - switch(mp2_object) - { - case MP2::OBJ_ARTIFACT: addon = FindArtifact(); break; - case MP2::OBJ_CAMPFIRE: addon = FindCampFire(); break; - - case MP2::OBJ_WATERCHEST: - case MP2::OBJ_BOTTLE: - case MP2::OBJ_FLOTSAM: - case MP2::OBJ_SHIPWRECKSURVIROR:addon = FindWaterResource(); break; - - case MP2::OBJ_TREASURECHEST: - case MP2::OBJ_ANCIENTLAMP: - case MP2::OBJ_RESOURCE: addon = FindResource(); break; - - case MP2::OBJ_JAIL: RemoveJailSprite(); return; - - case MP2::OBJ_BARRIER: RemoveBarrierSprite(); return; - - default: return; - } - - if(addon) - { - // remove shadow sprite from left cell - if(Maps::isValidDirection(maps_index, Direction::LEFT)) - world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::LEFT)).Remove(addon->uniq); - - Remove(addon->uniq); - } -} - -void Maps::Tiles::RemoveBarrierSprite(void) -{ - const Maps::TilesAddon *addon = FindBarrier(); - - if(addon) - { - // remove left sprite - if(Maps::isValidDirection(maps_index, Direction::LEFT)) - { - const s32 left = Maps::GetDirectionIndex(maps_index, Direction::LEFT); - world.GetTiles(left).Remove(addon->uniq); - } - - Remove(addon->uniq); - } -} - -void Maps::Tiles::RemoveJailSprite(void) -{ - const Maps::TilesAddon *addon = FindJail(); - - if(addon) - { - // remove left sprite - if(Maps::isValidDirection(maps_index, Direction::LEFT)) - { - const s32 left = Maps::GetDirectionIndex(maps_index, Direction::LEFT); - world.GetTiles(left).Remove(addon->uniq); - - // remove left left sprite - if(Maps::isValidDirection(left, Direction::LEFT)) - world.GetTiles(Maps::GetDirectionIndex(left, Direction::LEFT)).Remove(addon->uniq); - } - - // remove top sprite - if(Maps::isValidDirection(maps_index, Direction::TOP)) - { - const s32 top = Maps::GetDirectionIndex(maps_index, Direction::TOP); - world.GetTiles(top).Remove(addon->uniq); - world.GetTiles(top).SetObject(MP2::OBJ_ZERO); - - // remove top left sprite - if(Maps::isValidDirection(top, Direction::LEFT)) - { - world.GetTiles(Maps::GetDirectionIndex(top, Direction::LEFT)).Remove(addon->uniq); - world.GetTiles(Maps::GetDirectionIndex(top, Direction::LEFT)).SetObject(MP2::OBJ_ZERO); - } - } - - Remove(addon->uniq); - } -} - -u16 Maps::Tiles::GetCountMonster(void) const -{ - return quantity2 * 0xFF + quantity1; -} - -void Maps::Tiles::SetCountMonster(const u16 count) -{ - quantity1 = count % 0xFF; - quantity2 = count / 0xFF; -} - -void Maps::Tiles::UpdateMonsterInfo(void) -{ - switch(mp2_object) - { - case MP2::OBJ_RNDMONSTER: - case MP2::OBJ_RNDMONSTER1: - case MP2::OBJ_RNDMONSTER2: - case MP2::OBJ_RNDMONSTER3: - case MP2::OBJ_RNDMONSTER4: - UpdateRNDMonsterSprite(); break; - default: break; - } - - const TilesAddon* addons = FindMonster(); - const Monster m(addons ? Monster::FromInt(addons->index + 1) : Monster::UNKNOWN); - bool fixed = false; - - // update random count - if(0 == quantity1 && 0 == quantity2) - SetCountMonster(4 * m.GetRNDSize(false)); - // update fixed count (mp2 format) - else - { - u16 count = quantity2; - count <<= 8; - count |= quantity1; - count >>= 3; - - SetCountMonster(count); - fixed = true; - } - - // set monster - quantity3 = m(); - - // extra params: - // quantity4 - join conditions (0: skip, 1: money, 2: free, 3: force (for campain need store color also) - - // skip join - if(m() == Monster::GHOST || m.isElemental()) - quantity4 = 0; - else - if(fixed) - // for money - quantity4 = 1; - else - // 20% chance of joining - quantity4 = (3 > Rand::Get(1, 10) ? 2 : 1); -} - -void Maps::Tiles::UpdateRNDMonsterSprite(void) -{ - Maps::TilesAddon *addon = FindRNDMonster(); - - if(addon) - { - switch(mp2_object) - { - case MP2::OBJ_RNDMONSTER: addon->index = Monster::Rand(); break; - case MP2::OBJ_RNDMONSTER1: addon->index = Monster::Rand(Monster::LEVEL1); break; - case MP2::OBJ_RNDMONSTER2: addon->index = Monster::Rand(Monster::LEVEL2); break; - case MP2::OBJ_RNDMONSTER3: addon->index = Monster::Rand(Monster::LEVEL3); break; - case MP2::OBJ_RNDMONSTER4: addon->index = Monster::Rand(Monster::LEVEL4); break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Maps::Tiles::UpdateRNDMonsterSprite: unknown object, index: " << maps_index); return; - } - - // ICN::MONS32 start from PEASANT - addon->index = addon->index - 1; - - mp2_object = MP2::OBJ_MONSTER; - } - else - DEBUG(DBG_GAME , DBG_WARN, "Maps::Tiles::UpdateRNDMonsterSprite: FindRNDMonster return is NULL, index: " << maps_index); -} - -void Maps::Tiles::UpdateAbandoneMineSprite(void) -{ - u32 uniq = 0; - - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(ICN::OBJNGRAS == MP2::GetICNObject(addon.object) && 6 == addon.index) - { - addon.object = 128; - addon.index = 82; - uniq = addon.uniq; - } - - if(ICN::OBJNDIRT == MP2::GetICNObject(addon.object) && 8 == addon.index) - { - addon.object = 104; - addon.index = 112; - } - - if(ICN::EXTRAOVR == MP2::GetICNObject(addon.object) && 5 == addon.index) - { - switch(quantity4) - { - case Resource::ORE: addon.index = 0; break; - case Resource::SULFUR: addon.index = 1; break; - case Resource::CRYSTAL: addon.index = 2; break; - case Resource::GEMS: addon.index = 3; break; - case Resource::GOLD: addon.index = 4; break; - default: break; - } - } - } - } - - if(uniq && Maps::isValidDirection(maps_index, Direction::RIGHT)) - { - Tiles & tile = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::RIGHT)); - TilesAddon *mines = tile.FindAddonLevel1(uniq); - if(mines) - { - // dirt - if(ICN::OBJNDIRT == MP2::GetICNObject(mines->object) && mines->index == 9) - { - mines->object = 104; - mines->index = 113; - } - - // grass - if(ICN::OBJNGRAS == MP2::GetICNObject(mines->object) && mines->index == 7) - { - mines->object = 128; - mines->index = 83; - } - } - if(tile.mp2_object == MP2::OBJN_ABANDONEDMINE) tile.mp2_object = MP2::OBJN_MINES; - } - - if(Maps::isValidDirection(maps_index, Direction::LEFT)) - { - Tiles & tile = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::LEFT)); - if(tile.mp2_object == MP2::OBJN_ABANDONEDMINE) tile.mp2_object = MP2::OBJN_MINES; - } - - if(Maps::isValidDirection(maps_index, Direction::TOP)) - { - Tiles & tile = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::TOP)); - if(tile.mp2_object == MP2::OBJN_ABANDONEDMINE) tile.mp2_object = MP2::OBJN_MINES; - - if(Maps::isValidDirection(tile.maps_index, Direction::LEFT)) - { - Tiles & tile2 = world.GetTiles(Maps::GetDirectionIndex(tile.maps_index, Direction::LEFT)); - if(tile2.mp2_object == MP2::OBJN_ABANDONEDMINE) tile2.mp2_object = MP2::OBJN_MINES; - } - - if(Maps::isValidDirection(tile.maps_index, Direction::RIGHT)) - { - Tiles & tile2 = world.GetTiles(Maps::GetDirectionIndex(tile.maps_index, Direction::RIGHT)); - if(tile2.mp2_object == MP2::OBJN_ABANDONEDMINE) tile2.mp2_object = MP2::OBJN_MINES; - } - } -} - -void Maps::Tiles::UpdateStoneLightsSprite(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(ICN::OBJNMUL2 == MP2::GetICNObject(addon.object)) - switch(addon.index) - { - case 116: addon.object = 0x11; addon.index = 0; quantity1 = 1; break; - case 119: addon.object = 0x12; addon.index = 0; quantity1 = 2; break; - case 122: addon.object = 0x13; addon.index = 0; quantity1 = 3; break; - default: break; - } - } - } -} - -void Maps::Tiles::UpdateRNDArtifactSprite(void) -{ - TilesAddon *addon = NULL; - u8 index = 0; - - switch(mp2_object) - { - case MP2::OBJ_RNDARTIFACT: - addon = FindRNDArtifact(MP2::OBJ_RNDARTIFACT); - index = Artifact::IndexSprite(Artifact::Rand()); - break; - case MP2::OBJ_RNDARTIFACT1: - addon = FindRNDArtifact(MP2::OBJ_RNDARTIFACT1); - index = Artifact::IndexSprite(Artifact::Rand1()); - break; - case MP2::OBJ_RNDARTIFACT2: - addon = FindRNDArtifact(MP2::OBJ_RNDARTIFACT2); - index = Artifact::IndexSprite(Artifact::Rand2()); - break; - case MP2::OBJ_RNDARTIFACT3: - addon = FindRNDArtifact(MP2::OBJ_RNDARTIFACT3); - index = Artifact::IndexSprite(Artifact::Rand3()); - break; - default: return; - } - - if(addon) - { - addon->index = index; - mp2_object = MP2::OBJ_ARTIFACT; - - // replace shadow artifact - if(Maps::isValidDirection(maps_index, Direction::LEFT)) - { - Maps::Tiles & left_tile = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::LEFT)); - Maps::TilesAddon *shadow = left_tile.FindAddonLevel1(addon->uniq); - - if(shadow) shadow->index = index - 1; - } - } -} - -void Maps::Tiles::UpdateRNDResourceSprite(void) -{ - TilesAddon *addon = FindRNDResource(); - - if(addon) - { - addon->index = Resource::GetIndexSprite(Resource::Rand()); - mp2_object = MP2::OBJ_RESOURCE; - - // replace shadow artifact - if(Maps::isValidDirection(maps_index, Direction::LEFT)) - { - Maps::Tiles & left_tile = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::LEFT)); - Maps::TilesAddon *shadow = left_tile.FindAddonLevel1(addon->uniq); - - if(shadow) shadow->index = addon->index - 1; - } - } -} - -void Maps::Tiles::UpdateFountainSprite(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(ICN::OBJNMUL2 == MP2::GetICNObject(addon.object) && 15 == addon.index) - { - addon.object = 0x14; - addon.index = 0; - } - } - } -} - -void Maps::Tiles::UpdateTreasureChestSprite(void) -{ - if(!addons_level1.empty()) - { - std::list::iterator it1 = addons_level1.begin(); - std::list::iterator it2 = addons_level1.end(); - - for(; it1 != it2; ++it1) - { - TilesAddon & addon = *it1; - - if(ICN::OBJNRSRC == MP2::GetICNObject(addon.object) && 19 == addon.index) - { - addon.object = 0x15; - addon.index = 0; - } - } - } -} - -bool Maps::Tiles::isFog(u8 color) const -{ - return fogs & color; -} - -void Maps::Tiles::SetFog(u8 color) -{ - const Settings & conf = Settings::Get(); - fogs |= (conf.ExtUnionsAllowViewMaps() ? conf.GetUnions(color) : color); -} - -void Maps::Tiles::ClearFog(u8 color) -{ - const Settings & conf = Settings::Get(); - fogs &= ~(conf.ExtUnionsAllowViewMaps() ? conf.GetUnions(color) : color); -} - -void Maps::Tiles::ResetQuantity(void) -{ - quantity1 = 0; - quantity2 = 0; - quantity3 = 0; - quantity4 = 0; -} - -void Maps::Tiles::RedrawFogs(Surface & dst, u8 color) const -{ - const Interface::GameArea & area = Interface::GameArea::Get(); - const Point mp(maps_index % world.w(), maps_index / world.w()); - - // get direction around fogs - u16 around = 0; - - for(Direction::vector_t direct = Direction::TOP_LEFT; direct != Direction::CENTER; ++direct) - if(!Maps::isValidDirection(maps_index, direct) || - world.GetTiles(Maps::GetDirectionIndex(maps_index, direct)).isFog(color)) around |= direct; - - if(isFog(color)) around |= Direction::CENTER; - - // TIL::CLOF32 - if(DIRECTION_ALL == around) - { - const Surface & sf = AGG::GetTIL(TIL::CLOF32, maps_index % 4, 0); - area.BlitOnTile(dst, sf, 0, 0, mp); - } - else - { - u8 index = 0; - bool revert = false; - - // see ICN::CLOP32: sprite 10 - if((around & Direction::CENTER) && !(around & (Direction::TOP | Direction::BOTTOM | Direction::LEFT | Direction::RIGHT))) - { index = 10; revert = false; } - else - // see ICN::CLOP32: sprite 6, 7, 8 - if(around & (Direction::CENTER | Direction::TOP) && !(around & (Direction::BOTTOM | Direction::LEFT | Direction::RIGHT))) - { index = 6; revert = false; } - else - if(around & (Direction::CENTER | Direction::RIGHT) && !(around & (Direction::TOP | Direction::BOTTOM | Direction::LEFT))) - { index = 7; revert = false; } - else - if(around & (Direction::CENTER | Direction::LEFT) && !(around & (Direction::TOP | Direction::BOTTOM | Direction::RIGHT))) - { index = 7; revert = true; } - else - if(around & (Direction::CENTER | Direction::BOTTOM) && !(around & (Direction::TOP | Direction::LEFT | Direction::RIGHT))) - { index = 8; revert = false; } - else - // see ICN::CLOP32: sprite 9, 29 - if(around & (DIRECTION_CENTER_COL) && !(around & (Direction::LEFT | Direction::RIGHT))) - { index = 9; revert = false; } - else - if(around & (DIRECTION_CENTER_ROW) && !(around & (Direction::TOP | Direction::BOTTOM))) - { index = 29; revert = false; } - else - // see ICN::CLOP32: sprite 15, 22 - if(around == (DIRECTION_ALL & (~Direction::TOP_RIGHT))) - { index = 15; revert = false; } - else - if(around == (DIRECTION_ALL & (~Direction::TOP_LEFT))) - { index = 15; revert = true; } - else - if(around == (DIRECTION_ALL & (~Direction::BOTTOM_RIGHT))) - { index = 22; revert = false; } - else - if(around == (DIRECTION_ALL & (~Direction::BOTTOM_LEFT))) - { index = 22; revert = true; } - else - // see ICN::CLOP32: sprite 16, 17, 18, 23 - if(around == (DIRECTION_ALL & (~(Direction::TOP_RIGHT | Direction::BOTTOM_RIGHT)))) - { index = 16; revert = false; } - else - if(around == (DIRECTION_ALL & (~(Direction::TOP_LEFT | Direction::BOTTOM_LEFT)))) - { index = 16; revert = true; } - else - if(around == (DIRECTION_ALL & (~(Direction::TOP_RIGHT | Direction::BOTTOM_LEFT)))) - { index = 17; revert = false; } - else - if(around == (DIRECTION_ALL & (~(Direction::TOP_LEFT | Direction::BOTTOM_RIGHT)))) - { index = 17; revert = true; } - else - if(around == (DIRECTION_ALL & (~(Direction::TOP_LEFT | Direction::TOP_RIGHT)))) - { index = 18; revert = false; } - else - if(around == (DIRECTION_ALL & (~(Direction::BOTTOM_LEFT | Direction::BOTTOM_RIGHT)))) - { index = 23; revert = false; } - else - // see ICN::CLOP32: sprite 13, 14 - if(around == (DIRECTION_ALL & (~DIRECTION_TOP_RIGHT_CORNER))) - { index = 13; revert = false; } - else - if(around == (DIRECTION_ALL & (~DIRECTION_TOP_LEFT_CORNER))) - { index = 13; revert = true; } - else - if(around == (DIRECTION_ALL & (~DIRECTION_BOTTOM_RIGHT_CORNER))) - { index = 14; revert = false; } - else - if(around == (DIRECTION_ALL & (~DIRECTION_BOTTOM_LEFT_CORNER))) - { index = 14; revert = true; } - else - // see ICN::CLOP32: sprite 11, 12 - if(around & (Direction::CENTER | Direction::LEFT | Direction::BOTTOM_LEFT | Direction::BOTTOM) && - !(around & (Direction::TOP | Direction::TOP_RIGHT | Direction::RIGHT))) - { index = 11; revert = false; } - else - if(around & (Direction::CENTER | Direction::RIGHT | Direction::BOTTOM_RIGHT | Direction::BOTTOM) && - !(around & (Direction::TOP | Direction::TOP_LEFT | Direction::LEFT))) - { index = 11; revert = true; } - else - if(around & (Direction::CENTER | Direction::LEFT | Direction::TOP_LEFT | Direction::TOP) && - !(around & (Direction::BOTTOM | Direction::BOTTOM_RIGHT | Direction::RIGHT))) - { index = 12; revert = false; } - else - if(around & (Direction::CENTER | Direction::RIGHT | Direction::TOP_RIGHT | Direction::TOP) && - !(around & (Direction::BOTTOM | Direction::BOTTOM_LEFT | Direction::LEFT))) - { index = 12; revert = true; } - else - // see ICN::CLOP32: sprite 19, 20, 22 - if(around & (DIRECTION_CENTER_ROW | Direction::BOTTOM | Direction::TOP | Direction::TOP_LEFT) && - !(around & (Direction::BOTTOM_LEFT | Direction::BOTTOM_RIGHT | Direction::TOP_RIGHT))) - { index = 19; revert = false; } - else - if(around & (DIRECTION_CENTER_ROW | Direction::BOTTOM | Direction::TOP | Direction::TOP_RIGHT) && - !(around & (Direction::BOTTOM_LEFT | Direction::BOTTOM_RIGHT | Direction::TOP_LEFT))) - { index = 19; revert = true; } - else - if(around & (DIRECTION_CENTER_ROW | Direction::BOTTOM | Direction::TOP | Direction::BOTTOM_LEFT) && - !(around & (Direction::TOP_RIGHT | Direction::BOTTOM_RIGHT | Direction::TOP_LEFT))) - { index = 20; revert = false; } - else - if(around & (DIRECTION_CENTER_ROW | Direction::BOTTOM | Direction::TOP | Direction::BOTTOM_RIGHT) && - !(around & (Direction::TOP_RIGHT | Direction::BOTTOM_LEFT | Direction::TOP_LEFT))) - { index = 20; revert = true; } - else - if(around & (DIRECTION_CENTER_ROW | Direction::BOTTOM | Direction::TOP) && - !(around & (Direction::TOP_RIGHT | Direction::BOTTOM_RIGHT | Direction::BOTTOM_LEFT | Direction::TOP_LEFT))) - { index = 22; revert = false; } - else - // see ICN::CLOP32: sprite 24, 25, 26, 30 - if(around & (DIRECTION_CENTER_ROW | Direction::BOTTOM | Direction::BOTTOM_LEFT) && - !(around & (Direction::TOP | Direction::BOTTOM_RIGHT))) - { index = 24; revert = false; } - else - if(around & (DIRECTION_CENTER_ROW | Direction::BOTTOM | Direction::BOTTOM_RIGHT) && - !(around & (Direction::TOP | Direction::BOTTOM_LEFT))) - { index = 24; revert = true; } - else - if(around & (DIRECTION_CENTER_COL | Direction::LEFT | Direction::TOP_LEFT) && - !(around & (Direction::RIGHT | Direction::BOTTOM_LEFT))) - { index = 25; revert = false; } - else - if(around & (DIRECTION_CENTER_COL | Direction::RIGHT | Direction::TOP_RIGHT) && - !(around & (Direction::LEFT | Direction::BOTTOM_RIGHT))) - { index = 25; revert = true; } - else - if(around & (DIRECTION_CENTER_COL | Direction::BOTTOM_LEFT | Direction::LEFT) && - !(around & (Direction::RIGHT | Direction::TOP_LEFT))) - { index = 26; revert = false; } - else - if(around & (DIRECTION_CENTER_COL | Direction::BOTTOM_RIGHT | Direction::RIGHT) && - !(around & (Direction::LEFT | Direction::TOP_RIGHT))) - { index = 26; revert = true; } - else - if(around & (DIRECTION_CENTER_ROW | Direction::TOP_LEFT | Direction::TOP) && - !(around & (Direction::BOTTOM | Direction::TOP_RIGHT))) - { index = 30; revert = false; } - else - if(around & (DIRECTION_CENTER_ROW | Direction::TOP_RIGHT | Direction::TOP) && - !(around & (Direction::BOTTOM | Direction::TOP_LEFT))) - { index = 30; revert = true; } - else - // see ICN::CLOP32: sprite 27, 28 - if(around & (Direction::CENTER | Direction::BOTTOM | Direction::LEFT) && - !(around & (Direction::TOP | Direction::TOP_RIGHT | Direction::RIGHT | Direction::BOTTOM_LEFT))) - { index = 27; revert = false; } - else - if(around & (Direction::CENTER | Direction::BOTTOM | Direction::RIGHT) && - !(around & (Direction::TOP | Direction::TOP_LEFT | Direction::LEFT | Direction::BOTTOM_RIGHT))) - { index = 27; revert = true; } - else - if(around & (Direction::CENTER | Direction::LEFT | Direction::TOP) && - !(around & (Direction::TOP_LEFT | Direction::RIGHT | Direction::BOTTOM | Direction::BOTTOM_RIGHT))) - { index = 28; revert = false; } - else - if(around & (Direction::CENTER | Direction::RIGHT | Direction::TOP) && - !(around & (Direction::TOP_RIGHT | Direction::LEFT | Direction::BOTTOM | Direction::BOTTOM_LEFT))) - { index = 28; revert = true; } - else - // see ICN::CLOP32: sprite 31, 32, 33 - if(around & (DIRECTION_CENTER_ROW | Direction::TOP) && - !(around & (Direction::BOTTOM | Direction::TOP_LEFT | Direction::TOP_RIGHT))) - { index = 31; revert = false; } - else - if(around & (DIRECTION_CENTER_COL | Direction::RIGHT) && - !(around & (Direction::LEFT | Direction::TOP_RIGHT | Direction::BOTTOM_RIGHT))) - { index = 32; revert = false; } - else - if(around & (DIRECTION_CENTER_COL | Direction::LEFT) && - !(around & (Direction::RIGHT | Direction::TOP_LEFT | Direction::BOTTOM_LEFT))) - { index = 32; revert = true; } - else - if(around & (DIRECTION_CENTER_ROW | Direction::BOTTOM) && - !(around & (Direction::TOP | Direction::BOTTOM_LEFT | Direction::BOTTOM_RIGHT))) - { index = 33; revert = false; } - else - // see ICN::CLOP32: sprite 0, 1, 2, 3, 4, 5 - if(around & (DIRECTION_CENTER_ROW | DIRECTION_BOTTOM_ROW) && - !(around & (Direction::TOP))) - { index = maps_index % 2 ? 0 : 1; revert = false; } - else - if(around & (DIRECTION_CENTER_ROW | DIRECTION_TOP_ROW) && - !(around & (Direction::BOTTOM))) - { index = maps_index % 2 ? 4 : 5; revert = false; } - else - if(around & (DIRECTION_CENTER_COL | DIRECTION_LEFT_COL) && - !(around & (Direction::RIGHT))) - { index = maps_index % 2 ? 2 : 3; revert = false; } - else - if(around & (DIRECTION_CENTER_COL | DIRECTION_RIGHT_COL) && - !(around & (Direction::LEFT))) - { index = maps_index % 2 ? 2 : 3; revert = true; } - // unknown - else - { - const Surface & sf = AGG::GetTIL(TIL::CLOF32, maps_index % 4, 0); - area.BlitOnTile(dst, sf, 0, 0, mp); - return; - } - - const Sprite & sprite = AGG::GetICN(ICN::CLOP32, index, revert); - area.BlitOnTile(dst, sprite, (revert ? sprite.x() + TILEWIDTH - sprite.w() : sprite.x()), sprite.y(), mp); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/maps_tiles.h b/project/jni/application/fheroes2/src/fheroes2/maps/maps_tiles.h deleted file mode 100644 index 1ac706427..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/maps_tiles.h +++ /dev/null @@ -1,196 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2TILES_H -#define H2TILES_H - -#include -#include "ground.h" -#include "mp2.h" -#include "direction.h" -#include "gamedefs.h" -#include "game_io.h" -#include "color.h" - -class Sprite; -class Heroes; - -namespace Maps -{ - class TilesAddon - { - public: - enum level_t { GROUND = 0, DOWN = 1, SHADOW = 2, UPPER = 3 }; - - TilesAddon(); - TilesAddon(u8 lv, u32 gid, u8 obj, u8 ii); - - TilesAddon & operator= (const TilesAddon & ta); - - static u16 isRoad(const TilesAddon & ta); - static bool isStream(const TilesAddon & ta); - static bool PredicateSortRules1(const TilesAddon & ta1, const TilesAddon & ta2); - static bool PredicateSortRules2(const TilesAddon & ta1, const TilesAddon & ta2); - - u8 level; - u32 uniq; - u8 object; - u8 index; - }; - - class Tiles - { - public: - Tiles(s32); - Tiles(s32 mi, const MP2::mp2tile_t & mp2tile); - - s32 GetIndex(void) const{ return maps_index; } - MP2::object_t GetObject(void) const; - u8 GetQuantity1(void) const{ return quantity1; } - u8 GetQuantity2(void) const{ return quantity2; } - u8 GetQuantity3(void) const{ return quantity3; } - u8 GetQuantity4(void) const{ return quantity4; } - Ground::ground_t GetGround(void) const; - const Surface & GetTileSurface(void) const; - - bool isPassable(const Heroes * hero = NULL, bool skipfog = false) const; - bool isRoad(const Direction::vector_t & direct = Direction::CENTER) const; - bool isStream(void) const; - bool GoodForUltimateArtifact(void) const; - bool CheckEnemyGuardians(u8 color = 0) const; - - TilesAddon* FindAddonICN1(u16 icn1); - TilesAddon* FindAddonICN2(u16 icn2); - - TilesAddon* FindAddonLevel1(u32 uniq1); - TilesAddon* FindAddonLevel2(u32 uniq2); - - TilesAddon* FindCampFire(void); - TilesAddon* FindWaterResource(void); - TilesAddon* FindResource(void); - TilesAddon* FindRNDResource(void); - TilesAddon* FindArtifact(void); - TilesAddon* FindRNDArtifact(const u8 level = 0); - TilesAddon* FindUltimateArtifact(void); - TilesAddon* FindMiniHero(void); - TilesAddon* FindEvent(void); - TilesAddon* FindBoat(void); - TilesAddon* FindCastle(void); - TilesAddon* FindRNDCastle(void); - TilesAddon* FindFlags(void); - TilesAddon* FindRNDMonster(void); - TilesAddon* FindMonster(void); - const TilesAddon* FindMines(void) const; - const TilesAddon* FindStandingStones(void) const; - const TilesAddon* FindArtesianSpring(void) const; - const TilesAddon* FindWhirlpools(void) const; - const TilesAddon* FindOasis(void) const; - TilesAddon* FindJail(void); - TilesAddon* FindBarrier(void); - - void SetTile(const u16 sprite_index, const u8 shape); - - void SetQuantity1(u8 val){ quantity1 = val; } - void SetQuantity2(u8 val){ quantity2 = val; } - void SetQuantity3(u8 val){ quantity3 = val; } - void SetQuantity4(u8 val){ quantity4 = val; } - void ResetQuantity(void); - void SetObject(MP2::object_t object){ mp2_object = object; } - - void UpdateQuantity(void); - bool ValidQuantity(void) const; - void CaptureFlags32(const MP2::object_t obj, const Color::color_t col); - - void RedrawTile(Surface &) const; - void RedrawBottom(Surface &, const TilesAddon* skip = NULL) const; - void RedrawBottom4Hero(Surface &) const; - void RedrawTop(Surface &, const TilesAddon* skip = NULL) const; - void RedrawTop4Hero(Surface &, bool skip_ground) const; - void RedrawObjects(Surface &) const; - void RedrawFogs(Surface &, u8) const; - - void AddonsPushLevel1(const MP2::mp2tile_t & mt); - void AddonsPushLevel1(const MP2::mp2addon_t & ma); - void AddonsPushLevel1(const TilesAddon & ta); - void AddonsPushLevel2(const MP2::mp2tile_t & mt); - void AddonsPushLevel2(const MP2::mp2addon_t & ma); - void AddonsPushLevel2(const TilesAddon & ta); - - void AddonsSort(void); - void Remove(u32 uniq); - void RemoveObjectSprite(void); - - void DebugInfo(void) const; - - bool isFog(u8 color) const; - void SetFog(u8 color); - void ClearFog(u8 color); - - void FixLoyaltyVersion(void); - - u8 GetMinesType(void) const; - - u16 GetCountMonster(void) const; - void SetCountMonster(const u16 count); - void UpdateRNDMonsterSprite(void); - void UpdateMonsterInfo(void); - - void UpdateRNDArtifactSprite(void); - void UpdateRNDResourceSprite(void); - - void UpdateAbandoneMineSprite(void); - void UpdateStoneLightsSprite(void); - void UpdateFountainSprite(void); - void UpdateTreasureChestSprite(void); - - private: - void CorrectFlags32(const u8 index, bool); - void RemoveJailSprite(void); - void RemoveBarrierSprite(void); - - void RedrawBoat(Surface &) const; - void RedrawMonster(Surface &) const; - - private: - friend class Game::IO; - - std::list addons_level1; - std::list addons_level2; - - const s32 maps_index; - - u16 tile_sprite_index; - u8 tile_sprite_shape; - - u8 mp2_object; - u8 quantity1; - u8 quantity2; - u8 quantity3; - u8 quantity4; - u8 fogs; - - u8 unused1; /* memory align */ - u8 unused2; /* memory align */ - u8 unused3; /* memory align */ - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/mp2.cpp b/project/jni/application/fheroes2/src/fheroes2/maps/mp2.cpp deleted file mode 100644 index 5ac8f84b7..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/mp2.cpp +++ /dev/null @@ -1,936 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "settings.h" -#include "mp2.h" - -/* return name icn object */ -ICN::icn_t MP2::GetICNObject(const u8 type) -{ - switch(type) - { - // manual - case 0x11: - return ICN::TELEPORT1; - case 0x12: - return ICN::TELEPORT2; - case 0x13: - return ICN::TELEPORT3; - case 0x14: - return ICN::FOUNTAIN; - case 0x15: - return ICN::TREASURE; - - // artifact - case 0x2C: - case 0x2D: - case 0x2E: - case 0x2F: - return ICN::OBJNARTI; - - // monster - case 0x30: - case 0x31: - case 0x32: - case 0x33: - return ICN::MONS32; - - // castle flags - case 0x38: - case 0x39: - case 0x3A: - case 0x3B: - return ICN::FLAG32; - - // heroes - case 0x54: - case 0x55: - case 0x56: - case 0x57: - return ICN::MINIHERO; - - // relief: snow - case 0x58: - case 0x59: - case 0x5A: - case 0x5B: - return ICN::MTNSNOW; - - // relief: swamp - case 0x5C: - case 0x5D: - case 0x5E: - case 0x5F: - return ICN::MTNSWMP; - - // relief: lava - case 0x60: - case 0x61: - case 0x62: - case 0x63: - return ICN::MTNLAVA; - - // relief: desert - case 0x64: - case 0x65: - case 0x66: - case 0x67: - return ICN::MTNDSRT; - - // relief: dirt - case 0x68: - case 0x69: - case 0x6A: - case 0x6B: - return ICN::MTNDIRT; - - // relief: others - case 0x6C: - case 0x6D: - case 0x6E: - case 0x6F: - return ICN::MTNMULT; - - // mines - case 0x74: - return ICN::EXTRAOVR; - - // road - case 0x78: - case 0x79: - case 0x7A: - case 0x7B: - return ICN::ROAD; - - // relief: crck - case 0x7C: - case 0x7D: - case 0x7E: - case 0x7F: - return ICN::MTNCRCK; - - // relief: gras - case 0x80: - case 0x81: - case 0x82: - case 0x83: - return ICN::MTNGRAS; - - // trees jungle - case 0x84: - case 0x85: - case 0x86: - case 0x87: - return ICN::TREJNGL; - - // trees evil - case 0x88: - case 0x89: - case 0x8A: - case 0x8B: - return ICN::TREEVIL; - - // castle and tower - case 0x8C: - case 0x8D: - case 0x8E: - case 0x8F: - return ICN::OBJNTOWN; - - // castle lands - case 0x90: - case 0x91: - case 0x92: - case 0x93: - return ICN::OBJNTWBA; - - // castle shadow - case 0x94: - case 0x95: - case 0x96: - case 0x97: - return ICN::OBJNTWSH; - - // random castle - case 0x98: - case 0x99: - case 0x9A: - case 0x9B: - return ICN::OBJNTWRD; - - // water object - case 0xA0: - case 0xA1: - case 0xA2: - case 0xA3: - return ICN::OBJNWAT2; - - // object other - case 0xA4: - case 0xA5: - case 0xA6: - case 0xA7: - return ICN::OBJNMUL2; - - // trees snow - case 0xA8: - case 0xA9: - case 0xAA: - case 0xAB: - return ICN::TRESNOW; - - // trees trefir - case 0xAC: - case 0xAD: - case 0xAE: - case 0xAF: - return ICN::TREFIR; - - // trees - case 0xB0: - case 0xB1: - case 0xB2: - case 0xB3: - return ICN::TREFALL; - - // river - case 0xB4: - case 0xB5: - case 0xB6: - case 0xB7: - return ICN::STREAM; - - // resource - case 0xB8: - case 0xB9: - case 0xBA: - case 0xBB: - return ICN::OBJNRSRC; - - // gras object - case 0xC0: - case 0xC1: - case 0xC2: - case 0xC3: - return ICN::OBJNGRA2; - - // trees tredeci - case 0xC4: - case 0xC5: - case 0xC6: - case 0xC7: - return ICN::TREDECI; - - // sea object - case 0xC8: - case 0xC9: - case 0xCA: - case 0xCB: - return ICN::OBJNWATR; - - // vegetation gras - case 0xCC: - case 0xCD: - case 0xCE: - case 0xCF: - return ICN::OBJNGRAS; - - // object on snow - case 0xD0: - case 0xD1: - case 0xD2: - case 0xD3: - return ICN::OBJNSNOW; - - // object on swamp - case 0xD4: - case 0xD5: - case 0xD6: - case 0xD7: - return ICN::OBJNSWMP; - - // object on lava - case 0xD8: - case 0xD9: - case 0xDA: - case 0xDB: - return ICN::OBJNLAVA; - - // object on desert - case 0xDC: - case 0xDD: - case 0xDE: - case 0xDF: - return ICN::OBJNDSRT; - - // object on dirt - case 0xE0: - case 0xE1: - case 0xE2: - case 0xE3: - return ICN::OBJNDIRT; - - // object on crck - case 0xE4: - case 0xE5: - case 0xE6: - case 0xE7: - return ICN::OBJNCRCK; - - // object on lava - case 0xE8: - case 0xE9: - case 0xEA: - case 0xEB: - return ICN::OBJNLAV3; - - // object on earth - case 0xEC: - case 0xED: - case 0xEE: - case 0xEF: - return ICN::OBJNMULT; - - // object on lava - case 0xF0: - case 0xF1: - case 0xF2: - case 0xF3: - return ICN::OBJNLAV2; - - // extra objects for loyalty version - case 0xF4: - case 0xF5: - case 0xF6: - case 0xF7: - if(Settings::Get().PriceLoyaltyVersion()) return ICN::X_LOC1; - break; - - // extra objects for loyalty version - case 0xF8: - case 0xF9: - case 0xFA: - case 0xFB: - if(Settings::Get().PriceLoyaltyVersion()) return ICN::X_LOC2; - break; - - // extra objects for loyalty version - case 0xFC: - case 0xFD: - case 0xFE: - case 0xFF: - if(Settings::Get().PriceLoyaltyVersion()) return ICN::X_LOC3; - break; - - default: - break; - } - - DEBUG(DBG_GAME , DBG_WARN, "MP2::GetICNObject: unknown type: " << static_cast(type)); - - return ICN::UNKNOWN; -} - -const char* MP2::StringObject(u8 object) -{ - switch(object) - { - case MP2::OBJ_ZERO: return "OBJ_ZERO"; - case MP2::OBJN_ALCHEMYLAB: - case MP2::OBJ_ALCHEMYLAB: return _("Alchemist Lab"); - case MP2::OBJN_DAEMONCAVE: - case MP2::OBJ_DAEMONCAVE: return _("Daemon Cave"); - case MP2::OBJN_FAERIERING: - case MP2::OBJ_FAERIERING: return _("Faerie Ring"); - case MP2::OBJN_GRAVEYARD: - case MP2::OBJ_GRAVEYARD: return _("Graveyard"); - case MP2::OBJN_DRAGONCITY: - case MP2::OBJ_DRAGONCITY: return _("Dragon City"); - case MP2::OBJN_LIGHTHOUSE: - case MP2::OBJ_LIGHTHOUSE: return _("Light House"); - case MP2::OBJN_WATERWHEEL: - case MP2::OBJ_WATERWHEEL: return _("Water Wheel"); - case MP2::OBJN_MINES: - case MP2::OBJ_MINES: return _("Mines"); - case MP2::OBJN_OBELISK: - case MP2::OBJ_OBELISK: return _("Obelisk"); - case MP2::OBJN_OASIS: - case MP2::OBJ_OASIS: return _("Oasis"); - case MP2::OBJN_SAWMILL: - case MP2::OBJ_SAWMILL: return _("Sawmill"); - case MP2::OBJN_ORACLE: - case MP2::OBJ_ORACLE: return _("Oracle"); - case MP2::OBJN_DESERTTENT: - case MP2::OBJ_DESERTTENT: return _("Desert Tent"); - case MP2::OBJN_CASTLE: - case MP2::OBJ_CASTLE: return _("Castle"); - case MP2::OBJN_WAGONCAMP: - case MP2::OBJ_WAGONCAMP: return _("Wagon Camp"); - case MP2::OBJN_WINDMILL: - case MP2::OBJ_WINDMILL: return _("Windmill"); - case MP2::OBJN_RNDTOWN: - case MP2::OBJ_RNDTOWN: return _("Random Town"); - case MP2::OBJN_RNDCASTLE: - case MP2::OBJ_RNDCASTLE: return _("Random Castle"); - case MP2::OBJN_WATCHTOWER: - case MP2::OBJ_WATCHTOWER: return _("Watch Tower"); - case MP2::OBJN_TREECITY: - case MP2::OBJ_TREECITY: return _("Tree City"); - case MP2::OBJN_TREEHOUSE: - case MP2::OBJ_TREEHOUSE: return _("Tree House"); - case MP2::OBJN_RUINS: - case MP2::OBJ_RUINS: return _("Ruins"); - case MP2::OBJN_FORT: - case MP2::OBJ_FORT: return _("Fort"); - case MP2::OBJN_TRADINGPOST: - case MP2::OBJ_TRADINGPOST: return _("Trading Post"); - case MP2::OBJN_ABANDONEDMINE: - case MP2::OBJ_ABANDONEDMINE: return _("Abandoned Mine"); - case MP2::OBJN_TREEKNOWLEDGE: - case MP2::OBJ_TREEKNOWLEDGE: return _("Tree of Knowledge"); - case MP2::OBJN_DOCTORHUT: - case MP2::OBJ_DOCTORHUT: return _("Witch Doctor's Hut"); - case MP2::OBJN_TEMPLE: - case MP2::OBJ_TEMPLE: return _("Temple"); - case MP2::OBJN_HILLFORT: - case MP2::OBJ_HILLFORT: return _("Hill Fort"); - case MP2::OBJN_HALFLINGHOLE: - case MP2::OBJ_HALFLINGHOLE: return _("Halfling Hole"); - case MP2::OBJN_MERCENARYCAMP: - case MP2::OBJ_MERCENARYCAMP: return _("Mercenary Camp"); - case MP2::OBJN_PYRAMID: - case MP2::OBJ_PYRAMID: return _("Pyramid"); - case MP2::OBJN_CITYDEAD: - case MP2::OBJ_CITYDEAD: return _("City of the Dead"); - case MP2::OBJN_EXCAVATION: - case MP2::OBJ_EXCAVATION: return _("Excavation"); - case MP2::OBJN_SPHINX: - case MP2::OBJ_SPHINX: return _("Sphinx"); - case MP2::OBJN_TROLLBRIDGE: - case MP2::OBJ_TROLLBRIDGE: return _("Troll Bridge"); - case MP2::OBJN_WITCHSHUT: - case MP2::OBJ_WITCHSHUT: return _("Witch Hut"); - case MP2::OBJN_XANADU: - case MP2::OBJ_XANADU: return _("Xanadu"); - case MP2::OBJN_CAVE: - case MP2::OBJ_CAVE: return _("Cave"); - case MP2::OBJN_MAGELLANMAPS: - case MP2::OBJ_MAGELLANMAPS: return _("Magellan Maps"); - case MP2::OBJN_DERELICTSHIP: - case MP2::OBJ_DERELICTSHIP: return _("Derelict Ship"); - case MP2::OBJN_SHIPWRECK: - case MP2::OBJ_SHIPWRECK: return _("Ship Wreck"); - case MP2::OBJN_OBSERVATIONTOWER: - case MP2::OBJ_OBSERVATIONTOWER: return _("Observation Tower"); - case MP2::OBJN_FREEMANFOUNDRY: - case MP2::OBJ_FREEMANFOUNDRY: return _("Freeman Foundry"); - case MP2::OBJN_WATERINGHOLE: - case MP2::OBJ_WATERINGHOLE: return _("Watering Hole"); - case MP2::OBJN_ARTESIANSPRING: - case MP2::OBJ_ARTESIANSPRING: return _("Artesian Spring"); - case MP2::OBJN_GAZEBO: - case MP2::OBJ_GAZEBO: return _("Gazebo"); - case MP2::OBJN_ARCHERHOUSE: - case MP2::OBJ_ARCHERHOUSE: return _("Archer's House"); - case MP2::OBJN_PEASANTHUT: - case MP2::OBJ_PEASANTHUT: return _("Peasant Hut"); - case MP2::OBJN_DWARFCOTT: - case MP2::OBJ_DWARFCOTT: return _("Dwarf Cottage"); - case MP2::OBJN_STONELIGHTS: - case MP2::OBJ_STONELIGHTS: return _("Stone Liths"); - case MP2::OBJN_MAGICWELL: - case MP2::OBJ_MAGICWELL: return _("Magic Well"); - case MP2::OBJ_HEROES: return _("Heroes"); - case MP2::OBJ_SIGN: return _("Sign"); - case MP2::OBJ_SHRUB2: return _("Shrub"); - case MP2::OBJ_NOTHINGSPECIAL: return _("Nothing Special"); - case MP2::OBJ_TARPIT: return _("Tar Pit"); - case MP2::OBJ_COAST: return _("Coast"); - case MP2::OBJ_MOUND: return _("Mound"); - case MP2::OBJ_DUNE: return _("Dune"); - case MP2::OBJ_STUMP: return _("Stump"); - case MP2::OBJ_CACTUS: return _("Cactus"); - case MP2::OBJ_TREES: return _("Trees"); - case MP2::OBJ_DEADTREE: return _("Dead Tree"); - case MP2::OBJ_MOUNTS: return _("Mountains"); - case MP2::OBJ_VOLCANO: return _("Volcano"); - case MP2::OBJ_STONES: return _("Rock"); - case MP2::OBJ_FLOWERS: return _("Flowers"); - case MP2::OBJ_WATERLAKE: return _("Water Lake"); - case MP2::OBJ_MANDRAKE: return _("Mandrake"); - case MP2::OBJ_CRATER: return _("Crater"); - case MP2::OBJ_LAVAPOOL: return _("Lava Pool"); - case MP2::OBJ_SHRUB: return _("Shrub"); - case MP2::OBJ_BUOY: return _("Buoy"); - case MP2::OBJ_SKELETON: return _("Skeleton"); - case MP2::OBJ_TREASURECHEST: - case MP2::OBJ_WATERCHEST: return _("Treasure Chest"); - case MP2::OBJ_CAMPFIRE: return _("Campfire"); - case MP2::OBJ_FOUNTAIN: return _("Fountain"); - case MP2::OBJ_ANCIENTLAMP: return _("Genie Lamp"); - case MP2::OBJ_GOBLINHUT: return _("Goblin Hut"); - case MP2::OBJ_THATCHEDHUT: return _("Thatched Hut"); - case MP2::OBJ_MONSTER: return _("Monster"); - case MP2::OBJ_RESOURCE: return _("Resource"); - case MP2::OBJ_WHIRLPOOL: return _("Whirlpool"); - case MP2::OBJ_ARTIFACT: return _("Artifact"); - case MP2::OBJ_BOAT: return _("Boat"); - case MP2::OBJ_RNDARTIFACT: return "Random Artifact"; - case MP2::OBJ_RNDRESOURCE: return "Random Resource"; - case MP2::OBJ_RNDMONSTER1: return "OBJ_RNDMONSTER1"; - case MP2::OBJ_RNDMONSTER2: return "OBJ_RNDMONSTER2"; - case MP2::OBJ_RNDMONSTER3: return "OBJ_RNDMONSTER3"; - case MP2::OBJ_RNDMONSTER4: return "OBJ_RNDMONSTER4"; - case MP2::OBJ_STANDINGSTONES: return _("Standing Stones"); - case MP2::OBJ_EVENT: return "OBJ_EVENT"; - case MP2::OBJ_RNDMONSTER: return "OBJ_RNDMONSTER"; - case MP2::OBJ_RNDULTIMATEARTIFACT: return "OBJ_RNDULTIMATEARTIFACT"; - case MP2::OBJ_IDOL: return _("Idol"); - case MP2::OBJ_SHRINE1: return _("Shrine of the First Circle"); - case MP2::OBJ_SHRINE2: return _("Shrine of the Second Circle"); - case MP2::OBJ_SHRINE3: return _("Shrine of the Third Circle"); - case MP2::OBJ_WAGON: return _("Wagon"); - case MP2::OBJ_LEANTO: return _("Lean To"); - case MP2::OBJ_FLOTSAM: return _("Flotsam"); - case MP2::OBJ_SHIPWRECKSURVIROR: return _("Shipwreck Surviror"); - case MP2::OBJ_BOTTLE: return _("Bottle"); - case MP2::OBJ_MAGICGARDEN: return _("Magic Garden"); - case MP2::OBJ_RNDARTIFACT1: return "OBJ_RNDARTIFACT1"; - case MP2::OBJ_RNDARTIFACT2: return "OBJ_RNDARTIFACT2"; - case MP2::OBJ_RNDARTIFACT3: return "OBJ_RNDARTIFACT3"; - - case MP2::OBJN_JAIL: - case MP2::OBJ_JAIL: return _("Jail"); - case MP2::OBJN_TRAVELLERTENT: - case MP2::OBJ_TRAVELLERTENT: return _("Traveller's Tent"); - case MP2::OBJ_BARRIER: return _("Barrier"); - - case MP2::OBJN_FIREALTAR: - case MP2::OBJ_FIREALTAR: return _("Fire Summoning Altar"); - case MP2::OBJN_AIRALTAR: - case MP2::OBJ_AIRALTAR: return _("Air Summoning Altar"); - case MP2::OBJN_EARTHALTAR: - case MP2::OBJ_EARTHALTAR: return _("Earth Summoning Altar"); - case MP2::OBJN_WATERALTAR: - case MP2::OBJ_WATERALTAR: return _("Water Summoning Altar"); - case MP2::OBJN_BARROWMOUNDS: - case MP2::OBJ_BARROWMOUNDS: return _("Barrow Mounds"); - case MP2::OBJN_ARENA: - case MP2::OBJ_ARENA: return _("Arena"); - case MP2::OBJN_STABLES: - case MP2::OBJ_STABLES: return _("Stables"); - case MP2::OBJN_ALCHEMYTOWER: - case MP2::OBJ_ALCHEMYTOWER: return _("Alchemist's Tower"); - case MP2::OBJN_HUTMAGI: - case MP2::OBJ_HUTMAGI: return _("Hut of the Magi"); - case MP2::OBJN_EYEMAGI: - case MP2::OBJ_EYEMAGI: return _("Eye of the Magi"); - case MP2::OBJN_MERMAID: - case MP2::OBJ_MERMAID: return _("Mermaid"); - case MP2::OBJN_SIRENS: - case MP2::OBJ_SIRENS: return _("Sirens"); - case MP2::OBJ_REEFS: return _("Reefs"); - - case MP2::OBJ_UNKNW_02: return "OBJ_UNKNW_02"; - case MP2::OBJ_UNKNW_03: return "OBJ_UNKNW_03"; - case MP2::OBJ_UNKNW_04: return "OBJ_UNKNW_04"; - case MP2::OBJ_UNKNW_06: return "OBJ_UNKNW_06"; - case MP2::OBJ_UNKNW_08: return "OBJ_UNKNW_08"; - case MP2::OBJ_UNKNW_09: return "OBJ_UNKNW_09"; - case MP2::OBJ_UNKNW_0B: return "OBJ_UNKNW_0B"; - case MP2::OBJ_UNKNW_0E: return "OBJ_UNKNW_0E"; - case MP2::OBJ_UNKNW_11: return "OBJ_UNKNW_11"; - case MP2::OBJ_UNKNW_12: return "OBJ_UNKNW_12"; - case MP2::OBJ_UNKNW_13: return "OBJ_UNKNW_13"; - case MP2::OBJ_UNKNW_18: return "OBJ_UNKNW_18"; - case MP2::OBJ_UNKNW_1B: return "OBJ_UNKNW_1B"; - case MP2::OBJ_UNKNW_1F: return "OBJ_UNKNW_1F"; - case MP2::OBJ_UNKNW_21: return "OBJ_UNKNW_21"; - case MP2::OBJ_UNKNW_26: return "OBJ_UNKNW_26"; - case MP2::OBJ_UNKNW_27: return "OBJ_UNKNW_27"; - case MP2::OBJ_UNKNW_29: return "OBJ_UNKNW_29"; - case MP2::OBJ_UNKNW_2A: return "OBJ_UNKNW_2A"; - case MP2::OBJ_UNKNW_2B: return "OBJ_UNKNW_2B"; - case MP2::OBJ_UNKNW_2C: return "OBJ_UNKNW_2C"; - case MP2::OBJ_UNKNW_2D: return "OBJ_UNKNW_2D"; - case MP2::OBJ_UNKNW_2E: return "OBJ_UNKNW_2E"; - case MP2::OBJ_UNKNW_2F: return "OBJ_UNKNW_2F"; - case MP2::OBJ_UNKNW_32: return "OBJ_UNKNW_32"; - case MP2::OBJ_UNKNW_33: return "OBJ_UNKNW_33"; - case MP2::OBJ_UNKNW_34: return "OBJ_UNKNW_34"; - case MP2::OBJ_UNKNW_35: return "OBJ_UNKNW_35"; - case MP2::OBJ_UNKNW_36: return "OBJ_UNKNW_36"; - case MP2::OBJ_UNKNW_37: return "OBJ_UNKNW_37"; - case MP2::OBJ_UNKNW_41: return "OBJ_UNKNW_41"; - case MP2::OBJ_UNKNW_42: return "OBJ_UNKNW_42"; - case MP2::OBJ_UNKNW_43: return "OBJ_UNKNW_43"; - case MP2::OBJ_UNKNW_4A: return "OBJ_UNKNW_4A"; - case MP2::OBJ_UNKNW_4B: return "OBJ_UNKNW_4B"; - case MP2::OBJ_UNKNW_50: return "OBJ_UNKNW_50"; - case MP2::OBJ_UNKNW_58: return "OBJ_UNKNW_58"; - case MP2::OBJ_UNKNW_5A: return "OBJ_UNKNW_5A"; - case MP2::OBJ_UNKNW_5C: return "OBJ_UNKNW_5C"; - case MP2::OBJ_UNKNW_5D: return "OBJ_UNKNW_5D"; - case MP2::OBJ_UNKNW_5F: return "OBJ_UNKNW_5F"; - case MP2::OBJ_UNKNW_62: return "OBJ_UNKNW_62"; - case MP2::OBJ_UNKNW_79: return "OBJ_UNKNW_79"; - case MP2::OBJ_UNKNW_7A: return "OBJ_UNKNW_7A"; - case MP2::OBJ_UNKNW_91: return "OBJ_UNKNW_91"; - case MP2::OBJ_UNKNW_92: return "OBJ_UNKNW_92"; - case MP2::OBJ_UNKNW_A1: return "OBJ_UNKNW_A1"; - case MP2::OBJ_UNKNW_A6: return "OBJ_UNKNW_A6"; - case MP2::OBJ_UNKNW_AA: return "OBJ_UNKNW_AA"; - case MP2::OBJ_UNKNW_B2: return "OBJ_UNKNW_B2"; - case MP2::OBJ_UNKNW_B8: return "OBJ_UNKNW_B8"; - case MP2::OBJ_UNKNW_B9: return "OBJ_UNKNW_B9"; - case MP2::OBJ_UNKNW_D1: return "OBJ_UNKNW_D1"; - case MP2::OBJ_UNKNW_E2: return "OBJ_UNKNW_E2"; - case MP2::OBJ_UNKNW_E3: return "OBJ_UNKNW_E3"; - case MP2::OBJ_UNKNW_E4: return "OBJ_UNKNW_E4"; - case MP2::OBJ_UNKNW_E5: return "OBJ_UNKNW_E5"; - case MP2::OBJ_UNKNW_E6: return "OBJ_UNKNW_E6"; - case MP2::OBJ_UNKNW_E7: return "OBJ_UNKNW_E7"; - case MP2::OBJ_UNKNW_E8: return "OBJ_UNKNW_E8"; - case MP2::OBJ_UNKNW_F9: return "OBJ_UNKNW_F9"; - case MP2::OBJ_UNKNW_FA: return "OBJ_UNKNW_FA"; - - default: - DEBUG(DBG_GAME , DBG_WARN, "MP2::Object: unknown, " << static_cast(object)); - break; - } - - return NULL; -} - -bool MP2::isDayLife(const u8 obj) -{ - // FIXME: list day object life - switch(obj) - { - case OBJ_MAGICWELL: - return true; - - default: break; - } - - return false; -} - -bool MP2::isWeekLife(const u8 obj) -{ - // FIXME: list week object life - switch(obj) - { - case OBJ_STABLES: - case OBJ_MAGICGARDEN: - case OBJ_WATERWHEEL: - case OBJ_WINDMILL: - case OBJ_ARTESIANSPRING: - - // join army - case OBJ_WATCHTOWER: - case OBJ_EXCAVATION: - case OBJ_CAVE: - case OBJ_TREEHOUSE: - case OBJ_ARCHERHOUSE: - case OBJ_GOBLINHUT: - case OBJ_DWARFCOTT: - case OBJ_HALFLINGHOLE: - case OBJ_PEASANTHUT: - case OBJ_THATCHEDHUT: - - // recruit army - case OBJ_RUINS: - case OBJ_TREECITY: - case OBJ_WAGONCAMP: - case OBJ_DESERTTENT: - - // battle and recruit army - case OBJ_DRAGONCITY: - case OBJ_CITYDEAD: - case OBJ_TROLLBRIDGE: - - // for AI - case MP2::OBJ_COAST: - - return true; - - default: break; - } - - return false; -} - -bool MP2::isMonthLife(const u8 obj) -{ - // FIXME: list month object life - switch(obj) - { - // for AI - case OBJ_CASTLE: - - default: break; - } - - return false; -} - -bool MP2::isBattleLife(const u8 obj) -{ - // FIXME: list battle object life - switch(obj) - { - // luck modificators - case OBJ_IDOL: - case OBJ_FOUNTAIN: - case OBJ_FAERIERING: - case OBJ_PYRAMID: - - // morale modificators - case OBJ_BUOY: - case OBJ_OASIS: - case OBJ_TEMPLE: - case OBJ_WATERINGHOLE: - case OBJ_GRAVEYARD: - case OBJ_DERELICTSHIP: - case OBJ_SHIPWRECK: - - case OBJ_MERMAID: - - return true; - - default: break; - } - - return false; -} - -bool MP2::isActionObject(const u8 obj, const bool water) -{ - if(water) return isWaterObject(obj); - - return isGroundObject(obj); -} - -bool MP2::isWaterObject(const u8 obj) -{ - switch(obj) - { - case OBJ_WATERCHEST: - case OBJ_DERELICTSHIP: - case OBJ_WHIRLPOOL: - case OBJ_BUOY: - case OBJ_BOTTLE: - case OBJ_SHIPWRECKSURVIROR: - case OBJ_FLOTSAM: - case OBJ_MAGELLANMAPS: - case OBJ_COAST: - - case MP2::OBJ_MERMAID: - case MP2::OBJ_SIRENS: - return true; - - default: break; - } - - return false; -} - -bool MP2::isGroundObject(const u8 obj) -{ - switch(obj) - { - case OBJ_TREASURECHEST: - case OBJ_ALCHEMYLAB: - case OBJ_SIGN: - case OBJ_SKELETON: - case OBJ_DAEMONCAVE: - case OBJ_FAERIERING: - case OBJ_CAMPFIRE: - case OBJ_FOUNTAIN: - case OBJ_GAZEBO: - case OBJ_ANCIENTLAMP: - case OBJ_GRAVEYARD: - case OBJ_ARCHERHOUSE: - case OBJ_GOBLINHUT: - case OBJ_DWARFCOTT: - case OBJ_PEASANTHUT: - case OBJ_THATCHEDHUT: - case OBJ_DRAGONCITY: - case OBJ_LIGHTHOUSE: - case OBJ_WATERWHEEL: - case OBJ_MINES: - case OBJ_OBELISK: - case OBJ_OASIS: - case OBJ_RESOURCE: - case OBJ_SAWMILL: - case OBJ_ORACLE: - case OBJ_SHIPWRECK: - case OBJ_DESERTTENT: - case OBJ_STONELIGHTS: - case OBJ_WAGONCAMP: - case OBJ_WINDMILL: - case OBJ_ARTIFACT: - case OBJ_WATCHTOWER: - case OBJ_TREEHOUSE: - case OBJ_TREECITY: - case OBJ_RUINS: - case OBJ_FORT: - case OBJ_TRADINGPOST: - case OBJ_ABANDONEDMINE: - case OBJ_STANDINGSTONES: - case OBJ_IDOL: - case OBJ_TREEKNOWLEDGE: - case OBJ_DOCTORHUT: - case OBJ_TEMPLE: - case OBJ_HILLFORT: - case OBJ_HALFLINGHOLE: - case OBJ_MERCENARYCAMP: - case OBJ_WATERINGHOLE: - case OBJ_SHRINE1: - case OBJ_SHRINE2: - case OBJ_SHRINE3: - case OBJ_PYRAMID: - case OBJ_CITYDEAD: - case OBJ_EXCAVATION: - case OBJ_SPHINX: - case OBJ_WAGON: - case OBJ_ARTESIANSPRING: - case OBJ_TROLLBRIDGE: - case OBJ_WITCHSHUT: - case OBJ_XANADU: - case OBJ_CAVE: - case OBJ_LEANTO: - case OBJ_MAGICWELL: - case OBJ_MAGICGARDEN: - case OBJ_OBSERVATIONTOWER: - case OBJ_FREEMANFOUNDRY: - - case OBJ_MONSTER: - case OBJ_CASTLE: - case OBJ_BOAT: - - case MP2::OBJ_BARRIER: - case MP2::OBJ_TRAVELLERTENT: - case MP2::OBJ_FIREALTAR: - case MP2::OBJ_AIRALTAR: - case MP2::OBJ_EARTHALTAR: - case MP2::OBJ_WATERALTAR: - case MP2::OBJ_BARROWMOUNDS: - case MP2::OBJ_ARENA: - case MP2::OBJ_JAIL: - case MP2::OBJ_STABLES: - case MP2::OBJ_ALCHEMYTOWER: - case MP2::OBJ_HUTMAGI: - case MP2::OBJ_EYEMAGI: - return true; - - default: break; - } - - return false; -} - -bool MP2::isQuantityObject(const u8 obj) -{ - switch(obj) - { - case OBJ_SKELETON: - case OBJ_WAGON: - case OBJ_ARTIFACT: - case OBJ_RESOURCE: - case OBJ_MAGICGARDEN: - case OBJ_WATERWHEEL: - case OBJ_WINDMILL: - case OBJ_LEANTO: - case OBJ_CAMPFIRE: - case OBJ_FLOTSAM: - case OBJ_SHIPWRECKSURVIROR: - case OBJ_TREASURECHEST: - case OBJ_WATERCHEST: - case OBJ_DERELICTSHIP: - case OBJ_SHIPWRECK: - case OBJ_GRAVEYARD: - case OBJ_PYRAMID: - case OBJ_DAEMONCAVE: - case OBJ_ABANDONEDMINE: - return true; - - default: break; - } - - if(isPickupObject(obj)) return true; - - return false; -} - -bool MP2::isCaptureObject(const u8 obj) -{ - switch(obj) - { - case OBJ_MINES: - case OBJ_ALCHEMYLAB: - case OBJ_SAWMILL: - case OBJ_LIGHTHOUSE: - case OBJ_CASTLE: - return true; - - default: break; - } - - return false; -} - -bool MP2::isPickupObject(const u8 obj) -{ - switch(obj) - { - case MP2::OBJ_WATERCHEST: - case MP2::OBJ_SHIPWRECKSURVIROR: - case MP2::OBJ_FLOTSAM: - case MP2::OBJ_BOTTLE: - case MP2::OBJ_TREASURECHEST: - case MP2::OBJ_ANCIENTLAMP: - case MP2::OBJ_CAMPFIRE: - case MP2::OBJ_RESOURCE: - case MP2::OBJ_ARTIFACT: - return true; - - default: break; - } - - return false; -} - -bool MP2::isClearGroundObject(const u8 obj) -{ - switch(obj) - { - case MP2::OBJ_ZERO: - case MP2::OBJ_COAST: - return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/mp2.h b/project/jni/application/fheroes2/src/fheroes2/maps/mp2.h deleted file mode 100644 index 5e919ce86..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/mp2.h +++ /dev/null @@ -1,559 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2MP2_H -#define H2MP2_H - -#include "gamedefs.h" -#include "icn.h" - -#define MP2OFFSETDATA 428 -#define SIZEOFMP2TILE 20 -#define SIZEOFMP2ADDON 15 -#define SIZEOFMP2CASTLE 0x46 -#define SIZEOFMP2HEROES 0x4c - -#define SIZEOFMP2SIGN 0x0a -#define SIZEOFMP2RUMOR 0x09 -#define SIZEOFMP2EVENT 0x32 -#define SIZEOFMP2RIDDLE 0x8a - -namespace MP2 -{ - // origin mp2 tile - struct mp2tile_t - { - u16 tileIndex; // tile (ocean, grass, snow, swamp, lava, desert, dirt, wasteland, beach) - u8 objectName1; // level 1.0 - u8 indexName1; // index level 1.0 or 0xFF - u8 quantity1; // count - u8 quantity2; // count - u8 objectName2; // level 2.0 - u8 indexName2; // index level 2.0 or 0xFF - u8 shape; // shape reflect % 4, 0 none, 1 vertical, 2 horizontal, 3 any - u8 generalObject; // zero or object - u16 indexAddon; // zero or index addons_t - u32 uniqNumber1; // level 1.0 - u32 uniqNumber2; // level 2.0 - }; - - // origin mp2 addons tile - struct mp2addon_t - { - u16 indexAddon; // zero or next addons_t - u8 objectNameN1; // level 1.N - u8 indexNameN1; // level 1.N or 0xFF - u8 quantityN; // - u8 objectNameN2; // level 2.N - u8 indexNameN2; // level 1.N or 0xFF - u32 uniqNumberN1; // level 1.N - u32 uniqNumberN2; // level 2.N - }; - - // origin mp2 castle - // 0x0046 - size - struct mp2castle_t - { - u8 color; // 00 blue, 01 green, 02 red, 03 yellow, 04 orange, 05 purpl, ff unknown - bool customBuilding; - u16 building; - /* - 0000 0000 0000 0010 Thieve's Guild - 0000 0000 0000 0100 Tavern - 0000 0000 0000 1000 Shipyard - 0000 0000 0001 0000 Well - 0000 0000 1000 0000 Statue - 0000 0001 0000 0000 Left Turret - 0000 0010 0000 0000 Right Turret - 0000 0100 0000 0000 Marketplace - 0000 1000 0000 0000 Farm, Garbage He, Crystal Gar, Waterfall, Orchard, Skull Pile - 0001 0000 0000 0000 Moat - 0010 0000 0000 0000 Fortification, Coliseum, Rainbow, Dungeon, Library, Storm - */ - u16 dwelling; - /* - 0000 0000 0000 1000 dweling1 - 0000 0000 0001 0000 dweling2 - 0000 0000 0010 0000 dweling3 - 0000 0000 0100 0000 dweling4 - 0000 0000 1000 0000 dweling5 - 0000 0001 0000 0000 dweling6 - 0000 0010 0000 0000 upgDweling2 - 0000 0100 0000 0000 upgDweling3 - 0000 1000 0000 0000 upgDweling4 - 0001 0000 0000 0000 upgDweling5 - 0010 0000 0000 0000 upgDweling6 - */ - u8 magicTower; - bool customTroops; - u8 monster1; - u8 monster2; - u8 monster3; - u8 monster4; - u8 monster5; - u16 count1; - u16 count2; - u16 count3; - u16 count4; - u16 count5; - bool capitan; - bool customCastleName; - char castleName[13]; // name + '\0' - u8 type; // 00 knight, 01 barb, 02 sorc, 03 warl, 04 wiz, 05 necr, 06 rnd - bool castle; - u8 allowCastle; // 00 TRUE, 01 FALSE - u8 unknown[29]; - }; - - // origin mp2 heroes - // 0x004c - size - struct mp2heroes_t - { - u8 unknown; - bool customTroops; - u8 monster1; // 0xff none - u8 monster2; // 0xff none - u8 monster3; // 0xff none - u8 monster4; // 0xff none - u8 monster5; // 0xff none - u16 countMonter1; - u16 countMonter2; - u16 countMonter3; - u16 countMonter4; - u16 countMonter5; - u8 customPortrate; - u8 portrate; - u8 artifact1; // 0xff none - u8 artifact2; // 0xff none - u8 artifact3; // 0xff none - u8 unknown2; // 0 - u32 exerience; - bool customSkill; - u8 skill1; // 0xff none - u8 skill2; // pathfinding, archery, logistic, scouting, - u8 skill3; // diplomacy, navigation, leadership, wisdom, - u8 skill4; // mysticism, luck, ballistics, eagle, necromance, estate - u8 skill5; - u8 skill6; - u8 skill7; - u8 skill8; - u8 skillLevel1; - u8 skillLevel2; - u8 skillLevel3; - u8 skillLevel4; - u8 skillLevel5; - u8 skillLevel6; - u8 skillLevel7; - u8 skillLevel8; - u8 unknown3; // 0 - u8 customName; - char name[13]; // name + '\0' - bool patrol; - u8 countSquare; // for patrol - u8 unknown4[15]; // 0 - }; - - // origin mp2 sign or buttle - struct mp2info_t - { - u8 id; // 0x01 - u8 zero[8]; // 8 byte 0x00 - char text; // message + '/0' - }; - - // origin mp2 event for coord - struct mp2eventcoord_t - { - u8 id; // 0x01 - u32 wood; - u32 mercury; - u32 ore; - u32 sulfur; - u32 crystal; - u32 gems; - u32 golds; - u16 artifact; // 0xffff - none - bool computer; // allow events for computer - bool cancel; // cancel event after first visit - u8 zero[10]; // 10 byte 0x00 - bool blue; - bool green; - bool red; - bool yellow; - bool orange; - bool purple; - char text; // message + '/0' - }; - - - // origin mp2 event for day - struct mp2eventday_t - { - u8 id; // 0x00 - u32 wood; - u32 mercury; - u32 ore; - u32 sulfur; - u32 crystal; - u32 gems; - u32 golds; - u16 artifact; // always 0xffff - none - u16 computer; // allow events for computer - u16 first; // day of first occurent - u16 subsequent; // subsequent occurrences - u8 zero[6]; // 6 byte 0x00 and end 0x01 - bool blue; - bool green; - bool red; - bool yellow; - bool orange; - bool purple; - char text; // message + '/0' - }; - - // origin mp2 rumor - struct mp2rumor_t - { - u8 id; // 0x00 - u8 zero[7]; // 7 byte 0x00 - char text; // message + '/0' - }; - - // origin mp2 riddle sphinx - struct mp2riddle_t - { - u8 id; // 0x00 - u32 wood; - u32 mercury; - u32 ore; - u32 sulfur; - u32 crystal; - u32 gems; - u32 golds; - u16 artifact; // 0xffff - none - u8 count; // count answers (1, 8) - char answer1[13]; - char answer2[13]; - char answer3[13]; - char answer4[13]; - char answer5[13]; - char answer6[13]; - char answer7[13]; - char answer8[13]; - char text; // message + '/0' - }; - - /////////////////////////////////////////////////////////////////////////////// - - enum object_t - { - OBJ_ZERO = 0x00, - OBJ_UNKNW_02 = 0x02, - OBJN_ALCHEMYLAB = 0x01, - OBJ_UNKNW_03 = 0x03, - OBJ_UNKNW_04 = 0x04, - OBJN_DAEMONCAVE = 0x05, - OBJ_UNKNW_06 = 0x06, - OBJN_FAERIERING = 0x07, - OBJ_UNKNW_08 = 0x08, - OBJ_UNKNW_09 = 0x09, - OBJN_GAZEBO = 0x0A, - OBJ_UNKNW_0B = 0x0B, - OBJN_GRAVEYARD = 0x0C, - OBJN_ARCHERHOUSE = 0x0D, - OBJ_UNKNW_0E = 0x0E, - OBJN_DWARFCOTT = 0x0F, - - OBJN_PEASANTHUT = 0x10, - OBJ_UNKNW_11 = 0x11, - OBJ_UNKNW_12 = 0x12, - OBJ_UNKNW_13 = 0x13, - OBJN_DRAGONCITY = 0x14, - OBJN_LIGHTHOUSE = 0x15, - OBJN_WATERWHEEL = 0x16, - OBJN_MINES = 0x17, - OBJ_UNKNW_18 = 0x18, - OBJN_OBELISK = 0x19, - OBJN_OASIS = 0x1A, - OBJ_UNKNW_1B = 0x1B, - OBJ_COAST = 0x1C, - OBJN_SAWMILL = 0x1D, - OBJN_ORACLE = 0x1E, - OBJ_UNKNW_1F = 0x1F, - - OBJN_SHIPWRECK = 0x20, - OBJ_UNKNW_21 = 0x21, - OBJN_DESERTTENT = 0x22, - OBJN_CASTLE = 0x23, - OBJN_STONELIGHTS = 0x24, - OBJN_WAGONCAMP = 0x25, - OBJ_UNKNW_26 = 0x26, - OBJ_UNKNW_27 = 0x27, - OBJN_WINDMILL = 0x28, - OBJ_UNKNW_29 = 0x29, - OBJ_UNKNW_2A = 0x2A, - OBJ_UNKNW_2B = 0x2B, - OBJ_UNKNW_2C = 0x2C, - OBJ_UNKNW_2D = 0x2D, - OBJ_UNKNW_2E = 0x2E, - OBJ_UNKNW_2F = 0x2F, - - OBJN_RNDTOWN = 0x30, - OBJN_RNDCASTLE = 0x31, - OBJ_UNKNW_32 = 0x32, - OBJ_UNKNW_33 = 0x33, - OBJ_UNKNW_34 = 0x34, - OBJ_UNKNW_35 = 0x35, - OBJ_UNKNW_36 = 0x36, - OBJ_UNKNW_37 = 0x37, - OBJ_SHRUB2 = 0x38, - OBJ_NOTHINGSPECIAL = 0x39, - OBJN_WATCHTOWER = 0x3A, - OBJN_TREEHOUSE = 0x3B, - OBJN_TREECITY = 0x3C, - OBJN_RUINS = 0x3D, - OBJN_FORT = 0x3E, - OBJN_TRADINGPOST = 0x3F, - - OBJN_ABANDONEDMINE = 0x40, - OBJ_UNKNW_41 = 0x41, - OBJ_UNKNW_42 = 0x42, - OBJ_UNKNW_43 = 0x43, - OBJN_TREEKNOWLEDGE = 0x44, - OBJN_DOCTORHUT = 0x45, - OBJN_TEMPLE = 0x46, - OBJN_HILLFORT = 0x47, - OBJN_HALFLINGHOLE = 0x48, - OBJN_MERCENARYCAMP = 0x49, - OBJ_UNKNW_4A = 0x4A, - OBJ_UNKNW_4B = 0x4B, - OBJN_PYRAMID = 0x4C, - OBJN_CITYDEAD = 0x4D, - OBJN_EXCAVATION = 0x4E, - OBJN_SPHINX = 0x4F, - - OBJ_UNKNW_50 = 0x50, - OBJ_TARPIT = 0x51, - OBJN_ARTESIANSPRING = 0x52, - OBJN_TROLLBRIDGE = 0x53, - OBJN_WATERINGHOLE = 0x54, - OBJN_WITCHSHUT = 0x55, - OBJN_XANADU = 0x56, - OBJN_CAVE = 0x57, - OBJ_UNKNW_58 = 0x58, - OBJN_MAGELLANMAPS = 0x59, - OBJ_UNKNW_5A = 0x5A, - OBJN_DERELICTSHIP = 0x5B, - OBJ_UNKNW_5C = 0x5C, - OBJ_UNKNW_5D = 0x5D, - OBJN_MAGICWELL = 0x5E, - OBJ_UNKNW_5F = 0x5F, - - OBJN_OBSERVATIONTOWER = 0x60, - OBJN_FREEMANFOUNDRY = 0x61, - OBJ_UNKNW_62 = 0x62, - OBJ_TREES = 0x63, - OBJ_MOUNTS = 0x64, - OBJ_VOLCANO = 0x65, - OBJ_FLOWERS = 0x66, - OBJ_STONES = 0x67, - OBJ_WATERLAKE = 0x68, - OBJ_MANDRAKE = 0x69, - OBJ_DEADTREE = 0x6A, - OBJ_STUMP = 0x6B, - OBJ_CRATER = 0x6C, - OBJ_CACTUS = 0x6D, - OBJ_MOUND = 0x6E, - OBJ_DUNE = 0x6F, - - OBJ_LAVAPOOL = 0x70, - OBJ_SHRUB = 0x71, - OBJN_ARENA = 0x72, - OBJN_BARROWMOUNDS = 0x73, - OBJN_MERMAID = 0x74, - OBJN_SIRENS = 0x75, - OBJN_HUTMAGI = 0x76, - OBJN_EYEMAGI = 0x77, - OBJN_TRAVELLERTENT = 0x78, - OBJ_UNKNW_79 = 0x79, - OBJ_UNKNW_7A = 0x7A, - OBJN_JAIL = 0x7B, - OBJN_FIREALTAR = 0x7C, - OBJN_AIRALTAR = 0x7D, - OBJN_EARTHALTAR = 0x7E, - OBJN_WATERALTAR = 0x7F, - - OBJ_WATERCHEST = 0x80, - OBJ_ALCHEMYLAB = 0x81, - OBJ_SIGN = 0x82, - OBJ_BUOY = 0x83, - OBJ_SKELETON = 0x84, - OBJ_DAEMONCAVE = 0x85, - OBJ_TREASURECHEST = 0x86, - OBJ_FAERIERING = 0x87, - OBJ_CAMPFIRE = 0x88, - OBJ_FOUNTAIN = 0x89, - OBJ_GAZEBO = 0x8A, - OBJ_ANCIENTLAMP = 0x8B, - OBJ_GRAVEYARD = 0x8C, - OBJ_ARCHERHOUSE = 0x8D, - OBJ_GOBLINHUT = 0x8E, - OBJ_DWARFCOTT = 0x8F, - - OBJ_PEASANTHUT = 0x90, - OBJ_UNKNW_91 = 0x91, - OBJ_UNKNW_92 = 0x92, - OBJ_EVENT = 0x93, - OBJ_DRAGONCITY = 0x94, - OBJ_LIGHTHOUSE = 0x95, - OBJ_WATERWHEEL = 0x96, - OBJ_MINES = 0x97, - OBJ_MONSTER = 0x98, - OBJ_OBELISK = 0x99, - OBJ_OASIS = 0x9A, - OBJ_RESOURCE = 0x9B, - OBJ_SAWMILL = 0x9D, - OBJ_ORACLE = 0x9E, - OBJ_SHRINE1 = 0x9F, - - OBJ_SHIPWRECK = 0xA0, - OBJ_UNKNW_A1 = 0xA1, - OBJ_DESERTTENT = 0xA2, - OBJ_CASTLE = 0xA3, - OBJ_STONELIGHTS = 0xA4, - OBJ_WAGONCAMP = 0xA5, - OBJ_UNKNW_A6 = 0xA6, - OBJ_WHIRLPOOL = 0xA7, - OBJ_WINDMILL = 0xA8, - OBJ_ARTIFACT = 0xA9, - OBJ_UNKNW_AA = 0xAA, - OBJ_BOAT = 0xAB, - OBJ_RNDULTIMATEARTIFACT = 0xAC, - OBJ_RNDARTIFACT = 0xAD, - OBJ_RNDRESOURCE = 0xAE, - OBJ_RNDMONSTER = 0xAF, - - OBJ_RNDTOWN = 0xB0, - OBJ_RNDCASTLE = 0xB1, - OBJ_UNKNW_B2 = 0xB2, - OBJ_RNDMONSTER1 = 0xB3, - OBJ_RNDMONSTER2 = 0xB4, - OBJ_RNDMONSTER3 = 0xB5, - OBJ_RNDMONSTER4 = 0xB6, - OBJ_HEROES = 0xB7, - OBJ_UNKNW_B8 = 0xB8, - OBJ_UNKNW_B9 = 0xB9, - OBJ_WATCHTOWER = 0xBA, - OBJ_TREEHOUSE = 0xBB, - OBJ_TREECITY = 0xBC, - OBJ_RUINS = 0xBD, - OBJ_FORT = 0xBE, - OBJ_TRADINGPOST = 0xBF, - - OBJ_ABANDONEDMINE = 0xC0, - OBJ_THATCHEDHUT = 0xC1, - OBJ_STANDINGSTONES = 0xC2, - OBJ_IDOL = 0xC3, - OBJ_TREEKNOWLEDGE = 0xC4, - OBJ_DOCTORHUT = 0xC5, - OBJ_TEMPLE = 0xC6, - OBJ_HILLFORT = 0xC7, - OBJ_HALFLINGHOLE = 0xC8, - OBJ_MERCENARYCAMP = 0xC9, - OBJ_SHRINE2 = 0xCA, - OBJ_SHRINE3 = 0xCB, - OBJ_PYRAMID = 0xCC, - OBJ_CITYDEAD = 0xCD, - OBJ_EXCAVATION = 0xCE, - OBJ_SPHINX = 0xCF, - - OBJ_WAGON = 0xD0, - OBJ_UNKNW_D1 = 0xD1, - OBJ_ARTESIANSPRING = 0xD2, - OBJ_TROLLBRIDGE = 0xD3, - OBJ_WATERINGHOLE = 0xD4, - OBJ_WITCHSHUT = 0xD5, - OBJ_XANADU = 0xD6, - OBJ_CAVE = 0xD7, - OBJ_LEANTO = 0xD8, - OBJ_MAGELLANMAPS = 0xD9, - OBJ_FLOTSAM = 0xDA, - OBJ_DERELICTSHIP = 0xDB, - OBJ_SHIPWRECKSURVIROR = 0xDC, - OBJ_BOTTLE = 0xDD, - OBJ_MAGICWELL = 0xDE, - OBJ_MAGICGARDEN = 0xDF, - - OBJ_OBSERVATIONTOWER = 0xE0, - OBJ_FREEMANFOUNDRY = 0xE1, - OBJ_UNKNW_E2 = 0xE2, - OBJ_UNKNW_E3 = 0xE3, - OBJ_UNKNW_E4 = 0xE4, - OBJ_UNKNW_E5 = 0xE5, - OBJ_UNKNW_E6 = 0xE6, - OBJ_UNKNW_E7 = 0xE7, - OBJ_UNKNW_E8 = 0xE8, - OBJ_REEFS = 0xE9, - OBJN_ALCHEMYTOWER = 0xEA, - OBJN_STABLES = 0xEB, - OBJ_MERMAID = 0xEC, - OBJ_SIRENS = 0xED, - OBJ_HUTMAGI = 0xEE, - OBJ_EYEMAGI = 0xEF, - - OBJ_ALCHEMYTOWER = 0xF0, - OBJ_STABLES = 0xF1, - OBJ_ARENA = 0xF2, - OBJ_BARROWMOUNDS = 0xF3, - OBJ_RNDARTIFACT1 = 0xF4, - OBJ_RNDARTIFACT2 = 0xF5, - OBJ_RNDARTIFACT3 = 0xF6, - OBJ_BARRIER = 0xF7, - OBJ_TRAVELLERTENT = 0xF8, - OBJ_UNKNW_F9 = 0xF9, - OBJ_UNKNW_FA = 0xFA, - OBJ_JAIL = 0xFB, - OBJ_FIREALTAR = 0xFC, - OBJ_AIRALTAR = 0xFD, - OBJ_EARTHALTAR = 0xFE, - OBJ_WATERALTAR = 0xFF - - }; - - ICN::icn_t GetICNObject(const u8 type); - const char *StringObject(u8 object); - - bool isActionObject(const u8 obj, const bool water); - bool isGroundObject(const u8 obj); - bool isWaterObject(const u8 obj); - bool isQuantityObject(const u8 obj); - bool isCaptureObject(const u8 obj); - bool isPickupObject(const u8 obj); - - bool isClearGroundObject(const u8 obj); - - bool isDayLife(const u8 obj); - bool isWeekLife(const u8 obj); - bool isMonthLife(const u8 obj); - bool isBattleLife(const u8 obj); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/pairs.h b/project/jni/application/fheroes2/src/fheroes2/maps/pairs.h deleted file mode 100644 index 70264b4d3..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/pairs.h +++ /dev/null @@ -1,61 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2PAIRS_H -#define H2PAIRS_H - -#include -#include "maps_tiles.h" - -class IndexDistance : public std::pair -{ - public: - IndexDistance() : std::pair(-1, 0) {}; - IndexDistance(s32 i, u16 d) : std::pair(i, d) {}; - - static bool Shortest(const IndexDistance & id1, const IndexDistance & id2){ return id1.second < id2.second; }; - static bool Longest(const IndexDistance & id1, const IndexDistance & id2){ return id1.second > id2.second; }; -}; - -class IndexObject : public std::pair -{ - public: - IndexObject() : std::pair(-1, MP2::OBJ_ZERO) {}; - IndexObject(const std::pair & pair) : std::pair(pair) {}; - IndexObject(const s32 index, const MP2::object_t object) : std::pair(index, object) {}; - IndexObject(const Maps::Tiles & tile) : std::pair(tile.GetIndex(), tile.GetObject()) {}; - - bool isIndex(s32 index) const { return index == first; }; - bool isObject(u8 object) const { return object == second; }; -}; - -class ObjectColor : public std::pair -{ - public: - ObjectColor() : std::pair(MP2::OBJ_ZERO, Color::GRAY) {}; - ObjectColor(const MP2::object_t object, Color::color_t color) : std::pair(object, color) {}; - - bool isObject(u8 object) const { return object == first; }; - bool isColor(u8 color) const { return color == second; }; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/position.cpp b/project/jni/application/fheroes2/src/fheroes2/maps/position.cpp deleted file mode 100644 index 20b120ed5..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/position.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "maps.h" -#include "world.h" -#include "position.h" - -Maps::Position::Position(const Point & pt) : center(pt) -{ -} - -const Point & Maps::Position::GetCenter(void) const -{ - return center; -} - -s32 Maps::Position::GetIndex(void) const -{ - return Maps::GetIndexFromAbsPoint(center); -} - -void Maps::Position::SetCenter(const Point & pt) -{ - center = pt; -} - -void Maps::Position::SetIndex(s32 index) -{ - center = Maps::isValidAbsIndex(index) ? - Point(index % world.w(), index / world.w()) : Point(-1, -1); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/position.h b/project/jni/application/fheroes2/src/fheroes2/maps/position.h deleted file mode 100644 index 2e7ee5de0..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/position.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2010 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2POSITION_H -#define H2POSITION_H - -#include "gamedefs.h" - -namespace Maps -{ - class Position - { - public: - Position() {}; - Position(const Point &); - - const Point & GetCenter(void) const; - s32 GetIndex(void) const; - - void SetCenter(const Point &); - void SetIndex(s32); - - protected: - Point center; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/visit.cpp b/project/jni/application/fheroes2/src/fheroes2/maps/visit.cpp deleted file mode 100644 index e531a2740..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/visit.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "pairs.h" -#include "visit.h" - -bool Visit::isDayLife(const IndexObject & visit){ return MP2::isDayLife(visit.second); } -bool Visit::isWeekLife(const IndexObject & visit){ return MP2::isWeekLife(visit.second); } -bool Visit::isMonthLife(const IndexObject & visit){ return MP2::isMonthLife(visit.second); } -bool Visit::isBattleLife(const IndexObject & visit){ return MP2::isBattleLife(visit.second); } diff --git a/project/jni/application/fheroes2/src/fheroes2/maps/visit.h b/project/jni/application/fheroes2/src/fheroes2/maps/visit.h deleted file mode 100644 index 24c26a226..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/maps/visit.h +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2MAPSVISIT_H -#define H2MAPSVISIT_H - -class IndexObject; - -namespace Visit -{ - enum type_t { LOCAL, GLOBAL }; - - bool isDayLife(const IndexObject & visit); - bool isWeekLife(const IndexObject & visit); - bool isMonthLife(const IndexObject & visit); - bool isBattleLife(const IndexObject & visit); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/monster/monster.cpp b/project/jni/application/fheroes2/src/fheroes2/monster/monster.cpp deleted file mode 100644 index 0348b6305..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/monster/monster.cpp +++ /dev/null @@ -1,1175 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "castle.h" -#include "difficulty.h" -#include "mp2.h" -#include "speed.h" -#include "settings.h" -#include "luck.h" -#include "morale.h" -#include "payment.h" -#include "monster.h" - -#ifdef WITH_XML -#include "xmlccwrap.h" -#endif - -struct monstats_t -{ - u8 attack; - u8 defense; - u8 damageMin; - u8 damageMax; - u16 hp; - Speed::speed_t speed; - u8 grown; - u8 shots; - const char* name; - const char* multiname; - cost_t cost; -}; - -namespace -{ - static monstats_t monsters[] = { - { 0, 0, 0, 0, 0, Speed::VERYSLOW, 0, 0, "Unknown Monster", "Unknown Monsters" , { 0, 0, 0, 0, 0, 0, 0} }, - - // atck dfnc min max hp speed grwn shots name multiname cost - { 1, 1, 1, 1, 1, Speed::VERYSLOW, 12, 0, _("Peasant") , _("Peasants") , { 20, 0, 0, 0, 0, 0, 0} }, - { 5, 3, 2, 3, 10, Speed::VERYSLOW, 8, 12, _("Archer") , _("Archers") , { 150, 0, 0, 0, 0, 0, 0} }, - { 5, 3, 2, 3, 10, Speed::AVERAGE, 8, 24, _("Ranger") , _("Rangers") , { 200, 0, 0, 0, 0, 0, 0} }, - { 5, 9, 3, 4, 15, Speed::AVERAGE, 5, 0, _("Pikeman") , _("Pikemen") , { 200, 0, 0, 0, 0, 0, 0} }, - { 5, 9, 3, 4, 20, Speed::FAST, 5, 0, _("Veteran Pikeman"), _("Veteran Pikemen"), { 250, 0, 0, 0, 0, 0, 0} }, - { 7, 9, 4, 6, 25, Speed::AVERAGE, 4, 0, _("Swordsman") , _("Swordsmen") , { 250, 0, 0, 0, 0, 0, 0} }, - { 7, 9, 4, 6, 30, Speed::FAST, 4, 0, _("Master Swordsman"), _("Master Swordsmen"), { 300, 0, 0, 0, 0, 0, 0} }, - { 10, 9, 5, 10, 30, Speed::VERYFAST, 3, 0, _("Cavalry") , _("Cavalries") , { 300, 0, 0, 0, 0, 0, 0} }, - { 10, 9, 5, 10, 40, Speed::ULTRAFAST, 3, 0, _("Champion") , _("Champions") , { 375, 0, 0, 0, 0, 0, 0} }, - { 11, 12, 10, 20, 50, Speed::FAST, 2, 0, _("Paladin") , _("Paladins") , { 600, 0, 0, 0, 0, 0, 0} }, - { 11, 12, 10, 20, 65, Speed::VERYFAST, 2, 0, _("Crusader") , _("Crusaders") , { 1000, 0, 0, 0, 0, 0, 0} }, - - // atck dfnc min max hp speed grwn shots name multiname cost - { 3, 1, 1, 2, 3, Speed::AVERAGE, 10, 0, _("Goblin") , _("Goblins") , { 40, 0, 0, 0, 0, 0, 0} }, - { 3, 4, 2, 3, 10, Speed::VERYSLOW, 8, 8, _("Orc") , _("Orcs") , { 140, 0, 0, 0, 0, 0, 0} }, - { 3, 4, 3, 4, 15, Speed::SLOW, 8, 16, _("Orc Chief") , _("Orc Chiefs") , { 175, 0, 0, 0, 0, 0, 0} }, - { 6, 2, 3, 5, 20, Speed::VERYFAST, 5, 0, _("Wolf") , _("Wolves") , { 200, 0, 0, 0, 0, 0, 0} }, - { 9, 5, 4, 6, 40, Speed::VERYSLOW, 4, 0, _("Ogre") , _("Ogres") , { 300, 0, 0, 0, 0, 0, 0} }, - { 9, 5, 5, 7, 60, Speed::AVERAGE, 4, 0, _("Ogre Lord") , _("Ogre Lords") , { 500, 0, 0, 0, 0, 0, 0} }, - { 10, 5, 5, 7, 40, Speed::AVERAGE, 3, 8, _("Troll") , _("Trolls") , { 600, 0, 0, 0, 0, 0, 0} }, - { 10, 5, 7, 9, 40, Speed::FAST, 3, 16, _("War Troll") , _("War Trolls") , { 700, 0, 0, 0, 0, 0, 0} }, - { 12, 9, 12, 24, 80, Speed::FAST, 2, 0, _("Cyclops") , _("Cyclopes") , { 750, 0, 0, 0, 0, 1, 0} }, - - // atck dfnc min max hp speed grwn shots name multiname cost - { 4, 2, 1, 2, 2, Speed::AVERAGE, 8, 0, _("Sprite") , _("Sprites") , { 50, 0, 0, 0, 0, 0, 0} }, - { 6, 5, 2, 4, 20, Speed::VERYSLOW, 6, 0, _("Dwarf") , _("Dwarves") , { 200, 0, 0, 0, 0, 0, 0} }, - { 6, 6, 2, 4, 20, Speed::AVERAGE, 6, 0, _("Battle Dwarf") , _("Battle Dwarves"), { 250, 0, 0, 0, 0, 0, 0} }, - { 4, 3, 2, 3, 15, Speed::AVERAGE, 4, 24, _("Elf") , _("Elves") , { 250, 0, 0, 0, 0, 0, 0} }, - { 5, 5, 2, 3, 15, Speed::VERYFAST, 4, 24, _("Grand Elf") , _("Grand Elves") , { 300, 0, 0, 0, 0, 0, 0} }, - { 7, 5, 5, 8, 25, Speed::FAST, 3, 8, _("Druid") , _("Druids") , { 350, 0, 0, 0, 0, 0, 0} }, - { 7, 7, 5, 8, 25, Speed::VERYFAST, 3, 16, _("Greater Druid") , _("Greater Druids"), { 400, 0, 0, 0, 0, 0, 0} }, - { 10, 9, 7, 14, 40, Speed::FAST, 2, 0, _("Unicorn") , _("Unicorns") , { 500, 0, 0, 0, 0, 0, 0} }, - { 12, 10, 20, 40, 100, Speed::ULTRAFAST, 1, 0, _("Phoenix") , _("Phoenix") , { 1500, 0, 1, 0, 0, 0, 0} }, - - // atck dfnc min max hp speed grwn shots name multiname cost - { 3, 1, 1, 2, 5, Speed::AVERAGE, 8, 8, _("Centaur") , _("Centaurs") , { 60, 0, 0, 0, 0, 0, 0} }, - { 4, 7, 2, 3, 15, Speed::VERYFAST, 6, 0, _("Gargoyle") , _("Gargoyles") , { 200, 0, 0, 0, 0, 0, 0} }, - { 6, 6, 3, 5, 25, Speed::AVERAGE, 4, 0, _("Griffin") , _("Griffins") , { 300, 0, 0, 0, 0, 0, 0} }, - { 9, 8, 5, 10, 35, Speed::AVERAGE, 3, 0, _("Minotaur") , _("Minotaurs") , { 400, 0, 0, 0, 0, 0, 0} }, - { 9, 8, 5, 10, 45, Speed::VERYFAST, 3, 0, _("Minotaur King") , _("Minotaur Kings"), { 500, 0, 0, 0, 0, 0, 0} }, - { 8, 9, 6, 12, 75, Speed::VERYSLOW, 2, 0, _("Hydra") , _("Hydras") , { 800, 0, 0, 0, 0, 0, 0} }, - { 12, 12, 25, 50, 200, Speed::AVERAGE, 1, 0, _("Green Dragon") , _("Green Dragons") , { 3000, 0, 0, 0, 1, 0, 0} }, - { 13, 13, 25, 50, 250, Speed::FAST, 1, 0, _("Red Dragon") , _("Red Dragons") , { 3500, 0, 0, 0, 1, 0, 0} }, - { 14, 14, 25, 50, 300, Speed::VERYFAST, 1, 0, _("Black Dragon") , _("Black Dragons") , { 4000, 0, 0, 0, 2, 0, 0} }, - - // atck dfnc min max hp speed grwn shots name multiname cost - { 2, 1, 1, 3, 3, Speed::SLOW, 8, 12, _("Halfling") , _("Halflings") , { 50, 0, 0, 0, 0, 0, 0} }, - { 5, 4, 2, 3, 15, Speed::VERYFAST, 6, 0, _("Boar") , _("Boars") , { 150, 0, 0, 0, 0, 0, 0} }, - { 5, 10, 4, 5, 30, Speed::VERYSLOW, 4, 0, _("Iron Golem") , _("Iron Golems") , { 300, 0, 0, 0, 0, 0, 0} }, - { 7, 10, 4, 5, 35, Speed::SLOW, 4, 0, _("Steel Golem") , _("Steel Golems") , { 350, 0, 0, 0, 0, 0, 0} }, - { 7, 7, 4, 8, 40, Speed::AVERAGE, 3, 0, _("Roc") , _("Rocs") , { 400, 0, 0, 0, 0, 0, 0} }, - { 11, 7, 7, 9, 30, Speed::FAST, 2, 12, _("Mage") , _("Magi") , { 600, 0, 0, 0, 0, 0, 0} }, - { 12, 8, 7, 9, 35, Speed::VERYFAST, 2, 24, _("Archmage") , _("Archmagi") , { 700, 0, 0, 0, 0, 0, 0} }, - { 13, 10, 20, 30, 150, Speed::AVERAGE, 1, 0, _("Giant") , _("Giants") , { 2000, 0, 0, 0, 0, 0, 1} }, - { 15, 15, 20, 30, 300, Speed::VERYFAST, 1, 24, _("Titan") , _("Titans") , { 5000, 0, 0, 0, 0, 0, 2} }, - - // atck dfnc min max hp speed grwn shots name multiname cost - { 4, 3, 2, 3, 4, Speed::AVERAGE, 8, 0, _("Skeleton") , _("Skeletons") , { 75, 0, 0, 0, 0, 0, 0} }, - { 5, 2, 2, 3, 15, Speed::VERYSLOW, 6, 0, _("Zombie") , _("Zombies") , { 150, 0, 0, 0, 0, 0, 0} }, - { 5, 2, 2, 3, 25, Speed::AVERAGE, 6, 0, _("Mutant Zombie") , _("Mutant Zombies"), { 200, 0, 0, 0, 0, 0, 0} }, - { 6, 6, 3, 4, 25, Speed::AVERAGE, 4, 0, _("Mummy") , _("Mummies") , { 250, 0, 0, 0, 0, 0, 0} }, - { 6, 6, 3, 4, 30, Speed::FAST, 4, 0, _("Royal Mummy") , _("Royal Mummies") , { 300, 0, 0, 0, 0, 0, 0} }, - { 8, 6, 5, 7, 30, Speed::AVERAGE, 3, 0, _("Vampire") , _("Vampires") , { 500, 0, 0, 0, 0, 0, 0} }, - { 8, 6, 5, 7, 40, Speed::FAST, 3, 0, _("Vampire Lord") , _("Vampire Lords") , { 650, 0, 0, 0, 0, 0, 0} }, - { 7, 12, 8, 10, 25, Speed::FAST, 2, 12, _("Lich") , _("Liches") , { 750, 0, 0, 0, 0, 0, 0} }, - { 7, 13, 8, 10, 35, Speed::VERYFAST, 2, 24, _("Power Lich") , _("Power Liches") , { 900, 0, 0, 0, 0, 0, 0} }, - { 11, 9, 25, 45, 150, Speed::AVERAGE, 1, 0, _("Bone Dragon") , _("Bone Dragons") , { 1500, 0, 0, 0, 0, 0, 0} }, - - // atck dfnc min max hp speed grwn shots name multiname cost - { 6, 1, 1, 2, 4, Speed::FAST, 4, 0, _("Rogue") , _("Rogues") , { 50, 0, 0, 0, 0, 0, 0} }, - { 7, 6, 2, 5, 20, Speed::VERYFAST, 4, 0, _("Nomad") , _("Nomads") , { 200, 0, 0, 0, 0, 0, 0} }, - { 8, 7, 4, 6, 20, Speed::FAST, 4, 0, _("Ghost") , _("Ghosts") , { 1000, 0, 0, 0, 0, 0, 0} }, - { 10, 9, 20, 30, 50, Speed::VERYFAST, 4, 0, _("Genie") , _("Genies") , { 650, 0, 0, 0, 0, 0, 1} }, - { 8, 9, 6, 10, 35, Speed::AVERAGE, 4, 0, _("Medusa") , _("Medusas") , { 500, 0, 0, 0, 0, 0, 0} }, - { 8, 8, 4, 5, 50, Speed::SLOW, 4, 0, _("Earth Elemental") , _("Earth Elementals"), { 500, 0, 0, 0, 0, 0, 0} }, - { 7, 7, 2, 8, 35, Speed::VERYFAST, 4, 0, _("Air Elemental") , _("Air Elementals") , { 500, 0, 0, 0, 0, 0, 0} }, - { 8, 6, 4, 6, 40, Speed::FAST, 4, 0, _("Fire Elemental") , _("Fire Elementals") , { 500, 0, 0, 0, 0, 0, 0} }, - { 6, 8, 3, 7, 45, Speed::AVERAGE, 4, 0, _("Water Elemental") , _("Water Elementals"), { 500, 0, 0, 0, 0, 0, 0} }, - - { 0, 0, 0, 0, 0, Speed::VERYSLOW, 0, 0, "Random Monster" , "Random Monsters" , { 0, 0, 0, 0, 0, 0, 0} }, - { 0, 0, 0, 0, 0, Speed::VERYSLOW, 0, 0, "Random Monster 1", "Random Monsters 3", { 0, 0, 0, 0, 0, 0, 0} }, - { 0, 0, 0, 0, 0, Speed::VERYSLOW, 0, 0, "Random Monster 2", "Random Monsters 2", { 0, 0, 0, 0, 0, 0, 0} }, - { 0, 0, 0, 0, 0, Speed::VERYSLOW, 0, 0, "Random Monster 3", "Random Monsters 3", { 0, 0, 0, 0, 0, 0, 0} }, - { 0, 0, 0, 0, 0, Speed::VERYSLOW, 0, 0, "Random Monster 4", "Random Monsters 4", { 0, 0, 0, 0, 0, 0, 0} }, - }; -} - -void Monster::UpdateStats(const std::string & spec) -{ -#ifdef WITH_XML - // parse monsters.xml - TiXmlDocument doc; - const TiXmlElement* xml_monsters = NULL; - monstats_t* ptr = &monsters[0]; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_monsters = doc.FirstChildElement("monsters"))) - { - const TiXmlElement* xml_monster = xml_monsters->FirstChildElement("monster"); - for(; xml_monster; xml_monster = xml_monster->NextSiblingElement("monster")) - { - cost_t & cost = ptr->cost; - int value; - - xml_monster->Attribute("skip", &value); - if(0 == value) - { - xml_monster->Attribute("attack", &value); if(value) ptr->attack = value; - xml_monster->Attribute("defense", &value); if(value) ptr->defense = value; - xml_monster->Attribute("damage_min", &value); if(value) ptr->damageMin = value; - xml_monster->Attribute("damage_max", &value); if(value) ptr->damageMax = value; - xml_monster->Attribute("hp", &value); if(value) ptr->hp = value; - xml_monster->Attribute("speed", &value); ptr->speed = Speed::INSTANT < value ? Speed::INSTANT : (Speed::CRAWLING > value ? Speed::CRAWLING : static_cast(value)); - xml_monster->Attribute("grown", &value); ptr->grown = value; - xml_monster->Attribute("shots", &value); ptr->shots = value; - xml_monster->Attribute("gold", &value); cost.gold = value; - xml_monster->Attribute("wood", &value); cost.wood = value; - xml_monster->Attribute("mercury", &value); cost.mercury = value; - xml_monster->Attribute("ore", &value); cost.ore = value; - xml_monster->Attribute("sulfur", &value); cost.sulfur = value; - xml_monster->Attribute("crystal", &value); cost.crystal = value; - xml_monster->Attribute("gems", &value); cost.gems = value; - } - - ++ptr; - - // out of range - if((ptr - &monsters[0]) >= MONSTER_RND1) break; - } - } - else - VERBOSE(spec << ": " << doc.ErrorDesc()); -#endif -} - -Monster::Monster() : id(UNKNOWN) -{ -} - -Monster::Monster(monster_t m) : id(m) -{ -} - -Monster::Monster(u8 race, u32 dwelling) : id(FromDwelling(race, dwelling)) -{ -} - -bool Monster::operator== (monster_t m) const -{ - return id == m; -} - -bool Monster::operator!= (monster_t m) const -{ - return id != m; -} - -Monster::monster_t Monster::operator() (void) const -{ - return id; -} - -Monster::monster_t Monster::GetID(void) const -{ - return id; -} - -void Monster::Set(const Monster & m) -{ - id = m.id; -} - -void Monster::Set(monster_t m) -{ - id = m; -} - -void Monster::Upgrade(void) -{ - id = Upgrade(id); -} - -u8 Monster::GetAttack(void) const -{ - return monsters[id].attack; -} - -u8 Monster::GetDefense(void) const -{ - return monsters[id].defense; -} - -u8 Monster::GetPower(void) const -{ - return 0; -} - -u8 Monster::GetKnowledge(void) const -{ - return 0; -} - -s8 Monster::GetMorale(void) const -{ - return Morale::NORMAL; -} - -s8 Monster::GetLuck(void) const -{ - return Luck::NORMAL; -} - -Race::race_t Monster::GetRace(void) const -{ - if(UNKNOWN == id) return Race::BOMG; - else - if(GOBLIN > id) return Race::KNGT; - else - if(SPRITE > id) return Race::BARB; - else - if(CENTAUR > id) return Race::SORC; - else - if(HALFLING > id) return Race::WRLK; - else - if(SKELETON > id) return Race::WZRD; - else - if(ROGUE > id) return Race::NECR; - - return Race::BOMG; -} - -u8 Monster::GetType(void) const -{ - return Skill::Primary::MONSTER; -} - -u8 Monster::GetDamageMin(void) const -{ - return monsters[id].damageMin; -} - -u8 Monster::GetDamageMax(void) const -{ - return monsters[id].damageMax; -} - -u8 Monster::GetShots(void) const -{ - return monsters[id].shots; -} - -u16 Monster::GetHitPoints(void) const -{ - return monsters[id].hp; -} - -u8 Monster::GetSpeed(void) const -{ - return monsters[id].speed; -} - -u8 Monster::GetGrown(void) const -{ - return monsters[id].grown; -} - -u8 Monster::GetLevel(void) const -{ - return GetLevel(id); -} - -u16 Monster::GetRNDSize(bool skip_factor) const -{ - const u32 hps = (GetGrown() ? GetGrown() : 1) * GetHitPoints(); - u32 res = Rand::Get(hps, hps + hps / 2); - - if(!skip_factor) - { - u16 factor = 100; - - switch(Settings::Get().GameDifficulty()) - { - case Difficulty::EASY: factor = 80; break; - case Difficulty::NORMAL: factor = 100; break; - case Difficulty::HARD: factor = 130; break; - case Difficulty::EXPERT: factor = 160; break; - case Difficulty::IMPOSSIBLE:factor = 190; break; - default: break; - } - - res = (res * factor / 100); - // force minimal - if(res == 0) res = 1; - } - - return GetCountFromHitPoints(id, res); -} - -const char* Monster::GetName(void) const -{ - return GetName(id); -} - -const char* Monster::GetPluralName(u32 count) const -{ - return GetPluralName(id, count); -} - -const char* Monster::GetMultiName(void) const -{ - return GetMultiName(id); -} - -bool Monster::isUndead(void) const -{ - switch(id) - { - case SKELETON: - case ZOMBIE: - case MUTANT_ZOMBIE: - case MUMMY: - case ROYAL_MUMMY: - case VAMPIRE: - case VAMPIRE_LORD: - case LICH: - case POWER_LICH: - case BONE_DRAGON: - case GHOST: return true; - - default: break; - } - - return false; -} - -bool Monster::isElemental(void) const -{ - switch(id) - { - case EARTH_ELEMENT: - case AIR_ELEMENT: - case FIRE_ELEMENT: - case WATER_ELEMENT: return true; - - default: break; - } - - return false; -} - -bool Monster::isDragons(void) const -{ - switch(id) - { - case GREEN_DRAGON: - case RED_DRAGON: - case BLACK_DRAGON: - case BONE_DRAGON: return true; - - default: break; - } - - return false; -} - -bool Monster::isFly(void) const -{ - switch(id) - { - case SPRITE: - case PHOENIX: - case GARGOYLE: - case GRIFFIN: - case GREEN_DRAGON: - case RED_DRAGON: - case BLACK_DRAGON: - case ROC: - case VAMPIRE: - case VAMPIRE_LORD: - case BONE_DRAGON: - case GHOST: - case GENIE: return true; - - default: break; - } - - return false; -} - -bool Monster::isWide(void) const -{ - switch(id) - { - case CAVALRY: - case CHAMPION: - case WOLF: - case UNICORN: - case PHOENIX: - case CENTAUR: - case GRIFFIN: - case HYDRA: - case GREEN_DRAGON: - case RED_DRAGON: - case BLACK_DRAGON: - case BOAR: - case ROC: - case BONE_DRAGON: - case NOMAD: - case MEDUSA: return true; - - default: break; - } - - return false; -} - -bool Monster::isArchers(void) const -{ - return GetShots(); -} - -bool Monster::isAllowUpgrade(void) const -{ - return id != Upgrade(id); -} - -bool Monster::isTwiceAttack(void) const -{ - switch(id) - { - case WOLF: - case PALADIN: - case CRUSADER: - case ELF: - case GRAND_ELF: - case RANGER: return true; - - default: break; - } - - return false; -} - -Monster::monster_t Monster::Upgrade(monster_t m) -{ - switch(m) - { - case ARCHER: return RANGER; - case PIKEMAN: return VETERAN_PIKEMAN; - case SWORDSMAN: return MASTER_SWORDSMAN; - case CAVALRY: return CHAMPION; - case PALADIN: return CRUSADER; - case ORC: return ORC_CHIEF; - case OGRE: return OGRE_LORD; - case TROLL: return WAR_TROLL; - case DWARF: return BATTLE_DWARF; - case ELF: return GRAND_ELF; - case DRUID: return GREATER_DRUID; - case ZOMBIE: return MUTANT_ZOMBIE; - case MUMMY: return ROYAL_MUMMY; - case VAMPIRE: return VAMPIRE_LORD; - case LICH: return POWER_LICH; - case MINOTAUR: return MINOTAUR_KING; - case GREEN_DRAGON: return RED_DRAGON; - case RED_DRAGON: return BLACK_DRAGON; - case IRON_GOLEM: return STEEL_GOLEM; - case MAGE: return ARCHMAGE; - case GIANT: return TITAN; - - default: break; - } - - return m; -} - -Monster::monster_t Monster::FromInt(u8 num) -{ - return MONSTER_RND < num ? UNKNOWN : static_cast(num); -} - -Monster::monster_t Monster::FromDwelling(u8 race, u32 dwelling) -{ - switch(dwelling) - { - case DWELLING_MONSTER1: - switch(race) - { - case Race::KNGT: return PEASANT; - case Race::BARB: return GOBLIN; - case Race::SORC: return SPRITE; - case Race::WRLK: return CENTAUR; - case Race::WZRD: return HALFLING; - case Race::NECR: return SKELETON; - default: break; - } - break; - - case DWELLING_MONSTER2: - switch(race) - { - case Race::KNGT: return ARCHER; - case Race::BARB: return ORC; - case Race::SORC: return DWARF; - case Race::WRLK: return GARGOYLE; - case Race::WZRD: return BOAR; - case Race::NECR: return ZOMBIE; - default: break; - } - break; - - case DWELLING_UPGRADE2: - switch(race) - { - case Race::KNGT: return RANGER; - case Race::BARB: return ORC_CHIEF; - case Race::SORC: return BATTLE_DWARF; - case Race::WRLK: return GARGOYLE; - case Race::WZRD: return BOAR; - case Race::NECR: return MUTANT_ZOMBIE; - default: break; - } - break; - - case DWELLING_MONSTER3: - switch(race) - { - case Race::KNGT: return PIKEMAN; - case Race::BARB: return WOLF; - case Race::SORC: return ELF; - case Race::WRLK: return GRIFFIN; - case Race::WZRD: return IRON_GOLEM; - case Race::NECR: return MUMMY; - default: break; - } - break; - - case DWELLING_UPGRADE3: - switch(race) - { - case Race::KNGT: return VETERAN_PIKEMAN; - case Race::BARB: return WOLF; - case Race::SORC: return GRAND_ELF; - case Race::WRLK: return GRIFFIN; - case Race::WZRD: return STEEL_GOLEM; - case Race::NECR: return ROYAL_MUMMY; - default: break; - } - break; - - case DWELLING_MONSTER4: - switch(race) - { - case Race::KNGT: return SWORDSMAN; - case Race::BARB: return OGRE; - case Race::SORC: return DRUID; - case Race::WRLK: return MINOTAUR; - case Race::WZRD: return ROC; - case Race::NECR: return VAMPIRE; - default: break; - } - break; - - case DWELLING_UPGRADE4: - switch(race) - { - case Race::KNGT: return MASTER_SWORDSMAN; - case Race::BARB: return OGRE_LORD; - case Race::SORC: return GREATER_DRUID; - case Race::WRLK: return MINOTAUR_KING; - case Race::WZRD: return ROC; - case Race::NECR: return VAMPIRE_LORD; - default: break; - } - break; - - case DWELLING_MONSTER5: - switch(race) - { - case Race::KNGT: return CAVALRY; - case Race::BARB: return TROLL; - case Race::SORC: return UNICORN; - case Race::WRLK: return HYDRA; - case Race::WZRD: return MAGE; - case Race::NECR: return LICH; - default: break; - } - break; - - case DWELLING_UPGRADE5: - switch(race) - { - case Race::KNGT: return CHAMPION; - case Race::BARB: return WAR_TROLL; - case Race::SORC: return UNICORN; - case Race::WRLK: return HYDRA; - case Race::WZRD: return ARCHMAGE; - case Race::NECR: return POWER_LICH; - default: break; - } - break; - - case DWELLING_MONSTER6: - switch(race) - { - case Race::KNGT: return PALADIN; - case Race::BARB: return CYCLOPS; - case Race::SORC: return PHOENIX; - case Race::WRLK: return GREEN_DRAGON; - case Race::WZRD: return GIANT; - case Race::NECR: return BONE_DRAGON; - default: break; - } - break; - - case DWELLING_UPGRADE6: - switch(race) - { - case Race::KNGT: return CRUSADER; - case Race::BARB: return CYCLOPS; - case Race::SORC: return PHOENIX; - case Race::WRLK: return RED_DRAGON; - case Race::WZRD: return TITAN; - case Race::NECR: return BONE_DRAGON; - default: break; - } - break; - - case DWELLING_UPGRADE7: - switch(race) - { - case Race::KNGT: return CRUSADER; - case Race::BARB: return CYCLOPS; - case Race::SORC: return PHOENIX; - case Race::WRLK: return BLACK_DRAGON; - case Race::WZRD: return TITAN; - case Race::NECR: return BONE_DRAGON; - default: break; - } - break; - - default: break; - } - - return UNKNOWN; -} - -Monster::monster_t Monster::FromObject(u8 obj) -{ - switch(obj) - { - case MP2::OBJ_WATCHTOWER: return ORC; - case MP2::OBJ_EXCAVATION: return SKELETON; - case MP2::OBJ_CAVE: return CENTAUR; - case MP2::OBJ_TREEHOUSE: return SPRITE; - case MP2::OBJ_ARCHERHOUSE: return ARCHER; - case MP2::OBJ_GOBLINHUT: return GOBLIN; - case MP2::OBJ_DWARFCOTT: return DWARF; - case MP2::OBJ_HALFLINGHOLE: return HALFLING; - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_THATCHEDHUT: return PEASANT; - - case MP2::OBJ_RUINS: return MEDUSA; - case MP2::OBJ_TREECITY: return SPRITE; - case MP2::OBJ_WAGONCAMP: return ROGUE; - case MP2::OBJ_DESERTTENT: return NOMAD; - - case MP2::OBJ_TROLLBRIDGE: return TROLL; - case MP2::OBJ_DRAGONCITY: return RED_DRAGON; - case MP2::OBJ_CITYDEAD: return POWER_LICH; - - case MP2::OBJ_ANCIENTLAMP: return GENIE; - - // loyalty version - case MP2::OBJ_WATERALTAR: return WATER_ELEMENT; - case MP2::OBJ_AIRALTAR: return AIR_ELEMENT; - case MP2::OBJ_FIREALTAR: return FIRE_ELEMENT; - case MP2::OBJ_EARTHALTAR: return EARTH_ELEMENT; - case MP2::OBJ_BARROWMOUNDS: return GHOST; - - default: break; - } - - return UNKNOWN; -} - -Monster::monster_t Monster::Rand(level_t level) -{ - switch(level) - { - case LEVEL0: return FromInt(Rand::Get(PEASANT, WATER_ELEMENT)); - - case LEVEL1: - switch(Rand::Get(1, 9)) - { - case 1: return PEASANT; - case 2: return ARCHER; - case 3: return GOBLIN; - case 4: return ORC; - case 5: return SPRITE; - case 6: return CENTAUR; - case 7: return HALFLING; - case 8: return SKELETON; - case 9: return ZOMBIE; - default: break; - } - break; - - case LEVEL2: - switch(Rand::Get(1, 14)) - { - case 1: return RANGER; - case 2: return PIKEMAN; - case 3: return VETERAN_PIKEMAN; - case 4: return ORC_CHIEF; - case 5: return WOLF; - case 6: return DWARF; - case 7: return BATTLE_DWARF; - case 8: return ELF; - case 9: return GRAND_ELF; - case 10: return GARGOYLE; - case 11: return BOAR; - case 12: return IRON_GOLEM; - case 13: return MUTANT_ZOMBIE; - case 14: return MUMMY; - default: break; - } - break; - - case LEVEL3: - switch(Rand::Get(1, 26)) - { - case 1: return SWORDSMAN; - case 2: return MASTER_SWORDSMAN; - case 3: return CAVALRY; - case 4: return CHAMPION; - case 5: return OGRE; - case 6: return OGRE_LORD; - case 7: return TROLL; - case 8: return WAR_TROLL; - case 9: return DRUID; - case 10: return GREATER_DRUID; - case 11: return GRIFFIN; - case 12: return MINOTAUR; - case 13: return MINOTAUR_KING; - case 14: return STEEL_GOLEM; - case 15: return ROC; - case 16: return MAGE; - case 17: return ARCHMAGE; - case 18: return ROYAL_MUMMY; - case 19: return VAMPIRE; - case 20: return VAMPIRE_LORD; - case 21: return LICH; - case 22: return GHOST; - case 23: return MEDUSA; - case 24: return EARTH_ELEMENT; - case 25: return AIR_ELEMENT; - case 26: return FIRE_ELEMENT; - default: break; - } - break; - - case LEVEL4: - switch(Rand::Get(1, 13)) - { - case 1: return PALADIN; - case 2: return CRUSADER; - case 3: return CYCLOPS; - case 4: return UNICORN; - case 5: return PHOENIX; - case 6: return HYDRA; - case 7: return GREEN_DRAGON; - case 8: return RED_DRAGON; - case 9: return BLACK_DRAGON; - case 10: return GIANT; - case 11: return TITAN; - case 12: return POWER_LICH; - case 13: return BONE_DRAGON; - default: break; - } - break; - } - - return UNKNOWN; -} - -u8 Monster::GetLevel(monster_t m) -{ - switch(m) - { - case PEASANT: - case ARCHER: - case GOBLIN: - case ORC: - case SPRITE: - case CENTAUR: - case HALFLING: - case SKELETON: - case ZOMBIE: - case ROGUE: - case MONSTER_RND1: return LEVEL1; - - case RANGER: - case PIKEMAN: - case VETERAN_PIKEMAN: - case ORC_CHIEF: - case WOLF: - case DWARF: - case BATTLE_DWARF: - case ELF: - case GRAND_ELF: - case GARGOYLE: - case BOAR: - case IRON_GOLEM: - case MUTANT_ZOMBIE: - case MUMMY: - case NOMAD: - case MONSTER_RND2: return LEVEL2; - - case SWORDSMAN: - case MASTER_SWORDSMAN: - case CAVALRY: - case CHAMPION: - case OGRE: - case OGRE_LORD: - case TROLL: - case WAR_TROLL: - case DRUID: - case GREATER_DRUID: - case GRIFFIN: - case MINOTAUR: - case MINOTAUR_KING: - case STEEL_GOLEM: - case ROC: - case MAGE: - case ARCHMAGE: - case ROYAL_MUMMY: - case VAMPIRE: - case VAMPIRE_LORD: - case LICH: - case GHOST: - case MEDUSA: - case EARTH_ELEMENT: - case AIR_ELEMENT: - case FIRE_ELEMENT: - case WATER_ELEMENT: - case MONSTER_RND3: return LEVEL3; - - case PALADIN: - case CRUSADER: - case CYCLOPS: - case UNICORN: - case PHOENIX: - case HYDRA: - case GREEN_DRAGON: - case RED_DRAGON: - case BLACK_DRAGON: - case GIANT: - case TITAN: - case POWER_LICH: - case BONE_DRAGON: - case GENIE: - case MONSTER_RND4: return LEVEL4; - - case MONSTER_RND: - switch(Rand::Get(0, 3)) - { - default: return LEVEL1; - case 1: return LEVEL2; - case 2: return LEVEL3; - case 3: return LEVEL4; - } - break; - - default: break; - } - - return LEVEL0; -} - -u32 Monster::GetDwelling(monster_t m) -{ - switch(m) - { - case PEASANT: - case GOBLIN: - case SPRITE: - case CENTAUR: - case HALFLING: - case SKELETON: return DWELLING_MONSTER1; - - case ARCHER: - case ORC: - case ZOMBIE: - case DWARF: - case GARGOYLE: - case BOAR: return DWELLING_MONSTER2; - - case RANGER: - case ORC_CHIEF: - case BATTLE_DWARF: - case MUTANT_ZOMBIE: return DWELLING_UPGRADE2; - - case PIKEMAN: - case WOLF: - case ELF: - case IRON_GOLEM: - case MUMMY: - case GRIFFIN: return DWELLING_MONSTER3; - - case VETERAN_PIKEMAN: - case GRAND_ELF: - case STEEL_GOLEM: - case ROYAL_MUMMY: return DWELLING_UPGRADE3; - - case SWORDSMAN: - case OGRE: - case DRUID: - case MINOTAUR: - case ROC: - case VAMPIRE: return DWELLING_MONSTER4; - - case MASTER_SWORDSMAN: - case OGRE_LORD: - case GREATER_DRUID: - case MINOTAUR_KING: - case VAMPIRE_LORD: return DWELLING_UPGRADE4; - - case CAVALRY: - case TROLL: - case MAGE: - case LICH: - case UNICORN: - case HYDRA: return DWELLING_MONSTER5; - - case CHAMPION: - case WAR_TROLL: - case ARCHMAGE: - case POWER_LICH: return DWELLING_UPGRADE5; - - case PALADIN: - case CYCLOPS: - case PHOENIX: - case GREEN_DRAGON: - case GIANT: - case BONE_DRAGON: return DWELLING_MONSTER6; - - case CRUSADER: - case RED_DRAGON: - case TITAN: return DWELLING_UPGRADE6; - - case BLACK_DRAGON: return DWELLING_UPGRADE7; - - default: break; - } - - return 0; -} - -const char* Monster::GetName(monster_t m) -{ - return _(monsters[m].name); -} - -const char* Monster::GetMultiName(monster_t m) -{ - return _(monsters[m].multiname); -} - -const char* Monster::GetPluralName(monster_t m, u32 count) -{ - switch(m) - { - case PEASANT: return ngettext("Peasant", "Peasants", count); - case ARCHER: return ngettext("Archer", "Archers", count); - case RANGER: return ngettext("Ranger", "Rangers", count); - case PIKEMAN: return ngettext("Pikeman", "Pikemen", count); - case VETERAN_PIKEMAN: return ngettext("Veteran Pikeman", "Veteran Pikemen", count); - case SWORDSMAN: return ngettext("Swordsman", "Swordsmen", count); - case MASTER_SWORDSMAN: return ngettext("Master Swordsman", "Master Swordsmen", count); - case CAVALRY: return ngettext("Cavalry", "Cavalries", count); - case CHAMPION: return ngettext("Champion", "Champions", count); - case PALADIN: return ngettext("Paladin", "Paladins", count); - case CRUSADER: return ngettext("Crusader", "Crusaders", count); - - case GOBLIN: return ngettext("Goblin", "Goblins", count); - case ORC: return ngettext("Orc", "Orcs", count); - case ORC_CHIEF: return ngettext("Orc Chief", "Orc Chiefs", count); - case WOLF: return ngettext("Wolf", "Wolves", count); - case OGRE: return ngettext("Ogre", "Ogres", count); - case OGRE_LORD: return ngettext("Ogre Lord", "Ogre Lords", count); - case TROLL: return ngettext("Troll", "Trolls", count); - case WAR_TROLL: return ngettext("War Troll", "War Trolls", count); - case CYCLOPS: return ngettext("Cyclops", "Cyclopes", count); - - case SPRITE: return ngettext("Sprite", "Sprites", count); - case DWARF: return ngettext("Dwarf", "Dwarves", count); - case BATTLE_DWARF: return ngettext("Battle Dwarf", "Battle Dwarves", count); - case ELF: return ngettext("Elf", "Elves", count); - case GRAND_ELF: return ngettext("Grand Elf", "Grand Elves", count); - case DRUID: return ngettext("Druid", "Druids", count); - case GREATER_DRUID: return ngettext("Greater Druid", "Greater Druids", count); - case UNICORN: return ngettext("Unicorn", "Unicorns", count); - case PHOENIX: return ngettext("Phoenix", "Phoenix", count); - - case CENTAUR: return ngettext("Centaur", "Centaurs", count); - case GARGOYLE: return ngettext("Gargoyle", "Gargoyles", count); - case GRIFFIN: return ngettext("Griffin", "Griffins", count); - case MINOTAUR: return ngettext("Minotaur", "Minotaurs", count); - case MINOTAUR_KING: return ngettext("Minotaur King", "Minotaur Kings", count); - case HYDRA: return ngettext("Hydra", "Hydras", count); - case GREEN_DRAGON: return ngettext("Green Dragon", "Green Dragons", count); - case RED_DRAGON: return ngettext("Red Dragon", "Red Dragons", count); - case BLACK_DRAGON: return ngettext("Black Dragon", "Black Dragons", count); - - case HALFLING: return ngettext("Halfling", "Halflings", count); - case BOAR: return ngettext("Boar", "Boars", count); - case IRON_GOLEM: return ngettext("Iron Golem", "Iron Golems", count); - case STEEL_GOLEM: return ngettext("Steel Golem", "Steel Golems", count); - case ROC: return ngettext("Roc", "Rocs", count); - case MAGE: return ngettext("Mage", "Magi", count); - case ARCHMAGE: return ngettext("Archmage", "Archmagi", count); - case GIANT: return ngettext("Giant", "Giants", count); - case TITAN: return ngettext("Titan", "Titans", count); - - case SKELETON: return ngettext("Skeleton", "Skeletons", count); - case ZOMBIE: return ngettext("Zombie", "Zombies", count); - case MUTANT_ZOMBIE: return ngettext("Mutant Zombie", "Mutant Zombies", count); - case MUMMY: return ngettext("Mummy", "Mummies", count); - case ROYAL_MUMMY: return ngettext("Royal Mummy", "Royal Mummies", count); - case VAMPIRE: return ngettext("Vampire", "Vampires", count); - case VAMPIRE_LORD: return ngettext("Vampire Lord", "Vampire Lords", count); - case LICH: return ngettext("Lich", "Liches", count); - case POWER_LICH: return ngettext("Power Lich", "Power Liches", count); - case BONE_DRAGON: return ngettext("Bone Dragon", "Bone Dragons", count); - - case ROGUE: return ngettext("Rogue", "Rogues", count); - case NOMAD: return ngettext("Nomad", "Nomads", count); - case GHOST: return ngettext("Ghost", "Ghosts", count); - case GENIE: return ngettext("Genie", "Genies", count); - case MEDUSA: return ngettext("Medusa", "Medusas", count); - case EARTH_ELEMENT: return ngettext("Earth Elemental", "Earth Elementals", count); - case AIR_ELEMENT: return ngettext("Air Elemental", "Air Elementals", count); - case FIRE_ELEMENT: return ngettext("Fire Elemental", "Fire Elementals", count); - case WATER_ELEMENT: return ngettext("Water Elemental", "Water Elementals", count); - - default: break; - } - - return 1 == count ? GetName(m) : GetMultiName(m); -} - -u8 Monster::GetSpriteIndex(u8 m) -{ - return UNKNOWN < m ? m - 1 : 0; -} - -Monster::monster_t Monster::Upgrade(Monster & m) -{ - return Upgrade(m.id); -} - -u8 Monster::GetLevel(Monster & m) -{ - return GetLevel(m.id); -} - -u32 Monster::GetDwelling(Monster & m) -{ - return GetDwelling(m.id); -} - -ICN::icn_t Monster::ICNMonh(void) const -{ - - return id >= PEASANT && id <= WATER_ELEMENT ? static_cast(ICN::MONH0000 + id - PEASANT) : ICN::UNKNOWN; -} - -void Monster::GetCost(u8 id, payment_t & payment) -{ - cost_t & cost = monsters[FromInt(id)].cost; - - payment.gold = cost.gold; - payment.wood = cost.wood; - payment.mercury = cost.mercury; - payment.ore = cost.ore; - payment.sulfur = cost.sulfur; - payment.crystal = cost.crystal; - payment.gems = cost.gems; -} - -void Monster::GetUpgradeCost(u8 id, payment_t & payment) -{ - monster_t m1 = FromInt(id); - monster_t m2 = Upgrade(m1); - - if(m1 != m2) - { - payment_t payment2; - payment_t payment1; - GetCost(m2, payment2); - GetCost(m1, payment1); - payment = payment2 - payment1; - } - else - GetCost(m1, payment); -} - -u32 Monster::GetCountFromHitPoints(monster_t m, u32 hp) -{ - if(hp) - { - const u16 hp1 = monsters[m].hp; - const u32 count = hp / hp1; - return (count * hp1) < hp ? count + 1 : count; - } - - return 0; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/monster/monster.h b/project/jni/application/fheroes2/src/fheroes2/monster/monster.h deleted file mode 100644 index bd5c7e8c8..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/monster/monster.h +++ /dev/null @@ -1,198 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2MONSTER_H -#define H2MONSTER_H - -#include -#include "skill.h" -#include "icn.h" -#include "m82.h" -#include "payment.h" -#include "gamedefs.h" - -class Monster : public Skill::Primary -{ -public: - enum level_t - { - LEVEL0, - LEVEL1, - LEVEL2, - LEVEL3, - LEVEL4 - }; - - enum monster_t - { - UNKNOWN, - - PEASANT, - ARCHER, - RANGER, - PIKEMAN, - VETERAN_PIKEMAN, - SWORDSMAN, - MASTER_SWORDSMAN, - CAVALRY, - CHAMPION, - PALADIN, - CRUSADER, - GOBLIN, - ORC, - ORC_CHIEF, - WOLF, - OGRE, - OGRE_LORD, - TROLL, - WAR_TROLL, - CYCLOPS, - SPRITE, - DWARF, - BATTLE_DWARF, - ELF, - GRAND_ELF, - DRUID, - GREATER_DRUID, - UNICORN, - PHOENIX, - CENTAUR, - GARGOYLE, - GRIFFIN, - MINOTAUR, - MINOTAUR_KING, - HYDRA, - GREEN_DRAGON, - RED_DRAGON, - BLACK_DRAGON, - HALFLING, - BOAR, - IRON_GOLEM, - STEEL_GOLEM, - ROC, - MAGE, - ARCHMAGE, - GIANT, - TITAN, - SKELETON, - ZOMBIE, - MUTANT_ZOMBIE, - MUMMY, - ROYAL_MUMMY, - VAMPIRE, - VAMPIRE_LORD, - LICH, - POWER_LICH, - BONE_DRAGON, - - ROGUE, - NOMAD, - GHOST, - GENIE, - MEDUSA, - EARTH_ELEMENT, - AIR_ELEMENT, - FIRE_ELEMENT, - WATER_ELEMENT, - - MONSTER_RND1, - MONSTER_RND2, - MONSTER_RND3, - MONSTER_RND4, - MONSTER_RND - }; - - Monster(); - Monster(monster_t); - Monster(u8, u32); - - bool operator== (monster_t) const; - bool operator!= (monster_t) const; - monster_t operator() (void) const; - - monster_t GetID(void) const; - - void Set(monster_t); - void Set(const Monster &); - void Upgrade(void); - - u8 GetAttack(void) const; - u8 GetDefense(void) const; - u8 GetPower(void) const; - u8 GetKnowledge(void) const; - s8 GetMorale(void) const; - s8 GetLuck(void) const; - Race::race_t GetRace(void) const; - u8 GetType(void) const; - - u8 GetDamageMin(void) const; - u8 GetDamageMax(void) const; - u8 GetShots(void) const; - u16 GetHitPoints(void) const; - u8 GetSpeed(void) const; - u8 GetGrown(void) const; - u8 GetLevel(void) const; - u16 GetRNDSize(bool skip) const; - - const char* GetName(void) const; - const char* GetMultiName(void) const; - const char* GetPluralName(u32) const; - - bool isElemental(void) const; - bool isUndead(void) const; - bool isFly(void) const; - bool isWide(void) const; - bool isArchers(void) const; - bool isAllowUpgrade(void) const; - bool isTwiceAttack(void) const; - bool isDragons(void) const; - - ICN::icn_t ICNMonh(void) const; - - static monster_t Upgrade(Monster &); - static u8 GetLevel(Monster &); - static u32 GetDwelling(Monster &); - - static u8 GetSpriteIndex(u8); - static const char* GetName(monster_t); - static const char* GetMultiName(monster_t); - static const char* GetPluralName(monster_t, u32); - static monster_t Upgrade(monster_t); - static u8 GetLevel(monster_t); - static u32 GetDwelling(monster_t); - static u32 GetCountFromHitPoints(monster_t, u32); - - static void GetCost(u8, payment_t &); - static void GetUpgradeCost(u8, payment_t &); - - static monster_t FromInt(u8); - static monster_t FromDwelling(u8, u32); - static monster_t FromObject(u8); - static monster_t Rand(level_t = LEVEL0); - - static void UpdateStats(const std::string &); - -protected: - monster_t id; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/client.cpp b/project/jni/application/fheroes2/src/fheroes2/network/client.cpp deleted file mode 100644 index 51cd612d9..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/client.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_NET - -#include "settings.h" -#include "localevent.h" -#include "client.h" - -FH2Client::FH2Client() -{ -} - -bool FH2Client::IsConnected(void) const -{ - return Modes(ST_CONNECT) && sd; -} - -bool FH2Client::Wait(QueueMessage & packet, u16 id) -{ - while(LocalEvent::Get().HandleEvents()) - { - if(Ready()) - { - if(!Network::RecvMessage(*this, packet)) - { - Close(); - DEBUG(DBG_NETWORK , DBG_TRACE, "FH2Client::Wait: error"); - return false; - } - if(id == packet.GetID()) break; - } - DELAY(10); - } - return true; -} - -bool FH2Client::Send(QueueMessage & packet) -{ - if(!Network::SendMessage(*this, packet)) - { - packet.Dump(); - Close(); - DEBUG(DBG_NETWORK , DBG_TRACE, "FH2Client::Send: error"); - return false; - } - return true; -} - -bool FH2Client::Recv(QueueMessage & packet) -{ - if(!Network::RecvMessage(*this, packet)) - { - packet.Dump(); - Close(); - DEBUG(DBG_NETWORK , DBG_TRACE, "FH2Client::Recv: error"); - return false; - } - return true; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/client.h b/project/jni/application/fheroes2/src/fheroes2/network/client.h deleted file mode 100644 index 841b0af0e..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/client.h +++ /dev/null @@ -1,63 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2CLIENT_H -#define H2CLIENT_H - -#include "gamedefs.h" -#include "player.h" - -#ifdef WITH_NET - -#include -#include "bitmodes.h" -#include "sdlnet.h" - -enum status_t -{ - ST_CONNECT = 0x0001, - ST_INGAME = 0x0002, - ST_ADMIN = 0x0008, - ST_SHUTDOWN = 0x0010, - ST_ALLOWPLAYERS = 0x0020, - ST_LOCALSERVER = 0x0040, - ST_TURN = 0x0080 -}; - -class FH2Client : public Network::Socket, public BitModes, public Player -{ -public: - FH2Client(); - - virtual ~FH2Client(){}; - - bool IsConnected(void) const; - - bool Wait(QueueMessage &, u16); - bool Send(QueueMessage &); - bool Recv(QueueMessage &); - - QueueMessage packet; -}; - -#endif -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/localclient.cpp b/project/jni/application/fheroes2/src/fheroes2/network/localclient.cpp deleted file mode 100644 index 79c60f3e8..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/localclient.cpp +++ /dev/null @@ -1,510 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "dir.h" -#include "game.h" -#include "dialog.h" -#include "settings.h" -#include "network.h" -#include "remoteclient.h" -#include "localclient.h" -#include "cursor.h" -#include "button.h" -#include "world.h" -#include "agg.h" -#include "zzlib.h" -#include "dialog_selectscenario.h" -#include "server.h" - -#ifdef WITH_NET - -// game_scenarioinfo.cpp -void UpdateCoordOpponentsInfo(const Point &, std::vector &); -void UpdateCoordClassInfo(const Point &, std::vector &); - - - -FH2LocalClient & FH2LocalClient::Get(void) -{ - static FH2LocalClient fh2localclient; - - return fh2localclient; -} - -FH2LocalClient::FH2LocalClient() : admin_id(0) -{ - players.reserve(6); -} - -u8 GetPlayersColors(const std::vector & v) -{ - u8 res = 0; - std::vector::const_iterator it1 = v.begin(); - std::vector::const_iterator it2 = v.end(); - for(; it1 != it2; ++it1) if((*it1).player_id && (*it1).player_color) res |= (*it1).player_color; - - return res; -} - -bool FH2LocalClient::Connect(const std::string & srv, u16 port) -{ - server = srv; - IPaddress ip; - if(Network::ResolveHost(ip, srv.c_str(), port) && Open(ip)) - { - Settings::Get().SetNetworkLocalClient(true); - return true; - } - return false; -} - -void FH2LocalClient::PopPlayersInfo(QueueMessage & msg) -{ - Player cur; - u8 size, admin; - players.clear(); - admin_id = 0; - msg.Pop(size); - for(u8 ii = 0; ii < size; ++ii) - { - msg.Pop(cur.player_color); - msg.Pop(cur.player_race); - msg.Pop(cur.player_name); - msg.Pop(cur.player_id); - msg.Pop(admin); - if(admin) admin_id = cur.player_id; - if(cur.player_id) players.push_back(cur); - } -} - -int FH2LocalClient::Main(void) -{ - if(ConnectionChat()) - { - if(ScenarioInfoDialog()) - { - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - - cursor.Hide(); - display.Fill(0, 0, 0); - TextBox(_("Please wait..."), Font::BIG, Rect(0, display.h()/2, display.w(), display.h()/2)); - display.Flip(); - -/* - if(Game::IO::LoadBIN(packet)) - { - conf.SetMyColor(Color::Get(player_color)); - cursor.Hide(); - return true; - } -*/ - - StartGame(); - } - } - - Logout(); - - return 1; -} - -void FH2LocalClient::Logout(void) -{ - packet.Reset(); - packet.SetID(MSG_LOGOUT); - packet.Push(player_name); - Send(packet); - DELAY(100); - Close(); - modes = 0; - - if(Modes(ST_LOCALSERVER)) - { - FH2Server & server = FH2Server::Get(); - if(server.IsRun()) - { - server.SetExit(); - DELAY(100); - } - } -} - -bool FH2LocalClient::ConnectionChat(void) -{ - Settings & conf = Settings::Get(); - - player_color = 0; - player_race = 0; - player_name.clear(); - player_id = 0; - - // recv ready, banner - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ConnectionChat: " << "wait ready"); - if(!Wait(packet, MSG_READY)) return false; - - // get banner - std::string str; - packet.Pop(str); - - // dialog: input name - if(!Dialog::InputString("Connected to " + server + "\n \n" + str + "\n \nEnter player name:", player_name)) - return false; - - // send hello - packet.Reset(); - packet.SetID(MSG_HELLO); - packet.Push(player_name); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ConnectionChat: " << "send hello"); - if(!Send(packet)) return false; - - // recv hello, modes, player_id, cur maps - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ConnectionChat: " << "wait hello"); - if(!Wait(packet, MSG_HELLO)) return false; - packet.Pop(modes); - packet.Pop(player_id); - packet.Pop(player_color); - if(0 == player_id || 0 == player_color) DEBUG(DBG_NETWORK , DBG_WARN, "FH2LocalClient::" << "ConnectionChat: " << "player zero values"); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ConnectionChat: " << (Modes(ST_ADMIN) ? "admin" : "client") << " mode"); - - // get cur maps - Network::PacketPopMapsFileInfo(packet, conf.CurrentFileInfo()); - - // get players - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ConnectionChat: " << "wait players info"); - if(!Wait(packet, MSG_UPDATE_PLAYERS)) return false; - - MsgUpdatePlayers(); - - return true; -} - -bool FH2LocalClient::ScenarioInfoDialog(void) -{ - Settings & conf = Settings::Get(); - - // draw info dialog - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - const Point pointPanel(204, 32); - const Point pointOpponentInfo(pointPanel.x + 24, pointPanel.y + 202); - const Point pointClassInfo(pointPanel.x + 24, pointPanel.y + 282); - const Rect box(pointOpponentInfo, 360, 180); - - std::vector::const_iterator itr; - - std::vector coordColors(KINGDOMMAX); - std::vector coordRaces(KINGDOMMAX); - - UpdateCoordOpponentsInfo(pointOpponentInfo, coordColors); - UpdateCoordClassInfo(pointClassInfo, coordRaces); - - Game::Scenario::RedrawStaticInfo(pointPanel); - Game::Scenario::RedrawOpponentsInfo(pointOpponentInfo, &players); - Game::Scenario::RedrawClassInfo(pointClassInfo); - - Button buttonSelectMaps(pointPanel.x + 309, pointPanel.y + 45, ICN::NGEXTRA, 64, 65); - Button buttonOk(pointPanel.x + 31, pointPanel.y + 380, ICN::NGEXTRA, 66, 67); - Button buttonCancel(pointPanel.x + 287, pointPanel.y + 380, ICN::NGEXTRA, 68, 69); - - SpriteCursor sp; - sp.SetSprite(AGG::GetICN(ICN::NGEXTRA, 80)); - - if(! Modes(ST_ADMIN)) - { - buttonOk.Press(); - buttonOk.SetDisable(true); - buttonSelectMaps.Press(); - buttonSelectMaps.SetDisable(true); - } - - buttonSelectMaps.Draw(); - buttonOk.Draw(); - buttonCancel.Draw(); - cursor.Show(); - display.Flip(); - - bool exit = false; - bool update_info = false; - u8 change_color = Color::NONE; - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ScenarioInfoDialog: " << "start queue"); - - while(!exit && le.HandleEvents()) - { - if(Ready()) - { - if(!Recv(packet)) return false; - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ScenarioInfoDialog: " << "recv: " << Network::GetMsgString(packet.GetID())); - - switch(packet.GetID()) - { - case MSG_READY: - break; - - case MSG_CHANGE_RACE: - Network::UnpackRaceColors(packet); - update_info = true; - break; - - case MSG_UPDATE_PLAYERS: - { - MsgUpdatePlayers(); - if(Modes(ST_ADMIN)) - { - buttonOk.Release(); - buttonOk.SetDisable(false); - buttonSelectMaps.Release(); - buttonSelectMaps.SetDisable(false); - } - else - { - buttonOk.Press(); - buttonOk.SetDisable(true); - buttonSelectMaps.Press(); - buttonSelectMaps.SetDisable(true); - } - update_info = true; - break; - } - - case MSG_SET_CURRENT_MAP: - Network::PacketPopMapsFileInfo(packet, conf.CurrentFileInfo()); - UpdateCoordOpponentsInfo(pointOpponentInfo, coordColors); - UpdateCoordClassInfo(pointClassInfo, coordRaces); - update_info = true; - break; - - case MSG_MESSAGE: - break; - - case MSG_SHUTDOWN: - exit = true; - break; - - - default: break; - } - } - - if(update_info) - { - cursor.Hide(); - Game::Scenario::RedrawStaticInfo(pointPanel); - Game::Scenario::RedrawOpponentsInfo(pointOpponentInfo, &players); - Game::Scenario::RedrawClassInfo(pointClassInfo); - buttonSelectMaps.Draw(); - buttonOk.Draw(); - buttonCancel.Draw(); - cursor.Show(); - display.Flip(); - update_info = false; - } - - // press button - if(buttonSelectMaps.isEnable()) le.MousePressLeft(buttonSelectMaps) ? buttonSelectMaps.PressDraw() : buttonSelectMaps.ReleaseDraw(); - if(buttonOk.isEnable()) le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - - // click select - if(Game::HotKeyPress(Game::EVENT_BUTTON_SELECT) || - (buttonSelectMaps.isEnable() && le.MouseClickLeft(buttonSelectMaps))) - { - cursor.Hide(); - sp.Hide(); - cursor.Show(); - - // recv maps_info_list - packet.Reset(); - packet.SetID(MSG_GET_MAPS_LIST); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ScenarioInfoDialog: " << "send: " << Network::GetMsgString(packet.GetID())); - if(!Send(packet)) return false; - - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ScenarioInfoDialog: " << "wait: " << Network::GetMsgString(MSG_GET_MAPS_LIST)); - if(Wait(packet, MSG_GET_MAPS_LIST)) - { - MapsFileInfoList lists; - Network::PacketPopMapsFileInfoList(packet, lists); - - std::string filemaps; - if(Dialog::SelectScenario(lists, filemaps) && filemaps.size()) - { - // send set_maps_info - packet.Reset(); - packet.SetID(MSG_SET_CURRENT_MAP); - packet.Push(filemaps); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ScenarioInfoDialog: " << "send: " << Network::GetMsgString(packet.GetID())); - if(!Send(packet)) return false; - } - update_info = true; - } - } - else - // click cancel - if(le.MouseClickLeft(buttonCancel) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) - return false; - else - // click ok - if(Game::HotKeyPress(Game::EVENT_DEFAULT_READY) || (buttonOk.isEnable() && le.MouseClickLeft(buttonOk))) - { - packet.Reset(); - packet.SetID(MSG_START_GAME); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ScenarioInfoDialog: " << "send: " << Network::GetMsgString(packet.GetID())); - if(!Send(packet)) return false; - cursor.Hide(); - return true; - } - else - if(Modes(ST_ADMIN) && le.MouseClickLeft(box)) - { - // click colors - if(coordColors.end() != - (itr = std::find_if(coordColors.begin(), coordColors.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - { - u8 color = Color::GetFromIndex(itr - coordColors.begin()); - if((conf.PlayersColors() & color) && Color::NONE == change_color) - { - cursor.Hide(); - sp.Move((*itr).x - 3, (*itr).y - 3); - cursor.Show(); - display.Flip(); - change_color = color; - } - else - if(conf.AllowColors(color)) - { - cursor.Hide(); - sp.Hide(); - cursor.Show(); - display.Flip(); - if(Color::NONE != change_color) - { - packet.Reset(); - packet.SetID(MSG_CHANGE_COLORS); - packet.Push(change_color); - packet.Push(color); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ScenarioInfoDialog: " << "send: " << Network::GetMsgString(packet.GetID())); - if(!Send(packet)) return false; - change_color = Color::NONE; - } - } - } - else - // click races - if(coordRaces.end() != - (itr = std::find_if(coordRaces.begin(), coordRaces.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - { - u8 color = Color::GetFromIndex(itr - coordRaces.begin()); - if(conf.AllowChangeRace(color)) - { - u8 race = conf.KingdomRace(color); - switch(race) - { - case Race::KNGT: race = Race::BARB; break; - case Race::BARB: race = Race::SORC; break; - case Race::SORC: race = Race::WRLK; break; - case Race::WRLK: race = Race::WZRD; break; - case Race::WZRD: race = Race::NECR; break; - case Race::NECR: race = Race::RAND; break; - case Race::RAND: race = Race::KNGT; break; - default: break; - } - if(change_color) - { - cursor.Hide(); - sp.Hide(); - cursor.Show(); - display.Flip(); - change_color = Color::NONE; - } - if((race & Race::ALL) || race == Race::RAND) - { - packet.Reset(); - packet.SetID(MSG_CHANGE_RACE); - packet.Push(color); - packet.Push(race); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "ScenarioInfoDialog: " << "send: " << Network::GetMsgString(packet.GetID())); - if(!Send(packet)) return false; - } - } - } - } - - DELAY(10); - } - - return false; -} - -void FH2LocalClient::MsgUpdatePlayers(void) -{ - PopPlayersInfo(packet); - Settings::Get().SetPlayersColors(GetPlayersColors(players)); - std::vector::iterator itp = std::find_if(players.begin(), players.end(), std::bind2nd(std::mem_fun_ref(&Player::isID), player_id)); - if(itp != players.end()) - { - player_color = (*itp).player_color; - player_race = (*itp).player_race; - (admin_id == player_id ? SetModes(ST_ADMIN) : ResetModes(ST_ADMIN)); - } -} - -Game::menu_t Game::NetworkGuest(void) -{ - Settings & conf = Settings::Get(); - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - - // clear background - const Sprite &back = AGG::GetICN(ICN::HEROES, 0); - cursor.Hide(); - display.Blit(back); - cursor.Show(); - display.Flip(); - - std::string server; - if(!Dialog::InputString("Server Name", server)) return MAINMENU; - - FH2LocalClient & client = FH2LocalClient::Get(); - - if(! client.Connect(server, conf.GetPort())) - { - Dialog::Message(_("Error"), Network::GetError(), Font::BIG, Dialog::OK); - return Game::MAINMENU; - } - conf.SetGameType(Game::NETWORK); - - // main procedure - client.Main(); - - return QUITGAME; -} - -#else -Game::menu_t Game::NetworkGuest(void) -{ - Dialog::Message(_("Error"), _("This release is compiled without network support."), Font::BIG, Dialog::OK); - return MAINMENU; -} -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/localclient.h b/project/jni/application/fheroes2/src/fheroes2/network/localclient.h deleted file mode 100644 index 635279747..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/localclient.h +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2LOCALCLIENT_H -#define H2LOCALCLIENT_H - -#include "gamedefs.h" - -#ifdef WITH_NET - -#include "network.h" - -class heroes; -class Castle; -class Kingdom; -namespace Army { class army_t; } -namespace Battle2 { class Arena; class Result; } - -class FH2LocalClient : public FH2Client -{ -public: - static FH2LocalClient & Get(void); - - ~FH2LocalClient(){}; - - int Main(void); - bool Connect(const std::string &, u16); - void Logout(void); - - bool BattleLoop(Battle2::Arena &, Battle2::Result &); - - static void SendCastleBuyBuilding(const Castle &, u32); - static void SendCastleRecruitHero(const Castle &, const Heroes &); - static void SendCastleBuyBoat(const Castle &, u16); - static void SendCastleRecruitMonster(const Castle &, u32, u16); - - static void SendMarketSellResource(const Kingdom &, u8, u32, bool); - static void SendMarketBuyResource(const Kingdom &, u8, u32, bool); - - static void SendHeroesBuyMagicBook(const Heroes &); - static void SendHeroesSwapArtifacts(const Heroes &, u8, const Heroes &, u8); - - static void SendArmyUpgradeTroop(const Army::army_t &, u8); - static void SendArmyDismissTroop(const Army::army_t &, u8); - static void SendArmySwapTroops(const Army::army_t &, u8, const Army::army_t &, u8); - static void SendArmySplitTroop(const Army::army_t &, u8, const Army::army_t &, u8, u16); - static void SendArmyJoinTroops(const Army::army_t &, u8, const Army::army_t &, u8); - static void SendArmyCombatFormation(const Army::army_t &); - -private: - FH2LocalClient(); - - bool ConnectionChat(void); - bool ScenarioInfoDialog(void); - bool StartGame(void); - - void MsgUpdatePlayers(void); - void PopPlayersInfo(QueueMessage &); - - std::string server; - std::vector players; - u32 admin_id; -}; - -#endif -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/localclient_startgame.cpp b/project/jni/application/fheroes2/src/fheroes2/network/localclient_startgame.cpp deleted file mode 100644 index c621b1714..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/localclient_startgame.cpp +++ /dev/null @@ -1,710 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_NET - -#include -#include - -#include "agg.h" -#include "cursor.h" -#include "settings.h" -#include "dialog.h" -#include "world.h" -#include "castle.h" -#include "heroes.h" -#include "kingdom.h" -#include "army.h" -#include "battle2.h" -#include "battle_arena.h" -#include "battle_cell.h" -#include "battle_stats.h" -#include "battle_tower.h" -#include "battle_interface.h" -#include "game_interface.h" -#include "game_focus.h" -#include "localclient.h" - -namespace Game -{ - menu_t HumanTurn(void); -} - -bool FH2LocalClient::BattleLoop(Battle2::Arena & arena, Battle2::Result & result) -{ - Battle2::Interface* interface = arena.GetInterface(); - if(! interface) return false; - - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - //LocalEvent & le = LocalEvent::Get(); - //Settings & conf = Settings::Get(); - - cursor.SetThemes(Cursor::WAIT); - - cursor.Hide(); - interface->Redraw(); - cursor.Show(); - display.Flip(); - - bool exit = false; - QueueMessage packet; - - while(!exit && LocalEvent::Get().HandleEvents()) - { - if(Ready()) - { - if(!Recv(packet)) - { - Dialog::Message("Error", "FH2LocalClient::BattleLoop: recv: error", Font::BIG, Dialog::OK); - return false; - } - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "BattleLoop: " << "recv: " << Network::GetMsgString(packet.GetID())); - - switch(packet.GetID()) - { - case MSG_BATTLE_BOARD: - { - arena.UnpackBoard(packet); - break; - } - - case MSG_BATTLE_CAST: - { - u8 spell; - packet.Pop(spell); - - switch(spell) - { - case Spell::TELEPORT: - { - u16 src, dst; - packet.Pop(src); - packet.Pop(dst); - - arena.SpellActionTeleport(src, dst); - break; - } - - case Spell::EARTHQUAKE: - { - u8 id; - u32 size; - packet.Pop(size); - - std::vector targets; - while(size--) - { - packet.Pop(id); - targets.push_back(id); - } - - if(interface) interface->RedrawActionEarthQuakeSpell(targets); - break; - } - - default: - { - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "BattleLoop: " << "cast spell: " << Spell::GetName(Spell::FromInt(spell))); - - u8 color; - u16 id; - u32 size; - - packet.Pop(color); - packet.Pop(size); - - std::vector targets; - Battle2::TargetInfo target; - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "BattleLoop: " << " targets size0: " << size); - while(size--) - { - packet.Pop(id); - packet.Pop(target.damage); - packet.Pop(target.killed); - target.defender = arena.GetTroopID(id); - targets.push_back(target); - } - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "BattleLoop: " << " targets size: " << targets.size()); - - const HeroBase* hero = arena.GetArmy(color) ? arena.GetArmy(color)->GetCommander() : NULL; - - arena.TargetsApplySpell(hero, spell, targets); - if(interface) interface->RedrawActionSpellCastPart2(spell, targets); - break; - } - } - // end MSG_BATTLE_CAST - break; - } - case MSG_BATTLE_ATTACK: - { - u16 id1, id2; - u32 size; //, damage, killed; - packet.Pop(id1); - packet.Pop(size); - std::vector targets; - Battle2::TargetInfo target; - - while(size--) - { - packet.Pop(id2); - packet.Pop(target.damage); - packet.Pop(target.killed); - target.defender = arena.GetTroopID(id2); - targets.push_back(target); - } - - Battle2::Stats* attacker = arena.GetTroopID(id1); - Battle2::Stats* defender = targets.size() ? targets.front().defender : NULL; - if(attacker && defender) - { - if(interface) interface->RedrawActionAttackPart1(*attacker, *defender, targets); - arena.TargetsApplyDamage(*attacker, *defender, targets); - if(interface) interface->RedrawActionAttackPart2(*attacker, targets); - } - else - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "BattleLoop: " << "incorrect param"); - break; - } - - case MSG_BATTLE_END_TURN: - case MSG_BATTLE_MOVE: - case MSG_BATTLE_SKIP: - case MSG_BATTLE_MORALE: - case MSG_BATTLE_TOWER: - case MSG_BATTLE_CATAPULT: - arena.ApplyAction(packet); - break; - - case MSG_BATTLE_RESULT: - { - packet.Pop(result.army1); - packet.Pop(result.army2); - packet.Pop(result.exp1); - packet.Pop(result.exp2); - exit = true; - break; - } - - case MSG_BATTLE_TURN: - { - u16 id; - packet.Pop(id); - const Battle2::Stats* b = arena.GetTroopID(id); - - if(b) - { - Battle2::Actions a; - interface->HumanTurn(*b, a); - - while(a.size()) - { - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "BattleLoop: send: " << Network::GetMsgString(a.front().GetID())); - if(!Send(a.front())) return false; - a.pop_front(); - } - } - break; - } - - default: break; - } - } - } - - return true; -} - -bool FH2LocalClient::StartGame(void) -{ - Game::SetFixVideoMode(); - - Settings & conf = Settings::Get(); - -/* TEST FOR BATTLE - // cursor - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - - GameOver::Result::Get().Reset(); - - cursor.Hide(); - - AGG::FreeObject(ICN::HEROES); - AGG::FreeObject(ICN::BTNSHNGL); - AGG::FreeObject(ICN::SHNGANIM); - AGG::FreeObject(ICN::BTNNEWGM); - AGG::FreeObject(ICN::REDBACK); - AGG::FreeObject(ICN::NGEXTRA); - AGG::FreeObject(ICN::NGHSBKG); - AGG::FreeObject(ICN::REQSBKG); - AGG::FreeObject(ICN::REQUEST); - AGG::FreeObject(ICN::REQUESTS); - AGG::FreeObject(ICN::ESCROLL); - AGG::FreeObject(ICN::HSBKG); - AGG::FreeObject(ICN::HISCORE); - - if(Settings::Get().ExtLowMemory()) - { - AGG::ICNRegistryEnable(false); - AGG::ICNRegistryFreeObjects(); - } - - // preload sounds - Mixer::Reset(); -*/ - - // draw interface - Interface::Basic & I = Interface::Basic::Get(); - - Interface::GameArea & areaMaps = I.gameArea; - areaMaps.Build(); - - Game::Focus & global_focus = Game::Focus::Get(); - global_focus.Reset(); - - //Interface::Radar & radar = I.radar; - //Interface::StatusWindow& statusWin = I.statusWindow; - I.iconsPanel.ResetIcons(); - -/* - radar.Build(); - - I.Redraw(REDRAW_ICONS | REDRAW_BUTTONS | REDRAW_BORDER); - castleBar.Hide(); - heroesBar.Hide(); - - cursor.Show(); - display.Flip(); - - //Kingdom & kingdom = world.GetMyKingdom(); - - cursor.Hide(); - cursor.SetThemes(Cursor::WAIT); - cursor.Show(); - display.Flip(); -*/ - QueueMessage packet; - - while(LocalEvent::Get().HandleEvents()) - { - if(Ready()) - { - if(!Recv(packet)) - { - Dialog::Message("Error", "FH2LocalClient::StartGame: recv: error", Font::BIG, Dialog::OK); - return false; - } - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "StartGame: " << "recv: " << Network::GetMsgString(packet.GetID())); - - switch(packet.GetID()) - { -/* - case MSG_MAPS_LOAD: - { - if(Game::IO::LoadBIN(packet)) - { - conf.SetMyColor(Color::Get(player_color)); - heroesBar.Reset(); - castleBar.Reset(); - } - else - DEBUG(DBG_NETWORK , DBG_WARN, "FH2LocalClient::" << "StartGame: " << "MSG_MAPS_LOAD error"); - } - break; -*/ - case MSG_BATTLE: - { - u8 id1, id2; - u16 pos1, pos2, dst; - - packet.Pop(id1); - packet.Pop(pos1); - packet.Pop(id2); - packet.Pop(pos2); - packet.Pop(dst); - - if(id1 == 1 && id2 == 1) - { - Heroes* hero1 = world.GetHeroes(pos1); - Heroes* hero2 = world.GetHeroes(pos2); - - if(hero1 && hero2) - { - Battle2::Loader(hero1->GetArmy(), hero2->GetArmy(), dst); - } - else - DEBUG(DBG_NETWORK , DBG_WARN, "FH2LocalClient::" << "StartGame: " << "MSG_BATTLE unknown param"); - } - else - DEBUG(DBG_NETWORK , DBG_WARN, "FH2LocalClient::" << "StartGame: " << "MSG_BATTLE unknown param"); - } - break; -/* - case MSG_YOUR_TURN: - { - u8 color, percent; - packet.Pop(color); - packet.Pop(percent); - - radar.HideArea(); - conf.SetCurrentColor(Color::Get(color)); - //Interface::Basic::SetTurnProgress(percent); - - DEBUG(DBG_NETWORK , DBG_INFO, "FH2LocalClient::" << "StartGame: player: " << Color::String(color)); - world.ClearFog(color); - - if(conf.MyColor() == color) - { - if(Game::ENDTURN == Game::HumanTurn()) - { - //Network::PackKingdom(packet, kingdom); - //DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "StartGame: send MSG_KINGDOM"); - //if(!Send(packet)) return false; - - // send all heroes - //const std::vector & heroes = kingdom.GetHeroes(); - //std::vector::const_iterator ith1 = heroes.begin(); - //std::vector::const_iterator ith2 = heroes.end(); - //for(; ith1 != ith2; ++ith1) if(*ith1) - //{ - // Network::PackHero(packet, **ith1); - // DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "StartGame: send MSG_HEROES"); - // if(!Send(packet)) return false; - //} - - // send all castles - //const std::vector & castles = kingdom.GetCastles(); - //std::vector::const_iterator itc1 = castles.begin(); - //std::vector::const_iterator itc2 = castles.end(); - //for(; itc1 != itc2; ++itc1) if(*itc1) - //{ - // Network::PackCastle(packet, **itc1); - // DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "StartGame: send MSG_CASTLE"); - // if(!Send(packet)) return false; - //} - - packet.Reset(); - packet.SetID(MSG_END_TURN); - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "StartGame: send MSG_END_TURN"); - if(!Send(packet)) return false; - } - else - return true; - } - else - { - if(STATUS_AITURN != statusWin.GetState()) - { - // for pocketpc: show status window - if(conf.QVGA() && !conf.ShowStatus()) - { - conf.SetModes(Settings::SHOWSTATUS); - } - - cursor.Hide(); - - statusWin.Reset(); - statusWin.SetState(STATUS_AITURN); - - I.SetRedraw(REDRAW_GAMEAREA | REDRAW_STATUS); - - cursor.SetThemes(Cursor::WAIT); - I.Redraw(); - cursor.Show(); - display.Flip(); - } - - } - } - break; - - //case MSG_KINGDOM: - //{ - // Network::UnpackKingdom(packet); - //} - //break; - // - //case MSG_TILES: - //{ - // Network::UnpackTile(packet); - //} - //break; - // - //case MSG_HEROES: - //{ - // Network::unpackHero(packet); - //} - //break; -*/ - default: break; - } - } - } - - return true; -} - -void FH2LocalClient::SendCastleBuyBuilding(const Castle & castle, u32 build) -{ - if(!Network::isLocalClient()) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_CASTLE_BUILD); - packet.Push(castle.GetIndex()); - packet.Push(build); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendCastleBuyBuilding: " << castle.GetName() << ", build: " << Castle::GetStringBuilding(build, castle.GetRace())); - client.Send(packet); -} - -void FH2LocalClient::SendCastleRecruitHero(const Castle & castle, const Heroes & hero) -{ - if(!Network::isLocalClient()) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_CASTLE_RECRUIT_HERO); - packet.Push(castle.GetIndex()); - packet.Push(static_cast(hero.GetID())); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendCastleRecruitHero: " << castle.GetName() << ", recruit: " << hero.GetName()); - client.Send(packet); -} - -void FH2LocalClient::SendCastleBuyBoat(const Castle & castle, u16 index) -{ - if(!Network::isLocalClient()) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_CASTLE_BUY_BOAT); - packet.Push(castle.GetIndex()); - packet.Push(index); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendCastleBuyBoat: " << castle.GetName() << ", index: " << index); - client.Send(packet); -} - -void FH2LocalClient::SendCastleRecruitMonster(const Castle & castle, u32 dwelling, u16 count) -{ - if(!Network::isLocalClient()) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_CASTLE_RECRUIT_MONSTER); - packet.Push(castle.GetIndex()); - packet.Push(dwelling); - packet.Push(count); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendCastleRecruitMonster: " << castle.GetName()); - client.Send(packet); -} - -void FH2LocalClient::SendMarketSellResource(const Kingdom & kingdom, u8 resource, u32 count, bool tradingPost) -{ - if(!Network::isLocalClient()) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_MARKET_SELL_RESOURCE); - packet.Push(static_cast(tradingPost)); - packet.Push(static_cast(kingdom.GetColor())); - packet.Push(resource); - packet.Push(count); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendMarketSellResource: " << Resource::String(resource) << "(" << count << ")"); - client.Send(packet); -} - -void FH2LocalClient::SendMarketBuyResource(const Kingdom & kingdom, u8 resource, u32 count, bool tradingPost) -{ - if(!Network::isLocalClient()) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_MARKET_BUY_RESOURCE); - packet.Push(static_cast(tradingPost)); - packet.Push(static_cast(kingdom.GetColor())); - packet.Push(resource); - packet.Push(count); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendMarketBuyResource: " << Resource::String(resource) << "(" << count << ")"); - client.Send(packet); -} - -void FH2LocalClient::SendHeroesBuyMagicBook(const Heroes & hero) -{ - if(!Network::isLocalClient()) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_HEROES_BUY_MAGICBOOK); - packet.Push(static_cast(hero.GetID())); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendHeroesBuyMagicBook: " << hero.GetName()); - client.Send(packet); -} - -void FH2LocalClient::SendHeroesSwapArtifacts(const Heroes & hero1, u8 index1, const Heroes & hero2, u8 index2) -{ - if(!Network::isLocalClient()) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_HEROES_SWAP_ARTIFACTS); - packet.Push(static_cast(hero1.GetID())); - packet.Push(index1); - packet.Push(static_cast(hero2.GetID())); - packet.Push(index2); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendHeroesSwapArtifacts: "); - client.Send(packet); -} - -void FH2LocalClient::SendArmyUpgradeTroop(const Army::army_t & army, u8 index) -{ - const HeroBase* commander = army.GetCommander(); - if(!Network::isLocalClient() || !commander) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_ARMY_UPGRADE_TROOP); - packet.Push(static_cast(commander->GetType())); - packet.Push(commander->GetIndex()); - packet.Push(index); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendArmyUpgradeTroop: "); - client.Send(packet); -} - -void FH2LocalClient::SendArmyDismissTroop(const Army::army_t & army, u8 index) -{ - const HeroBase* commander = army.GetCommander(); - if(!Network::isLocalClient() || !commander) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_ARMY_DISMISS_TROOP); - packet.Push(static_cast(commander->GetType())); - packet.Push(commander->GetIndex()); - packet.Push(index); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendArmyDismissTroop: "); - client.Send(packet); -} - -void FH2LocalClient::SendArmySwapTroops(const Army::army_t & army1, u8 index1, const Army::army_t & army2, u8 index2) -{ - const HeroBase* commander1 = army1.GetCommander(); - const HeroBase* commander2 = army2.GetCommander(); - if(!Network::isLocalClient() || !commander1 || !commander2) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_ARMY_SWAP_TROOPS); - packet.Push(static_cast(commander1->GetType())); - packet.Push(commander1->GetIndex()); - packet.Push(index1); - packet.Push(static_cast(commander2->GetType())); - packet.Push(commander2->GetIndex()); - packet.Push(index2); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendArmySwapTroop: "); - client.Send(packet); -} - -void FH2LocalClient::SendArmySplitTroop(const Army::army_t & army1, u8 index1, const Army::army_t & army2, u8 index2, u16 count) -{ - const HeroBase* commander1 = army1.GetCommander(); - const HeroBase* commander2 = army2.GetCommander(); - if(!Network::isLocalClient() || !commander1 || !commander2) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_ARMY_SPLIT_TROOP); - packet.Push(static_cast(commander1->GetType())); - packet.Push(commander1->GetIndex()); - packet.Push(index1); - packet.Push(static_cast(commander2->GetType())); - packet.Push(commander2->GetIndex()); - packet.Push(index2); - packet.Push(count); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendArmySplitTroop: "); - client.Send(packet); -} - -void FH2LocalClient::SendArmyJoinTroops(const Army::army_t & army1, u8 index1, const Army::army_t & army2, u8 index2) -{ - const HeroBase* commander1 = army1.GetCommander(); - const HeroBase* commander2 = army2.GetCommander(); - if(!Network::isLocalClient() || !commander1 || !commander2) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_ARMY_JOIN_TROOP); - packet.Push(static_cast(commander1->GetType())); - packet.Push(commander1->GetIndex()); - packet.Push(index1); - packet.Push(static_cast(commander2->GetType())); - packet.Push(commander2->GetIndex()); - packet.Push(index2); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendArmyJoinTroop: "); - client.Send(packet); -} - -void FH2LocalClient::SendArmyCombatFormation(const Army::army_t & army) -{ - const HeroBase* commander = army.GetCommander(); - if(!Network::isLocalClient() || !commander) return; - - FH2LocalClient & client = FH2LocalClient::Get(); - QueueMessage packet; - - packet.SetID(MSG_ARMY_COMBAT_FORMATION); - packet.Push(static_cast(commander->GetType())); - packet.Push(commander->GetIndex()); - packet.Push(army.GetCombatFormat()); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2LocalClient::" << "SendArmyCombatFormation: "); - client.Send(packet); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/network.cpp b/project/jni/application/fheroes2/src/fheroes2/network/network.cpp deleted file mode 100644 index b3f2dfa71..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/network.cpp +++ /dev/null @@ -1,386 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include - -#include "sdlnet.h" -#include "settings.h" -#include "server.h" -#include "error.h" -#include "remoteclient.h" -#include "localclient.h" -#include "kingdom.h" -#include "castle.h" -#include "heroes.h" -#include "game_io.h" -#include "maps_tiles.h" -#include "world.h" -#include "network.h" - -#ifdef WITH_NET - -const char* Network::GetMsgString(u16 msg) -{ - switch(msg) - { - case MSG_RAW: return "MSG_RAW"; - - case MSG_PING: return "MSG_PING"; - case MSG_READY: return "MSG_READY"; - case MSG_MESSAGE: return "MSG_MESSAGE"; - - case MSG_HELLO: return "MSG_HELLO"; - case MSG_LOGOUT: return "MSG_LOGOUT"; - case MSG_SHUTDOWN: return "MSG_SHUTDOWN"; - case MSG_ACCESS_DENIED: return "MSG_ACCESS_DENIED"; - - case MSG_UPDATE_PLAYERS: return "MSG_UPDATE_PLAYERS"; - case MSG_GET_MAPS_LIST: return "MSG_GET_MAPS_LIST"; - case MSG_SET_CURRENT_MAP: return "MSG_SET_CURRENT_MAP"; - case MSG_CHANGE_COLORS: return "MSG_CHANGE_COLORS"; - case MSG_CHANGE_RACE: return "MSG_CHANGE_RACE"; - - - case MSG_START_GAME: return "MSG_START_GAME"; - case MSG_MAPS_LOAD: return "MSG_MAPS_LOAD"; - case MSG_MAPS_LOAD_ERR: return "MSG_MAPS_LOAD_ERR"; - - - case MSG_CASTLE_BUILD: return "MSG_CASTLE_BUILD"; - case MSG_CASTLE_RECRUIT_HERO: return "MSG_CASTLE_RECRUIT_HERO"; - case MSG_CASTLE_BUY_BOAT: return "MSG_CASTLE_BUY_BOAT"; - case MSG_CASTLE_RECRUIT_MONSTER:return "MSG_CASTLE_RECRUIT_MONSTER"; - - case MSG_MARKET_SELL_RESOURCE: return "MSG_MARKET_SELL_RESOURCE"; - case MSG_MARKET_BUY_RESOURCE: return "MSG_MARKET_BUY_RESOURCE"; - - case MSG_HEROES_BUY_MAGICBOOK: return "MSG_HEROES_BUY_MAGICBOOK"; - case MSG_HEROES_SWAP_ARTIFACTS: return "MSG_HEROES_SWAP_ARTIFACTS"; - - case MSG_ARMY_UPGRADE_TROOP: return "MSG_ARMY_UPGRADE_TROOP"; - case MSG_ARMY_DISMISS_TROOP: return "MSG_ARMY_DISMISS_TROOP"; - case MSG_ARMY_SWAP_TROOPS: return "MSG_ARMY_SWAP_TROOPS"; - case MSG_ARMY_SPLIT_TROOP: return "MSG_ARMY_SPLIT_TROOP"; - case MSG_ARMY_JOIN_TROOP: return "MSG_ARMY_JOIN_TROOP"; - case MSG_ARMY_COMBAT_FORMATION: return "MSG_ARMY_COMBAT_FORMATION"; - - case MSG_BATTLE_BOARD: return "MSG_BATTLE_BOARD"; - case MSG_BATTLE_MOVE: return "MSG_BATTLE_MOVE"; - case MSG_BATTLE_ATTACK: return "MSG_BATTLE_ATTACK"; - case MSG_BATTLE_DEFENSE: return "MSG_BATTLE_DEFENSE"; - case MSG_BATTLE_DAMAGE: return "MSG_BATTLE_DAMAGE"; - case MSG_BATTLE_CAST: return "MSG_BATTLE_CAST"; - case MSG_BATTLE_SKIP: return "MSG_BATTLE_SKIP"; - case MSG_BATTLE_MORALE: return "MSG_BATTLE_MORALE"; - case MSG_BATTLE_LUCK: return "MSG_BATTLE_LUCK"; - case MSG_BATTLE_CATAPULT: return "MSG_BATTLE_CATAPULT"; - case MSG_BATTLE_TOWER: return "MSG_BATTLE_TOWER"; - case MSG_BATTLE_END_TURN: return "MSG_BATTLE_END_TURN"; - case MSG_BATTLE_RETREAT: return "MSG_BATTLE_RETREAT"; - case MSG_BATTLE_SURRENDER: return "MSG_BATTLE_SURRENDER"; - case MSG_BATTLE_TURN: return "MSG_BATTLE_TURN"; - case MSG_BATTLE_RESULT: return "MSG_BATTLE_RESULT"; - - case MSG_YOUR_TURN: return "MSG_YOUR_TURN"; - case MSG_END_TURN: return "MSG_END_TURN"; - case MSG_TILES: return "MSG_TILES"; - case MSG_HEROES: return "MSG_HEROES"; - case MSG_BATTLE: return "MSG_BATTLE"; - case MSG_CASTLE: return "MSG_CASTLE"; - case MSG_SPELL: return "MSG_SPELL"; - case MSG_MAPS: return "MSG_MAPS"; - case MSG_KINGDOM: return "MSG_KINGDOM"; - case MSG_WORLD: return "MSG_WORLD"; - - default: break; - } - - return "MSG_UNKNOWN"; -} - -msg_t Network::GetMsg(u16 msg) -{ - return msg < MSG_UNKNOWN ? static_cast(msg) : MSG_UNKNOWN; -} - -bool Network::isLocalClient(void) -{ - Settings & conf = Settings::Get(); - return conf.GameType() == Game::NETWORK && conf.NetworkLocalClient() && !conf.NetworkDedicatedServer(); -} - -bool Network::isRemoteClient(void) -{ - Settings & conf = Settings::Get(); - return conf.GameType() == Game::NETWORK && !isLocalClient(); -} - -bool Network::MsgIsBroadcast(u16 msg) -{ - switch(msg) - { - case MSG_SHUTDOWN: - case MSG_MESSAGE: - return true; - } - return false; -} - -int Network::RunDedicatedServer(void) -{ - Settings & conf = Settings::Get(); - - Network::SetProtocolVersion(static_cast((conf.MajorVersion() << 8)) | conf.MinorVersion()); - - if(SDL::Init(INIT_TIMER)) - try - { - std::atexit(SDL::Quit); - - FH2Server & server = FH2Server::Get(); - - if(! server.Bind(conf.GetPort())) - { - DEBUG(DBG_NETWORK , DBG_WARN, "Network::RunDedicatedServer: " << Network::GetError()); - return -1; - } - - conf.SetNetworkDedicatedServer(true); - conf.SetGameType(Game::NETWORK); - - return FH2Server::callbackCreateThread(&server); - } - catch(std::bad_alloc) - { - } - catch(Error::Exception) - { - conf.Dump(); - } - - return 0; -} - -void Network::PacketPopMapsFileInfoList(QueueMessage & packet, MapsFileInfoList & flist) -{ - flist.clear(); - u16 count; - packet.Pop(count); - for(u16 ii = 0; ii < count; ++ii) - { - Maps::FileInfo fi; - PacketPopMapsFileInfo(packet, fi); - flist.push_back(fi); - } -} - -void Network::PacketPushMapsFileInfo(QueueMessage & packet, const Maps::FileInfo & fi) -{ - packet.Push(fi.file); - packet.Push(fi.name); - packet.Push(fi.description); - packet.Push(fi.size_w); - packet.Push(fi.size_h); - packet.Push(fi.difficulty); - - packet.Push(static_cast(KINGDOMMAX)); - for(u8 ii = 0; ii < KINGDOMMAX; ++ii) packet.Push(fi.races[ii]); - - packet.Push(fi.kingdom_colors); - packet.Push(fi.human_colors); - packet.Push(fi.computer_colors); - packet.Push(fi.rnd_races); - packet.Push(fi.conditions_wins); - packet.Push(fi.wins1); - packet.Push(fi.wins2); - packet.Push(fi.wins3); - packet.Push(fi.wins4); - packet.Push(fi.conditions_loss); - packet.Push(fi.loss1); - packet.Push(fi.loss2); - packet.Push(static_cast(fi.localtime)); - packet.Push(static_cast(fi.with_heroes)); -} - -void Network::PacketPopMapsFileInfo(QueueMessage & packet, Maps::FileInfo & fi) -{ - u8 byte8, race; - u32 byte32; - - packet.Pop(fi.file); - packet.Pop(fi.name); - packet.Pop(fi.description); - packet.Pop(fi.size_w); - packet.Pop(fi.size_h); - packet.Pop(fi.difficulty); - - packet.Pop(byte8); - for(u8 ii = 0; ii < byte8; ++ii){ packet.Pop(race); fi.races[ii] = race; } - - packet.Pop(fi.kingdom_colors); - packet.Pop(fi.human_colors); - packet.Pop(fi.computer_colors); - packet.Pop(fi.rnd_races); - packet.Pop(fi.conditions_wins); - packet.Pop(fi.wins1); - packet.Pop(fi.wins2); - packet.Pop(fi.wins3); - packet.Pop(fi.wins4); - packet.Pop(fi.conditions_loss); - packet.Pop(fi.loss1); - packet.Pop(fi.loss2); - packet.Pop(byte32); - fi.localtime = byte32; - packet.Pop(byte8); - fi.with_heroes = byte8; -} - -void Network::PacketPushPlayersInfo(QueueMessage & m, const std::vector & v, u32 exclude) -{ - u8 count = std::count_if(v.begin(), v.end(), std::not1(std::bind2nd(std::mem_fun_ref(&Player::isID), 0))); - m.Push(count); - - if(count) - { - std::vector::const_iterator itc1 = v.begin(); - std::vector::const_iterator itc2 = v.end(); - for(; itc1 != itc2; ++itc1) if((*itc1).player_id && (*itc1).player_id != exclude) - { - m.Push((*itc1).player_color); - m.Push((*itc1).player_race); - m.Push((*itc1).player_name); - m.Push((*itc1).player_id); - m.Push(static_cast((*itc1).Modes(ST_ADMIN))); - } - } -} - -void Network::PackRaceColors(QueueMessage & m) -{ - m.Push(static_cast(KINGDOMMAX)); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - { - m.Push(static_cast(color)); - m.Push(static_cast(Settings::Get().KingdomRace(color))); - } -} - -void Network::UnpackRaceColors(QueueMessage & m) -{ - u8 max, color, race; - - m.Pop(max); - if(max == KINGDOMMAX) - { - for(u8 ii = 0; ii < max; ++ii) - { - m.Pop(color); - m.Pop(race); - Settings::Get().SetKingdomRace(color, race); - } - } -} - -u8 Network::GetPlayersColors(const std::vector & v) -{ - u8 res = 0; - std::vector::const_iterator it1 = v.begin(); - std::vector::const_iterator it2 = v.end(); - for(; it1 != it2; ++it1) if((*it1).player_id && (*it1).player_color) res |= (*it1).player_color; - - return res; -} - -void Network::PackKingdom(QueueMessage & msg, const Kingdom & kingdom) -{ - msg.Reset(); - msg.SetID(MSG_KINGDOM); - msg.Push(static_cast(kingdom.GetColor())); - Game::IO::PackKingdom(msg, kingdom); -} - -void Network::UnpackKingdom(QueueMessage & msg) -{ - u8 kingdom_color; - msg.Pop(kingdom_color); - Kingdom & kingdom = world.GetKingdom(kingdom_color); - Game::IO::UnpackKingdom(msg, kingdom); -} - -void Network::PackHero(QueueMessage & msg, const Heroes & hero) -{ - msg.Reset(); - msg.SetID(MSG_HEROES); - msg.Push(static_cast(hero.GetID())); - Game::IO::PackHeroes(msg, hero); -} - -void Network::UnpackHero(QueueMessage & msg) -{ - u8 hero_id; - msg.Pop(hero_id); - Heroes *hero = world.GetHeroes(Heroes::ConvertID(hero_id)); - if(hero) - Game::IO::UnpackHeroes(msg, *hero); - else - DEBUG(DBG_NETWORK, DBG_WARN, "Network::UnpackHero: unknown hero id"); -} - -void Network::PackTile(QueueMessage & msg, const Maps::Tiles & tile) -{ - msg.Reset(); - msg.SetID(MSG_TILES); - msg.Push(tile.GetIndex()); - Game::IO::PackTile(msg, tile); -} - -void Network::UnpackTile(QueueMessage & msg) -{ - s32 tile_index; - msg.Pop(tile_index); - Maps::Tiles & tile = world.GetTiles(tile_index); - Game::IO::UnpackTile(msg, tile); -} - -void Network::PackCastle(QueueMessage & msg, const Castle & castle) -{ - msg.Reset(); - msg.SetID(MSG_CASTLE); - msg.Push(castle.GetIndex()); - Game::IO::PackCastle(msg, castle); -} - -void Network::UnpackCastle(QueueMessage & msg) -{ - s32 castle_index; - msg.Pop(castle_index); - Castle *castle = world.GetCastle(castle_index); - if(castle) - Game::IO::UnpackCastle(msg, *castle); - else - DEBUG(DBG_NETWORK, DBG_WARN, "Network::UnpackCastle: unknown index id"); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/network.h b/project/jni/application/fheroes2/src/fheroes2/network/network.h deleted file mode 100644 index 0df0dfd13..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/network.h +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2NETWORK_H -#define H2NETWORK_H - -#include "sdlnet.h" -#include "gamedefs.h" - -enum msg_t -{ - MSG_RAW, - - MSG_PING, - MSG_READY, - MSG_MESSAGE, - - MSG_HELLO, - MSG_LOGOUT, - MSG_SHUTDOWN, - MSG_ACCESS_DENIED, - - MSG_UPDATE_PLAYERS, - MSG_GET_MAPS_LIST, - MSG_SET_CURRENT_MAP, - MSG_CHANGE_COLORS, - MSG_CHANGE_RACE, - - MSG_START_GAME, - MSG_MAPS_LOAD, - MSG_MAPS_LOAD_ERR, - - - MSG_YOUR_TURN, - MSG_END_TURN, - - MSG_CASTLE_BUILD, - MSG_CASTLE_RECRUIT_HERO, - MSG_CASTLE_BUY_BOAT, - MSG_CASTLE_RECRUIT_MONSTER, - - MSG_MARKET_SELL_RESOURCE, - MSG_MARKET_BUY_RESOURCE, - - MSG_HEROES_BUY_MAGICBOOK, - MSG_HEROES_SWAP_ARTIFACTS, - - MSG_ARMY_UPGRADE_TROOP, - MSG_ARMY_DISMISS_TROOP, - MSG_ARMY_SWAP_TROOPS, - MSG_ARMY_JOIN_TROOP, - MSG_ARMY_SPLIT_TROOP, - MSG_ARMY_COMBAT_FORMATION, - - MSG_BATTLE_BOARD, - MSG_BATTLE_MOVE, - MSG_BATTLE_ATTACK, - MSG_BATTLE_DEFENSE, - MSG_BATTLE_DAMAGE, - MSG_BATTLE_CAST, - MSG_BATTLE_MORALE, - MSG_BATTLE_LUCK, - MSG_BATTLE_CATAPULT, - MSG_BATTLE_TOWER, - MSG_BATTLE_RETREAT, - MSG_BATTLE_SURRENDER, - MSG_BATTLE_SKIP, - MSG_BATTLE_END_TURN, - MSG_BATTLE_TURN, - MSG_BATTLE_RESULT, - - MSG_TILES, - MSG_HEROES, - MSG_BATTLE, - MSG_CASTLE, - MSG_SPELL, - MSG_MAPS, - MSG_KINGDOM, - MSG_WORLD, - - MSG_UNKNOWN -}; - -#ifdef WITH_NET - -#include "client.h" -#include "maps_fileinfo.h" - -typedef std::pair MessageID; -class FH2RemoteClient; -class Kingdom; -class Heroes; -class Castle; -namespace Maps { class Tiles; } - - -namespace Network -{ - int RunDedicatedServer(void); - const char* GetMsgString(u16); - msg_t GetMsg(u16); - bool MsgIsBroadcast(u16); - - bool isLocalClient(void); - bool isRemoteClient(void); - - void PacketPopMapsFileInfoList(QueueMessage &, MapsFileInfoList &); - void PacketPushMapsFileInfo(QueueMessage &, const Maps::FileInfo &); - void PacketPopMapsFileInfo(QueueMessage &, Maps::FileInfo &); - void PacketPushPlayersInfo(QueueMessage &, const std::vector &, u32 exclude = 0); - - void PackRaceColors(QueueMessage &); - void UnpackRaceColors(QueueMessage &); - - u8 GetPlayersColors(const std::vector &); - - void PackKingdom(QueueMessage &, const Kingdom &); - void UnpackKingdom(QueueMessage &); - - void PackTile(QueueMessage &, const Maps::Tiles &); - void UnpackTile(QueueMessage &); - - void PackHero(QueueMessage &, const Heroes &); - void UnpackHero(QueueMessage &); - - void PackCastle(QueueMessage &, const Castle &); - void UnpackCastle(QueueMessage &); -} - -#endif - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/player.cpp b/project/jni/application/fheroes2/src/fheroes2/network/player.cpp deleted file mode 100644 index f0a2260c2..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/player.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "color.h" -#include "settings.h" -#include "player.h" - -void Player::FixRandomRace(Player & p) -{ - if(p.player_id && p.player_color && Color::GRAY != p.player_color) - p.player_race = Settings::Get().KingdomRace(Color::Get(p.player_color)); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/network/player.h b/project/jni/application/fheroes2/src/fheroes2/network/player.h deleted file mode 100644 index 31e032b93..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/player.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2PLAYER_H -#define H2PLAYER_H - -#include -#include "gamedefs.h" - -class Player -{ -public: - Player() : player_color(0) {} - - bool isID(u32 id) const { return id == player_id; } - bool isColor(u8 color) const { return color == player_color; } - bool isName(const std::string & name) const { return name == player_name; } - - static void FixRandomRace(Player &); - - u8 player_color; - u8 player_race; - std::string player_name; - u32 player_id; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/remoteclient.cpp b/project/jni/application/fheroes2/src/fheroes2/network/remoteclient.cpp deleted file mode 100644 index e92c9f9b9..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/remoteclient.cpp +++ /dev/null @@ -1,439 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_NET - -#include -#include -#include -#include "world.h" -#include "settings.h" -#include "server.h" -#include "client.h" -#include "kingdom.h" -#include "battle2.h" -#include "battle_stats.h" -#include "remoteclient.h" -#include "zzlib.h" - -int FH2RemoteClient::callbackCreateThread(void *data) -{ - return data ? reinterpret_cast(data)->Main() : -1; -} - -FH2RemoteClient::FH2RemoteClient() -{ -} - -void FH2RemoteClient::RunThread(void) -{ - if(thread.IsRun()) thread.Wait(); - thread.Create(callbackCreateThread, this); -} - -void FH2RemoteClient::ShutdownThread(void) -{ - SetModes(ST_SHUTDOWN); - DELAY(100); - - if(thread.IsRun()) thread.Kill(); - - if(sd) - { - packet.Reset(); - packet.SetID(MSG_SHUTDOWN); - Network::SendMessage(*this, packet); - CloseConnection(); - } - SetModes(0); -} - -void FH2RemoteClient::CloseConnection(void) -{ - Close(); - - modes = 0; - player_id = 0; - player_color = 0; -} - -int FH2RemoteClient::Main(void) -{ - if(ConnectionChat()) - { - FH2Server & server = FH2Server::Get(); - - server.Lock(); - server.SetStartGame(); - server.Unlock(); - - StartGame(); - } - - CloseConnection(); - - return 1; -} - -bool FH2RemoteClient::ConnectionChat(void) -{ - Settings & conf = Settings::Get(); - - player_color = 0; - player_race = Race::RAND; - player_name.clear(); - - // wait thread id - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "ConnectionChat: " << "wait start thread"); - while(0 == thread.GetID()){ DELAY(10); }; - player_id = thread.GetID(); - - SetModes(ST_CONNECT); - - // send banner - std::ostringstream banner; - banner << "Free Heroes II Server, version: " << static_cast(conf.MajorVersion()) << "." << static_cast(conf.MinorVersion()) << std::endl; - - packet.Reset(); - packet.SetID(MSG_READY); - packet.Push(banner.str()); - - // send ready - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "ConnectionChat: " << "id: 0x" << std::hex << player_id << ", send ready"); - if(!Send(packet)) return false; - - // recv hello - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "ConnectionChat: " << "id: 0x" << std::hex << player_id << ", wait hello"); - if(!Wait(packet, MSG_HELLO)) return false; - - packet.Pop(player_name); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "ConnectionChat: " << "id: 0x" << std::hex << player_id << ", connected " << " player: " << player_name << ", host 0x" << std::hex << Host() << ":0x" << Port()); - - FH2Server & server = FH2Server::Get(); - - // check color - server.Lock(); - player_color = Color::GetFirst(conf.CurrentFileInfo().human_colors & (~conf.PlayersColors())); - server.Unlock(); - if(0 == player_color) - { - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "ConnectionChat: " << "id: 0x" << std::hex << player_id << ", player_color = 0, logout"); - return false; - } - - // send hello, modes, id, color, cur maps - packet.Reset(); - packet.SetID(MSG_HELLO); - packet.Push(modes); - packet.Push(player_id); - packet.Push(player_color); - // added cur maps info - Network::PacketPushMapsFileInfo(packet, conf.CurrentFileInfo()); - // send - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::" << "ConnectionChat: " << "id: 0x" << std::hex << player_id << ", send hello"); - if(!Send(packet)) return false; - - // update colors - server.Lock(); - conf.SetPlayersColors(server.GetPlayersColors()); - server.Unlock(); - - // send to all: update players - SendUpdatePlayers(0); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::" << "ConnectionChat: " << (Modes(ST_ADMIN) ? "admin" : "client") << " mode"); - if(Modes(ST_ADMIN)) SetModes(ST_ALLOWPLAYERS); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::" << "ConnectionChat: " << "start queue"); - - while(1) - { - if(Modes(ST_SHUTDOWN)) return false; - - if(Ready()) - { - if(!Recv(packet)) return false; - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::" << "ConnectionChat: " << "recv: " << Network::GetMsgString(packet.GetID())); - - // check broadcast - MsgBroadcast(); - - // msg processing - switch(Network::GetMsg(packet.GetID())) - { - case MSG_PING: - MsgPing(); - break; - - case MSG_LOGOUT: - MsgLogout(); - return false; - - case MSG_CHANGE_COLORS: - if(Modes(ST_ADMIN)) MsgChangeColors(); - break; - - case MSG_CHANGE_RACE: - if(Modes(ST_ADMIN)) MsgChangeRace(); - break; - - case MSG_SET_CURRENT_MAP: - { - std::string str; - packet.Pop(str); - - if(Modes(ST_ADMIN) && - Settings::Get().LoadFileMapsMP2(str) && !SendSetCurrentMap()) return false; - } - break; - - case MSG_GET_MAPS_LIST: - if(Modes(ST_ADMIN)) - { - if(!SendMapsInfoList()) return false; - } - else - { - if(!SendAccessDenied()) return false; - } - break; - - case MSG_START_GAME: - if(Modes(ST_ADMIN)) return true; - break; - - default: - break; - } - } - - DELAY(100); - } - - return false; -} - -bool FH2RemoteClient::StartGame(void) -{ - //Settings & conf = Settings::Get(); - //FH2Server & server = FH2Server::Get(); - bool exit = false; - - while(!exit) - { - if(Modes(ST_SHUTDOWN)) return false; - - if(Ready()) - { - if(!Recv(packet)) return false; - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "StartGame: " << "recv: " << Network::GetMsgString(packet.GetID())); - - // check broadcast - MsgBroadcast(); - - // msg processing - switch(Network::GetMsg(packet.GetID())) - { - case MSG_PING: - MsgPing(); - break; - - case MSG_LOGOUT: - MsgLogout(); - return false; - - case MSG_TILES: - Network::UnpackTile(packet); - break; - - case MSG_CASTLE: - Network::UnpackCastle(packet); - break; - - case MSG_HEROES: - Network::UnpackHero(packet); - break; - - case MSG_KINGDOM: - Network::UnpackKingdom(packet); - break; - - case MSG_END_TURN: - // FIX FIX: check heroes and castles for current kingdom - ResetModes(ST_TURN); - break; - - default: - break; - } - } - - DELAY(100); - } - - return true; -} - -void FH2RemoteClient::MsgBroadcast(void) -{ - if(MSG_UNKNOWN != Network::GetMsg(packet.GetID()) && Network::MsgIsBroadcast(packet.GetID())) - { - FH2Server & server = FH2Server::Get(); - - server.Lock(); - server.SendToAllClients(packet, player_id); - server.Unlock(); - } -} - -void FH2RemoteClient::MsgPing(void) -{ - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "MsgPing:"); - packet.Reset(); - packet.SetID(MSG_PING); - Network::SendMessage(*this, packet); -} - -void FH2RemoteClient::MsgLogout(void) -{ - // send message - packet.Reset(); - packet.SetID(MSG_MESSAGE); - std::string str = "logout player: " + player_name; - packet.Push(str); - - FH2Server & server = FH2Server::Get(); - Settings & conf = Settings::Get(); - - server.Lock(); - server.SendToAllClients(packet, player_id); - if(Modes(ST_ADMIN)) server.SetNewAdmin(player_id); - server.Unlock(); - // - conf.SetPlayersColors(server.GetPlayersColors() & (~player_color)); - if(Modes(ST_INGAME)) world.GetKingdom(player_color).SetControl(Game::AI); // FIXME: MSGLOGOUT: INGAME AND CURRENT TURN? - // send players - SendUpdatePlayers(player_id); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "MsgLogout: " << str); -} - -void FH2RemoteClient::MsgChangeRace(void) -{ - FH2Server & server = FH2Server::Get(); - Settings & conf = Settings::Get(); - u8 color, race; - - packet.Pop(color); - packet.Pop(race); - - if(conf.AllowChangeRace(color)) - { - conf.SetKingdomRace(color, race); - packet.Reset(); - packet.SetID(MSG_CHANGE_RACE); - server.Lock(); - server.ChangeClientRace(color, race); - Network::PackRaceColors(packet); - server.SendToAllClients(packet); - server.Unlock(); - } -} - -void FH2RemoteClient::MsgChangeColors(void) -{ - FH2Server & server = FH2Server::Get(); - Settings & conf = Settings::Get(); - u8 from, to; - - packet.Pop(from); - packet.Pop(to); - - if(conf.AllowColors(from) && conf.AllowColors(to)) - { - server.Lock(); - server.ChangeClientColors(from, to); - server.Unlock(); - SendUpdatePlayers(0); - } -} - -void FH2RemoteClient::SendUpdatePlayers(u32 exclude) -{ - FH2Server & server = FH2Server::Get(); - packet.Reset(); - packet.SetID(MSG_UPDATE_PLAYERS); - server.Lock(); - server.PushPlayersInfo(packet, exclude); - server.SendToAllClients(packet, exclude); - server.Unlock(); -} - -bool FH2RemoteClient::SendSetCurrentMap(void) -{ - FH2Server & server = FH2Server::Get(); - Settings & conf = Settings::Get(); - - packet.Reset(); - packet.SetID(MSG_SET_CURRENT_MAP); - server.Lock(); - Network::PacketPushMapsFileInfo(packet, conf.CurrentFileInfo()); - server.SendToAllClients(packet, 0); - server.Unlock(); - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "SendSetCurrentMap:"); - if(!Send(packet)) return false; - - // reset players - server.Lock(); - server.ResetPlayers(); - server.Unlock(); - - // send players - SendUpdatePlayers(0); - - return true; -} - -bool FH2RemoteClient::SendAccessDenied(void) -{ - packet.Reset(); - packet.SetID(MSG_ACCESS_DENIED); - - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "SendAccessDenied: "); - return Send(packet); -} - -bool FH2RemoteClient::SendMapsInfoList(void) -{ - FH2Server & server = FH2Server::Get(); - - packet.Reset(); - packet.SetID(MSG_GET_MAPS_LIST); - - server.Lock(); - server.PushMapsFileInfoList(packet); - server.Unlock(); - - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::" << "SendMapsInfoList: "); - return Send(packet); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/remoteclient.h b/project/jni/application/fheroes2/src/fheroes2/network/remoteclient.h deleted file mode 100644 index 0aab6f885..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/remoteclient.h +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2REMOTECLIENT_H -#define H2REMOTECLIENT_H - -#ifdef WITH_NET - -#include "gamedefs.h" -#include "thread.h" -#include "network.h" - -class FH2Server; -namespace Battle2 -{ - class Actions; - class Arena; - class Stats; - struct Result; - struct TargetInfo; -} - -class FH2RemoteClient : public FH2Client -{ -public: - FH2RemoteClient(); - - int Main(void); - bool ConnectionChat(void); - bool StartGame(void); - void CloseConnection(void); - - void RunThread(void); - void ShutdownThread(void); - - void MsgBroadcast(void); - void MsgPing(void); - void MsgLogout(void); - void MsgChangeColors(void); - void MsgChangeRace(void); - - bool RecvBattleHumanTurn(const Battle2::Stats &, const Battle2::Arena & arena, Battle2::Actions &); - - bool SendSetCurrentMap(void); - bool SendMapsInfoList(void); - bool SendAccessDenied(void); - void SendUpdatePlayers(u32 exclude); - - static bool SendBattleAction(u8, QueueMessage &); - static bool SendBattleResult(u8, const Battle2::Result &); - static bool SendBattleAttack(u8, u16, const std::vector &); - static bool SendBattleBoard(u8, const Battle2::Arena &); - static bool SendBattleSpell(u8, u8, u8, const std::vector &); - static bool SendBattleTeleportSpell(u8, u16, u16); - static bool SendBattleEarthQuakeSpell(u8, const std::vector &); - - static int callbackCreateThread(void *); - - SDL::Thread thread; -}; - -#endif -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/remoteclient_battle.cpp b/project/jni/application/fheroes2/src/fheroes2/network/remoteclient_battle.cpp deleted file mode 100644 index 050889d4e..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/remoteclient_battle.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifdef WITH_NET - -#include -#include -#include "world.h" -#include "settings.h" -#include "server.h" -#include "client.h" -#include "kingdom.h" -#include "battle2.h" -#include "battle_stats.h" -#include "battle_cell.h" -#include "remoteclient.h" - -bool FH2RemoteClient::SendBattleAction(u8 color, QueueMessage & msg) -{ - FH2RemoteClient* remote = FH2Server::Get().GetRemoteClient(color); - - if(remote) - { - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::SendBattleAction: " << Network::GetMsgString(msg.GetID())); - return remote->Send(msg); - } - else - DEBUG(DBG_NETWORK, DBG_WARN, "FH2RemoteClient::SendBattleAction: " << "incorrect param: " << static_cast(color)); - return false; -} - -bool FH2RemoteClient::SendBattleEarthQuakeSpell(u8 color, const std::vector & targets) -{ - FH2RemoteClient* remote = FH2Server::Get().GetRemoteClient(color); - - if(remote) - { - remote->packet.Reset(); - remote->packet.SetID(MSG_BATTLE_CAST); - remote->packet.Push(static_cast(Spell::EARTHQUAKE)); - remote->packet.Push(static_cast(targets.size())); - - std::vector::const_iterator it1 = targets.begin(); - std::vector::const_iterator it2 = targets.end(); - - for(; it1 != it2; ++it1) - remote->packet.Push(*it1); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::SendBattleEarthQquakeSpell: "); - return remote->Send(remote->packet); - } - else - DEBUG(DBG_NETWORK, DBG_WARN, "FH2RemoteClient::SendBattleEarthQquakeSpell: " << "incorrect param"); - return false; -} - -bool FH2RemoteClient::SendBattleSpell(u8 color, u8 spell, u8 hero_color, const std::vector & targets) -{ - FH2RemoteClient* remote = FH2Server::Get().GetRemoteClient(color); - - if(remote) - { - remote->packet.Reset(); - remote->packet.SetID(MSG_BATTLE_CAST); - remote->packet.Push(spell); - remote->packet.Push(hero_color); - remote->packet.Push(static_cast(targets.size())); - - std::vector::const_iterator it1 = targets.begin(); - std::vector::const_iterator it2 = targets.end(); - - for(; it1 != it2; ++it1) - { - const u16 id = (*it1).defender ? (*it1).defender->GetID() : 0; - remote->packet.Push(id); - remote->packet.Push((*it1).damage); - remote->packet.Push((*it1).killed); - } - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::SendBattleSpell: "); - return remote->Send(remote->packet); - } - else - DEBUG(DBG_NETWORK, DBG_WARN, "FH2RemoteClient::SendBattleSpell: " << "incorrect param"); - return false; -} - -bool FH2RemoteClient::SendBattleTeleportSpell(u8 color, u16 src, u16 dst) -{ - FH2RemoteClient* remote = FH2Server::Get().GetRemoteClient(color); - - if(remote) - { - remote->packet.Reset(); - remote->packet.SetID(MSG_BATTLE_CAST); - remote->packet.Push(static_cast(Spell::TELEPORT)); - remote->packet.Push(src); - remote->packet.Push(dst); - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::SendBattleTeleportSpell: "); - return remote->Send(remote->packet); - } - else - DEBUG(DBG_NETWORK, DBG_WARN, "FH2RemoteClient::SendBattleTeleportSpell: " << "incorrect param"); - return false; -} - -bool FH2RemoteClient::SendBattleResult(u8 color, const Battle2::Result & result) -{ - FH2RemoteClient* remote = FH2Server::Get().GetRemoteClient(color); - - if(remote) - { - remote->packet.Reset(); - remote->packet.SetID(MSG_BATTLE_RESULT); - remote->packet.Push(result.army1); - remote->packet.Push(result.army2); - remote->packet.Push(result.exp1); - remote->packet.Push(result.exp2); - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::SendBattleResult: "); - return remote->Send(remote->packet); - } - else - DEBUG(DBG_NETWORK, DBG_WARN, "FH2RemoteClient::SendBattleResult: " << "incorrect param"); - return false; -} - -bool FH2RemoteClient::SendBattleBoard(u8 color, const Battle2::Arena & arena) -{ - FH2RemoteClient* remote = FH2Server::Get().GetRemoteClient(color); - - if(remote) - { - remote->packet.Reset(); - remote->packet.SetID(MSG_BATTLE_BOARD); - - arena.PackBoard(remote->packet); - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::SendBattleBoard: "); - return remote->Send(remote->packet); - } - else - DEBUG(DBG_NETWORK, DBG_WARN, "FH2RemoteClient::SendBattleBoard: " << "incorrect param"); - return false; -} - -bool FH2RemoteClient::SendBattleAttack(u8 color, u16 id, const std::vector & targets) -{ - FH2RemoteClient* remote = FH2Server::Get().GetRemoteClient(color); - - if(remote) - { - remote->packet.Reset(); - remote->packet.SetID(MSG_BATTLE_ATTACK); - remote->packet.Push(id); - remote->packet.Push(static_cast(targets.size())); - - std::vector::const_iterator it1 = targets.begin(); - std::vector::const_iterator it2 = targets.end(); - - for(; it1 != it2; ++it1) - { - const u16 id = (*it1).defender ? (*it1).defender->GetID() : 0; - remote->packet.Push(id); - remote->packet.Push((*it1).damage); - remote->packet.Push((*it1).killed); - } - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::SendBattleAttack: "); - return remote->Send(remote->packet); - } - else - DEBUG(DBG_NETWORK, DBG_WARN, "FH2RemoteClient::SendBattleAttack: " << "incorrect param"); - return false; -} - -bool FH2RemoteClient::RecvBattleHumanTurn(const Battle2::Stats & b, const Battle2::Arena & arena, Battle2::Actions & a) -{ - bool exit = false; - - packet.Reset(); - packet.SetID(MSG_BATTLE_TURN); - packet.Push(b.GetID()); - - // send battle turn - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::BattleHumanTurn: id: 0x" << b.GetID() << ", send battle turn"); - if(!Send(packet)) return false; - - DEBUG(DBG_NETWORK, DBG_INFO, "FH2RemoteClient::BattleHumanTurn: id: 0x" << b.GetID() << ", send battle board"); - if(!SendBattleBoard(player_color, arena)) return false; - - while(!exit) - { - if(Modes(ST_SHUTDOWN)) return false; - - if(Ready()) - { - if(!Recv(packet)) return false; - DEBUG(DBG_NETWORK , DBG_INFO, "FH2RemoteClient::RecvHumanTurn: recv: " << Network::GetMsgString(packet.GetID())); - - // check broadcast - MsgBroadcast(); - - // msg processing - switch(Network::GetMsg(packet.GetID())) - { - case MSG_BATTLE_CAST: - case MSG_BATTLE_SKIP: - case MSG_BATTLE_END_TURN: - exit = 1; - a.push_back(packet); - break; - - case MSG_BATTLE_MOVE: - case MSG_BATTLE_ATTACK: - case MSG_BATTLE_DEFENSE: - case MSG_BATTLE_DAMAGE: - case MSG_BATTLE_MORALE: - case MSG_BATTLE_LUCK: - case MSG_BATTLE_CATAPULT: - case MSG_BATTLE_TOWER: - case MSG_BATTLE_RETREAT: - case MSG_BATTLE_SURRENDER: - a.push_back(packet); - break; - - default: break; - } - } - - DELAY(100); - } - return true; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/server.cpp b/project/jni/application/fheroes2/src/fheroes2/network/server.cpp deleted file mode 100644 index 58e47a2fc..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/server.cpp +++ /dev/null @@ -1,516 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include - -#include "game.h" -#include "dialog.h" -#include "agg.h" -#include "settings.h" -#include "cursor.h" -#include "localclient.h" -#include "world.h" -#include "kingdom.h" -#include "battle2.h" -#include "server.h" - -#ifdef WITH_NET - -u8 SelectCountPlayers(void); - -void SendPacketToAllClients(std::vector & clients, const QueueMessage & msg, u32 owner) -{ - static const QueueMessage ready(MSG_READY); - - std::vector::iterator it = clients.begin(); - for(; it != clients.end(); ++it) if((*it).IsConnected()) - (*it).player_id != owner ? Network::SendMessage(*it, msg) : Network::SendMessage(*it, ready); -} - -FH2Server::FH2Server() -{ - AGG::Cache & cache = AGG::Cache::Get(); - if(! cache.ReadDataDir()) Error::Except("FH2Server::", " AGG data files not found."); - - if(!PrepareMapsFileInfoList(finfo_list, true) || - !Settings::Get().LoadFileMapsMP2(finfo_list.front().file)) DEBUG(DBG_NETWORK , DBG_WARN, "FH2Server::" << " No maps available!"); -} - -FH2Server::~FH2Server() -{ -} - -FH2Server & FH2Server::Get(void) -{ - static FH2Server fh2server; - - return fh2server; -} - -int FH2Server::callbackCreateThread(void *ptr) -{ - return ptr ? reinterpret_cast(ptr)->Main() : -1; -} - -bool FH2Server::Bind(u16 port) -{ - IPaddress ip; - - return Network::ResolveHost(ip, NULL, port) && Open(ip); -} - -void FH2Server::Lock(void) -{ - mutex.Lock(); -} - -void FH2Server::Unlock(void) -{ - mutex.Unlock(); -} - -void FH2Server::SetExit(void) -{ - exit = true; -} - -void FH2Server::SetStartGame(void) -{ - start_game = true; -} - -void FH2Server::SendToAllClients(const QueueMessage & msg, u32 id) -{ - DEBUG(DBG_NETWORK , DBG_INFO, "FH2Server::" << "SendToAllClients: " << Network::GetMsgString(msg.GetID())); - SendPacketToAllClients(clients, msg, id); -} - -void FH2Server::PushMapsFileInfoList(QueueMessage & msg) const -{ - msg.Push(static_cast(finfo_list.size())); - MapsFileInfoList::const_iterator it1 = finfo_list.begin(); - MapsFileInfoList::const_iterator it2 = finfo_list.end(); - - for(; it1 != it2; ++it1) Network::PacketPushMapsFileInfo(msg, *it1); -} - -void FH2Server::ChangeClientColors(u8 from, u8 to) -{ - std::vector::iterator it1, it2; - - it1 = std::find_if(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::isColor), from)); - it2 = std::find_if(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::isColor), to)); - - if(it2 == clients.end()) - { - (*it1).player_color = to; - Settings::Get().SetPlayersColors(GetPlayersColors()); - } - else - if(it1 != clients.end()) - { - std::swap((*it1).player_color, (*it2).player_color); - } -} - -void FH2Server::ChangeClientRace(u8 color, u8 race) -{ - std::vector::iterator it; - - it = std::find_if(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::isColor), color)); - if(it != clients.end()) - (*it).player_race = race; -} - -void FH2Server::SetNewAdmin(u32 old_admin) -{ - std::vector::iterator it; - - it = std::find_if(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::isID), old_admin)); - if(it != clients.end()) (*it).ResetModes(ST_ADMIN); - - it = std::find_if(clients.begin(), clients.end(), std::not1(std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::isID), old_admin))); - if(it != clients.end()) (*it).SetModes(ST_ADMIN); -} - -void FH2Server::PushPlayersInfo(QueueMessage & msg, u32 exclude) const -{ - Network::PacketPushPlayersInfo(msg, clients, exclude); -} - -void FH2Server::PopMapsFileInfoList(QueueMessage & msg) -{ - Network::PacketPopMapsFileInfoList(msg, finfo_list); -} - -u8 FH2Server::GetPlayersColors(void) const -{ - return Network::GetPlayersColors(clients); -} - -void FH2Server::ResetPlayers(void) -{ - Settings & conf = Settings::Get(); - - // reset all - std::vector::iterator it1 = clients.begin(); - std::vector::const_iterator it2 = clients.end(); - for(; it1 != it2; ++it1) - { - (*it1).player_color = 0; - (*it1).player_race = 0; - } - - conf.SetPlayersColors(0); - u8 colors = 0; - - // set first admin - it1 = std::find_if(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::Modes), ST_ADMIN)); - if(it1 != clients.end()) - { - (*it1).player_color = conf.FirstAllowColor(); - colors |= (*it1).player_color; - } - - // set other - it1 = clients.begin(); - it2 = clients.end(); - for(; it1 != it2; ++it1) if(0 == (*it1).player_color) - { - const u8 color = Color::GetFirst(conf.AllowColors() & (~colors)); - if(color) - { - (*it1).player_color = color; - colors |= color; - } - else - // no free colors, shutdown client - { - (*it1).SetModes(ST_SHUTDOWN); - } - } - - conf.SetPlayersColors(colors); -} - -void FH2Server::CloseClients(void) -{ - std::for_each(clients.begin(), clients.end(), std::mem_fun_ref(&FH2RemoteClient::ShutdownThread)); -} - -int FH2Server::Main(void) -{ - WaitClients(); - StartGame(); - - // stop scan queue - //Timer::Remove(timer); - - CloseClients(); - - Close(); - - return 1; -} - -bool FH2Server::IsRun(void) const -{ - return !exit; -} - -void FH2Server::WaitClients(void) -{ - Settings & conf = Settings::Get(); - std::vector::iterator it; - QueueMessage packet(MSG_UNKNOWN); - - clients.reserve(8); - exit = false; - start_game = false; - - // wait players - while(!exit && !start_game) - { - if(TCPsocket csd = Accept()) - { - const u8 players = std::count_if(clients.begin(), clients.end(), std::mem_fun_ref(&FH2RemoteClient::IsConnected)); - - // request admin - it = std::find_if(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::Modes), ST_ADMIN)); - - // check count players - if((conf.PreferablyCountPlayers() <= players) || - // check admin allow connect - ((clients.end() != it && (*it).Modes(ST_CONNECT)) && !(*it).Modes(ST_ALLOWPLAYERS))) - { - DEBUG(DBG_NETWORK, DBG_INFO, "FH2Server::" << "WaitClients: " << "max players, current: " << static_cast(conf.PreferablyCountPlayers())); - Socket sct(csd); - // send message - sct.Close(); - } - else - // connect - { - // find free socket - it = std::find_if(clients.begin(), clients.end(), std::not1(std::mem_fun_ref(&FH2RemoteClient::IsConnected))); - if(it == clients.end()) - { - clients.push_back(FH2RemoteClient()); - it = clients.end(); - --it; - } - - // first player: set admin mode - if(0 == players) - (*it).SetModes(ST_ADMIN); - - (*it).Assign(csd); - (*it).RunThread(); - } - } - - DELAY(100); - } -} - -void FH2Server::StartGame(void) -{ - Settings & conf = Settings::Get(); - - conf.FixKingdomRandomRace(); - std::for_each(clients.begin(), clients.end(), Player::FixRandomRace); - conf.SetPlayersColors(Network::GetPlayersColors(clients)); - - QueueMessage packet; - - world.LoadMaps(conf.MapsFile()); - - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) if(color & conf.PlayersColors()) - world.GetKingdom(color).SetControl(Game::REMOTE); - - std::for_each(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::SetModes), ST_INGAME)); - - GameOver::Result::Get().Reset(); - std::vector::iterator it; - -/* - while(!exit && conf.PlayersColors()) - { - world.NewDay(); - - // sync world - mutex.Lock(); - packet.Reset(); - Game::IO::SaveBIN(packet); - packet.SetID(MSG_LOAD_KINGDOM); - SendPacketToAllClients(clients, packet, 0); - mutex.Unlock(); -*/ - - // TEST BATTLE NETWORK - it = std::find_if(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::Modes), ST_ADMIN)); - Kingdom & kingdom = world.GetKingdom((*it).player_color); - - Heroes & hero1 = *world.GetHeroes(Heroes::SANDYSANDY); - Heroes & hero2 = *world.GetHeroes(Heroes::RIALDO); - - hero1.SetSpellPoints(150); - hero1.Recruit(kingdom.GetColor(), Point(20, 20)); - hero2.Recruit(Color::GRAY, Point(20, 21)); - - Army::army_t & army1 = hero1.GetArmy(); - Army::army_t & army2 = hero2.GetArmy(); - - army1.Clear(); - army1.JoinTroop(Monster::PHOENIX, 10); - army1.JoinTroop(Monster::RANGER, 80); - - army2.Clear(); - army2.At(0) = Army::Troop(Monster::SKELETON, 400); - army2.At(2) = Army::Troop(Monster::SKELETON, 400); - army2.At(4) = Army::Troop(Monster::SKELETON, 400); - - // sync world - mutex.Lock(); - packet.Reset(); - Game::IO::SaveBIN(packet); - packet.SetID(MSG_MAPS_LOAD); - SendPacketToAllClients(clients, packet, 0); - mutex.Unlock(); - - const u16 index = 33; - - packet.Reset(); - packet.SetID(MSG_BATTLE); - // attacker monster oor hero - packet.Push(static_cast(1)); - packet.Push(hero1.GetIndex()); - // defender monster, hero or castle - packet.Push(static_cast(1)); - packet.Push(hero2.GetIndex()); - packet.Push(index); - - Lock(); - SendToAllClients(packet); - Unlock(); - - Battle2::Loader(army1, army2, index); - -/* - // send all tiles - // send action new day - - for(Color::color_t color = Color::BLUE; color != Color::GRAY && !exit; ++color) - { - Kingdom & kingdom = world.GetKingdom(color); - - if(!kingdom.isPlay()) continue; - - conf.SetCurrentColor(color); - world.ClearFog(color); - - // send turn - mutex.Lock(); - packet.Reset(); - packet.SetID(MSG_YOUR_TURN); - packet.Push(static_cast(color)); - packet.Push(static_cast(0)); - SendPacketToAllClients(clients, packet, 0); - mutex.Unlock(); - - switch(kingdom.Control()) - { - default: - conf.SetMyColor(color); - - it = std::find_if(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::isColor), color)); - if(it == clients.end()) break; - - (*it).SetModes(ST_TURN); - DEBUG(DBG_NETWORK, DBG_INFO, "Server: Player turn: " << Color::String(color)); - // wait turn - while(!exit && (*it).Modes(ST_TURN)) DELAY(100); - // lost connection - if(!(*it).Modes(ST_CONNECT)) - { - mutex.Lock(); - world.GetKingdom(color).SetControl(Game::AI); - conf.SetPlayersColors(conf.PlayersColors() & (~color)); - mutex.Unlock(); - } - break; - - case Game::AI: - DEBUG(DBG_NETWORK, DBG_INFO, "Server: AI turn: " << Color::String(color)); - kingdom.AITurns(); - - //packet.Reset(); - //packet.SetID(MSG_KINGDOM); - //packet.Push(static_cast(kingdom.GetColor())); - //Game::IO::PackKingdom(packet, kingdom); - //Lock(); - //SendToAllClients(packet); - //Unlock(); - break; - } - } - - DELAY(100); - } -*/ -} - - -FH2RemoteClient* FH2Server::GetRemoteClient(u8 color) -{ - std::vector::iterator it; - it = std::find_if(clients.begin(), clients.end(), std::bind2nd(std::mem_fun_ref(&FH2RemoteClient::isColor), color)); - - return it != clients.end() ? &(*it) : NULL; -} - -Game::menu_t Game::NetworkHost(void) -{ - Settings & conf = Settings::Get(); - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - - // select count players - const u8 max_players = SelectCountPlayers(); - - if(2 > max_players) return Game::MAINMENU; - conf.SetPreferablyCountPlayers(max_players); - conf.SetGameType(Game::NETWORK); - - // clear background - const Sprite &back = AGG::GetICN(ICN::HEROES, 0); - cursor.Hide(); - display.Blit(back); - cursor.Show(); - display.Flip(); - - // create local server - FH2Server & server = FH2Server::Get(); - - if(! server.Bind(conf.GetPort())) - { - Dialog::Message(_("Error"), Network::GetError(), Font::BIG, Dialog::OK); - return Game::MAINMENU; - } - - SDL::Thread thread; - thread.Create(FH2Server::callbackCreateThread, &server); - - // create local client - const std::string localhost("127.0.0.1"); - FH2LocalClient & client = FH2LocalClient::Get(); - - // connect to server - if(client.Connect(localhost, conf.GetPort())) - { - client.SetModes(ST_LOCALSERVER); - client.Main(); - } - else - Dialog::Message(_("Error"), Network::GetError(), Font::BIG, Dialog::OK); - - server.Lock(); - server.SetExit(); - server.Unlock(); - - if(0 > thread.Wait()) - { - Dialog::Message(_("Error"), Network::GetError(), Font::BIG, Dialog::OK); - return Game::MAINMENU; - } - server.Close(); - - return QUITGAME; -} - -#else -Game::menu_t Game::NetworkHost(void) -{ - Dialog::Message(_("Error"), _("This release is compiled without network support."), Font::BIG, Dialog::OK); - return MAINMENU; -} -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/network/server.h b/project/jni/application/fheroes2/src/fheroes2/network/server.h deleted file mode 100644 index 51a81bf36..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/network/server.h +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2SERVER_H -#define H2SERVER_H - -#include "gamedefs.h" - -#ifdef WITH_NET - -#include -#include "network.h" -#include "remoteclient.h" -#include "maps_fileinfo.h" - -class FH2Server : public Network::Server -{ -public: - static FH2Server & Get(void); - static int callbackCreateThread(void *); - - ~FH2Server(); - - bool Bind(u16); - - bool IsRun(void) const; - void Lock(void); - void Unlock(void); - void PushMapsFileInfoList(QueueMessage &) const; - void PushPlayersInfo(QueueMessage &, u32 exclude = 0) const; - void SetNewAdmin(u32 old_admin); - void PopMapsFileInfoList(QueueMessage &); - u8 GetPlayersColors(void) const; - void ResetPlayers(void); - void SendToAllClients(const QueueMessage &, u32 = 0); - void ChangeClientColors(u8, u8); - void ChangeClientRace(u8 color, u8 race); - - FH2RemoteClient* GetRemoteClient(u8); - - void SetExit(void); - void SetStartGame(void); - -protected: - void ScanQueue(void); - - FH2Server(); - int Main(void); - void WaitClients(void); - void CloseClients(void); - void StartGame(void); - - SDL::Mutex mutex; - SDL::Timer timer; - std::vector clients; - bool exit; - bool start_game; - MapsFileInfoList finfo_list; -}; - -#endif - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/mounts.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/mounts.cpp deleted file mode 100644 index 54703df44..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/mounts.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "settings.h" -#include "mounts.h" - -Mounts::Mounts(const ICN::icn_t icn) : Object(MP2::OBJ_MOUNTS, icn) -{ - switch(icn) - { - case ICN::MTNCRCK: - case ICN::MTNSNOW: - case ICN::MTNSWMP: - case ICN::MTNLAVA: - case ICN::MTNDSRT: - case ICN::MTNDIRT: - case ICN::MTNMULT: - case ICN::MTNGRAS: break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Mounts::Mounts: unknown type"); break; - } -} - -bool Mounts::isPassable(const u16 icn, const u8 index) -{ - // bug fix - switch(icn) - { - case ICN::MTNGRAS: - if(43 == index || 44 == index || 53 == index || 54 == index || 78 == index) return false; - break; - case ICN::MTNDIRT: - if(73 == index || 84 == index || 86 == index) return false; - break; - - default: break; - } - - // all - switch(icn) - { - // 133 sprites - case ICN::MTNCRCK: - case ICN::MTNDIRT: - if((5 < index && index < 10) || (11 < index && index < 17) || (17 < index && index < 21)) return false; // LARGE LEFT - else - if((27 < index && index < 32) || (32 < index && index < 38) || (38 < index && index < 42)) return false; // LARGE RIGHT - else - if((47 < index && index < 53) || (53 < index && index < 57)) return false; // MEDIUM LEFT (51 and 52 for dirt need close) - else - if((64 < index && index < 68) || (68 < index && index < 72)) return false; // MEDIUM RIGHT - else - if((75 < index && index < 79) || (79 < index && index < 82)) return false; // MEDIUM2 RIGHT - else - if((86 < index && index < 89) || (89 < index && index < 92)) return false; // MEDIUM2 LEFT - else - if((92 < index && index < 95) || (95 < index && index < 98)) return false; // SMALL LEFT - else - if((98 < index && index < 101) || (101 < index && index < 104)) return false; // SMALL RIGHT - else - if(110 < index && index < 114) return false; // MINES - else return true; - - // 83 sprites - case ICN::MTNDSRT: - case ICN::MTNGRAS: - case ICN::MTNLAVA: - case ICN::MTNMULT: - case ICN::MTNSNOW: - case ICN::MTNSWMP: - if((5 < index && index < 10) || (11 < index && index < 17) || (17 < index && index < 21)) return false; // LARGE LEFT - else - if(25 == index) return false; // bug: level 1 sprite for mtngrass - else - if((27 < index && index < 32) || (32 < index && index < 38) || (38 < index && index < 42)) return false; // LARGE RIGHT - else - if((45 < index && index < 49) || (49 < index && index < 52)) return false; // MEDIUM LEFT - else - if((55 < index && index < 59) || (59 < index && index < 62)) return false; // MEDIUM RIGHT - else - if((62 < index && index < 65) || (65 < index && index < 68)) return false; // SMALL LEFT - else - if((68 < index && index < 71) || (71 < index && index < 74)) return false; // SMALL RIGHT - else - if(80 < index && index < 84) return false; // MINES - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/mounts.h b/project/jni/application/fheroes2/src/fheroes2/objects/mounts.h deleted file mode 100644 index a7c3cbdfa..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/mounts.h +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2MOUNTS_H -#define H2MOUNTS_H - -#include "icn.h" -#include "object.h" -#include "gamedefs.h" - -class Mounts : public Object -{ - public: - Mounts(const ICN::icn_t icn); - - static bool isPassable(const u16 icn, const u8 index); - - private: -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objcrck.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objcrck.cpp deleted file mode 100644 index 15ffafeda..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objcrck.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "objcrck.h" - -bool ObjWasteLand::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::OBJNCRCK: - // artesian spring - if(2 < index && index < 5) return false; - else - // rock - if((9 < index && index < 12) || 18 == index || (20 < index && index < 23) || - (23 < index && index < 26) || (28 < index && index < 33) || (33 < index && index < 36) || - (36 < index && index < 39) || (39 < index && index < 44) || 46 == index || - 49 == index || 52 == index || 55 == index) return false; - else - // cactus - if(14 == index || 16 == index) return false; - else - // skull - if(17 == index) return false; - else - // crater - if((57 < index && index < 60) || (61 < index && index < 66) || (67 < index && index < 70) || - (220 < index && index < 226) || (226 < index && index < 236)) return false; - else - // shrub - if(70 < index && index < 73) return false; - else - // wagon - if(74 == index) return false; - else - // tar pit - if(80 == index || 91 == index || - 102 == index || 113 == index || 124 == index || - (134 < index && index < 138) || 148 == index || 159 == index || - 170 == index || 181 == index) return false; - else - // troll bridge - if(181 < index && index < 190) return false; - else - // market - if(202 == index || 213 == index) return false; - else - // watering hole - if(216 < index && index < 221) return false; - else - // obelisk - if(238 == index) return false; - else - // saw mill - if(240 < index && index < 246) return false; - - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objcrck.h b/project/jni/application/fheroes2/src/fheroes2/objects/objcrck.h deleted file mode 100644 index 7cb660deb..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objcrck.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJCRCK_H -#define H2OBJCRCK_H - -#include "gamedefs.h" - -namespace ObjWasteLand -{ - bool isPassable(const u16 icn, const u8 index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objdirt.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objdirt.cpp deleted file mode 100644 index 865396c23..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objdirt.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "objdirt.h" - -bool ObjDirt::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::OBJNDIRT: - // abandone mines - if(6 < index && index < 10) return false; - else - // mound - if((11 < index && index < 14) || (14 < index && index < 17)) return false; - else - // crater - if(16 < index && index < 23) return false; - // lake - else - if((22 < index && index < 39) || (39 < index && index < 46) || - (47 < index && index < 52) || (52 < index && index < 59)) return false; - else - // shrub - if((59 < index && index < 62) || (62 < index && index < 65) || (65 < index && index < 68) || - 69 == index || 71 == index || (72 < index && index < 75) || (75 < index && index < 78) || - (78 < index && index < 81) || (81 < index && index < 84) || (84 < index && index < 87) || (87 < index && index < 91)) return false; - else - // rock - if((91 < index && index < 94) || (97 < index && index < 100) || (100 < index && index < 103) || (103 < index && index < 106)) return false; - else - // trees - if(118 == index || 123 == index || 127 == index) return false; - else - // faerie ring - if(128 < index && index < 131) return false; - else - // hill fort - if(132 < index && index < 136) return false; - else - // halfling hole - if(136 < index && index < 140) return false; - else - // tree city - if(150 < index && index < 153) return false; - else - // wind mill - if(185 == index || 189 == index) return false; - else - // oracul - if(196 < index && index < 199) return false; - else - // obelisk - if(201 == index) return false; - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objdirt.h b/project/jni/application/fheroes2/src/fheroes2/objects/objdirt.h deleted file mode 100644 index d4345f5e0..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objdirt.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJDIRT_H -#define H2OBJDIRT_H - -#include "gamedefs.h" - -namespace ObjDirt -{ - bool isPassable(const u16 icn, const u8 index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objdsrt.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objdsrt.cpp deleted file mode 100644 index 00feff4b3..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objdsrt.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "objdsrt.h" - -bool ObjDesert::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::OBJNDSRT: - // trees - if(3 == index || 6 == index || 9 == index || 12 == index || - 24 == index || 26 == index || 28 == index || 76 == index) return false; - else - // dune - if((13 < index && index < 16) || (16 < index && index < 19) || (19 < index && index < 23)) return false; - else - // cactus - if((29 < index && index < 33) || 34 == index || 36 == index || - (38 < index && index < 41) || 42 == index || 45 == index || - (47 < index && index < 50) || 51 == index || 53 == index) return false; - else - // camp fire - if(61 == index) return false; - else - // desert tent - if(71 < index && index < 74) return false; - else - // piramids - if(80 < index && index < 83) return false; - else - // skeleton - if(82 < index && index < 85) return false; - else - // sphinx - if(86 < index && index < 89) return false; - else - // city of dead - if(88 < index && index < 102) return false; - else - // obelisk - if(104 == index) return false; - else - // oasis - if((104 < index && index < 107) || (107 < index && index < 110)) return false; - else - // desert - if(109 < index && index < 113) return false; - else - // daemon cave - if(115 < index && index < 118) return false; - else - // sign - if(119 == index) return false; - else - // grave yard - if(120 < index && index < 123) return false; - else - // saw mill - if(124 < index && index < 130) return false; - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objdsrt.h b/project/jni/application/fheroes2/src/fheroes2/objects/objdsrt.h deleted file mode 100644 index 23000d08c..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objdsrt.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJDSRT_H -#define H2OBJDSRT_H - -#include "gamedefs.h" - -namespace ObjDesert -{ - bool isPassable(const u16 icn, const u8 index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/object.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/object.cpp deleted file mode 100644 index ac17042ca..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/object.cpp +++ /dev/null @@ -1,223 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "world.h" -#include "maps_tiles.h" -#include "mounts.h" -#include "trees.h" -#include "objxloc.h" -#include "objtown.h" -#include "objwatr.h" -#include "objlava.h" -#include "objmult.h" -#include "objdsrt.h" -#include "objdirt.h" -#include "objsnow.h" -#include "objswmp.h" -#include "objgras.h" -#include "objcrck.h" -#include "direction.h" -#include "object.h" - -Object::Object(const MP2::object_t obj, const u16 sicn, const u32 uid) - : object(obj), icn(sicn), id(uid ? uid : World::GetUniq()) -{ -} - -Object::~Object() -{ -} - -bool Object::isPassable(const std::list & bottoms, const s32 maps_index) -{ - if(bottoms.size()) - { - std::list::const_iterator it1 = bottoms.begin(); - std::list::const_iterator it2 = bottoms.end(); - - for(; it1 != it2; ++it1) - { - const Maps::TilesAddon & addon = *it1; - const ICN::icn_t icn = MP2::GetICNObject(addon.object); - - switch(icn) - { - case ICN::MTNCRCK: - case ICN::MTNSNOW: - case ICN::MTNSWMP: - case ICN::MTNLAVA: - case ICN::MTNDSRT: - case ICN::MTNDIRT: - case ICN::MTNMULT: - case ICN::MTNGRAS: if(! Mounts::isPassable(icn, addon.index)) return false; break; - - case ICN::TREJNGL: - case ICN::TREEVIL: - case ICN::TRESNOW: - case ICN::TREFIR: - case ICN::TREFALL: - case ICN::TREDECI: if(! Trees::isPassable(icn, addon.index)) return false; break; - - case ICN::OBJNSNOW: if(! ObjSnow::isPassable(icn, addon.index)) return false; break; - case ICN::OBJNSWMP: if(! ObjSwamp::isPassable(icn, addon.index)) return false; break; - case ICN::OBJNGRAS: - case ICN::OBJNGRA2: if(! ObjGrass::isPassable(icn, addon.index)) return false; break; - case ICN::OBJNCRCK: if(! ObjWasteLand::isPassable(icn, addon.index)) return false; break; - case ICN::OBJNDIRT: if(! ObjDirt::isPassable(icn, addon.index)) return false; break; - case ICN::OBJNDSRT: if(! ObjDesert::isPassable(icn, addon.index)) return false; break; - case ICN::OBJNMUL2: - case ICN::OBJNMULT: if(! ObjMulti::isPassable(icn, addon.index)) return false; break; - case ICN::OBJNLAVA: - case ICN::OBJNLAV3: - case ICN::OBJNLAV2: if(! ObjLava::isPassable(icn, addon.index)) return false; break; - case ICN::OBJNWAT2: - case ICN::OBJNWATR: if(! ObjWater::isPassable(icn, addon.index)) return false; break; - - case ICN::MONS32: - case ICN::MINIMON: return false; - - case ICN::OBJNARTI: - case ICN::OBJNRSRC: if(addon.index % 2) return false; break; - - case ICN::OBJNTWBA: - case ICN::OBJNTOWN: if(! ObjTown::isPassable(icn, addon.index, maps_index)) return false; break; - - case ICN::X_LOC1: - case ICN::X_LOC2: - case ICN::X_LOC3: if(! ObjLoyalty::isPassable(icn, addon.index)) return false; break; - - // MANUAL.ICN - case ICN::TREASURE: - case ICN::TELEPORT1: - case ICN::TELEPORT2: - case ICN::TELEPORT3: - case ICN::FOUNTAIN: return false; break; - - default: break; - } - } - } - - return true; -} - -bool Object::AllowDirect(const u8 general, const u16 direct) -{ - switch(general) - { - case MP2::OBJ_SHIPWRECK: - return (direct & (Direction::LEFT | Direction::BOTTOM_LEFT)); - - case MP2::OBJ_DERELICTSHIP: - return (direct & (Direction::LEFT | Direction::BOTTOM_LEFT | Direction::BOTTOM)); - - case MP2::OBJ_ARCHERHOUSE: - case MP2::OBJ_DOCTORHUT: - case MP2::OBJ_DWARFCOTT: - case MP2::OBJ_THATCHEDHUT: - case MP2::OBJ_FOUNTAIN: - case MP2::OBJ_IDOL: - case MP2::OBJ_LIGHTHOUSE: - case MP2::OBJ_OBELISK: - case MP2::OBJ_SIGN: - case MP2::OBJ_WATCHTOWER: - case MP2::OBJ_WITCHSHUT: - case MP2::OBJ_GAZEBO: - case MP2::OBJ_MAGICWELL: - case MP2::OBJ_OBSERVATIONTOWER: - case MP2::OBJ_PEASANTHUT: - case MP2::OBJ_STONELIGHTS: - case MP2::OBJ_STANDINGSTONES: - case MP2::OBJ_GOBLINHUT: - case MP2::OBJ_SHRINE1: - case MP2::OBJ_SHRINE2: - case MP2::OBJ_SHRINE3: - case MP2::OBJ_TREEHOUSE: - case MP2::OBJ_ARTESIANSPRING: - case MP2::OBJ_SKELETON: - case MP2::OBJ_TREEKNOWLEDGE: - case MP2::OBJ_ORACLE: - case MP2::OBJ_OASIS: - case MP2::OBJ_LEANTO: - case MP2::OBJ_MAGICGARDEN: - case MP2::OBJ_WAGON: - //case MP2::OBJ_BARRIER: // because Barrier used with any direction - case MP2::OBJ_TRAVELLERTENT: - case MP2::OBJ_JAIL: - case MP2::OBJ_ALCHEMYTOWER: - case MP2::OBJ_HUTMAGI: - case MP2::OBJ_EYEMAGI: - case MP2::OBJ_WATERINGHOLE: - return (direct & (Direction::LEFT | Direction::RIGHT | DIRECTION_BOTTOM_ROW)); - - case MP2::OBJ_TRADINGPOST: - case MP2::OBJ_EXCAVATION: - case MP2::OBJ_DESERTTENT: - case MP2::OBJ_DAEMONCAVE: - case MP2::OBJ_PYRAMID: - case MP2::OBJ_FORT: - case MP2::OBJ_RUINS: - case MP2::OBJ_TROLLBRIDGE: - case MP2::OBJ_WATERWHEEL: - case MP2::OBJ_HILLFORT: - case MP2::OBJ_FREEMANFOUNDRY: - case MP2::OBJ_SAWMILL: - return (direct & (Direction::RIGHT | DIRECTION_BOTTOM_ROW)); - - case MP2::OBJ_TREECITY: - case MP2::OBJ_MAGELLANMAPS: - case MP2::OBJ_SPHINX: - case MP2::OBJ_TEMPLE: - case MP2::OBJ_WINDMILL: - case MP2::OBJ_FAERIERING: - case MP2::OBJ_BARROWMOUNDS: - case MP2::OBJ_STABLES: - return (direct & (Direction::LEFT | DIRECTION_BOTTOM_ROW)); - - case MP2::OBJ_MINES: - case MP2::OBJ_ABANDONEDMINE: - case MP2::OBJ_ALCHEMYLAB: - case MP2::OBJ_CAVE: - case MP2::OBJ_CITYDEAD: - case MP2::OBJ_GRAVEYARD: - case MP2::OBJ_DRAGONCITY: - case MP2::OBJ_XANADU: - case MP2::OBJ_MERCENARYCAMP: - case MP2::OBJ_HALFLINGHOLE: - case MP2::OBJ_WAGONCAMP: - case MP2::OBJ_WATERALTAR: - case MP2::OBJ_AIRALTAR: - case MP2::OBJ_FIREALTAR: - case MP2::OBJ_EARTHALTAR: - case MP2::OBJ_ARENA: - case MP2::OBJ_SIRENS: - case MP2::OBJ_MERMAID: - return (direct & (DIRECTION_BOTTOM_ROW)); - - case MP2::OBJ_CASTLE: - return (direct & Direction::BOTTOM); - - default: break; - } - - return true; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/object.h b/project/jni/application/fheroes2/src/fheroes2/objects/object.h deleted file mode 100644 index 2b8aa5a8b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/object.h +++ /dev/null @@ -1,47 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJECT_H -#define H2OBJECT_H - -#include "mp2.h" -#include "gamedefs.h" - -namespace Maps { class TilesAddon; } - -class Object -{ - public: - Object(const MP2::object_t obj = MP2::OBJ_ZERO, const u16 sicn = ICN::UNKNOWN, const u32 uid = 0); - ~Object(); - - static bool isPassable(const std::list & bottoms, const s32 maps_index); - static bool AllowDirect(const u8 general, const u16 direct); - - const MP2::object_t object; - const u16 icn; - const u32 id; - - private: -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objgras.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objgras.cpp deleted file mode 100644 index ba4da5b8c..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objgras.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "objgras.h" - -bool ObjGrass::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::OBJNGRA2: - // hill fort - if(1 < index && index < 5) return false; - else - // halfling hole - if(5 < index && index < 9) return false; - else - // tree city - if(20 < index && index < 23) return false; - else - // wind mill - if(55 == index || 59 == index) return false; - else - // archer house - if(84 == index) return false; - else - // goblin hut - if(92 == index) return false; - else - // dwarf cottadge - if(114 == index) return false; - else - // oracul - if(124 < index && index < 127) return false; - else - // obelisk - if(129 == index) return false; - else return true; - - case ICN::OBJNGRAS: - // abandoned mines - if(3 == index || (4 < index && index < 8)) return false; - else - // faerie ring - if(29 < index && index < 32) return false; - else - // rock - if((32 < index && index < 35) || (36 < index && index < 39) || (39 < index && index < 42) || - 43 == index || 45 == index || 47 == index || 49 == index) return false; - else - // lake - if((53 < index && index < 64) || (64 < index && index < 76)) return false; - else - // mound - if((76 < index && index < 79) || (148 < index && index < 151)) return false; - else - // trees - if((82 < index && index < 86) || (88 < index && index < 91) || 93 == index) return false; - else - // shrub - if((94 < index && index < 98) || (98 < index && index < 102) || (102 < index && index < 105) || - (105 < index && index < 108) || (108 < index && index < 111) || 112 == index || - (113 < index && index < 117) || (120 < index && index < 124) || (124 < index && index < 128) || - (128 < index && index < 132) || (134 < index && index < 137) || (138 < index && index < 141) || - 142 == index || 144 == index || 146 == index || 148 == index) return false; - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objgras.h b/project/jni/application/fheroes2/src/fheroes2/objects/objgras.h deleted file mode 100644 index 5fdf654dd..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objgras.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJGRAS_H -#define H2OBJGRAS_H - -#include "gamedefs.h" - -namespace ObjGrass -{ - bool isPassable(const u16 icn, const u8 index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objlava.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objlava.cpp deleted file mode 100644 index d12c5ab61..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objlava.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "objlava.h" - -bool ObjLava::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::OBJNLAV2: - // volcano - if((129 < index && index < 133) || (78 < index && index < 82)) return false; - else return true; - - case ICN::OBJNLAV3: - // volcano - if(243 < index && index < 247) return false; - else return true; - - case ICN::OBJNLAVA: - // crater - if((1 < index && index < 10) || (11 < index && index < 18)) return false; - else - // lava pool - if((17 < index && index < 21) || (26 < index && index < 45) || (45 < index && index < 49) || - ( 49 < index && index < 64) || (64 < index && index < 74)) return false; - else - // volcano - if((75 < index && index < 78) || 88 == index || 98 == index) return false; - else - // obelisk - if(110 == index) return false; - else - // daemon cave - if(113 < index && index < 116) return false; - else - // sign - if(117 == index) return false; - else - // saw mill - if(119 < index && index < 125) return false; - - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objlava.h b/project/jni/application/fheroes2/src/fheroes2/objects/objlava.h deleted file mode 100644 index 17623b882..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objlava.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJLAVA_H -#define H2OBJLAVA_H - -#include "gamedefs.h" - -namespace ObjLava -{ - bool isPassable(const u16 icn, const u8 index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objmult.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objmult.cpp deleted file mode 100644 index c57fb9fbc..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objmult.cpp +++ /dev/null @@ -1,142 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "objmult.h" - -bool ObjMulti::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::OBJNMUL2: - // fountain - if(15 == index) return false; - else - // stub - if(16 == index || (17 < index && index < 20)) return false; - else - // alchemy tower - if(24 < index && index < 28) return false; - else - // dragon city - if(46 == index || (50 < index && index < 56)) return false; - else - // grave yard - if(56 < index && index < 59) return false; - else - // light house - if(73 == index) return false; - else - // saw mill - if(75 < index && index < 82) return false; - else - // water well - if(98 == index || 105 == index || 112 == index) return false; - else - // sign - if(114 == index) return false; - else - // teleport - if(116 == index || 119 == index || 122 == index) return false; - else - // wagon camp - if((123 < index && index < 127) || (127 < index && index < 130) || 136 == index) return false; - else - // well - if(162 == index || 165 == index) return false; - else - // freeman foundry - if(186 < index && index < 189) return false; - else - // magick garden - if(190 == index) return false; - else - // observation tower - if(201 == index) return false; - else - // grave yard - if(206 < index && index < 210) return false; - else - // saw mill - if(211 < index && index < 217) return false; - - else return true; - - case ICN::OBJNMULT: - // dead tree - if(2 == index || 4 == index) return false; - else - // peasant hut - if(35 == index) return false; - else - // fort - if(57 < index && index < 60) return false; - else - // gasebo - if(62 == index) return false; - else - // shrub - if(62 < index && index < 66) return false; - else - // witch hut - if(69 == index) return false; - else - // mercenary camp - if(69 < index && index < 73) return false; - else - // ruins - if(72 < index && index < 75) return false; - else - // shrine - if(76 == index || 78 == index || 80 == index) return false; - else - // idol - if(82 == index) return false; - else - // standing stones - if(83 < index && index < 86) return false; - else - // temple - if(87 < index && index < 90) return false; - else - // market - if(104 == index || 111 == index) return false; - else - // tree house - if(114 == index) return false; - else - // watch tower - if(116 == index) return false; - else - // tree knowledge - if(123 == index) return false; - else - // camp fire - if(131 == index) return false; - - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objmult.h b/project/jni/application/fheroes2/src/fheroes2/objects/objmult.h deleted file mode 100644 index 574abed38..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objmult.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJMULT_H -#define H2OBJMULT_H - -#include "gamedefs.h" - -namespace ObjMulti -{ - bool isPassable(const u16 icn, const u8 index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objsnow.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objsnow.cpp deleted file mode 100644 index f02df3e04..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objsnow.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "objsnow.h" - -bool ObjSnow::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::OBJNSNOW: - // cave for centaur - if((1 < index && index < 4)) return false; - else - // camp fire - if(4 == index) return false; - else - // rock - if(22 == index || (25 < index && index < 29) || 30 == index || - 32 == index || (33 < index && index < 36) || (36 < index && index < 40)) return false; - else - // stub - if(40 < index && index < 43) return false; - else - // trees - if((48 < index && index < 51) || (54 < index && index < 58) || 60 == index || - (63 < index && index < 66) || 68 == index || 71 == index || - 74 == index || 77 == index || 80 == index) return false; - else - // lake - if((80 < index && index < 93) || (93 < index && index < 96)) return false; - else - //wind mill - if(128 == index || 132 == index) return false; - else - // watch tower - if(138 == index) return false; - else - // obelisk - if(141 == index) return false; - else - // sign - if(143 == index) return false; - else - // alchemy tower - if(148 < index && index < 152) return false; - else - // graveyard - if((158 < index && index < 161) || (207 < index && index < 211)) return false; - else - // water mill - if(177 == index || 184 == index || 191 == index) return false; - else - // well - if(194 == index) return false; - else - // saw mill - if((196 < index && index < 202)) return false; - - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objsnow.h b/project/jni/application/fheroes2/src/fheroes2/objects/objsnow.h deleted file mode 100644 index ed03f6457..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objsnow.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJSNOW_H -#define H2OBJSNOW_H - -#include "gamedefs.h" - -namespace ObjSnow -{ - bool isPassable(const u16 icn, const u8 index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objswmp.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objswmp.cpp deleted file mode 100644 index 1327c1c57..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objswmp.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "objswmp.h" - -bool ObjSwamp::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::OBJNSWMP: - // witch hut - if(22 == index) return false; - else - // shrub - if((31 < index && index < 34)) return false; - else - // xanadu - if(67 == index || 74 == index || (80 < index && index < 83)) return false; - else - // faerie ring - if((83 < index && index < 86)) return false; - else - // lake - if((87 < index && index < 92) || (93 < index && index < 99) || (100 < index && index < 106)) return false; - else - if((107 < index && index < 111) || (111 < index && index < 114)) return false; - else - if((114 < index && index < 117) || (117 < index && index < 120) || (121 < index && index < 124)) return false; - else - // mandrake - if(126 == index || (127 < index && index < 130) || 131 == index || (132 < index && index < 136) || 137 == index) return false; - else - // swamp - if((137 < index && index < 140) || (142 < index && index < 161)) return false; - else - // sign - if(140 == index) return false; - else - // trees - if((165 < index && index < 168) || (170 < index && index < 173) || (175 < index && index < 178)) return false; - else - // swamp - if((178 < index && index < 193) || (211 < index && index < 214)) return false; - else - // shrub - if((192 < index && index < 195) || 196 == index || (197 < index && index < 202)) return false; - else - // rock - if(203 == index || 205 == index || (207 < index && index < 211)) return false; - else - // obelisk - if(216 == index) return false; - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objswmp.h b/project/jni/application/fheroes2/src/fheroes2/objects/objswmp.h deleted file mode 100644 index dbce9112f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objswmp.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJSWMP_H -#define H2OBJSWMP_H - -#include "gamedefs.h" - -namespace ObjSwamp -{ - bool isPassable(const u16 icn, const u8 index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objtown.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objtown.cpp deleted file mode 100644 index 2cbd5af31..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objtown.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "maps.h" -#include "world.h" -#include "maps_tiles.h" -#include "game_focus.h" -#include "direction.h" -#include "objtown.h" - -bool ObjTown::isPassable(const u16 icn, const u8 index, const s32 maps_index) -{ - switch(icn) - { - case ICN::OBJNTWBA: - if(4 < index && index < 10 && 7 != index) - { - if(!Maps::isValidDirection(maps_index, Direction::BOTTOM)) return false; - const Maps::Tiles & tiles = world.GetTiles(Maps::GetDirectionIndex(maps_index, Direction::BOTTOM)); - Game::Focus & focus = Game::Focus::Get(); - return tiles.isPassable((Game::Focus::HEROES == focus.Type() ? &focus.GetHeroes() : NULL), false); - } - - if(index < 5 || ( 9 < index && index < 15) || (19 < index && index < 25) || - (29 < index && index < 35) || (39 < index && index < 45) || (49 < index && index < 55) || - (59 < index && index < 65) || (69 < index && index < 75) || 79 < index) return false; - else return true; - break; - - case ICN::OBJNTOWN: - // kngt - if((5 < index && index < 13) || (13 < index && index < 16) || - (21 < index && index < 29) || (29 < index && index < 32)) return false; - else - // barb - if((37 < index && index < 45) || (45 < index && index < 48) || - (53 < index && index < 61) || (61 < index && index < 64)) return false; - else - // sorc - if((69 < index && index < 77) || (77 < index && index < 80) || - (85 < index && index < 93) || (93 < index && index < 96)) return false; - else - // wrlk - if((101 < index && index < 109) || (109 < index && index < 112) || - (117 < index && index < 125) || (125 < index && index < 128)) return false; - else - // wzrd - if((133 < index && index < 141) || (141 < index && index < 144) || - (149 < index && index < 157) || (157 < index && index < 160)) return false; - else - // necr - if((165 < index && index < 173) || (173 < index && index < 176) || - (181 < index && index < 189) || (189 < index && index < 192)) return false; - - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objtown.h b/project/jni/application/fheroes2/src/fheroes2/objects/objtown.h deleted file mode 100644 index 41ce5ef47..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objtown.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJTOWN_H -#define H2OBJTOWN_H - -#include "gamedefs.h" - -namespace ObjTown -{ - bool isPassable(const u16 icn, const u8 index, const s32 maps_index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objwatr.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objwatr.cpp deleted file mode 100644 index 3c807959a..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objwatr.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "objwatr.h" - -bool ObjWater::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::OBJNWAT2: - // rock - if(2 == index) return false; - else - // ship - if(11 == index || 12 == index || (18 < index && index < 23)) return false; - - else return true; - - case ICN::OBJNWATR: - // buttle - if(0 == index) return false; - else - // chest - if(19 == index) return false; - else - // flotsam - if(45 == index) return false; - else - // magellan maps - if(62 == index || 69 == index) return false; - else - // surviror - if(111 == index) return false; - else - // rock - if((181 < index && index < 184) || (184 < index && index < 188)) return false; - else - // buoy - if(195 == index) return false; - else - // whirlpoll - if(202 == index || 206 == index || 210 == index || 214 == index || 218 == index || 222 == index) return false; - else - // ship - if(241 == index || 248 == index) return false; - - else return true; - - default: break; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objwatr.h b/project/jni/application/fheroes2/src/fheroes2/objects/objwatr.h deleted file mode 100644 index 747bfa323..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objwatr.h +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJWATR_H -#define H2OBJWATR_H - -#include "gamedefs.h" - -namespace ObjWater -{ - bool isPassable(const u16 icn, const u8 index); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objxloc.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/objxloc.cpp deleted file mode 100644 index fe2f13565..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objxloc.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "icn.h" -#include "mp2.h" -#include "maps_tiles.h" -#include "objxloc.h" - -bool ObjLoyalty::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - case ICN::X_LOC1: - // alchemist tower - if(3 == index) return false; - else - // arena - if(31 == index || 40 == index || (48 < index && index < 51) || - (68 < index && index < 72)) return false; - else - // barrow mounds - if(74 < index && index < 78) return false; - else - // eath altar - if(85 == index || 94 == index || 103 == index) return false; - else - // air altar - if(116 < index && index < 120) return false; - else - // air altar - if(125 < index && index < 129) return false; - else - // water altar - if(133 < index && index < 137) return false; - else return true; - - case ICN::X_LOC2: - // stables - if(2 < index && index < 5) return false; - else - // jail - if(9 == index) return false; - else - // mermaid - if(28 == index || 37 == index || 46 == index) return false; - else - // sirens - if(92 == index || (100 < index && index < 103)) return false; - else - // reefs - if(110 < index && index < 136) return false; - else return true; - - case ICN::X_LOC3: - // hut magi - if(30 == index) return false; - else - // eyes magi - if(50 == index) return false; - else - // barrier - if(60 == index || 66 == index || 72 == index || - 78 == index || 84 == index || 90 == index || - 96 == index || 102 == index) return false; - else - // traveller tent - if(110 == index || 114 == index || 118 == index || - 122 == index || 126 == index || 130 == index || - 134 == index || 138 == index) return false; - else return true; - - default: break; - } - - return false; -} - -u8 ObjLoyalty::LearnObject(const Maps::TilesAddon & addon) -{ - switch(MP2::GetICNObject(addon.object)) - { - case ICN::X_LOC1: - if(addon.index == 3) return MP2::OBJ_ALCHEMYTOWER; - else - if(addon.index < 3) return MP2::OBJN_ALCHEMYTOWER; - else - if(70 == addon.index) return MP2::OBJ_ARENA; - else - if(3 < addon.index && addon.index < 72) return MP2::OBJN_ARENA; - else - if(77 == addon.index) return MP2::OBJ_BARROWMOUNDS; - else - if(71 < addon.index && addon.index < 78) return MP2::OBJN_BARROWMOUNDS; - else - if(94 == addon.index) return MP2::OBJ_EARTHALTAR; - else - if(77 < addon.index && addon.index < 112) return MP2::OBJN_EARTHALTAR; - else - if(118 == addon.index) return MP2::OBJ_AIRALTAR; - else - if(111 < addon.index && addon.index < 120) return MP2::OBJN_AIRALTAR; - else - if(127 == addon.index) return MP2::OBJ_FIREALTAR; - else - if(119 < addon.index && addon.index < 129) return MP2::OBJN_FIREALTAR; - else - if(135 == addon.index) return MP2::OBJ_WATERALTAR; - else - if(128 < addon.index && addon.index < 137) return MP2::OBJN_WATERALTAR; - break; - - case ICN::X_LOC2: - if(addon.index == 4) return MP2::OBJ_STABLES; - else - if(addon.index < 4) return MP2::OBJN_STABLES; - else - if(addon.index == 9) return MP2::OBJ_JAIL; - else - if(4 < addon.index && addon.index < 10) return MP2::OBJN_JAIL; - else - if(addon.index == 37) return MP2::OBJ_MERMAID; - else - if(9 < addon.index && addon.index < 47) return MP2::OBJN_MERMAID; - else - if(addon.index == 101) return MP2::OBJ_SIRENS; - else - if(46 < addon.index && addon.index < 111) return MP2::OBJN_SIRENS; - else - if(110 < addon.index && addon.index < 136) return MP2::OBJ_REEFS; - break; - - case ICN::X_LOC3: - if(addon.index == 30) return MP2::OBJ_HUTMAGI; - else - if(addon.index < 32) return MP2::OBJN_HUTMAGI; - else - if(addon.index == 50) return MP2::OBJ_EYEMAGI; - else - if(31 < addon.index && addon.index < 59) return MP2::OBJN_EYEMAGI; - // fix - break; - - default: break; - } - - return MP2::OBJ_ZERO; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/objxloc.h b/project/jni/application/fheroes2/src/fheroes2/objects/objxloc.h deleted file mode 100644 index 9e2307808..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/objxloc.h +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2OBJXLOC_H -#define H2OBJXLOC_H - -#include "gamedefs.h" - -namespace Maps { class TilesAddon; } - -namespace ObjLoyalty -{ - bool isPassable(const u16 icn, const u8 index); - u8 LearnObject(const Maps::TilesAddon & addon); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/trees.cpp b/project/jni/application/fheroes2/src/fheroes2/objects/trees.cpp deleted file mode 100644 index c4bfaf33e..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/trees.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "settings.h" -#include "trees.h" - -Trees::Trees(const ICN::icn_t icn) : Object(MP2::OBJ_TREES, icn) -{ - switch(icn) - { - case ICN::TREJNGL: - case ICN::TREEVIL: - case ICN::TRESNOW: - case ICN::TREFIR: - case ICN::TREFALL: - case ICN::TREDECI: break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Trees::Trees: unknown type"); break; - } -} - -bool Trees::isPassable(const u16 icn, const u8 index) -{ - switch(icn) - { - // 36 sprites - case ICN::TREDECI: - case ICN::TREEVIL: - case ICN::TREFALL: - case ICN::TREFIR: - case ICN::TREJNGL: - case ICN::TRESNOW: - if((3 < index && index < 6) || (7 < index && index < 10)) return false; // LARGE LEFT - else - if((14 < index && index < 17) || (17 < index && index < 20)) return false; // LARGE RIGHT - else - if((20 < index && index < 23) || (23 < index && index < 26)) return false; // MEDIUM LEFT - else - if((26 < index && index < 29) || (29 < index && index < 32)) return false; // MEDIUM RIGHT - else - if(33 == index || 35 == index) return false; // SMALL - else return true; - - default: break;; - } - - return false; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/objects/trees.h b/project/jni/application/fheroes2/src/fheroes2/objects/trees.h deleted file mode 100644 index e5dd7456c..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/objects/trees.h +++ /dev/null @@ -1,40 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2TREES_H -#define H2TREES_H - -#include "icn.h" -#include "object.h" -#include "gamedefs.h" - -class Trees : public Object -{ - public: - Trees(const ICN::icn_t icn); - - static bool isPassable(const u16 icn, const u8 index); - - private: -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc.h b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc.h deleted file mode 100644 index 5c0a10f26..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc.h +++ /dev/null @@ -1,48 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2POCKETPC_H -#define H2POCKETPC_H - -#include "game.h" -#include "dialog.h" -#include "maps_fileinfo.h" -#include "gamedefs.h" - -namespace PocketPC -{ - Game::menu_t MainMenu(void); - Game::menu_t NewGame(void); - Game::menu_t NewMulti(void); - Game::menu_t SelectScenario(void); - Game::menu_t ScenarioInfo(void); - Game::menu_t LoadGame(void); - Dialog::answer_t HeroesOpenDialog(Heroes &, bool); - Dialog::answer_t CastleOpenDialog(Castle &); - Dialog::answer_t DialogArmyInfo(const Army::Troop &, u16); - void HeroesMeeting(Heroes &, Heroes &); - void KeyboardDialog(std::string &); - u16 GetCursorAttackDialog(const Point &, u8); - void ThievesGuild(bool oracle); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_armyinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_armyinfo.cpp deleted file mode 100644 index 192cb3559..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_armyinfo.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "cursor.h" -#include "settings.h" -#include "text.h" -#include "button.h" -#include "army.h" -#include "selectarmybar.h" -#include "army.h" -#include "battle_stats.h" -#include "pocketpc.h" - -void DrawMonsterStats(const Point &, const Army::Troop &); -void DrawBattleStats(const Point &, const Battle2::Stats &); - -Dialog::answer_t PocketPC::DialogArmyInfo(const Army::Troop & troop, u16 flags) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Monster & mons = troop; - const Battle2::Stats* battle = troop.GetBattleStats(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - // name - Text text; - text.Set(mons.GetName(), Font::BIG); - text.Blit(dst_rt.x + (dst_rt.w - text.w()) / 2, dst_rt.y + 10); - - const Sprite & frame = AGG::GetICN(troop.ICNMonh(), 0); - display.Blit(frame, dst_rt.x + 50 - frame.w() / 2, dst_rt.y + 145 - frame.h()); - - std::string message; - String::AddInt(message, (battle ? battle->GetCount() : troop.GetCount())); - text.Set(message); - text.Blit(dst_rt.x + 50 - text.w() / 2, dst_rt.y + 150); - - // stats - DrawMonsterStats(Point(dst_rt.x + 200, dst_rt.y + 40), troop); - - if(battle) - DrawBattleStats(Point(dst_rt.x + 160, dst_rt.y + 160), *battle); - - Button buttonDismiss(dst_rt.x + dst_rt.w / 2 - 160, dst_rt.y + dst_rt.h - 30, ICN::VIEWARMY, 1, 2); - Button buttonUpgrade(dst_rt.x + dst_rt.w / 2 - 60, dst_rt.y + dst_rt.h - 30, ICN::VIEWARMY, 5, 6); - Button buttonExit(dst_rt.x + dst_rt.w / 2 + 60, dst_rt.y + dst_rt.h - 30, ICN::VIEWARMY, 3, 4); - - if(Dialog::READONLY & flags) - { - buttonDismiss.Press(); - buttonDismiss.SetDisable(true); - } - - if(!(Dialog::BATTLE & flags) && mons.isAllowUpgrade()) - { - if(Dialog::UPGRADE & flags) - { - buttonUpgrade.SetDisable(false); - buttonUpgrade.Draw(); - } - else if(Dialog::READONLY & flags) - { - buttonUpgrade.Press(); - buttonUpgrade.SetDisable(true); - buttonUpgrade.Draw(); - } - else buttonUpgrade.SetDisable(true); - } - else buttonUpgrade.SetDisable(true); - - if(!(Dialog::BATTLE & flags)) - { - buttonDismiss.Draw(); - buttonExit.Draw(); - } - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - if(buttonUpgrade.isEnable()) le.MousePressLeft(buttonUpgrade) ? (buttonUpgrade).PressDraw() : (buttonUpgrade).ReleaseDraw(); - if(buttonDismiss.isEnable()) le.MousePressLeft(buttonDismiss) ? (buttonDismiss).PressDraw() : (buttonDismiss).ReleaseDraw(); - le.MousePressLeft(buttonExit) ? (buttonExit).PressDraw() : (buttonExit).ReleaseDraw(); - - if(buttonUpgrade.isEnable() && le.MouseClickLeft(buttonUpgrade)) return Dialog::UPGRADE; - else - if(buttonDismiss.isEnable() && le.MouseClickLeft(buttonDismiss)) return Dialog::DISMISS; - else - if(le.MouseClickLeft(buttonExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) return Dialog::CANCEL; - } - - return Dialog::ZERO; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_castle.cpp b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_castle.cpp deleted file mode 100644 index 47b405696..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_castle.cpp +++ /dev/null @@ -1,1080 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "cursor.h" -#include "settings.h" -#include "text.h" -#include "button.h" -#include "castle.h" -#include "kingdom.h" -#include "heroes.h" -#include "portrait.h" -#include "world.h" -#include "selectarmybar.h" -#include "buildinginfo.h" -#include "profit.h" -#include "pocketpc.h" - -class DwellingBar : protected Rect -{ -public: - DwellingBar(const Point &, const Castle &); - void Redraw(void) const; - const Rect & GetArea(void) const; - bool QueueEventProcessing(void); - static u32 GetDwellingFromIndex(u8); - -private: - const Castle & castle; - std::vector dw; -}; - -void RedrawTownSprite(const Rect &, const Castle &); -void RedrawBackground(const Rect &, const Castle &); -void RedrawResourceBar(const Point &, const Resource::funds_t &); - -enum screen_t { SCREENOUT, SCREENOUT_PREV, SCREENOUT_NEXT, SCREEN1, SCREEN2, SCREEN3, SCREEN4, SCREEN5, SCREEN6 }; - -screen_t CastleOpenDialog1(Castle &); -screen_t CastleOpenDialog2(Castle &); -screen_t CastleOpenDialog3(Castle &); -screen_t CastleOpenDialog4(Castle &); -screen_t CastleOpenDialog5(Castle &); -screen_t CastleOpenDialog6(Castle &); - -Dialog::answer_t PocketPC::CastleOpenDialog(Castle & castle) -{ - Mixer::Reset(); - AGG::PlayMusic(MUS::FromRace(castle.GetRace())); - - screen_t screen = CastleOpenDialog1(castle); - while(SCREENOUT != screen) - switch(screen) - { - case SCREEN1: screen = CastleOpenDialog1(castle); break; - case SCREEN2: screen = CastleOpenDialog2(castle); break; - case SCREEN3: screen = CastleOpenDialog3(castle); break; - case SCREEN4: screen = CastleOpenDialog4(castle); break; - case SCREEN5: screen = CastleOpenDialog5(castle); break; - case SCREEN6: screen = CastleOpenDialog6(castle); break; - case SCREENOUT_PREV: return Dialog::PREV; - case SCREENOUT_NEXT: return Dialog::NEXT; - default: break; - } - return Dialog::CANCEL; -} - -screen_t CastleOpenDialog1(Castle & castle) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & backSprite = AGG::GetICN(ICN::SWAPWIN, 0); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - RedrawBackground(dst_rt, castle); - - Text text; - text.Set(castle.GetName(), Font::YELLOW_SMALL); - text.Blit(dst_rt.x + (dst_rt.w - text.w()) / 2, dst_rt.y + 3); - - // town icon - const Sprite & slock = AGG::GetICN(ICN::LOCATORS, 23); - const Rect rectTown(dst_rt.x, dst_rt.y + 2, slock.w(), slock.h()); - RedrawTownSprite(rectTown, castle); - - // dwelling bar - DwellingBar dwbar(Point(dst_rt.x + 2, dst_rt.y + 34), castle); - dwbar.Redraw(); - - Point pt; - - // castle army bar - pt.x = dst_rt.x + 2; - pt.y = dst_rt.y + 79; - - display.Blit(AGG::GetICN(ICN::SWAPWIN, 0), Rect(36, 267, 43, 43), pt.x, pt.y); - if(castle.isBuild(BUILD_CAPTAIN)) - { - const Surface & icon = Portrait::Captain(castle.GetRace(), Portrait::BIG); - display.Blit(icon, Rect((icon.w() - 41) / 2, 15, 41, 41), pt.x + 1, pt.y + 1); - } - else - { - const Sprite & crest = AGG::GetICN(ICN::BRCREST, Color::GetIndex(castle.GetColor())); - display.Blit(crest, Rect((crest.w() - 41) / 2, (crest.h() - 41) / 2, 41, 41), pt.x + 1, pt.y + 1); - } - - const Rect rt1(36, 267, 43, 53); - Surface sfb1(rt1.w, rt1.h); - sfb1.Blit(backSprite, rt1, 0, 0); - Surface sfc1(rt1.w, rt1.h - 10); - Cursor::DrawCursor(sfc1, 0x10, true); - - SelectArmyBar selectCastleArmy; - selectCastleArmy.SetArmy(castle.GetArmy()); - selectCastleArmy.SetPos(pt.x + 45, pt.y); - selectCastleArmy.SetInterval(2); - selectCastleArmy.SetBackgroundSprite(sfb1); - selectCastleArmy.SetCursorSprite(sfc1); - selectCastleArmy.SetUseMons32Sprite(); - selectCastleArmy.SetCastle(castle); - selectCastleArmy.Redraw(); - - // hero army bar - pt.x = dst_rt.x + 2; - pt.y = dst_rt.y + 132; - const Heroes* hero = castle.GetHeroes(); - - SelectArmyBar selectHeroesArmy; - selectHeroesArmy.SetPos(pt.x + 45, pt.y); - selectHeroesArmy.SetInterval(2); - selectHeroesArmy.SetBackgroundSprite(sfb1); - selectHeroesArmy.SetCursorSprite(sfc1); - selectHeroesArmy.SetUseMons32Sprite(); - selectHeroesArmy.SetSaveLastTroop(); - selectHeroesArmy.SetCastle(castle); - - display.Blit(AGG::GetICN(ICN::SWAPWIN, 0), Rect(36, 267, 43, 43), pt.x, pt.y); - const Rect heroSign(pt.x + 1, pt.y + 1, 41, 41); - if(hero) - { - const Surface & icon = Portrait::Hero(*hero, Portrait::MEDIUM); - display.Blit(icon, Rect((icon.w() - 41) / 2, (icon.h() - 41) / 2, 41, 41), heroSign); - - selectHeroesArmy.SetArmy(const_cast(hero->GetArmy())); - selectHeroesArmy.Redraw(); - } - else - { - const Sprite & crest = AGG::GetICN(ICN::BRCREST, Color::GetIndex(castle.GetColor())); - display.Blit(crest, Rect((crest.w() - 41) / 2, (crest.h() - 41) / 2, 41, 41), heroSign); - } - - // resource bar - RedrawResourceBar(Point(dst_rt.x + 4, dst_rt.y + 181), world.GetMyKingdom().GetFundsResource()); - - const Rect rectExit(dst_rt.x + dst_rt.w - 26, dst_rt.y + 7, 25, 25); - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), rectExit.x, rectExit.y); - - const Rect rectScreen1(dst_rt.x + dst_rt.w - 27, dst_rt.y + 32, 25, 25); - const Rect rectScreen2(dst_rt.x + dst_rt.w - 27, dst_rt.y + 58, 25, 25); - const Rect rectScreen3(dst_rt.x + dst_rt.w - 27, dst_rt.y + 84, 25, 25); - const Rect rectScreen4(dst_rt.x + dst_rt.w - 27, dst_rt.y + 110, 25, 25); - const Rect rectScreen5(dst_rt.x + dst_rt.w - 27, dst_rt.y + 136, 25, 25); - const Rect rectScreen6(dst_rt.x + dst_rt.w - 27, dst_rt.y + 162, 25, 25); - - display.Blit(AGG::GetICN(ICN::REQUESTS, 20), rectScreen1.x, rectScreen1.y); - - if(castle.isBuild(BUILD_CASTLE)) - { - display.Blit(AGG::GetICN(ICN::REQUESTS, 21), rectScreen2.x, rectScreen2.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 22), rectScreen3.x, rectScreen3.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 23), rectScreen4.x, rectScreen4.y); - } - if(castle.isBuild(BUILD_CASTLE) || castle.isBuild(BUILD_TAVERN)) - display.Blit(AGG::GetICN(ICN::REQUESTS, 24), rectScreen5.x, rectScreen5.y); - if(castle.isBuild(BUILD_MAGEGUILD1)) - display.Blit(AGG::GetICN(ICN::REQUESTS, 25), rectScreen6.x, rectScreen6.y); - - // update extra description - std::string description_castle = castle.GetDescriptionBuilding(BUILD_CASTLE, castle.GetRace()); - { - payment_t profit = ProfitConditions::FromBuilding(BUILD_CASTLE, castle.GetRace()); - String::Replace(description_castle, "%{count}", profit.gold); - } - - Button buttonPrev(dst_rt.x + 64, dst_rt.y + 5, ICN::TRADPOST, 3, 4); - Button buttonNext(dst_rt.x + 245, dst_rt.y + 5, ICN::TRADPOST, 5, 6); - if(2 > world.GetMyKingdom().GetCastles().size()) - { - buttonNext.Press(); - buttonPrev.Press(); - buttonNext.SetDisable(true); - buttonPrev.SetDisable(true); - } - buttonNext.Draw(); - buttonPrev.Draw(); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - le.MousePressLeft(buttonNext) ? buttonNext.PressDraw() : buttonNext.ReleaseDraw(); - le.MousePressLeft(buttonPrev) ? buttonPrev.PressDraw() : buttonPrev.ReleaseDraw(); - - //if(le.MouseClickLeft(rectScreen1)) return SCREEN1; - //else - if(castle.isBuild(BUILD_CASTLE) && le.MouseClickLeft(rectScreen2)) return SCREEN2; - else - if(castle.isBuild(BUILD_CASTLE) && le.MouseClickLeft(rectScreen3)) return SCREEN3; - else - if(castle.isBuild(BUILD_CASTLE) && le.MouseClickLeft(rectScreen4)) return SCREEN4; - else - if(castle.isBuild(BUILD_CASTLE) && le.MouseClickLeft(rectScreen5)) return SCREEN5; - else - if(castle.isBuild(BUILD_MAGEGUILD1) && le.MouseClickLeft(rectScreen6)) return SCREEN6; - else - // exit - if(le.MouseClickLeft(rectExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break; - else - if(buttonNext.isEnable() && le.MouseClickLeft(buttonNext)) return SCREENOUT_NEXT; - else - if(buttonPrev.isEnable() && le.MouseClickLeft(buttonPrev)) return SCREENOUT_PREV; - else - if(le.MouseClickLeft(rectTown)) - { - if(castle.isBuild(BUILD_CASTLE)) - Dialog::Message(castle.GetStringBuilding(BUILD_CASTLE), description_castle, Font::BIG, Dialog::OK); - else - if(!castle.Modes(Castle::ALLOWCASTLE)) - Dialog::Message(_("Town"), _("This town may not be upgraded to a castle."), Font::BIG, Dialog::OK); - else - if(Dialog::OK == castle.DialogBuyCastle(true)) - { - // play sound - AGG::PlaySound(M82::BUILDTWN); - castle.BuyBuilding(BUILD_CASTLE); - cursor.Hide(); - RedrawTownSprite(rectTown, castle); - cursor.Show(); - display.Flip(); - } - } - else - if(le.MouseClickLeft(dwbar.GetArea()) && dwbar.QueueEventProcessing()) - { - cursor.Hide(); - dwbar.Redraw(); - selectCastleArmy.Redraw(); - RedrawResourceBar(Point(dst_rt.x + 4, dst_rt.y + 181), world.GetMyKingdom().GetFundsResource()); - cursor.Show(); - display.Flip(); - } - else - if(hero && le.MouseClickLeft(heroSign)) - { - cursor.Hide(); - const_cast(hero)->OpenDialog(false, false); - cursor.Show(); - display.Flip(); - } - - // troops event - if(hero && selectHeroesArmy.isValid()) - { - if(le.MouseCursor(selectCastleArmy.GetArea()) || le.MouseCursor(selectHeroesArmy.GetArea())) - SelectArmyBar::QueueEventProcessing(selectCastleArmy, selectHeroesArmy); - } - else - { - if(le.MouseCursor(selectCastleArmy.GetArea())) - SelectArmyBar::QueueEventProcessing(selectCastleArmy); - } - } - return SCREENOUT; -} - -screen_t CastleOpenDialog2(Castle & castle) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - const Rect rectExit(dst_rt.x + dst_rt.w - 26, dst_rt.y + 7, 25, 25); - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), rectExit.x, rectExit.y); - - const Rect rectScreen1(dst_rt.x + dst_rt.w - 27, dst_rt.y + 32, 25, 25); - const Rect rectScreen2(dst_rt.x + dst_rt.w - 27, dst_rt.y + 58, 25, 25); - const Rect rectScreen3(dst_rt.x + dst_rt.w - 27, dst_rt.y + 84, 25, 25); - const Rect rectScreen4(dst_rt.x + dst_rt.w - 27, dst_rt.y + 110, 25, 25); - const Rect rectScreen5(dst_rt.x + dst_rt.w - 27, dst_rt.y + 136, 25, 25); - const Rect rectScreen6(dst_rt.x + dst_rt.w - 27, dst_rt.y + 162, 25, 25); - - display.Blit(AGG::GetICN(ICN::REQUESTS, 20), rectScreen1.x, rectScreen1.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 21), rectScreen2.x, rectScreen2.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 22), rectScreen3.x, rectScreen3.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 23), rectScreen4.x, rectScreen4.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 24), rectScreen5.x, rectScreen5.y); - if(castle.isBuild(BUILD_MAGEGUILD1)) display.Blit(AGG::GetICN(ICN::REQUESTS, 25), rectScreen6.x, rectScreen6.y); - - BuildingInfo dwelling1(castle, DWELLING_MONSTER1); - dwelling1.SetPos(dst_rt.x + 2, dst_rt.y + 2); - dwelling1.Redraw(); - - BuildingInfo dwelling2(castle, DWELLING_MONSTER2); - dwelling2.SetPos(dst_rt.x + 141, dst_rt.y + 2); - dwelling2.Redraw(); - - BuildingInfo dwelling3(castle, DWELLING_MONSTER3); - dwelling3.SetPos(dst_rt.x + 2, dst_rt.y + 76); - dwelling3.Redraw(); - - BuildingInfo dwelling4(castle, DWELLING_MONSTER4); - dwelling4.SetPos(dst_rt.x + 141, dst_rt.y + 76); - dwelling4.Redraw(); - - BuildingInfo dwelling5(castle, DWELLING_MONSTER5); - dwelling5.SetPos(dst_rt.x + 2, dst_rt.y + 150); - dwelling5.Redraw(); - - BuildingInfo dwelling6(castle, DWELLING_MONSTER6); - dwelling6.SetPos(dst_rt.x + 141, dst_rt.y + 150); - dwelling6.Redraw(); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - if(le.MouseClickLeft(rectScreen1)) return SCREEN1; - else - if(le.MouseClickLeft(rectScreen3)) return SCREEN3; - else - if(le.MouseClickLeft(rectScreen4)) return SCREEN4; - else - if(le.MouseClickLeft(rectScreen5)) return SCREEN5; - else - if(castle.isBuild(BUILD_MAGEGUILD1) && le.MouseClickLeft(rectScreen6)) return SCREEN6; - else - // exit - if(le.MouseClickLeft(rectExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break; - - if(le.MouseCursor(dwelling1.GetArea()) && dwelling1.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(dwelling1()); return SCREEN1; } - else - if(le.MouseCursor(dwelling2.GetArea()) && dwelling2.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(dwelling2()); return SCREEN1; } - else - if(le.MouseCursor(dwelling3.GetArea()) && dwelling3.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(dwelling3()); return SCREEN1; } - else - if(le.MouseCursor(dwelling4.GetArea()) && dwelling4.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(dwelling4()); return SCREEN1; } - else - if(le.MouseCursor(dwelling5.GetArea()) && dwelling5.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(dwelling5()); return SCREEN1; } - else - if(le.MouseCursor(dwelling6.GetArea()) && dwelling6.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(dwelling6()); return SCREEN1; } - } - return SCREENOUT; -} - -screen_t CastleOpenDialog3(Castle & castle) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - const Rect rectExit(dst_rt.x + dst_rt.w - 26, dst_rt.y + 7, 25, 25); - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), rectExit.x, rectExit.y); - - const Rect rectScreen1(dst_rt.x + dst_rt.w - 27, dst_rt.y + 32, 25, 25); - const Rect rectScreen2(dst_rt.x + dst_rt.w - 27, dst_rt.y + 58, 25, 25); - const Rect rectScreen3(dst_rt.x + dst_rt.w - 27, dst_rt.y + 84, 25, 25); - const Rect rectScreen4(dst_rt.x + dst_rt.w - 27, dst_rt.y + 110, 25, 25); - const Rect rectScreen5(dst_rt.x + dst_rt.w - 27, dst_rt.y + 136, 25, 25); - const Rect rectScreen6(dst_rt.x + dst_rt.w - 27, dst_rt.y + 162, 25, 25); - - display.Blit(AGG::GetICN(ICN::REQUESTS, 20), rectScreen1.x, rectScreen1.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 21), rectScreen2.x, rectScreen2.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 22), rectScreen3.x, rectScreen3.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 23), rectScreen4.x, rectScreen4.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 24), rectScreen5.x, rectScreen5.y); - if(castle.isBuild(BUILD_MAGEGUILD1)) display.Blit(AGG::GetICN(ICN::REQUESTS, 25), rectScreen6.x, rectScreen6.y); - - building_t level = BUILD_NOTHING; - switch(castle.GetLevelMageGuild()) - { - case 0: level = BUILD_MAGEGUILD1; break; - case 1: level = BUILD_MAGEGUILD2; break; - case 2: level = BUILD_MAGEGUILD3; break; - case 3: level = BUILD_MAGEGUILD4; break; - default:level = BUILD_MAGEGUILD5; break; - } - - BuildingInfo building1(castle, level); - building1.SetPos(dst_rt.x + 2, dst_rt.y + 2); - building1.Redraw(); - - BuildingInfo building2(castle, BUILD_TAVERN); - building2.SetPos(dst_rt.x + 141, dst_rt.y + 2); - building2.Redraw(); - - BuildingInfo building3(castle, BUILD_THIEVESGUILD); - building3.SetPos(dst_rt.x + 2, dst_rt.y + 76); - building3.Redraw(); - - BuildingInfo building4(castle, BUILD_SHIPYARD); - building4.SetPos(dst_rt.x + 141, dst_rt.y + 76); - building4.Redraw(); - - BuildingInfo building5(castle, BUILD_STATUE); - building5.SetPos(dst_rt.x + 2, dst_rt.y + 150); - building5.Redraw(); - - BuildingInfo building6(castle, BUILD_MARKETPLACE); - building6.SetPos(dst_rt.x + 141, dst_rt.y + 150); - building6.Redraw(); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - if(le.MouseClickLeft(rectScreen1)) return SCREEN1; - else - if(le.MouseClickLeft(rectScreen2)) return SCREEN2; - else - if(le.MouseClickLeft(rectScreen4)) return SCREEN4; - else - if(le.MouseClickLeft(rectScreen5)) return SCREEN5; - else - if(castle.isBuild(BUILD_MAGEGUILD1) && le.MouseClickLeft(rectScreen6)) return SCREEN6; - else - // exit - if(le.MouseClickLeft(rectExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break; - - if(le.MouseCursor(building1.GetArea()) && building1.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building1()); return SCREEN1; } - else - if(le.MouseCursor(building2.GetArea()) && building2.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building2()); return SCREEN1; } - else - if(le.MouseCursor(building3.GetArea())) - { - // show thieves guild - if(castle.isBuild(BUILD_THIEVESGUILD)) - { - if(le.MouseClickLeft(building3.GetArea())){ PocketPC::ThievesGuild(false); return SCREEN1; } - } - else - if(building3.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building3()); return SCREEN1; } - } - else - if(le.MouseCursor(building4.GetArea())) - { - // buy boat - if(castle.isBuild(BUILD_SHIPYARD)) - { - if(le.MouseClickLeft(building4.GetArea()) && Dialog::OK == Dialog::BuyBoat(castle.AllowBuyBoat())) castle.BuyBoat(); - } - else - if(building4.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building4()); return SCREEN1; } - } - else - if(le.MouseCursor(building5.GetArea()) && building5.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building5()); return SCREEN1; } - else - if(le.MouseCursor(building6.GetArea())) - { - // show marketplace - if(castle.isBuild(BUILD_MARKETPLACE)) - { - if(le.MouseClickLeft(building6.GetArea())) Dialog::Marketplace(); - } - else - if(building6.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building6()); return SCREEN1; } - } - } - return SCREENOUT; -} - -screen_t CastleOpenDialog4(Castle & castle) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - const Rect rectExit(dst_rt.x + dst_rt.w - 26, dst_rt.y + 7, 25, 25); - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), rectExit.x, rectExit.y); - - const Rect rectScreen1(dst_rt.x + dst_rt.w - 27, dst_rt.y + 32, 25, 25); - const Rect rectScreen2(dst_rt.x + dst_rt.w - 27, dst_rt.y + 58, 25, 25); - const Rect rectScreen3(dst_rt.x + dst_rt.w - 27, dst_rt.y + 84, 25, 25); - const Rect rectScreen4(dst_rt.x + dst_rt.w - 27, dst_rt.y + 110, 25, 25); - const Rect rectScreen5(dst_rt.x + dst_rt.w - 27, dst_rt.y + 136, 25, 25); - const Rect rectScreen6(dst_rt.x + dst_rt.w - 27, dst_rt.y + 162, 25, 25); - - display.Blit(AGG::GetICN(ICN::REQUESTS, 20), rectScreen1.x, rectScreen1.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 21), rectScreen2.x, rectScreen2.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 22), rectScreen3.x, rectScreen3.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 23), rectScreen4.x, rectScreen4.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 24), rectScreen5.x, rectScreen5.y); - if(castle.isBuild(BUILD_MAGEGUILD1)) display.Blit(AGG::GetICN(ICN::REQUESTS, 25), rectScreen6.x, rectScreen6.y); - - BuildingInfo building1(castle, BUILD_WELL); - building1.SetPos(dst_rt.x + 2, dst_rt.y + 2); - building1.Redraw(); - - BuildingInfo building2(castle, BUILD_WEL2); - building2.SetPos(dst_rt.x + 141, dst_rt.y + 2); - building2.Redraw(); - - BuildingInfo building3(castle, BUILD_SPEC); - building3.SetPos(dst_rt.x + 2, dst_rt.y + 76); - building3.Redraw(); - - BuildingInfo building4(castle, BUILD_LEFTTURRET); - building4.SetPos(dst_rt.x + 141, dst_rt.y + 76); - building4.Redraw(); - - BuildingInfo building5(castle, BUILD_RIGHTTURRET); - building5.SetPos(dst_rt.x + 2, dst_rt.y + 150); - building5.Redraw(); - - BuildingInfo building6(castle, BUILD_MOAT); - building6.SetPos(dst_rt.x + 141, dst_rt.y + 150); - building6.Redraw(); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - if(le.MouseClickLeft(rectScreen1)) return SCREEN1; - else - if(le.MouseClickLeft(rectScreen2)) return SCREEN2; - else - if(le.MouseClickLeft(rectScreen3)) return SCREEN3; - else - if(le.MouseClickLeft(rectScreen5)) return SCREEN5; - else - if(castle.isBuild(BUILD_MAGEGUILD1) && le.MouseClickLeft(rectScreen6)) return SCREEN6; - else - // exit - if(le.MouseClickLeft(rectExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break; - - if(le.MouseCursor(building1.GetArea()) && building1.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building1()); return SCREEN1; } - else - if(le.MouseCursor(building2.GetArea()) && building2.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building2()); return SCREEN1; } - else - if(le.MouseCursor(building3.GetArea()) && building3.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building3()); return SCREEN1; } - else - if(le.MouseCursor(building4.GetArea()) && building4.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building4()); return SCREEN1; } - else - if(le.MouseCursor(building5.GetArea()) && building5.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building5()); return SCREEN1; } - else - if(le.MouseCursor(building6.GetArea()) && building6.QueueEventProcessing()) { AGG::PlaySound(M82::BUILDTWN); castle.BuyBuilding(building6()); return SCREEN1; } - } - return SCREENOUT; -} - -screen_t CastleOpenDialog5(Castle & castle) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - // tavern - Point dst_pt; - if(castle.isBuild(BUILD_TAVERN)) - { - Text text; - text.Set(castle.GetStringBuilding(BUILD_TAVERN), Font::SMALL); - text.Blit(dst_rt.x + (dst_rt.w - text.w()) / 2, dst_rt.y + 3); - - TextBox box1(_("A generous tip for the barkeep yields the following rumor:"), Font::SMALL, 186); - TextBox box2(world.GetRumors(), Font::SMALL, 186); - - box1.Blit(dst_rt.x + 67, dst_rt.y + 120); - box2.Blit(dst_rt.x + 67, dst_rt.y + 130 + box1.h()); - - const Sprite & s1 = AGG::GetICN(ICN::TAVWIN, 0); - dst_pt = Point(dst_rt.x + (dst_rt.w - s1.w()) / 2, dst_rt.y + 18); - display.Blit(s1, dst_pt); - - const Sprite & s20 = AGG::GetICN(ICN::TAVWIN, 1); - display.Blit(s20, dst_pt.x + 3, dst_pt.y + 3); - } - - Rect rectRecruit1, rectRecruit2, rectCaptain; - Heroes* hero1 = NULL; - Heroes* hero2 = NULL; - - if(castle.isBuild(BUILD_CASTLE)) - { - // hero - const Sprite & crest = AGG::GetICN(ICN::BRCREST, 6); - rectRecruit1 = Rect(dst_rt.x + 4, dst_rt.y + 18, crest.w(), crest.h()); - rectRecruit2 = Rect(dst_rt.x + 4, dst_rt.y + 77, crest.w(), crest.h()); - rectCaptain = Rect(dst_rt.x + 4, dst_rt.y + 136, crest.w(), crest.h()); - - hero1 = world.GetMyKingdom().GetRecruits().GetHero1(); - hero2 = world.GetMyKingdom().GetRecruits().GetHero2(); - - display.Blit(crest, rectRecruit1); - if(hero1) display.Blit(hero1->GetPortrait50x46(), rectRecruit1.x + 4, rectRecruit1.y + 4); - - display.Blit(crest, rectRecruit2); - if(hero2) display.Blit(hero2->GetPortrait50x46(), rectRecruit2.x + 4, rectRecruit2.y + 4); - - // captain - display.Blit(crest, rectCaptain); - const Surface & captain = Portrait::Captain(castle.GetRace(), Portrait::BIG); - display.Blit(captain, Rect((captain.w() - 50) / 2, 15, 50, 47), rectCaptain.x + 4, rectCaptain.y + 4); - } - - // buttons - const Rect rectExit(dst_rt.x + dst_rt.w - 26, dst_rt.y + 7, 25, 25); - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), rectExit.x, rectExit.y); - - const Rect rectScreen1(dst_rt.x + dst_rt.w - 27, dst_rt.y + 32, 25, 25); - const Rect rectScreen2(dst_rt.x + dst_rt.w - 27, dst_rt.y + 58, 25, 25); - const Rect rectScreen3(dst_rt.x + dst_rt.w - 27, dst_rt.y + 84, 25, 25); - const Rect rectScreen4(dst_rt.x + dst_rt.w - 27, dst_rt.y + 110, 25, 25); - const Rect rectScreen5(dst_rt.x + dst_rt.w - 27, dst_rt.y + 136, 25, 25); - const Rect rectScreen6(dst_rt.x + dst_rt.w - 27, dst_rt.y + 162, 25, 25); - - display.Blit(AGG::GetICN(ICN::REQUESTS, 20), rectScreen1.x, rectScreen1.y); - if(castle.isBuild(BUILD_CASTLE)) - { - display.Blit(AGG::GetICN(ICN::REQUESTS, 21), rectScreen2.x, rectScreen2.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 22), rectScreen3.x, rectScreen3.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 23), rectScreen4.x, rectScreen4.y); - } - display.Blit(AGG::GetICN(ICN::REQUESTS, 24), rectScreen5.x, rectScreen5.y); - if(castle.isBuild(BUILD_MAGEGUILD1)) display.Blit(AGG::GetICN(ICN::REQUESTS, 25), rectScreen6.x, rectScreen6.y); - - u32 frame = 0; - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - if(le.MouseClickLeft(rectScreen1)) return SCREEN1; - else - if(le.MouseClickLeft(rectScreen2)) return SCREEN2; - else - if(le.MouseClickLeft(rectScreen3)) return SCREEN3; - else - if(le.MouseClickLeft(rectScreen4)) return SCREEN4; - else - if(castle.isBuild(BUILD_MAGEGUILD1) && le.MouseClickLeft(rectScreen6)) return SCREEN6; - else - // exit - if(le.MouseClickLeft(rectExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break; - else - if(hero1 && le.MouseClickLeft(rectRecruit1) && - Dialog::OK == castle.DialogBuyHero(hero1)) - { - castle.RecruitHero(hero1); - return SCREEN1; - } - else - if(hero2 && le.MouseClickLeft(rectRecruit2) && - Dialog::OK == castle.DialogBuyHero(hero2)) - { - castle.RecruitHero(hero2); - return SCREEN1; - } - else - if(le.MouseClickLeft(rectCaptain)) - { - BuildingInfo b(castle, BUILD_CAPTAIN); - if(castle.isBuild(BUILD_CAPTAIN)) - Dialog::Message(b.GetName(), b.GetDescription(), Font::SMALL, Dialog::OK); - else - if(b.DialogBuyBuilding(true)) - { - AGG::PlaySound(M82::BUILDTWN); - castle.BuyBuilding(b()); - return SCREEN1; - } - } - - // animation - if(castle.isBuild(BUILD_TAVERN) && Game::AnimateInfrequent(Game::CASTLE_TAVERN_DELAY)) - { - cursor.Hide(); - const Sprite & s20 = AGG::GetICN(ICN::TAVWIN, 1); - display.Blit(s20, dst_pt.x + 3, dst_pt.y + 3); - if(const u16 index = ICN::AnimationFrame(ICN::TAVWIN, 0, frame++)) - { - const Sprite & s22 = AGG::GetICN(ICN::TAVWIN, index); - display.Blit(s22, dst_pt.x + s22.x() + 3, dst_pt.y + s22.y() + 3); - } - cursor.Show(); - display.Flip(); - } - } - - return SCREENOUT; -} - -screen_t CastleOpenDialog6(Castle & castle) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - - RowSpells spells1(Point(dst_rt.x + 38, dst_rt.y + 220 - 44), castle.GetMageGuild(), 1); - RowSpells spells2(Point(dst_rt.x + 38, dst_rt.y + 220 - 44 * 2), castle.GetMageGuild(), 2); - RowSpells spells3(Point(dst_rt.x + 38, dst_rt.y + 220 - 44 * 3), castle.GetMageGuild(), 3); - RowSpells spells4(Point(dst_rt.x + 38, dst_rt.y + 220 - 44 * 4), castle.GetMageGuild(), 4); - RowSpells spells5(Point(dst_rt.x + 38, dst_rt.y + 220 - 44 * 5), castle.GetMageGuild(), 5); - - spells1.Redraw(); - spells2.Redraw(); - spells3.Redraw(); - spells4.Redraw(); - spells5.Redraw(); - - // magic book sprite - const Heroes* hero = castle.GetHeroes(); - bool need_buy_book = hero && !hero->HasArtifact(Artifact::MAGIC_BOOK) && castle.GetLevelMageGuild(); - const Rect book_pos(dst_rt.x + 250, dst_rt.y + 5, 32, 32); - if(need_buy_book) - { - display.Blit(AGG::GetICN(ICN::ARTFX, 81), book_pos); - Text text(_("buy"), Font::SMALL); - text.Blit(book_pos.x + (book_pos.w - text.w()) / 2, book_pos.y + book_pos.h - 12); - } - - // buttons - const Rect rectExit(dst_rt.x + dst_rt.w - 26, dst_rt.y + 7, 25, 25); - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), rectExit.x, rectExit.y); - - const Rect rectScreen1(dst_rt.x + dst_rt.w - 27, dst_rt.y + 32, 25, 25); - const Rect rectScreen2(dst_rt.x + dst_rt.w - 27, dst_rt.y + 58, 25, 25); - const Rect rectScreen3(dst_rt.x + dst_rt.w - 27, dst_rt.y + 84, 25, 25); - const Rect rectScreen4(dst_rt.x + dst_rt.w - 27, dst_rt.y + 110, 25, 25); - const Rect rectScreen5(dst_rt.x + dst_rt.w - 27, dst_rt.y + 136, 25, 25); - const Rect rectScreen6(dst_rt.x + dst_rt.w - 27, dst_rt.y + 162, 25, 25); - - display.Blit(AGG::GetICN(ICN::REQUESTS, 20), rectScreen1.x, rectScreen1.y); - if(castle.isBuild(BUILD_CASTLE)) - { - display.Blit(AGG::GetICN(ICN::REQUESTS, 21), rectScreen2.x, rectScreen2.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 22), rectScreen3.x, rectScreen3.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 23), rectScreen4.x, rectScreen4.y); - } - if(castle.isBuild(BUILD_CASTLE) || castle.isBuild(BUILD_TAVERN)) - display.Blit(AGG::GetICN(ICN::REQUESTS, 24), rectScreen5.x, rectScreen5.y); - display.Blit(AGG::GetICN(ICN::REQUESTS, 25), rectScreen6.x, rectScreen6.y); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - if(le.MouseClickLeft(rectScreen1)) return SCREEN1; - else - if(le.MouseClickLeft(rectScreen2)) return SCREEN2; - else - if(le.MouseClickLeft(rectScreen3)) return SCREEN3; - else - if(le.MouseClickLeft(rectScreen4)) return SCREEN4; - else - if(le.MouseClickLeft(rectScreen5)) return SCREEN5; - else - // exit - if(le.MouseClickLeft(rectExit) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break; - else - if(need_buy_book && le.MouseClickLeft(book_pos)) { const_cast(hero)->BuySpellBook(&castle.GetMageGuild()); return SCREEN1; } - - spells1.QueueEventProcessing(); - spells2.QueueEventProcessing(); - spells3.QueueEventProcessing(); - spells4.QueueEventProcessing(); - spells5.QueueEventProcessing(); - } - - return SCREENOUT; -} - - -void RedrawResourceBar(const Point & dst, const Resource::funds_t & rs) -{ - Display & display = Display::Get(); - display.Blit(AGG::GetICN(ICN::STONEBAK, 0), Rect(0, 0, 312, 13), dst.x, dst.y + 30); - - const Sprite & ore = AGG::GetICN(ICN::RESOURCE, 2); - const Sprite & wood = AGG::GetICN(ICN::RESOURCE, 0); - const Sprite & mercury = AGG::GetICN(ICN::RESOURCE, 1); - const Sprite & sulfur = AGG::GetICN(ICN::RESOURCE, 3); - const Sprite & crystal = AGG::GetICN(ICN::RESOURCE, 4); - const Sprite & gems = AGG::GetICN(ICN::RESOURCE, 5); - const Sprite & gold = AGG::GetICN(ICN::RESOURCE, 6); - - Text text; - std::string str; - - display.Blit(ore, dst.x + 22 - ore.w() / 2, dst.y + 34 - ore.h()); - str.clear(); - String::AddInt(str, rs.ore); - text.Set(str, Font::SMALL); - text.Blit(dst.x + 22 - text.w() / 2, dst.y + 33); - - display.Blit(wood, dst.x + 68 - wood.w() / 2, dst.y + 34 - wood.h()); - str.clear(); - String::AddInt(str, rs.wood); - text.Set(str, Font::SMALL); - text.Blit(dst.x + 68 - text.w() / 2, dst.y + 33); - - display.Blit(mercury, dst.x + 114 - mercury.w() / 2, dst.y + 34 - mercury.h()); - str.clear(); - String::AddInt(str, rs.mercury); - text.Set(str, Font::SMALL); - text.Blit(dst.x + 114 - text.w() / 2, dst.y + 33); - - display.Blit(sulfur, dst.x + 160 - sulfur.w() / 2, dst.y + 34 - sulfur.h()); - str.clear(); - String::AddInt(str, rs.sulfur); - text.Set(str, Font::SMALL); - text.Blit(dst.x + 160 - text.w() / 2, dst.y + 33); - - display.Blit(crystal, dst.x + 206 - crystal.w() / 2, dst.y + 34 - crystal.h()); - str.clear(); - String::AddInt(str, rs.crystal); - text.Set(str, Font::SMALL); - text.Blit(dst.x + 206 - text.w() / 2, dst.y + 33); - - display.Blit(gems, dst.x + 252 - gems.w() / 2, dst.y + 34 - gems.h()); - str.clear(); - String::AddInt(str, rs.gems); - text.Set(str, Font::SMALL); - text.Blit(dst.x + 252 - text.w() / 2, dst.y + 33); - - display.Blit(gold, Rect(0, 0, 40, gold.h()), dst.x + 292 - 20, dst.y + 34 - gold.h()); - str.clear(); - String::AddInt(str, rs.gold); - text.Set(str, Font::SMALL); - text.Blit(dst.x + 292 - text.w() / 2, dst.y + 33); -} - -void RedrawBackground(const Rect & rt, const Castle & castle) -{ - const Sprite* sprite = NULL; - Rect src; - - switch(castle.GetRace()) - { - case Race::KNGT: sprite = &AGG::GetICN(ICN::TOWNBKG0, 0); src = Rect(148, 0, rt.w, 123); break; - case Race::BARB: sprite = &AGG::GetICN(ICN::TOWNBKG1, 0); src = Rect(142, 0, rt.w, 123); break; - case Race::SORC: sprite = &AGG::GetICN(ICN::TOWNBKG2, 0); src = Rect(218, 0, rt.w, 123); break; - case Race::WRLK: sprite = &AGG::GetICN(ICN::TOWNBKG3, 0); src = Rect(300, 0, rt.w, 123); break; - case Race::WZRD: sprite = &AGG::GetICN(ICN::TOWNBKG4, 0); src = Rect(150, 0, rt.w, 123); break; - case Race::NECR: sprite = &AGG::GetICN(ICN::TOWNBKG5, 0); src = Rect(0, 0, rt.w, 123); break; - default: break; - } - - if(sprite) Display::Get().Blit(*sprite, src, rt.x, rt.y); -} - -const Rect & DwellingBar::GetArea(void) const -{ - return *this; -} - -DwellingBar::DwellingBar(const Point & dst, const Castle & cst) : Rect(dst.x, dst.y, 0, 0), castle(cst), dw(CASTLEMAXMONSTER) -{ - for(u8 ii = 0; ii < dw.size(); ++ii) - dw[ii] = Rect(dst.x + ii * (43 + 2), dst.y, 43, 43); - - const Rect max = Rect(dw); - - w = max.w; - h = max.h; -} - -u32 DwellingBar::GetDwellingFromIndex(u8 ii) -{ - switch(ii) - { - case 0: return DWELLING_MONSTER1; - case 1: return DWELLING_MONSTER2; - case 2: return DWELLING_MONSTER3; - case 3: return DWELLING_MONSTER4; - case 4: return DWELLING_MONSTER5; - case 5: return DWELLING_MONSTER6; - default: break; - } - return 0; -} - -void DwellingBar::Redraw(void) const -{ - Display & display = Display::Get(); - const u8 w = 43; - const u8 h = 43; - std::string str; - Text text(str, Font::SMALL); - - for(u8 ii = 0; ii < dw.size(); ++ii) - { - display.Blit(AGG::GetICN(ICN::SWAPWIN, 0), Rect(36, 267, w, h), dw[ii].x, dw[ii].y); - const u32 dwelling = castle.GetActualDwelling(GetDwellingFromIndex(ii)); - Monster m(castle.GetRace(), dwelling); - const Sprite & mons32 = AGG::GetICN(ICN::MONS32, Monster::GetSpriteIndex(m())); - display.Blit(mons32, dw[ii].x + (w - mons32.w()) / 2, dw[ii].y + (h - 3 - mons32.h())); - - if(castle.isBuild(dwelling)) - { - // count - str.clear(); - String::AddInt(str, castle.GetDwellingLivedCount(dwelling)); - text.Set(str); - text.Blit(dw[ii].x + dw[ii].w - text.w() - 3, dw[ii].y + dw[ii].h - text.h() - 1); - - // grown - u8 grown = m.GetGrown(); - if(castle.isBuild(BUILD_WELL)) grown += Castle::GetGrownWell(); - if(castle.isBuild(BUILD_WEL2) && DWELLING_MONSTER1 == dwelling) grown += Castle::GetGrownWel2(); - str = "+"; - String::AddInt(str, grown); - text.Set(str, Font::YELLOW_SMALL); - text.Blit(dw[ii].x + dw[ii].w - text.w() - 3, dw[ii].y + 2); - } - else - { - display.Blit(AGG::GetICN(ICN::LOCATORS, 24), dw[ii].x + w - 8, dw[ii].y + 3); - } - } -} - -bool DwellingBar::QueueEventProcessing(void) -{ - LocalEvent & le = LocalEvent::Get(); - std::vector::const_iterator itr; - - if(dw.end() != (itr = std::find_if(dw.begin(), dw.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - { - const u32 dwelling = GetDwellingFromIndex(itr - dw.begin()); - if(castle.isBuild(dwelling)) - { - const u16 recruit = Dialog::RecruitMonster(Monster(castle.GetRace(), castle.GetActualDwelling(dwelling)), castle.GetDwellingLivedCount(dwelling)); - return const_cast(castle).RecruitMonster(dwelling, recruit); - } - else - { - BuildingInfo dwelling2(castle, static_cast(dwelling)); - if(dwelling2.DialogBuyBuilding(true)) - { - AGG::PlaySound(M82::BUILDTWN); - const_cast(castle).BuyBuilding(dwelling); - return true; - } - } - } - return false; -} - -void RedrawTownSprite(const Rect & rt, const Castle & castle) -{ - Display & display = Display::Get(); - const Sprite & slock = AGG::GetICN(ICN::LOCATORS, 23); - display.Blit(slock, rt.x, rt.y); - switch(castle.GetRace()) - { - case Race::KNGT: display.Blit(AGG::GetICN(ICN::LOCATORS, castle.isCastle() ? 9 : 15), rt.x + 4, rt.y + 4); break; - case Race::BARB: display.Blit(AGG::GetICN(ICN::LOCATORS, castle.isCastle() ? 10 : 16), rt.x + 4, rt.y + 4); break; - case Race::SORC: display.Blit(AGG::GetICN(ICN::LOCATORS, castle.isCastle() ? 11 : 17), rt.x + 4, rt.y + 4); break; - case Race::WRLK: display.Blit(AGG::GetICN(ICN::LOCATORS, castle.isCastle() ? 12 : 18), rt.x + 4, rt.y + 4); break; - case Race::WZRD: display.Blit(AGG::GetICN(ICN::LOCATORS, castle.isCastle() ? 13 : 19), rt.x + 4, rt.y + 4); break; - case Race::NECR: display.Blit(AGG::GetICN(ICN::LOCATORS, castle.isCastle() ? 14 : 20), rt.x + 4, rt.y + 4); break; - default: break; - } - if(! castle.AllowBuild()) display.Blit(AGG::GetICN(ICN::LOCATORS, 24), rt.x + 43, rt.y + 5); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_dialog.cpp b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_dialog.cpp deleted file mode 100644 index e8a7f3629..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_dialog.cpp +++ /dev/null @@ -1,543 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * afletdinov@mail.dc.baikal.ru * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "engine.h" -#include "cursor.h" -#include "battle2.h" -#include "text.h" -#include "settings.h" -#include "pocketpc.h" - -u16 PocketPC::GetCursorAttackDialog(const Point & dst, u8 allow) -{ - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - const Rect rt(dst.x - 24, dst.y - 24, 70, 70); - - const Sprite & sp_info = AGG::GetICN(ICN::CMSECO, 5); - const Sprite & sp_bleft = AGG::GetICN(ICN::CMSECO, 10); - const Sprite & sp_left = AGG::GetICN(ICN::CMSECO, 11); - const Sprite & sp_tleft = AGG::GetICN(ICN::CMSECO, 12); - const Sprite & sp_tright = AGG::GetICN(ICN::CMSECO, 7); - const Sprite & sp_right = AGG::GetICN(ICN::CMSECO, 8); - const Sprite & sp_bright = AGG::GetICN(ICN::CMSECO, 9); - - Surface shadow(rt.w, rt.h); - shadow.SetAlpha(170); - Background back(rt); - back.Save(); - - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(Cursor::POINTER); - - display.Blit(shadow, rt.x, rt.y); - - const Rect rt_info(rt.x + (rt.w - sp_info.w()) / 2, rt.y + (rt.h - sp_info.h()) / 2, sp_info.w(), sp_info.h()); - display.Blit(sp_info, rt_info.x, rt_info.y); - - const Rect rt_tright(rt.x + 1, rt.y + rt.h - 1 - sp_tright.h(), sp_tright.w(), sp_tright.h()); - if(allow & Battle2::BOTTOM_LEFT) display.Blit(sp_tright, rt_tright.x, rt_tright.y); - - const Rect rt_right(rt.x + 1, rt.y + (rt.h - sp_right.h()) / 2, sp_right.w(), sp_right.h()); - if(allow & Battle2::LEFT) display.Blit(sp_right, rt_right.x, rt_right.y); - - const Rect rt_bright(rt.x + 1, rt.y + 1, sp_bright.w(), sp_bright.h()); - if(allow & Battle2::TOP_LEFT) display.Blit(sp_bright, rt_bright.x, rt_bright.y); - - const Rect rt_tleft(rt.x + rt.w - 1 - sp_tleft.w(), rt.y + rt.h - 1 - sp_tleft.h(), sp_tleft.w(), sp_tleft.h()); - if(allow & Battle2::BOTTOM_RIGHT) display.Blit(sp_tleft, rt_tleft.x, rt_tleft.y); - - const Rect rt_left(rt.x + rt.w - 1 - sp_left.w(), rt.y + (rt.h - sp_left.h()) / 2, sp_left.w(), sp_left.h()); - if(allow & Battle2::RIGHT) display.Blit(sp_left, rt_left.x, rt_left.y); - - const Rect rt_bleft(rt.x + rt.w - 1 - sp_bleft.w(), rt.y + 1, sp_bleft.w(), sp_bleft.h()); - if(allow & Battle2::TOP_RIGHT) display.Blit(sp_bleft, rt_bleft.x, rt_bleft.y); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents() && !le.MouseClickLeft()); - - if((allow & Battle2::BOTTOM_LEFT) && (rt_tright & le.GetMouseCursor())) return Cursor::SWORD_TOPRIGHT; - else - if((allow & Battle2::LEFT) && (rt_right & le.GetMouseCursor())) return Cursor::SWORD_RIGHT; - else - if((allow & Battle2::TOP_LEFT) && (rt_bright & le.GetMouseCursor())) return Cursor::SWORD_BOTTOMRIGHT; - else - if((allow & Battle2::BOTTOM_RIGHT) && (rt_tleft & le.GetMouseCursor())) return Cursor::SWORD_TOPLEFT; - else - if((allow & Battle2::RIGHT) && (rt_left & le.GetMouseCursor())) return Cursor::SWORD_LEFT; - else - if((allow & Battle2::TOP_RIGHT) && (rt_bleft & le.GetMouseCursor())) return Cursor::SWORD_BOTTOMLEFT; - - return Cursor::WAR_INFO; -} - -void DrawWideCell(const Rect & dst) -{ - Display & display = Display::Get(); - const Sprite & sp = AGG::GetICN(ICN::EDITBTNS, 32); - - Rect rt = Rect(0, 0, 4, 16); - display.Blit(sp, rt, dst.x, dst.y); - - - if(dst.w > 8) - { - rt = Rect(4, 0, 4, 16); - const u16 count = (dst.w - 4) / rt.w; - for(u16 ii = 0; ii < count; ++ii) - { - display.Blit(sp, rt, dst.x + 4 + rt.w * ii, dst.y); - } - } - - rt = Rect(12, 0, 4, 16); - display.Blit(sp, rt, dst.x + dst.w - rt.w, dst.y); -} - -void PocketPC::KeyboardDialog(std::string & str) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - cursor.Hide(); - - const u16 width = 240; - const u16 height = 88; - - Background back; - back.Save((display.w() - width) / 2, 0, width, height); - const Rect & top = back.GetRect(); - display.FillRect(0, 0, 0, top); - - const Sprite & sp = AGG::GetICN(ICN::EDITBTNS, 32); - - Text tx; - tx.Set(Font::SMALL); - - // 1 - const Rect rt_1(top.x + 2, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_1); - tx.Set("1"); - tx.Blit(rt_1.x + (rt_1.w - tx.w()) / 2, rt_1.y + 2); - - const Rect rt_2(top.x + 19, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_2); - tx.Set("2"); - tx.Blit(rt_2.x + (rt_2.w - tx.w()) / 2, rt_2.y + 2); - - const Rect rt_3(top.x + 36, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_3); - tx.Set("3"); - tx.Blit(rt_3.x + (rt_3.w - tx.w()) / 2, rt_3.y + 2); - - const Rect rt_4(top.x + 53, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_4); - tx.Set("4"); - tx.Blit(rt_4.x + (rt_4.w - tx.w()) / 2, rt_4.y + 2); - - const Rect rt_5(top.x + 70, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_5); - tx.Set("5"); - tx.Blit(rt_5.x + (rt_5.w - tx.w()) / 2, rt_5.y + 2); - - const Rect rt_6(top.x + 87, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_6); - tx.Set("6"); - tx.Blit(rt_6.x + (rt_6.w - tx.w()) / 2, rt_6.y + 2); - - const Rect rt_7(top.x + 104, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_7); - tx.Set("7"); - tx.Blit(rt_7.x + (rt_7.w - tx.w()) / 2, rt_7.y + 2); - - const Rect rt_8(top.x + 121, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_8); - tx.Set("8"); - tx.Blit(rt_8.x + (rt_8.w - tx.w()) / 2, rt_8.y + 2); - - const Rect rt_9(top.x + 138, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_9); - tx.Set("9"); - tx.Blit(rt_9.x + (rt_9.w - tx.w()) / 2, rt_9.y + 2); - - const Rect rt_0(top.x + 155, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_0); - tx.Set("0"); - tx.Blit(rt_0.x + (rt_0.w - tx.w()) / 2, rt_0.y + 2); - - const Rect rt_MINUS(top.x + 172, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_MINUS); - tx.Set("-"); - tx.Blit(rt_MINUS.x + (rt_MINUS.w - tx.w()) / 2, rt_MINUS.y + 2); - - const Rect rt_EQUAL(top.x + 189, top.y + 2, sp.w(), sp.h()); - display.Blit(sp, rt_EQUAL); - tx.Set("="); - tx.Blit(rt_EQUAL.x + (rt_EQUAL.w - tx.w()) / 2, rt_EQUAL.y + 1); - - const Rect rt_BACKSPACE(top.x + 206, top.y + 2, 32, sp.h()); - DrawWideCell(rt_BACKSPACE); - - tx.Set("back"); - tx.Blit(rt_BACKSPACE.x + 2, rt_BACKSPACE.y + 1); - - // 2 - const Rect rt_EMPTY1(top.x + 2, top.y + 19, 7, sp.h()); - DrawWideCell(rt_EMPTY1); - - const Rect rt_Q(top.x + 10, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_Q); - tx.Set("q"); - tx.Blit(rt_Q.x + (rt_Q.w - tx.w()) / 2, rt_Q.y + 2); - - const Rect rt_W(top.x + 27, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_W); - tx.Set("w"); - tx.Blit(rt_W.x + (rt_W.w - tx.w()) / 2, rt_W.y + 2); - - const Rect rt_E(top.x + 44, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_E); - tx.Set("e"); - tx.Blit(rt_E.x + (rt_E.w - tx.w()) / 2, rt_E.y + 2); - - const Rect rt_R(top.x + 61, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_R); - tx.Set("r"); - tx.Blit(rt_R.x + (rt_R.w - tx.w()) / 2, rt_R.y + 2); - - const Rect rt_T(top.x + 78, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_T); - tx.Set("t"); - tx.Blit(rt_T.x + (rt_T.w - tx.w()) / 2, rt_T.y + 2); - - const Rect rt_Y(top.x + 95, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_Y); - tx.Set("y"); - tx.Blit(rt_Y.x + (rt_Y.w - tx.w()) / 2, rt_Y.y + 2); - - const Rect rt_U(top.x + 112, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_U); - tx.Set("u"); - tx.Blit(rt_U.x + (rt_U.w - tx.w()) / 2, rt_U.y + 2); - - const Rect rt_I(top.x + 129, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_I); - tx.Set("i"); - tx.Blit(rt_I.x + (rt_I.w - tx.w()) / 2, rt_I.y + 2); - - const Rect rt_O(top.x + 146, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_O); - tx.Set("o"); - tx.Blit(rt_O.x + (rt_O.w - tx.w()) / 2, rt_O.y + 2); - - const Rect rt_P(top.x + 163, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_P); - tx.Set("p"); - tx.Blit(rt_P.x + (rt_P.w - tx.w()) / 2, rt_P.y + 2); - - const Rect rt_LB(top.x + 180, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_LB); - tx.Set("["); - tx.Blit(rt_LB.x + (rt_LB.w - tx.w()) / 2, rt_LB.y + 2); - - const Rect rt_RB(top.x + 197, top.y + 19, sp.w(), sp.h()); - display.Blit(sp, rt_RB); - tx.Set("]"); - tx.Blit(rt_RB.x + (rt_RB.w - tx.w()) / 2, rt_RB.y + 2); - - const Rect rt_EMPTY2(top.x + 214, top.y + 19, 24, sp.h()); - DrawWideCell(rt_EMPTY2); - - // 3 - const Rect rt_EMPTY3(top.x + 2, top.y + 36, 15, sp.h()); - DrawWideCell(rt_EMPTY3); - - const Rect rt_A(top.x + 18, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_A); - tx.Set("a"); - tx.Blit(rt_A.x + (rt_A.w - tx.w()) / 2, rt_A.y + 2); - - const Rect rt_S(top.x + 35, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_S); - tx.Set("s"); - tx.Blit(rt_S.x + (rt_S.w - tx.w()) / 2, rt_S.y + 2); - - const Rect rt_D(top.x + 52, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_D); - tx.Set("d"); - tx.Blit(rt_D.x + (rt_D.w - tx.w()) / 2, rt_D.y + 2); - - const Rect rt_F(top.x + 69, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_F); - tx.Set("f"); - tx.Blit(rt_F.x + (rt_F.w - tx.w()) / 2, rt_F.y + 2); - - const Rect rt_G(top.x + 86, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_G); - tx.Set("g"); - tx.Blit(rt_G.x + (rt_G.w - tx.w()) / 2, rt_G.y + 2); - - const Rect rt_H(top.x + 103, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_H); - tx.Set("h"); - tx.Blit(rt_H.x + (rt_H.w - tx.w()) / 2, rt_H.y + 2); - - const Rect rt_J(top.x + 120, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_J); - tx.Set("j"); - tx.Blit(rt_J.x + (rt_J.w - tx.w()) / 2, rt_J.y + 2); - - const Rect rt_K(top.x + 137, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_K); - tx.Set("k"); - tx.Blit(rt_K.x + (rt_K.w - tx.w()) / 2, rt_K.y + 2); - - const Rect rt_L(top.x + 154, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_L); - tx.Set("l"); - tx.Blit(rt_L.x + (rt_L.w - tx.w()) / 2, rt_L.y + 2); - - const Rect rt_SP(top.x + 171, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_SP); - tx.Set(";"); - tx.Blit(rt_SP.x + (rt_SP.w - tx.w()) / 2, rt_SP.y + 2); - - const Rect rt_CM(top.x + 188, top.y + 36, sp.w(), sp.h()); - display.Blit(sp, rt_CM); - tx.Set("'"); - tx.Blit(rt_CM.x + (rt_CM.w - tx.w()) / 2, rt_CM.y + 2); - - const Rect rt_RETURN(top.x + 205, top.y + 36, 33, sp.h()); - DrawWideCell(rt_RETURN); - - tx.Set("rtrn"); - tx.Blit(rt_RETURN.x + (rt_RETURN.w - tx.w()) / 2, rt_RETURN.y + 2); - - // 4 - const Rect rt_EMPTY5(top.x + 2, top.y + 53, 23, sp.h()); - DrawWideCell(rt_EMPTY5); - - const Rect rt_Z(top.x + 26, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_Z); - tx.Set("z"); - tx.Blit(rt_Z.x + (rt_Z.w - tx.w()) / 2, rt_Z.y + 2); - - const Rect rt_X(top.x + 43, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_X); - tx.Set("x"); - tx.Blit(rt_X.x + (rt_X.w - tx.w()) / 2, rt_X.y + 2); - - const Rect rt_C(top.x + 60, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_C); - tx.Set("c"); - tx.Blit(rt_C.x + (rt_C.w - tx.w()) / 2, rt_C.y + 2); - - const Rect rt_V(top.x + 77, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_V); - tx.Set("v"); - tx.Blit(rt_V.x + (rt_V.w - tx.w()) / 2, rt_V.y + 2); - - const Rect rt_B(top.x + 94, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_B); - tx.Set("b"); - tx.Blit(rt_B.x + (rt_B.w - tx.w()) / 2, rt_B.y + 2); - - const Rect rt_N(top.x + 111, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_N); - tx.Set("n"); - tx.Blit(rt_N.x + (rt_N.w - tx.w()) / 2, rt_N.y + 2); - - const Rect rt_M(top.x + 128, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_M); - tx.Set("m"); - tx.Blit(rt_M.x + (rt_M.w - tx.w()) / 2, rt_M.y + 2); - - const Rect rt_CS(top.x + 145, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_CS); - tx.Set(","); - tx.Blit(rt_CS.x + (rt_CS.w - tx.w()) / 2, rt_CS.y + 2); - - const Rect rt_DT(top.x + 162, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_DT); - tx.Set("."); - tx.Blit(rt_DT.x + (rt_DT.w - tx.w()) / 2, rt_DT.y + 2); - - const Rect rt_SL(top.x + 179, top.y + 53, sp.w(), sp.h()); - display.Blit(sp, rt_SL); - tx.Set("/"); - tx.Blit(rt_SL.x + (rt_SL.w - tx.w()) / 2, rt_SL.y + 2); - - const Rect rt_SPACE(top.x + 196, top.y + 53, 42, sp.h()); - DrawWideCell(rt_SPACE); - - tx.Set("space"); - tx.Blit(rt_SPACE.x + (rt_SPACE.w - tx.w()) / 2, rt_SPACE.y + 2); - - Rect rectClose; - - cursor.Show(); - display.Flip(); - - char ch = 0; - bool redraw = true; - - // mainmenu loop - while(le.HandleEvents()) - { - if(le.MouseClickLeft(rectClose) || Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) - { - str.clear(); - break; - } - - ch = 0; - - if(le.MouseClickLeft(rt_0)) ch = '0'; - else - if(le.MouseClickLeft(rt_1)) ch = '1'; - else - if(le.MouseClickLeft(rt_2)) ch = '2'; - else - if(le.MouseClickLeft(rt_3)) ch = '3'; - else - if(le.MouseClickLeft(rt_4)) ch = '4'; - else - if(le.MouseClickLeft(rt_5)) ch = '5'; - else - if(le.MouseClickLeft(rt_6)) ch = '6'; - else - if(le.MouseClickLeft(rt_7)) ch = '7'; - else - if(le.MouseClickLeft(rt_8)) ch = '8'; - else - if(le.MouseClickLeft(rt_9)) ch = '9'; - else - if(le.MouseClickLeft(rt_A)) ch = 'a'; - else - if(le.MouseClickLeft(rt_B)) ch = 'b'; - else - if(le.MouseClickLeft(rt_C)) ch = 'c'; - else - if(le.MouseClickLeft(rt_D)) ch = 'd'; - else - if(le.MouseClickLeft(rt_E)) ch = 'e'; - else - if(le.MouseClickLeft(rt_F)) ch = 'f'; - else - if(le.MouseClickLeft(rt_G)) ch = 'g'; - else - if(le.MouseClickLeft(rt_H)) ch = 'h'; - else - if(le.MouseClickLeft(rt_I)) ch = 'i'; - else - if(le.MouseClickLeft(rt_J)) ch = 'j'; - else - if(le.MouseClickLeft(rt_K)) ch = 'k'; - else - if(le.MouseClickLeft(rt_L)) ch = 'l'; - else - if(le.MouseClickLeft(rt_M)) ch = 'm'; - else - if(le.MouseClickLeft(rt_N)) ch = 'n'; - else - if(le.MouseClickLeft(rt_O)) ch = 'o'; - else - if(le.MouseClickLeft(rt_P)) ch = 'p'; - else - if(le.MouseClickLeft(rt_Q)) ch = 'q'; - else - if(le.MouseClickLeft(rt_R)) ch = 'r'; - else - if(le.MouseClickLeft(rt_S)) ch = 's'; - else - if(le.MouseClickLeft(rt_T)) ch = 't'; - else - if(le.MouseClickLeft(rt_U)) ch = 'u'; - else - if(le.MouseClickLeft(rt_V)) ch = 'v'; - else - if(le.MouseClickLeft(rt_W)) ch = 'w'; - else - if(le.MouseClickLeft(rt_X)) ch = 'x'; - else - if(le.MouseClickLeft(rt_Y)) ch = 'y'; - else - if(le.MouseClickLeft(rt_Z)) ch = 'z'; - else - if(le.MouseClickLeft(rt_EQUAL)) ch = '='; - else - if(le.MouseClickLeft(rt_MINUS)) ch = '-'; - else - if(le.MouseClickLeft(rt_LB)) ch = '['; - else - if(le.MouseClickLeft(rt_RB)) ch = ']'; - else - if(le.MouseClickLeft(rt_SP)) ch = ';'; - else - if(le.MouseClickLeft(rt_CM)) ch = '\''; - else - if(le.MouseClickLeft(rt_CS)) ch = ','; - else - if(le.MouseClickLeft(rt_DT)) ch = '.'; - else - if(le.MouseClickLeft(rt_SL)) ch = '/'; - else - if(le.MouseClickLeft(rt_SPACE)) ch = 0x20; - - if(le.MouseClickLeft(rt_BACKSPACE) && str.size()) - { - str.resize(str.size() - 1); - redraw = true; - } - else - if(le.MouseClickLeft(rt_RETURN)) - break; - else - if(ch) - { - str += ch; - redraw = true; - } - - if(redraw) - { - tx.Set(str); - if(tx.w() < top.w) - { - cursor.Hide(); - display.FillRect(0, 0, 0, Rect(top.x, top.y + top.h - 16, top.w, 16)); - tx.Blit(top.x + (top.w - tx.w()) / 2, top.y + top.h - 16 + 2); - cursor.Show(); - display.Flip(); - } - redraw = false; - } - } - - cursor.Hide(); - back.Restore(); - cursor.Show(); - display.Flip(); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_heroes.cpp b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_heroes.cpp deleted file mode 100644 index 124d8a61f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_heroes.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "cursor.h" -#include "text.h" -#include "button.h" -#include "heroes.h" -#include "heroes_indicator.h" -#include "selectarmybar.h" -#include "selectartifactbar.h" -#include "world.h" -#include "kingdom.h" -#include "pocketpc.h" - -Dialog::answer_t PocketPC::HeroesOpenDialog(Heroes & hero, bool readonly) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - const Sprite & backSprite = AGG::GetICN(ICN::SWAPWIN, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - // portrait - display.Blit(AGG::GetICN(ICN::BRCREST, 6), dst_rt.x + 8, dst_rt.y); - display.Blit(hero.GetPortrait50x46(), dst_rt.x + 12, dst_rt.y + 4); - - // name - std::string message = _("%{name} the %{race} ( Level %{level} )"); - String::Replace(message, "%{name}", hero.GetName()); - String::Replace(message, "%{race}", Race::String(hero.GetRace())); - String::Replace(message, "%{level}", hero.GetLevel()); - Text text(message, Font::SMALL); - text.Blit(dst_rt.x + 73, dst_rt.y + 1); - - // experience - ExperienceIndicator experienceInfo(hero); - experienceInfo.SetPos(Point(dst_rt.x + 205, dst_rt.y + 14)); - experienceInfo.Redraw(); - - // spell points - SpellPointsIndicator spellPointsInfo(hero); - spellPointsInfo.SetPos(Point(dst_rt.x + 238, dst_rt.y + 16)); - spellPointsInfo.Redraw(); - - // morale - MoraleIndicator moraleIndicator(hero); - moraleIndicator.SetPos(Point(dst_rt.x + 280, dst_rt.y + 20)); - moraleIndicator.Redraw(); - - // luck - LuckIndicator luckIndicator(hero); - luckIndicator.SetPos(Point(dst_rt.x + 280, dst_rt.y + 60)); - luckIndicator.Redraw(); - - // prim skill - const Rect ras(dst_rt.x + 74, dst_rt.y + 14, 34, 34); - display.Blit(backSprite, Rect(216, 51, ras.w, ras.h), ras); - message.clear(); - String::AddInt(message, hero.GetAttack()); - text.Set(message); - text.Blit(dst_rt.x + 74 + (34 - text.w()) / 2, dst_rt.y + 47); - - const Rect rds(dst_rt.x + 107, dst_rt.y + 14, 34, 34); - display.Blit(backSprite, Rect(216, 84, rds.w, rds.h), rds); - message.clear(); - String::AddInt(message, hero.GetDefense()); - text.Set(message); - text.Blit(dst_rt.x + 107 + (34 - text.w()) / 2, dst_rt.y + 47); - - const Rect rps(dst_rt.x + 140, dst_rt.y + 14, 34, 34); - display.Blit(backSprite, Rect(216, 117, rps.w, rps.h), rps); - message.clear(); - String::AddInt(message, hero.GetPower()); - text.Set(message); - text.Blit(dst_rt.x + 140 + (34 - text.w()) / 2, dst_rt.y + 47); - - const Rect rks(dst_rt.x + 173, dst_rt.y + 14, 34, 34); - display.Blit(backSprite, Rect(216, 150, rks.w, rks.h), rks); - message.clear(); - String::AddInt(message, hero.GetKnowledge()); - text.Set(message); - text.Blit(dst_rt.x + 173 + (34 - text.w()) / 2, dst_rt.y + 47); - - // sec skill - display.Blit(backSprite, Rect(21, 198, 267, 36), dst_rt.x + 7, dst_rt.y + 57); - // secondary skill - SecondarySkillBar secskill_bar; - secskill_bar.SetPos(dst_rt.x + 9, dst_rt.y + 59); - secskill_bar.SetUseMiniSprite(); - secskill_bar.SetInterval(1); - secskill_bar.SetSkills(hero.GetSecondarySkills()); - secskill_bar.Redraw(); - - // army bar - const Rect rt1(36, 267, 43, 53); - Surface sfb1(rt1.w, rt1.h); - sfb1.Blit(backSprite, rt1, 0, 0); - Surface sfc1(rt1.w, rt1.h - 10); - Cursor::DrawCursor(sfc1, 0xd6, true); - - SelectArmyBar selectArmy; - selectArmy.SetArmy(hero.GetArmy()); - selectArmy.SetPos(dst_rt.x + 50, dst_rt.y + 170); - selectArmy.SetInterval(2); - selectArmy.SetBackgroundSprite(sfb1); - selectArmy.SetCursorSprite(sfc1); - selectArmy.SetUseMons32Sprite(); - selectArmy.SetSaveLastTroop(); - if(readonly) selectArmy.SetReadOnly(); - const Castle* castle = hero.inCastle(); - if(castle) selectArmy.SetCastle(*castle); - selectArmy.Redraw(); - - // art bar - const Rect rt2(23, 347, 34, 34); - Surface sfb2(rt2.w, rt2.h); - sfb2.Blit(backSprite, rt2, 0, 0); - Surface sfc2(rt2.w, rt2.h); - Cursor::DrawCursor(sfc2, 0xd6, true); - - SelectArtifactsBar selectArtifacts(hero); - selectArtifacts.SetPos(dst_rt.x + 37, dst_rt.y + 95); - selectArtifacts.SetInterval(2); - selectArtifacts.SetBackgroundSprite(sfb2); - selectArtifacts.SetCursorSprite(sfc2); - selectArtifacts.SetUseArts32Sprite(); - if(readonly) selectArtifacts.SetReadOnly(); - selectArtifacts.Redraw(); - - Button buttonDismiss(dst_rt.x + dst_rt.w / 2 - 160, dst_rt.y + dst_rt.h - 125, ICN::HSBTNS, 0, 1); - Button buttonExit(dst_rt.x + dst_rt.w / 2 + 130, dst_rt.y + dst_rt.h - 125, ICN::HSBTNS, 2, 3); - - Button buttonPrev(dst_rt.x + 34, dst_rt.y + 200, ICN::TRADPOST, 3, 4); - Button buttonNext(dst_rt.x + 275, dst_rt.y + 200, ICN::TRADPOST, 5, 6); - - if(castle || readonly) - { - buttonDismiss.Press(); - buttonDismiss.SetDisable(true); - } - - if(readonly || 2 > world.GetMyKingdom().GetHeroes().size()) - { - buttonNext.Press(); - buttonPrev.Press(); - buttonNext.SetDisable(true); - buttonPrev.SetDisable(true); - } - - buttonDismiss.Draw(); - buttonExit.Draw(); - buttonNext.Draw(); - buttonPrev.Draw(); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - le.MousePressLeft(buttonNext) ? buttonNext.PressDraw() : buttonNext.ReleaseDraw(); - le.MousePressLeft(buttonPrev) ? buttonPrev.PressDraw() : buttonPrev.ReleaseDraw(); - le.MousePressLeft(buttonExit) ? buttonExit.PressDraw() : buttonExit.ReleaseDraw(); - if(buttonDismiss.isEnable()) le.MousePressLeft(buttonDismiss) ? buttonDismiss.PressDraw() : buttonDismiss.ReleaseDraw(); - - if(buttonNext.isEnable() && le.MouseClickLeft(buttonNext)) return Dialog::NEXT; - else - if(buttonPrev.isEnable() && le.MouseClickLeft(buttonPrev)) return Dialog::PREV; - else - // exit - if(le.MouseClickLeft(buttonExit) || - Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) return Dialog::CANCEL; - else - // dismiss - if(buttonDismiss.isEnable() && le.MouseClickLeft(buttonDismiss) && - Dialog::YES == Dialog::Message(hero.GetName(), _("Are you sure you want to dismiss this Hero?"), Font::BIG, Dialog::YES | Dialog::NO)) - { return Dialog::DISMISS; } - - // primary click info - if(le.MouseClickLeft(ras)) Dialog::Message(_("Attack Skill"), _("Your attack skill is a bonus added to each creature's attack skill."), Font::BIG, Dialog::OK); - else - if(le.MouseClickLeft(rds)) Dialog::Message(_("Defense Skill"), _("Your defense skill is a bonus added to each creature's defense skill."), Font::BIG, Dialog::OK); - else - if(le.MouseClickLeft(rps)) Dialog::Message(_("Spell Power"), _("Your spell power determines the length or power of a spell."), Font::BIG, Dialog::OK); - else - if(le.MouseClickLeft(rks)) Dialog::Message(_("Knowledge"), _("Your knowledge determines how many spell points your hero may have. Under normal cirumstances, a hero is limited to 10 spell points per level of knowledge."), Font::BIG, Dialog::OK); - - if(le.MouseCursor(secskill_bar.GetArea())) secskill_bar.QueueEventProcessing(); - - // selector troops event - if(le.MouseCursor(selectArmy.GetArea())) - { - if(selectArtifacts.isSelected()) selectArtifacts.Reset(); - if(SelectArmyBar::QueueEventProcessing(selectArmy)) - { - cursor.Hide(); - moraleIndicator.Redraw(); - luckIndicator.Redraw(); - cursor.Show(); - display.Flip(); - } - } - - // selector artifacts event - if(le.MouseCursor(selectArtifacts.GetArea())) - { - if(selectArmy.isSelected()) selectArmy.Reset(); - SelectArtifactsBar::QueueEventProcessing(selectArtifacts); - } - - if(le.MouseCursor(moraleIndicator.GetArea())) MoraleIndicator::QueueEventProcessing(moraleIndicator); - else - if(le.MouseCursor(luckIndicator.GetArea())) LuckIndicator::QueueEventProcessing(luckIndicator); - else - if(le.MouseCursor(experienceInfo.GetArea())) experienceInfo.QueueEventProcessing(); - else - if(le.MouseCursor(spellPointsInfo.GetArea())) spellPointsInfo.QueueEventProcessing(); - } - - return Dialog::ZERO; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_mainmenu.cpp b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_mainmenu.cpp deleted file mode 100644 index fa16c491f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_mainmenu.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "cursor.h" -#include "settings.h" -#include "text.h" -#include "pocketpc.h" - -Game::menu_t PocketPC::LoadGame(void) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite &sprite = AGG::GetICN(ICN::HEROES, 0); - Rect src_rt((sprite.w() - display.w()) / 2, 0, display.w(), display.h()); - display.Blit(sprite, src_rt, 0, 0); - - cursor.Show(); - display.Flip(); - - std::string file; - if(!Dialog::SelectFileLoad(file) || file.empty() || !Game::Load(file)) return Game::MAINMENU; - - return Game::STARTGAME; -} - -Game::menu_t PocketPC::MainMenu(void) -{ - Game::SetFixVideoMode(); - - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite &sprite = AGG::GetICN(ICN::HEROES, 0); - Rect src_rt((sprite.w() - display.w()) / 2, 0, display.w(), display.h()); - display.Blit(sprite, src_rt, 0, 0); - - const Sprite &board = AGG::GetICN(ICN::QWIKTOWN, 0); - src_rt = Rect(13, 0, board.w() - 13, board.h() - 13); - Point dst_pt((display.w() - src_rt.w) / 2, (display.h() - src_rt.h) / 2); - display.Blit(board, src_rt, dst_pt.x , dst_pt.y); - - Text text; - - text.Set("Free Heroes II", Font::YELLOW_BIG); - text.Blit(dst_pt.x + (src_rt.w - text.w()) / 2, dst_pt.y + 12); - - text.Set(_("New Game"), Font::BIG); - const Rect rectNewGame(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 35, text.w() + 10, text.h() + 10); - text.Blit(rectNewGame); - - text.Set(_("Load Game")); - const Rect rectLoadGame(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 55, text.w() + 10, text.h() + 10); - text.Blit(rectLoadGame); - - text.Set(_("Settings")); - const Rect rectSettings(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 75, text.w() + 10, text.h() + 10); - text.Blit(rectSettings); - - text.Set(_("High Scores")); - const Rect rectHighScores(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 95, text.w() + 10, text.h() + 10); - text.Blit(rectHighScores); - - text.Set(_("Credits")); - const Rect rectCredits(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 115, text.w() + 10, text.h() + 10); - text.Blit(rectCredits); - - text.Set(_("Quit")); - const Rect rectQuitGame(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 135, text.w() + 10, text.h() + 10); - text.Blit(rectQuitGame); - - cursor.Show(); - display.Flip(); - - std::string test; - - // mainmenu loop - while(le.HandleEvents()) - { - if(Game::HotKeyPress(Game::EVENT_BUTTON_NEWGAME) || - le.MouseClickLeft(rectNewGame)) return Game::NEWGAME; - else - if(Game::HotKeyPress(Game::EVENT_BUTTON_LOADGAME) || - le.MouseClickLeft(rectLoadGame)) return Game::LOADGAME; - else - if(Game::HotKeyPress(Game::EVENT_BUTTON_SETTINGS) || - le.MouseClickLeft(rectSettings)){ Dialog::ExtSettings(); cursor.Show(); display.Flip(); } - else - if(Game::HotKeyPress(Game::EVENT_BUTTON_CREDITS) || - le.MouseClickLeft(rectCredits)) return Game::CREDITS; - else - if(Game::HotKeyPress(Game::EVENT_BUTTON_HIGHSCORES) || - le.MouseClickLeft(rectHighScores)) return Game::HIGHSCORES; - else - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || - le.MouseClickLeft(rectQuitGame)) return Game::QUITGAME; - } - - return Game::QUITGAME; -} - -Game::menu_t PocketPC::NewGame(void) -{ - Game::SetFixVideoMode(); - - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite &sprite = AGG::GetICN(ICN::HEROES, 0); - Rect src_rt((sprite.w() - display.w()) / 2, 0, display.w(), display.h()); - display.Blit(sprite, src_rt, 0, 0); - - const Sprite &board = AGG::GetICN(ICN::QWIKTOWN, 0); - src_rt = Rect(13, 0, board.w() - 13, board.h() - 13); - Point dst_pt((display.w() - src_rt.w) / 2, (display.h() - src_rt.h) / 2); - display.Blit(board, src_rt, dst_pt.x , dst_pt.y); - - Text text; - - text.Set("Free Heroes II", Font::YELLOW_BIG); - text.Blit(dst_pt.x + (src_rt.w - text.w()) / 2, dst_pt.y + 12); - - text.Set(conf.BuildVersion(), Font::YELLOW_SMALL); - text.Blit(dst_pt.x + (src_rt.w - text.w()) / 2, dst_pt.y + 148); - - text.Set(_("Standard Game"), Font::BIG); - const Rect rectStandardGame(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 40 + 5, text.w() + 10, text.h() + 10); - text.Blit(rectStandardGame); - - text.Set(_("Campaign Game")); - const Rect rectCampaignGame(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 65 + 5, text.w() + 10, text.h() + 10); - text.Blit(rectCampaignGame); - - text.Set(_("Multi-Player Game")); - const Rect rectMultiGame(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 90 + 5, text.w() + 10, text.h() + 10); - text.Blit(rectMultiGame); - - text.Set(_("Cancel")); - const Rect rectCancel(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 115 + 5, text.w() + 10, text.h() + 10); - text.Blit(rectCancel); - - cursor.Show(); - display.Flip(); - - // mainmenu loop - while(le.HandleEvents()) - { - if(Game::HotKeyPress(Game::EVENT_BUTTON_STANDARD) || - le.MouseClickLeft(rectStandardGame)) return Game::NEWSTANDARD; - else - if(Game::HotKeyPress(Game::EVENT_BUTTON_CAMPAIN) || - le.MouseClickLeft(rectCampaignGame)) return Game::MAINMENU; - else - if(Game::HotKeyPress(Game::EVENT_BUTTON_MULTI) || - le.MouseClickLeft(rectMultiGame)) return Game::NEWMULTI; - else - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || - le.MouseClickLeft(rectCancel)) return Game::MAINMENU; - } - - return Game::QUITGAME; -} - -Game::menu_t PocketPC::NewMulti(void) -{ - Game::SetFixVideoMode(); - - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite &sprite = AGG::GetICN(ICN::HEROES, 0); - Rect src_rt((sprite.w() - display.w()) / 2, 0, display.w(), display.h()); - display.Blit(sprite, src_rt, 0, 0); - - const Sprite &board = AGG::GetICN(ICN::QWIKTOWN, 0); - src_rt = Rect(13, 0, board.w() - 13, board.h() - 13); - Point dst_pt((display.w() - src_rt.w) / 2, (display.h() - src_rt.h) / 2); - display.Blit(board, src_rt, dst_pt.x , dst_pt.y); - - Text text; - - text.Set("Free Heroes II", Font::YELLOW_BIG); - text.Blit(dst_pt.x + (src_rt.w - text.w()) / 2, dst_pt.y + 12); - - text.Set(conf.BuildVersion(), Font::YELLOW_SMALL); - text.Blit(dst_pt.x + (src_rt.w - text.w()) / 2, dst_pt.y + 148); - - text.Set(_("Hot Seat"), Font::BIG); - const Rect rectHotSeat(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 40 + 5, text.w() + 10, text.h() + 10); - text.Blit(rectHotSeat); - - text.Set(_("Network")); - const Rect rectNetwork(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 65 + 5, text.w() + 10, text.h() + 10); - text.Blit(rectNetwork); - - text.Set(_("Cancel")); - const Rect rectCancel(dst_pt.x + (src_rt.w - text.w()) / 2 - 5, dst_pt.y + 115 + 5, text.w() + 10, text.h() + 10); - text.Blit(rectCancel); - - cursor.Show(); - display.Flip(); - - // mainmenu loop - while(le.HandleEvents()) - { - if(Game::HotKeyPress(Game::EVENT_BUTTON_HOTSEAT) || - le.MouseClickLeft(rectHotSeat)) return Game::NEWHOTSEAT; - else - if(Game::HotKeyPress(Game::EVENT_BUTTON_NETWORK) || - le.MouseClickLeft(rectNetwork)) - { - Dialog::Message(_("Error"), _("This release is compiled without network support."), Font::BIG, Dialog::OK); - return Game::MAINMENU; - } - else - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT) || - le.MouseClickLeft(rectCancel)) return Game::MAINMENU; - } - - return Game::QUITGAME; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_meeting.cpp b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_meeting.cpp deleted file mode 100644 index f88dbd345..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_meeting.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "cursor.h" -#include "text.h" -#include "button.h" -#include "heroes.h" -#include "heroes_indicator.h" -#include "selectarmybar.h" -#include "selectartifactbar.h" -#include "world.h" -#include "kingdom.h" -#include "pocketpc.h" - -void PocketPC::HeroesMeeting(Heroes & hero1, Heroes & hero2) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 236; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - const Sprite & backSprite = AGG::GetICN(ICN::SWAPWIN, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - // portrait - display.Blit(AGG::GetICN(ICN::BRCREST, 6), dst_rt.x + 4, dst_rt.y + 4); - display.Blit(hero1.GetPortrait50x46(), dst_rt.x + 8, dst_rt.y + 8); - - display.Blit(AGG::GetICN(ICN::BRCREST, 6), dst_rt.x + 4, dst_rt.y + 118); - display.Blit(hero2.GetPortrait50x46(), dst_rt.x + 8, dst_rt.y + 122); - - // art bar - const Rect rt2(23, 347, 34, 34); - Surface sfb2(rt2.w, rt2.h); - sfb2.Blit(backSprite, rt2, 0, 0); - Surface sfc2(rt2.w, rt2.h); - Cursor::DrawCursor(sfc2, 0xd6, true); - - SelectArtifactsBar selectArtifacts1(hero1); - selectArtifacts1.SetPos(dst_rt.x + 68, dst_rt.y + 2); - selectArtifacts1.SetInterval(2); - selectArtifacts1.SetBackgroundSprite(sfb2); - selectArtifacts1.SetCursorSprite(sfc2); - selectArtifacts1.SetUseArts32Sprite(); - selectArtifacts1.Redraw(); - - SelectArtifactsBar selectArtifacts2(hero2); - selectArtifacts2.SetPos(dst_rt.x + 68, dst_rt.y + 164); - selectArtifacts2.SetInterval(2); - selectArtifacts2.SetBackgroundSprite(sfb2); - selectArtifacts2.SetCursorSprite(sfc2); - selectArtifacts2.SetUseArts32Sprite(); - selectArtifacts2.Redraw(); - - // army bar - const Rect rt1(36, 267, 43, 43); - Surface sfb1(rt1.w, rt1.h); - sfb1.Blit(backSprite, rt1, 0, 0); - Surface sfc1(rt1.w, rt1.h); - Cursor::DrawCursor(sfc1, 0xd6, true); - - SelectArmyBar selectArmy1; - selectArmy1.SetArmy(hero1.GetArmy()); - selectArmy1.SetPos(dst_rt.x + 68, dst_rt.y + 74); - selectArmy1.SetInterval(2); - selectArmy1.SetBackgroundSprite(sfb1); - selectArmy1.SetCursorSprite(sfc1); - selectArmy1.SetUseMons32Sprite(); - selectArmy1.SetCount2Sprite(); - selectArmy1.SetSaveLastTroop(); - selectArmy1.Redraw(); - - SelectArmyBar selectArmy2; - selectArmy2.SetArmy(hero2.GetArmy()); - selectArmy2.SetPos(dst_rt.x + 68, dst_rt.y + 119); - selectArmy2.SetInterval(2); - selectArmy2.SetBackgroundSprite(sfb1); - selectArmy2.SetCursorSprite(sfc1); - selectArmy2.SetUseMons32Sprite(); - selectArmy2.SetCount2Sprite(); - selectArmy2.SetSaveLastTroop(); - selectArmy2.Redraw(); - - const Rect rectExit(dst_rt.x + dst_rt.w - 25, dst_rt.y + (dst_rt.h - 25) / 2, 25, 25); - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), rectExit.x + 4, rectExit.y + 4); - - cursor.Show(); - display.Flip(); - - while(le.HandleEvents()) - { - // exit - if(le.MouseClickLeft(rectExit) || HotKeyCloseWindow) break; - - if(SelectArmyBar::QueueEventProcessing(selectArmy1, selectArmy2)) - { - if(selectArtifacts1.isSelected()) selectArtifacts1.Reset(); - else - if(selectArtifacts2.isSelected()) selectArtifacts2.Reset(); - } - - if(SelectArtifactsBar::QueueEventProcessing(selectArtifacts1, selectArtifacts2)) - { - if(selectArmy1.isSelected()) selectArmy1.Reset(); - else - if(selectArmy2.isSelected()) selectArmy2.Reset(); - } - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_scenarioinfo.cpp b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_scenarioinfo.cpp deleted file mode 100644 index 1e67f2a2e..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_scenarioinfo.cpp +++ /dev/null @@ -1,196 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "agg.h" -#include "cursor.h" -#include "settings.h" -#include "text.h" -#include "button.h" -#include "difficulty.h" -#include "world.h" -#include "pocketpc.h" - -void UpdateCoordOpponentsInfo(const Point &, std::vector &); -void UpdateCoordClassInfo(const Point &, std::vector &); - -Game::menu_t PocketPC::ScenarioInfo(void) -{ - Game::SetFixVideoMode(); - - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - Settings & conf = Settings::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 380; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - Button buttonOk(dst_rt.x + dst_rt.w / 2 - 160, dst_rt.y + dst_rt.h - 30, ICN::NGEXTRA, 66, 67); - Button buttonCancel(dst_rt.x + dst_rt.w / 2 + 60, dst_rt.y + dst_rt.h - 30, ICN::NGEXTRA, 68, 69); - - Text text; - text.Set(conf.CurrentFileInfo().name, Font::BIG); - text.Blit(dst_rt.x + (dst_rt.w - text.w()) / 2, dst_rt.y + 5); - - const Rect box(dst_rt.x + 4, dst_rt.y + 24, 372, 200); - const Point pointDifficultyInfo(dst_rt.x + 4, dst_rt.y + 24); - const Point pointOpponentInfo(dst_rt.x + 4, dst_rt.y + 94); - const Point pointClassInfo(dst_rt.x + 4, dst_rt.y + 144); - - std::vector::iterator itr; - std::vector coordDifficulty(5); - std::vector coordColors(KINGDOMMAX); - std::vector coordClass(KINGDOMMAX); - - Game::Scenario::RedrawDifficultyInfo(pointDifficultyInfo, false); - - UpdateCoordOpponentsInfo(pointOpponentInfo, coordColors); - Game::Scenario::RedrawOpponentsInfo(pointOpponentInfo); - - UpdateCoordClassInfo(pointClassInfo, coordClass); - Game::Scenario::RedrawClassInfo(pointClassInfo, false); - - const Point pointDifficultyNormal(dst_rt.x + 78, dst_rt.y + 21); - SpriteCursor levelCursor(AGG::GetICN(ICN::NGEXTRA, 62), pointDifficultyNormal); - levelCursor.Show(pointDifficultyNormal); - conf.SetGameDifficulty(Difficulty::NORMAL); - - coordDifficulty[0] = Rect(dst_rt.x + 1, dst_rt.y + 21, levelCursor.w(), levelCursor.h()); - coordDifficulty[1] = Rect(pointDifficultyNormal.x, pointDifficultyNormal.y, levelCursor.w(), levelCursor.h()); - coordDifficulty[2] = Rect(dst_rt.x + 154, dst_rt.y + 21, levelCursor.w(), levelCursor.h()); - coordDifficulty[3] = Rect(dst_rt.x + 231, dst_rt.y + 21, levelCursor.w(), levelCursor.h()); - coordDifficulty[4] = Rect(dst_rt.x + 308, dst_rt.y + 21, levelCursor.w(), levelCursor.h()); - - buttonOk.Draw(); - buttonCancel.Draw(); - - cursor.Show(); - display.Flip(); - - // mainmenu loop - while(le.HandleEvents()) - { - le.MousePressLeft(buttonOk) ? buttonOk.PressDraw() : buttonOk.ReleaseDraw(); - le.MousePressLeft(buttonCancel) ? buttonCancel.PressDraw() : buttonCancel.ReleaseDraw(); - - // click cancel - if(le.MouseClickLeft(buttonCancel) || - Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) - { - Settings::Get().SetGameType(Game::UNKNOWN); - return Game::MAINMENU; - break; - } - else - // click ok - if(le.MouseClickLeft(buttonOk) || - Game::HotKeyPress(Game::EVENT_DEFAULT_READY)) - { - DEBUG(DBG_GAME , DBG_INFO, "PocketPC::ScenarioInfo: select maps: " << conf.MapsFile() \ - << ", difficulty: " << Difficulty::String(conf.GameDifficulty()) << ", select color: " << Color::String(conf.MyColor())); - conf.FixKingdomRandomRace(); - Game::ShowLoadMapsText(); - cursor.Hide(); - world.LoadMaps(conf.MapsFile()); - return Game::STARTGAME; - break; - } - else - if(le.MouseClickLeft(box)) - { - // select difficulty - if(coordDifficulty.end() != (itr = std::find_if(coordDifficulty.begin(), coordDifficulty.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - { - cursor.Hide(); - levelCursor.Move((*itr).x, (*itr).y); - conf.SetGameDifficulty(Difficulty::Get(itr - coordDifficulty.begin())); - cursor.Show(); - display.Flip(); - } - else - // select color - if(coordColors.end() != (itr = std::find_if(coordColors.begin(), coordColors.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - { - Color::color_t color = Color::GetFromIndex(itr - coordColors.begin()); - if(conf.KingdomColors(color) && conf.AllowColors(color)) - { - cursor.Hide(); - switch(conf.GameType()) - { - case Game::NETWORK: - case Game::HOTSEAT: - conf.SetPlayersColors(conf.PlayersColors() & color ? conf.PlayersColors() & ~color : conf.PlayersColors() | color); - break; - default: - conf.SetMyColor(color); - conf.SetPlayersColors(conf.MyColor()); - break; - } - Game::Scenario::RedrawOpponentsInfo(pointOpponentInfo); - cursor.Show(); - display.Flip(); - } - } - else - // select class - if(coordClass.end() != (itr = std::find_if(coordClass.begin(), coordClass.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())))) - { - Color::color_t color = Color::GetFromIndex(itr - coordClass.begin()); - if(conf.AllowChangeRace(color)) - { - cursor.Hide(); - u8 index = 0; - Race::race_t race = conf.KingdomRace(color); - switch(race) - { - case Race::KNGT: index = 52; race = Race::BARB; break; - case Race::BARB: index = 53; race = Race::SORC; break; - case Race::SORC: index = 54; race = Race::WRLK; break; - case Race::WRLK: index = 55; race = Race::WZRD; break; - case Race::WZRD: index = 56; race = Race::NECR; break; - case Race::NECR: index = 58; race = Race::RAND; break; - case Race::RAND: index = 51; race = Race::KNGT; break; - default: break; - } - conf.SetKingdomRace(color, race); - Game::Scenario::RedrawClassInfo(pointClassInfo, false); - cursor.Show(); - display.Flip(); - } - } - } - } - - return Game::QUITGAME; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_selectscenario.cpp b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_selectscenario.cpp deleted file mode 100644 index 79d546b88..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_selectscenario.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "difficulty.h" -#include "settings.h" -#include "maps.h" -#include "maps_fileinfo.h" -#include "dialog_selectscenario.h" -#include "text.h" -#include "tools.h" -#include "pocketpc.h" - -Game::menu_t PocketPC::SelectScenario(void) -{ - Game::SetFixVideoMode(); - - Settings & conf = Settings::Get(); - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const Sprite &sprite = AGG::GetICN(ICN::HEROES, 0); - Rect src_rt((sprite.w() - display.w()) / 2, 0, display.w(), display.h()); - display.Blit(sprite, src_rt, 0, 0); - - MapsFileInfoList all; - if(!PrepareMapsFileInfoList(all, false)) - { - Dialog::Message(_("Warning"), _("No maps available!"), Font::BIG, Dialog::OK); - return Game::MAINMENU; - } - - std::string filename; - - MapsFileInfoList small; - MapsFileInfoList medium; - MapsFileInfoList large; - MapsFileInfoList xlarge; - - small.reserve(all.size()); - medium.reserve(all.size()); - large.reserve(all.size()); - xlarge.reserve(all.size()); - - for(MapsFileInfoList::iterator cur = all.begin(); cur != all.end(); ++ cur) - { - switch((*cur).size_w) - { - case Maps::SMALL: small.push_back(*cur); break; - case Maps::MEDIUM: medium.push_back(*cur); break; - case Maps::LARGE: large.push_back(*cur); break; - case Maps::XLARGE: xlarge.push_back(*cur); break; - default: continue; - } - } - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), rt); - - ButtonGroups btnGroups(rt, Dialog::OK|Dialog::CANCEL); - - Button buttonSelectSmall(rt.x + 7, rt.y + 12, ICN::REQUESTS, 9, 10); - Button buttonSelectMedium(rt.x + 69, rt.y + 12, ICN::REQUESTS, 11, 12); - Button buttonSelectLarge(rt.x + 131, rt.y + 12, ICN::REQUESTS, 13, 14); - Button buttonSelectXLarge(rt.x + 193, rt.y + 12, ICN::REQUESTS, 15, 16); - Button buttonSelectAll(rt.x + 255, rt.y + 12, ICN::REQUESTS, 17, 18); - - if(all.empty()) btnGroups.DisableButton1(true); - if(small.empty()) buttonSelectSmall.SetDisable(true); - if(medium.empty()) buttonSelectMedium.SetDisable(true); - if(large.empty()) buttonSelectLarge.SetDisable(true); - if(xlarge.empty()) buttonSelectXLarge.SetDisable(true); - - ScenarioListBox listbox(rt); - - listbox.RedrawBackground(rt); - listbox.SetScrollButtonUp(ICN::REQUESTS, 5, 6, Point(rt.x + 285, rt.y + 40)); - listbox.SetScrollButtonDn(ICN::REQUESTS, 7, 8, Point(rt.x + 285, rt.y + 175)); - listbox.SetScrollSplitter(AGG::GetICN(ICN::ESCROLL, 3), Rect(rt.x + 288, rt.y + 58, 12, 114)); - listbox.SetAreaMaxItems(8); - listbox.SetAreaItems(Rect(rt.x + 17, rt.y + 37, 266, 156)); - listbox.SetListContent(all); - - listbox.Redraw(); - - btnGroups.Draw(); - - buttonSelectSmall.Draw(); - buttonSelectMedium.Draw(); - buttonSelectLarge.Draw(); - buttonSelectXLarge.Draw(); - buttonSelectAll.Draw(); - - u16 result = Dialog::ZERO; - - cursor.Show(); - display.Flip(); - - while(result == Dialog::ZERO && le.HandleEvents()) - { - le.MousePressLeft(buttonSelectSmall) && buttonSelectSmall.isEnable() ? buttonSelectSmall.PressDraw() : buttonSelectSmall.ReleaseDraw(); - le.MousePressLeft(buttonSelectMedium) && buttonSelectMedium.isEnable() ? buttonSelectMedium.PressDraw() : buttonSelectMedium.ReleaseDraw(); - le.MousePressLeft(buttonSelectLarge) && buttonSelectLarge.isEnable() ? buttonSelectLarge.PressDraw() : buttonSelectLarge.ReleaseDraw(); - le.MousePressLeft(buttonSelectXLarge) && buttonSelectXLarge.isEnable() ? buttonSelectXLarge.PressDraw() : buttonSelectXLarge.ReleaseDraw(); - le.MousePressLeft(buttonSelectAll) ? buttonSelectAll.PressDraw() : buttonSelectAll.ReleaseDraw(); - - result = btnGroups.QueueEventProcessing(); - - if(((le.MouseClickLeft(buttonSelectSmall) || le.KeyPress(KEY_s)) && buttonSelectSmall.isEnable()) && buttonSelectSmall.isEnable()) - { - listbox.SetListContent(small); - cursor.Hide(); - } - else - if(((le.MouseClickLeft(buttonSelectMedium) || le.KeyPress(KEY_m)) && buttonSelectMedium.isEnable()) && buttonSelectMedium.isEnable()) - { - listbox.SetListContent(medium); - cursor.Hide(); - } - else - if(((le.MouseClickLeft(buttonSelectLarge) || le.KeyPress(KEY_l)) && buttonSelectLarge.isEnable()) && buttonSelectLarge.isEnable()) - { - listbox.SetListContent(large); - cursor.Hide(); - } - else - if(((le.MouseClickLeft(buttonSelectXLarge) || le.KeyPress(KEY_x)) && buttonSelectXLarge.isEnable()) && buttonSelectXLarge.isEnable()) - { - listbox.SetListContent(xlarge); - cursor.Hide(); - } - else - if(le.MouseClickLeft(buttonSelectAll) || le.KeyPress(KEY_a)) - { - listbox.SetListContent(all); - cursor.Hide(); - } - - listbox.QueueEventProcessing(); - - if(!cursor.isVisible()) - { - listbox.Redraw(); - cursor.Show(); - display.Flip(); - } - } - - if(Dialog::OK == result) - { - if(conf.LoadFileMapsMP2(listbox.GetCurrent().file)) - { - conf.SetMyColor(conf.FirstAllowColor()); - conf.SetPlayersColors(conf.MyColor()); - conf.SetGameDifficulty(Difficulty::NORMAL); - } - return Game::SCENARIOINFO; - } - - return Game::MAINMENU; -} - diff --git a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_thievesguild.cpp b/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_thievesguild.cpp deleted file mode 100644 index 477c3f6bc..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/pocketpc/pocketpc_thievesguild.cpp +++ /dev/null @@ -1,261 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "button.h" -#include "cursor.h" -#include "settings.h" -#include "text.h" -#include "world.h" -#include "kingdom.h" -#include "castle.h" -#include "pocketpc.h" - -// dialog_thievesguild.cpp -struct ValueColors : std::pair -{ - ValueColors(); - ValueColors(int v, int c); - - bool IsValue(int v) const; - bool IsColor(Color::color_t c) const; - - static bool SortValueGreat(const ValueColors & v1, const ValueColors & v2); -}; - -void GetTownsInfo(std::vector & v); -void GetCastlesInfo(std::vector & v); -void GetHeroesInfo(std::vector & v); -void GetGoldsInfo(std::vector & v); -void GetWoodOreInfo(std::vector & v); -void GetGemsCrSlfMerInfo(std::vector & v); -void GetObelisksInfo(std::vector & v); -void GetArmyInfo(std::vector & v); -void GetIncomesInfo(std::vector & v); -void GetBestHeroArmyInfo(std::vector & v); -void DrawFlags(const std::vector & v, const Point & pos, const u16 width, const u8 count); -void DrawHeroIcons(const std::vector & v, const Point & pos, const u16 width); - -void PocketPC::ThievesGuild(bool oracle) -{ - Cursor & cursor = Cursor::Get(); - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - cursor.Hide(); - cursor.SetThemes(cursor.POINTER); - - const u16 window_w = 320; - const u16 window_h = 224; - - Dialog::FrameBorder frameborder; - frameborder.SetPosition((display.w() - window_w) / 2 - BORDERWIDTH, (display.h() - window_h) / 2 - BORDERWIDTH, window_w, window_h); - frameborder.Redraw(); - - const Rect & dst_rt = frameborder.GetArea(); - const Sprite & background = AGG::GetICN(ICN::STONEBAK, 0); - display.Blit(background, Rect(0, 0, window_w, window_h), dst_rt); - - const Point & cur_pt = dst_rt; - Point dst_pt(cur_pt); - - const u8 count = oracle ? 0xFF : world.GetMyKingdom().GetCountBuilding(BUILD_THIEVESGUILD); - - std::vector v; - v.reserve(KINGDOMMAX); - const u8 colors = Color::Count(Settings::Get().KingdomColors()); - u16 textx = 115; - u16 startx = 120; - u16 maxw = 200; - Text text; - text.Set(Font::SMALL); - - // head 1 - u8 ii = 0; - for(ii = 0; ii < colors; ++ii) - { - switch(ii+1) - { - case 1: text.Set(_("1st")); break; - case 2: text.Set(_("2nd")); break; - case 3: text.Set(_("3rd")); break; - case 4: text.Set(_("4th")); break; - case 5: text.Set(_("5th")); break; - case 6: text.Set(_("6th")); break; - default: break; - } - - dst_pt.x = cur_pt.x + startx + maxw / (colors * 2) + ii * maxw / colors - text.w() / 2; - dst_pt.y = cur_pt.y + 25; - text.Blit(dst_pt); - } - - // button exit - const Rect rectExit(dst_rt.x + dst_rt.w - 26, dst_rt.y + 7, 25, 25); - display.Blit(AGG::GetICN(ICN::TOWNWIND, 12), rectExit.x, rectExit.y); - - text.Set(_("Number of Towns:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 35; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetTownsInfo(v); - DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Number of Castles:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 47; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetCastlesInfo(v); - DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Number of Heroes:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 59; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetHeroesInfo(v); - DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Gold in Treasury:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 71; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetGoldsInfo(v); - if(1 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Wood & Ore:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 83; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetWoodOreInfo(v); - if(1 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Gems, Cr, Slf & Mer:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 95; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetGemsCrSlfMerInfo(v); - if(1 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Obelisks Found:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 107; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetObelisksInfo(v); - if(2 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Total Army Strength:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 119; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetArmyInfo(v); - if(3 < count) DrawFlags(v, dst_pt, maxw, colors); - - text.Set(_("Income:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 131; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetIncomesInfo(v); - if(4 < count) DrawFlags(v, dst_pt, maxw, colors); - - textx = 75; - startx = 80; - maxw = 240; - - // head 2 - ii = 0; - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) - if(Settings::Get().KingdomColors() & color) - { - text.Set(Color::String(color), Font::SMALL); - dst_pt.x = cur_pt.x + startx + maxw / (colors * 2) + ii * maxw / colors - text.w() / 2; - dst_pt.y = cur_pt.y + 145; - text.Blit(dst_pt); - ++ii; - } - - text.Set(_("Best Hero:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 160; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - GetBestHeroArmyInfo(v); - DrawHeroIcons(v, dst_pt, maxw); - - text.Set(_("Best Hero Stats:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 200; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - //GetBestHeroStatsInfo(v); - //if(1 < count) DrawHeroIcons(v, dst_pt, maxw); -/* - text.Set(_("Personality:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 388; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - //GetPersonalityInfo(v); - //if(2 < count) DrawHeroIcons(v, dst_pt, maxw); - - text.Set(_("Best Monster:")); - dst_pt.x = cur_pt.x + textx - text.w(); - dst_pt.y = cur_pt.y + 429; - text.Blit(dst_pt); - - dst_pt.x = cur_pt.x + startx; - //GetBestMonsterInfo(v); - //if(3 < count) DrawHeroIcons(v, dst_pt, maxw); - - //buttonExit.Draw(); -*/ - cursor.Show(); - display.Flip(); - - // message loop - while(le.HandleEvents()) - { - if(le.MouseClickLeft(rectExit) || HotKeyCloseWindow) break; - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/resource/artifact.cpp b/project/jni/application/fheroes2/src/fheroes2/resource/artifact.cpp deleted file mode 100644 index 9e4dab013..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/resource/artifact.cpp +++ /dev/null @@ -1,670 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "settings.h" -#include "world.h" -#include "artifact.h" - -static std::bitset used; - -static struct -{ - const char* name; - const char* description; -} artifacts[] = { - { _("Ultimate Book of Knowledge"), _("The Ultimate Book of Knowledge increases your knowledge by 12.") }, - { _("Ultimate Sword of Dominion"), _("The Ultimate Sword of Dominion increases your attack skill by 12.") }, - { _("Ultimate Cloak of Protection"), _("The Ultimate Cloak of Protection increases your defense skill by 12.") }, - { _("Ultimate Wand of Magic"), _("The Ultimate Wand of Magic increases your spell power by 12.") }, - { _("Ultimate Shield"), _("The Ultimate Shield increases your attack and defense skills by 6 each.") }, - { _("Ultimate Staff"), _("The Ultimate Staff increases your spell power and knowledge by 6 each.") }, - { _("Ultimate Crown"), _("The Ultimate Crown increases each of your basic skills by 4 points.") }, - { _("Golden Goose"), _("The Golden Goose brings in an income of 10,000 gold per turn.") }, - { _("Arcane Necklace of Magic"), _("The Arcane Necklace of Magic increases your spell power by 4.") }, - { _("Caster's Bracelet of Magic"), _("The Caster's Bracelet of Magic increases your spell power by 2.") }, - { _("Mage's Ring of Power"), _("The Mage's Ring of Power increases your spell power by 2.") }, - { _("Witch's Broach of Magic"), _("The Witch's Broach of Magic increases your spell power by 3.") }, - { _("Medal of Valor"), _("The Medal of Valor increases your morale.") }, - { _("Medal of Courage"), _("The Medal of Courage increases your morale.") }, - { _("Medal of Honor"), _("The Medal of Honor increases your morale.") }, - { _("Medal of Distinction"), _("The Medal of Distinction increases your morale.") }, - { _("Fizbin of Misfortune"), _("The Fizbin of Misfortune greatly decreases your morale.") }, - { _("Thunder Mace of Dominion"), _("The Thunder Mace of Dominion increases your attack skill by 1.") }, - { _("Armored Gauntlets of Protection"), _("The Armored Gauntlets of Protection increase your defense skill by 1.") }, - { _("Defender Helm of Protection"), _("The Defender Helm of Protection increases your defense skill by 1.") }, - { _("Giant Flail of Dominion"), _("The Giant Flail of Dominion increases your attack skill by 1.") }, - { _("Ballista of Quickness"), _("The Ballista of Quickness lets your catapult fire twice per combat round.") }, - { _("Stealth Shield of Protection"), _("The Stealth Shield of Protection increases your defense skill by 2.") }, - { _("Dragon Sword of Dominion"), _("The Dragon Sword of Dominion increases your attack skill by 3.") }, - { _("Power Axe of Dominion"), _("The Power Axe of Dominion increases your attack skill by 2.") }, - { _("Divine Breastplate of Protection"), _("The Divine Breastplate of Protection increases your defense skill by 3.") }, - { _("Minor Scroll of Knowledge"), _("The Minor Scroll of Knowledge increases your knowledge by 2.") }, - { _("Major Scroll of Knowledge"), _("The Major Scroll of Knowledge increases your knowledge by 3.") }, - { _("Superior Scroll of Knowledge"), _("The Superior Scroll of Knowledge increases your knowledge by 4.") }, - { _("Foremost Scroll of Knowledge"), _("The Foremost Scroll of Knowledge increases your knowledge by 5.") }, - { _("Endless Sack of Gold"), _("The Endless Sack of Gold provides you with 1000 gold per day.") }, - { _("Endless Bag of Gold"), _("The Endless Bag of Gold provides you with 750 gold per day.") }, - { _("Endless Purse of Gold"), _("The Endless Purse of Gold provides you with 500 gold per day.") }, - { _("Nomad Boots of Mobility"), _("The Nomad Boots of Mobility increase your movement on land.") }, - { _("Traveler's Boots of Mobility"), _("The Traveler's Boots of Mobility increase your movement on land.") }, - { _("Lucky Rabbit's Foot"), _("The Lucky Rabbit's Foot increases your luck in combat.") }, - { _("Golden Horseshoe"), _("The Golden Horseshoe increases your luck in combat.") }, - { _("Gambler's Lucky Coin"), _("The Gambler's Lucky Coin increases your luck in combat.") }, - { _("Four-Leaf Clover"), _("The Four-Leaf Clover increases your luck in combat.") }, - { _("True Compass of Mobility"), _("The True Compass of Mobility increases your movement on land and sea.") }, - { _("Sailor's Astrolabe of Mobility"), _("The Sailors' Astrolabe of Mobility increases your movement on sea.") }, - { _("Evil Eye"), _("The Evil Eye reduces the casting cost of curse spells by half.") }, - { _("Enchanted Hourglass"), _("The Enchanted Hourglass extends the duration of all your spells by 2 turns.") }, - { _("Gold Watch"), _("The Gold Watch doubles the effectiveness of your hypnotize spells.") }, - { _("Skullcap"), _("The Skullcap halves the casting cost of all mind influencing spells.") }, - { _("Ice Cloak"), _("The Ice Cloak halves all damage your troops take from cold spells.") }, - { _("Fire Cloak"), _("The Fire Cloak halves all damage your troops take from fire spells.") }, - { _("Lightning Helm"), _("The Lightning Helm halves all damage your troops take from lightning spells.") }, - { _("Evercold Icicle"), _("The Evercold Icicle causes your cold spells to do 50 percent more damage to enemy troops.") }, - { _("Everhot Lava Rock"), _("The Everhot Lava Rock causes your fire spells to do 50 percent more damage to enemy troops.") }, - { _("Lightning Rod"), _("The Lightning Rod causes your lightning spells to do 50 percent more damage to enemy troops.") }, - { _("Snake-Ring"), _("The Snake Ring halves the casting cost of all your bless spells.") }, - { _("Ankh"), _("The Ankh doubles the effectiveness of all your resurrect and animate spells.") }, - { _("Book of Elements"), _("The Book of Elements doubles the effectiveness of all your summoning spells.") }, - { _("Elemental Ring"), _("The Elemental Ring halves the casting cost of all summoning spells.") }, - { _("Holy Pendant"), _("The Holy Pendant makes all your troops immune to curse spells.") }, - { _("Pendant of Free Will"), _("The Pendant of Free Will makes all your troops immune to hypnotize spells.") }, - { _("Pendant of Life"), _("The Pendant of Life makes all your troops immune to death spells.") }, - { _("Serenity Pendant"), _("The Serenity Pendant makes all your troops immune to berserk spells.") }, - { _("Seeing-eye Pendant"), _("The Seeing-eye Pendant makes all your troops immune to blindness spells.") }, - { _("Kinetic Pendant"), _("The Kinetic Pendant makes all your troops immune to paralyze spells.") }, - { _("Pendant of Death"), _("The Pendant of Death makes all your troops immune to holy spells.") }, - { _("Wand of Negation"), _("The Wand of Negation protects your troops from the Dispel Magic spell.") }, - { _("Golden Bow"), _("The Golden Bow eliminates the 50 percent penalty for your troops shooting past obstacles. (e.g. castle walls)") }, - { _("Telescope"), _("The Telescope increases the amount of terrain your hero reveals when adventuring by 1 extra square.") }, - { _("Statesman's Quill"), _("The Statesman's Quill reduces the cost of surrender to 10 percent of the total cost of troops you have in your army.") }, - { _("Wizard's Hat"), _("The Wizard's Hat increases the duration of your spells by 10 turns!") }, - { _("Power Ring"), _("The Power Ring returns 2 extra power points/turn to your hero.") }, - { _("Ammo Cart"), _("The Ammo Cart provides endless ammunition for all your troops that shoot.") }, - { _("Tax Lien"), _("The Tax Lien costs you 250 gold pieces/turn.") }, - { _("Hideous Mask"), _("The Hideous Mask prevents all 'wandering' armies from joining your hero.") }, - { _("Endless Pouch of Sulfur"), _("The Endless Pouch of Sulfur provides 1 unit of sulfur per day.") }, - { _("Endless Vial of Mercury"), _("The Endless Vial of Mercury provides 1 unit of mercury per day.") }, - { _("Endless Pouch of Gems"), _("The Endless Pouch of Gems provides 1 unit of gems per day.") }, - { _("Endless Cord of Wood"), _("The Endless Cord of Wood provides 1 unit of wood per day.") }, - { _("Endless Cart of Ore"), _("The Endless Cart of Ore provides 1 unit of ore per day.") }, - { _("Endless Pouch of Crystal"), _("The Endless Pouch of Crystal provides 1 unit of crystal/day.") }, - { _("Spiked Helm"), _("The Spiked Helm increases your attack and defense skills by 1 each.") }, - { _("Spiked Shield"), _("The Spiked Shield increases your attack and defense skills by 2 each.") }, - { _("White Pearl"), _("The White Pearl increases your spell power and knowledge by 1 each.") }, - { _("Black Pearl"), _("The Black Pearl increases your spell power and knowledge by 2 each.") }, - - { _("Magic Book"), _("The Magic Book enables you to cast spells.") }, - - { "Dummy 1", "The reserved artifact." }, - { "Dummy 2", "The reserved artifact." }, - { "Dummy 3", "The reserved artifact." }, - { "Dummy 4", "The reserved artifact." }, - - { _("Spell Scroll"), _("This Spell Scroll gives your hero the ability to cast the %{spell} spell.") }, - { _("Arm of the Martyr"), _("The Arm of the Martyr increases your spell power by 3 but adds the undead morale penalty.") }, - { _("Breastplate of Anduran"), _("The Breastplate increases your defense by 5.") }, - { _("Broach of Shielding"), _("The Broach of Shielding provides 50 percent protection from Armageddon and Elemental Storm, but decreases spell power by 2.") }, - { _("Battle Garb of Anduran"), _("The Battle Garb of Anduran combines the powers of the three Anduran artifacts. It provides maximum luck and morale for your troops and gives you the Town Portal spell.") }, - { _("Crystal Ball"), _("The Crystal Ball lets you get more specific information about monsters, enemy heroes, and castles nearby the hero who holds it.") }, - { _("Heart of Fire"), _("The Heart of Fire provides 50 percent protection from fire, but doubles the damage taken from cold.") }, - { _("Heart of Ice"), _("The Heart of Ice provides 50 percent protection from cold, but doubles the damage taken from fire.") }, - { _("Helmet of Anduran"), _("The Helmet increases your spell power by 5.") }, - { _("Holy Hammer"), _("The Holy Hammer increases your attack skill by 5.") }, - { _("Legendary Scepter"), _("The Legendary Scepter adds 2 points to all attributes.") }, - { _("Masthead"), _("The Masthead boosts your luck and morale by 1 each in sea combat.") }, - { _("Sphere of Negation"), _("The Sphere of Negation disables all spell casting, for both sides, in combat.") }, - { _("Staff of Wizardry"), _("The Staff of Wizardry boosts your spell power by 5.") }, - { _("Sword Breaker"), _("The Sword Breaker increases your defense by 4 and attack by 1.") }, - { _("Sword of Anduran"), _("The Sword increases your attack skill by 5.") }, - { _("Spade of Necromancy"), _("The Spade gives you increased necromancy skill.") }, - - { "Unknown", "Unknown" }, -}; - -Artifact::Artifact() : id(Artifact::UNKNOWN), ext(0) -{ -} - -Artifact::Artifact(artifact_t a) : id(a), ext(0) -{ -} - -void Artifact::Set(artifact_t a) -{ - id = a; -} - -bool Artifact::operator== (artifact_t a) const -{ - return id == a; -} - -bool Artifact::operator!= (artifact_t a) const -{ - return id != a; -} - -Artifact::artifact_t Artifact::operator() (void) const -{ - return id; -} - -Artifact::artifact_t Artifact::GetID(void) const -{ - return id; -} - -const char* Artifact::GetName(void) const -{ - return GetName(id); -} - -const char* Artifact::GetDescription(void) const -{ - return GetDescription(id); -} - -bool Artifact::isUltimate(void) const -{ - switch(id) - { - case ULTIMATE_BOOK: - case ULTIMATE_SWORD: - case ULTIMATE_CLOAK: - case ULTIMATE_WAND: - case ULTIMATE_SHIELD: - case ULTIMATE_STAFF: - case ULTIMATE_CROWN: - case GOLDEN_GOOSE: return true; - default: break; - } - - return false; -} - -bool Artifact::isValid(void) const -{ - return id != UNKNOWN; -} - -u8 Artifact::GetIndexSprite(void) const -{ - return IndexSprite(id); -} - -u8 Artifact::GetIndexSprite32(void) const -{ - return IndexSprite32(id); -} - -u8 Artifact::GetIndexSprite64(void) const -{ - return IndexSprite64(id); -} - -Artifact::artifact_t Artifact::RandUltimate(void) -{ - switch(Rand::Get(1, 8)) - { - case 1: return Artifact::ULTIMATE_BOOK; - case 2: return Artifact::ULTIMATE_SWORD; - case 3: return Artifact::ULTIMATE_CLOAK; - case 4: return Artifact::ULTIMATE_WAND; - case 5: return Artifact::ULTIMATE_SHIELD; - case 6: return Artifact::ULTIMATE_STAFF; - case 7: return Artifact::ULTIMATE_CROWN; - default: break; - } - return Artifact::GOLDEN_GOOSE; -} - -/* get rand all artifact */ -Artifact::artifact_t Artifact::Rand(bool uniq) -{ - switch(Rand::Get(1, 3)) - { - case 1: return Artifact::Rand1(); - case 2: return Artifact::Rand2(); - default: break; - } - - return Artifact::Rand3(); -} - -/* get rand level 1 artifact */ -Artifact::artifact_t Artifact::Rand1(bool uniq) -{ - std::vector arts; - arts.reserve(27); - - if(uniq) - { - if(!used.test(MEDAL_VALOR)) arts.push_back(MEDAL_VALOR); - if(!used.test(MEDAL_COURAGE)) arts.push_back(MEDAL_COURAGE); - if(!used.test(MEDAL_HONOR)) arts.push_back(MEDAL_HONOR); - if(!used.test(MEDAL_DISTINCTION)) arts.push_back(MEDAL_DISTINCTION); - if(!used.test(THUNDER_MACE)) arts.push_back(THUNDER_MACE); - if(!used.test(ARMORED_GAUNTLETS)) arts.push_back(ARMORED_GAUNTLETS); - if(!used.test(DEFENDER_HELM)) arts.push_back(DEFENDER_HELM); - if(!used.test(GIANT_FLAIL)) arts.push_back(GIANT_FLAIL); - if(!used.test(RABBIT_FOOT)) arts.push_back(RABBIT_FOOT); - if(!used.test(GOLDEN_HORSESHOE)) arts.push_back(GOLDEN_HORSESHOE); - if(!used.test(GAMBLER_LUCKY_COIN)) arts.push_back(GAMBLER_LUCKY_COIN); - if(!used.test(FOUR_LEAF_CLOVER)) arts.push_back(FOUR_LEAF_CLOVER); - if(!used.test(ENCHANTED_HOURGLASS)) arts.push_back(ENCHANTED_HOURGLASS); - if(!used.test(ICE_CLOAK)) arts.push_back(ICE_CLOAK); - if(!used.test(FIRE_CLOAK)) arts.push_back(FIRE_CLOAK); - if(!used.test(LIGHTNING_HELM)) arts.push_back(LIGHTNING_HELM); - if(!used.test(SNAKE_RING)) arts.push_back(SNAKE_RING); - if(!used.test(HOLY_PENDANT)) arts.push_back(HOLY_PENDANT); - if(!used.test(PENDANT_FREE_WILL)) arts.push_back(PENDANT_FREE_WILL); - if(!used.test(PENDANT_LIFE)) arts.push_back(PENDANT_LIFE); - if(!used.test(PENDANT_DEATH)) arts.push_back(PENDANT_DEATH); - if(!used.test(GOLDEN_BOW)) arts.push_back(GOLDEN_BOW); - if(!used.test(TELESCOPE)) arts.push_back(TELESCOPE); - if(!used.test(SERENITY_PENDANT)) arts.push_back(SERENITY_PENDANT); - if(!used.test(STATESMAN_QUILL)) arts.push_back(STATESMAN_QUILL); - if(!used.test(KINETIC_PENDANT)) arts.push_back(KINETIC_PENDANT); - if(!used.test(SEEING_EYE_PENDANT)) arts.push_back(SEEING_EYE_PENDANT); - } - else - { - arts.push_back(MEDAL_VALOR); - arts.push_back(MEDAL_COURAGE); - arts.push_back(MEDAL_HONOR); - arts.push_back(MEDAL_DISTINCTION); - arts.push_back(THUNDER_MACE); - arts.push_back(ARMORED_GAUNTLETS); - arts.push_back(DEFENDER_HELM); - arts.push_back(GIANT_FLAIL); - arts.push_back(RABBIT_FOOT); - arts.push_back(GOLDEN_HORSESHOE); - arts.push_back(GAMBLER_LUCKY_COIN); - arts.push_back(FOUR_LEAF_CLOVER); - arts.push_back(ENCHANTED_HOURGLASS); - arts.push_back(ICE_CLOAK); - arts.push_back(FIRE_CLOAK); - arts.push_back(LIGHTNING_HELM); - arts.push_back(SNAKE_RING); - arts.push_back(HOLY_PENDANT); - arts.push_back(PENDANT_FREE_WILL); - arts.push_back(PENDANT_LIFE); - arts.push_back(PENDANT_DEATH); - arts.push_back(GOLDEN_BOW); - arts.push_back(TELESCOPE); - arts.push_back(SERENITY_PENDANT); - arts.push_back(STATESMAN_QUILL); - arts.push_back(KINETIC_PENDANT); - arts.push_back(SEEING_EYE_PENDANT); - } - - if(arts.empty()) return Rand1(false); - const artifact_t res = *Rand::Get(arts); - used.set(res); - - return res; -} - -/* get rand level 2 artifact */ -Artifact::artifact_t Artifact::Rand2(bool uniq) -{ - std::vector arts; - arts.reserve(21); - - if(uniq) - { - if(!used.test(CASTER_BRACELET)) arts.push_back(CASTER_BRACELET); - if(!used.test(MAGE_RING)) arts.push_back(MAGE_RING); - if(!used.test(STEALTH_SHIELD)) arts.push_back(STEALTH_SHIELD); - if(!used.test(POWER_AXE)) arts.push_back(POWER_AXE); - if(!used.test(MINOR_SCROLL)) arts.push_back(MINOR_SCROLL); - if(!used.test(ENDLESS_PURSE_GOLD)) arts.push_back(ENDLESS_PURSE_GOLD); - if(!used.test(SAILORS_ASTROLABE_MOBILITY)) arts.push_back(SAILORS_ASTROLABE_MOBILITY); - if(!used.test(ENDLESS_CORD_WOOD)) arts.push_back(ENDLESS_CORD_WOOD); - if(!used.test(ENDLESS_CART_ORE)) arts.push_back(ENDLESS_CART_ORE); - if(!used.test(SPIKED_HELM)) arts.push_back(SPIKED_HELM); - if(!used.test(WHITE_PEARL)) arts.push_back(WHITE_PEARL); - if(!used.test(EVIL_EYE)) arts.push_back(EVIL_EYE); - if(!used.test(GOLD_WATCH)) arts.push_back(GOLD_WATCH); - if(!used.test(ANKH)) arts.push_back(ANKH); - if(!used.test(BOOK_ELEMENTS)) arts.push_back(BOOK_ELEMENTS); - if(!used.test(ELEMENTAL_RING)) arts.push_back(ELEMENTAL_RING); - if(!used.test(SKULLCAP)) arts.push_back(SKULLCAP); - if(!used.test(EVERCOLD_ICICLE)) arts.push_back(EVERCOLD_ICICLE); - if(!used.test(POWER_RING)) arts.push_back(POWER_RING); - if(!used.test(AMMO_CART)) arts.push_back(AMMO_CART); - if(!used.test(EVERHOT_LAVA_ROCK)) arts.push_back(EVERHOT_LAVA_ROCK); - } - else - { - arts.push_back(CASTER_BRACELET); - arts.push_back(MAGE_RING); - arts.push_back(STEALTH_SHIELD); - arts.push_back(POWER_AXE); - arts.push_back(MINOR_SCROLL); - arts.push_back(ENDLESS_PURSE_GOLD); - arts.push_back(SAILORS_ASTROLABE_MOBILITY); - arts.push_back(ENDLESS_CORD_WOOD); - arts.push_back(ENDLESS_CART_ORE); - arts.push_back(SPIKED_HELM); - arts.push_back(WHITE_PEARL); - arts.push_back(EVIL_EYE); - arts.push_back(GOLD_WATCH); - arts.push_back(ANKH); - arts.push_back(BOOK_ELEMENTS); - arts.push_back(ELEMENTAL_RING); - arts.push_back(SKULLCAP); - arts.push_back(EVERCOLD_ICICLE); - arts.push_back(POWER_RING); - arts.push_back(AMMO_CART); - arts.push_back(EVERHOT_LAVA_ROCK); - } - - if(arts.empty()) return Rand2(false); - const artifact_t res = *Rand::Get(arts); - used.set(res); - - return res; -} - -/* get rand level 3 artifact */ -Artifact::artifact_t Artifact::Rand3(bool uniq) -{ - std::vector arts; - arts.reserve(22); - - if(uniq) - { - if(!used.test(ARCANE_NECKLACE)) arts.push_back(ARCANE_NECKLACE); - if(!used.test(WITCHES_BROACH)) arts.push_back(WITCHES_BROACH); - if(!used.test(BALLISTA)) arts.push_back(BALLISTA); - if(!used.test(DRAGON_SWORD)) arts.push_back(DRAGON_SWORD); - if(!used.test(DIVINE_BREASTPLATE)) arts.push_back(DIVINE_BREASTPLATE); - if(!used.test(MAJOR_SCROLL)) arts.push_back(MAJOR_SCROLL); - if(!used.test(SUPERIOR_SCROLL)) arts.push_back(SUPERIOR_SCROLL); - if(!used.test(FOREMOST_SCROLL)) arts.push_back(FOREMOST_SCROLL); - if(!used.test(ENDLESS_SACK_GOLD)) arts.push_back(ENDLESS_SACK_GOLD); - if(!used.test(ENDLESS_BAG_GOLD)) arts.push_back(ENDLESS_BAG_GOLD); - if(!used.test(NOMAD_BOOTS_MOBILITY)) arts.push_back(NOMAD_BOOTS_MOBILITY); - if(!used.test(TRAVELER_BOOTS_MOBILITY)) arts.push_back(TRAVELER_BOOTS_MOBILITY); - if(!used.test(TRUE_COMPASS_MOBILITY)) arts.push_back(TRUE_COMPASS_MOBILITY); - if(!used.test(ENDLESS_POUCH_SULFUR)) arts.push_back(ENDLESS_POUCH_SULFUR); - if(!used.test(ENDLESS_POUCH_GEMS)) arts.push_back(ENDLESS_POUCH_GEMS); - if(!used.test(ENDLESS_POUCH_CRYSTAL)) arts.push_back(ENDLESS_POUCH_CRYSTAL); - if(!used.test(ENDLESS_VIAL_MERCURY)) arts.push_back(ENDLESS_VIAL_MERCURY); - if(!used.test(SPIKED_SHIELD)) arts.push_back(SPIKED_SHIELD); - if(!used.test(BLACK_PEARL)) arts.push_back(BLACK_PEARL); - if(!used.test(LIGHTNING_ROD)) arts.push_back(LIGHTNING_ROD); - if(!used.test(WAND_NEGATION)) arts.push_back(WAND_NEGATION); - if(!used.test(WIZARD_HAT)) arts.push_back(WIZARD_HAT); - } - else - { - arts.push_back(ARCANE_NECKLACE); - arts.push_back(WITCHES_BROACH); - arts.push_back(BALLISTA); - arts.push_back(DRAGON_SWORD); - arts.push_back(DIVINE_BREASTPLATE); - arts.push_back(MAJOR_SCROLL); - arts.push_back(SUPERIOR_SCROLL); - arts.push_back(FOREMOST_SCROLL); - arts.push_back(ENDLESS_SACK_GOLD); - arts.push_back(ENDLESS_BAG_GOLD); - arts.push_back(NOMAD_BOOTS_MOBILITY); - arts.push_back(TRAVELER_BOOTS_MOBILITY); - arts.push_back(TRUE_COMPASS_MOBILITY); - arts.push_back(ENDLESS_POUCH_SULFUR); - arts.push_back(ENDLESS_POUCH_GEMS); - arts.push_back(ENDLESS_POUCH_CRYSTAL); - arts.push_back(ENDLESS_VIAL_MERCURY); - arts.push_back(SPIKED_SHIELD); - arts.push_back(BLACK_PEARL); - arts.push_back(LIGHTNING_ROD); - arts.push_back(WAND_NEGATION); - arts.push_back(WIZARD_HAT); - } - - if(arts.empty()) return Rand3(false); - const artifact_t res = *Rand::Get(arts); - used.set(res); - - return res; -} - -const char* Artifact::GetName(artifact_t a) -{ - return _(artifacts[a].name); -} - -const char* Artifact::GetDescription(artifact_t a) -{ - return _(artifacts[a].description); -} - -Artifact::artifact_t Artifact::FromInt(u16 index) -{ - return index > UNKNOWN ? UNKNOWN : static_cast(index); -} - -Artifact::artifact_t Artifact::FromIndexSprite(u8 index) -{ - if(0x10 < index && 0xA2 > index) return Artifact::FromInt((index - 1)/2); - else - if(Settings::Get().PriceLoyaltyVersion() && 0xAB < index && 0xCE > index) return Artifact::FromInt((index - 1)/2); - else - if(0xA3 == index) return Artifact::Rand(); - else - if(0xA4 == index) return Artifact::RandUltimate(); - else - if(0xA7 == index) return Artifact::Rand1(); - else - if(0xA9 == index) return Artifact::Rand2(); - else - if(0xAB == index) return Artifact::Rand3(); - else - DEBUG(DBG_GAME , DBG_WARN, "Artifact::FromIndexSprite: unknown: " << static_cast(index)); - - return Artifact::UNKNOWN; -} - -/* return index sprite objnarti.icn */ -u8 Artifact::IndexSprite(Artifact::artifact_t a) -{ - switch(a) - { - // null sprite - case ULTIMATE_BOOK: return 0x01; - // null sprite - case ULTIMATE_SWORD: return 0x03; - // null sprite - case ULTIMATE_CLOAK: return 0x05; - // null sprite - case ULTIMATE_WAND: return 0x07; - // sprite artifact - case ULTIMATE_SHIELD: return 0x09; - case ULTIMATE_STAFF: return 0x0B; - case ULTIMATE_CROWN: return 0x0D; - case GOLDEN_GOOSE: return 0x0F; - case ARCANE_NECKLACE: return 0x11; - case CASTER_BRACELET: return 0x13; - case MAGE_RING: return 0x15; - case WITCHES_BROACH: return 0x17; - case MEDAL_VALOR: return 0x19; - case MEDAL_COURAGE: return 0x1B; - case MEDAL_HONOR: return 0x1D; - case MEDAL_DISTINCTION: return 0x1F; - case FIZBIN_MISFORTUNE: return 0x21; - case THUNDER_MACE: return 0x23; - case ARMORED_GAUNTLETS: return 0x25; - case DEFENDER_HELM: return 0x27; - case GIANT_FLAIL: return 0x29; - case BALLISTA: return 0x2B; - case STEALTH_SHIELD: return 0x2D; - case DRAGON_SWORD: return 0x2F; - case POWER_AXE: return 0x31; - case DIVINE_BREASTPLATE: return 0x33; - case MINOR_SCROLL: return 0x35; - case MAJOR_SCROLL: return 0x37; - case SUPERIOR_SCROLL: return 0x39; - case FOREMOST_SCROLL: return 0x3B; - case ENDLESS_SACK_GOLD: return 0x3D; - case ENDLESS_BAG_GOLD: return 0x3F; - case ENDLESS_PURSE_GOLD: return 0x41; - case NOMAD_BOOTS_MOBILITY: return 0x43; - case TRAVELER_BOOTS_MOBILITY: return 0x45; - case RABBIT_FOOT: return 0x47; - case GOLDEN_HORSESHOE: return 0x49; - case GAMBLER_LUCKY_COIN: return 0x4B; - case FOUR_LEAF_CLOVER: return 0x4D; - case TRUE_COMPASS_MOBILITY: return 0x4F; - case SAILORS_ASTROLABE_MOBILITY: return 0x51; - case EVIL_EYE: return 0x53; - case ENCHANTED_HOURGLASS: return 0x55; - case GOLD_WATCH: return 0x57; - case SKULLCAP: return 0x59; - case ICE_CLOAK: return 0x5B; - case FIRE_CLOAK: return 0x5D; - case LIGHTNING_HELM: return 0x5F; - case EVERCOLD_ICICLE: return 0x61; - case EVERHOT_LAVA_ROCK: return 0x63; - case LIGHTNING_ROD: return 0x65; - case SNAKE_RING: return 0x67; - case ANKH: return 0x69; - case BOOK_ELEMENTS: return 0x6B; - case ELEMENTAL_RING: return 0x6D; - case HOLY_PENDANT: return 0x6F; - case PENDANT_FREE_WILL: return 0x71; - case PENDANT_LIFE: return 0x73; - case SERENITY_PENDANT: return 0x75; - case SEEING_EYE_PENDANT: return 0x77; - case KINETIC_PENDANT: return 0x79; - case PENDANT_DEATH: return 0x7B; - case WAND_NEGATION: return 0x7D; - case GOLDEN_BOW: return 0x7F; - case TELESCOPE: return 0x81; - case STATESMAN_QUILL: return 0x83; - case WIZARD_HAT: return 0x85; - case POWER_RING: return 0x87; - case AMMO_CART: return 0x89; - case TAX_LIEN: return 0x8B; - case HIDEOUS_MASK: return 0x8D; - case ENDLESS_POUCH_SULFUR: return 0x8F; - case ENDLESS_VIAL_MERCURY: return 0x91; - case ENDLESS_POUCH_GEMS: return 0x93; - case ENDLESS_CORD_WOOD: return 0x95; - case ENDLESS_CART_ORE: return 0x97; - case ENDLESS_POUCH_CRYSTAL: return 0x99; - case SPIKED_HELM: return 0x9B; - case SPIKED_SHIELD: return 0x9D; - case WHITE_PEARL: return 0x9F; - case BLACK_PEARL: return 0xA1; - - case MAGIC_BOOK: return 0xA3; // sprite RND_ARTIFACT - case DUMMY1: return 0xA4; // sprite ULTIMA_ARTIFACT - case DUMMY2: return 0xA7; // sprite RND1_ARTIFACT - case DUMMY3: return 0xA9; // sprite RND2_ARTIFACT - case DUMMY4: return 0xAB; // sprite RND3_ARTIFACT - - default: break; - } - - if(Settings::Get().PriceLoyaltyVersion()) - switch(a) - { - case SPELL_SCROLL: return 0xAD; - case ARM_MARTYR: return 0xAF; - case BREASTPLATE_ANDURAN: return 0xB1; - case BROACH_SHIELDING: return 0xB3; - case BATTLE_GARB: return 0xB5; - case CRYSTAL_BALL: return 0xB7; - case HEART_FIRE: return 0xB9; - case HEART_ICE: return 0xBB; - case HELMET_ANDURAN: return 0xBD; - case HOLY_HAMMER: return 0xBF; - case LEGENDARY_SCEPTER: return 0xC1; - case MASTHEAD: return 0xC3; - case SPHERE_NEGATION: return 0xC5; - case STAFF_WIZARDRY: return 0xC7; - case SWORD_BREAKER: return 0xC9; - case SWORD_ANDURAN: return 0xCB; - case SPADE_NECROMANCY: return 0xCD; - - default: break; - } - - DEBUG(DBG_GAME , DBG_WARN, "Artifact::IndexSprite: unknown:" << static_cast(a)); - - // null sprite - return 0; -} - -u8 Artifact::IndexSprite32(Artifact::artifact_t a) -{ - return a; -} - -u8 Artifact::IndexSprite64(Artifact::artifact_t a) -{ - return a + 1; -} - -void Artifact::SetExt(u8 v) -{ - ext = v; -} - -u8 Artifact::GetExt(void) const -{ - return ext; -} - -const char* Artifact::GetScenario(artifact_t art) -{ - switch(art) - { - case SPELL_SCROLL: return _("You find an elaborate aontainer which housesan old vellum scroll. The runes on the container are very old, and the artistry with whitch it was put together is stunning. As you pull the scroll out, you feel imbued with magical power."); - case ARM_MARTYR: return _("One of the less intelligent members of your party picks up an arm off of the ground. Despite its missing a body, it is still moving. Your troops find the dismembered arm repulsive, but you cannot bring yourself to drop it: it seems to hold some sort of magical power that influences your decision making."); - case BREASTPLATE_ANDURAN: return _("You come upon a sign. It reads: \"Here lies the body of Anduran. Bow and swear fealty, and you shall be rewarded.\" You decide to do as it says. As you stand up, you feel a coldness against your skin. Looking down, you find that you are suddenly wearing a gleaming, ornate breastplate."); - case BROACH_SHIELDING: return _("A kindly Sorceress thinks that your army's defenses could use a magical boost. She offers to enchant the Broach that you wear on your cloak, and you accept."); - case BATTLE_GARB: return _("Out of pity for a poor peasant, you purchase a chest of old junk they are hawking for too much gold. Later, as you search through it, you find it contains the 3 pieces of the legendary battle garb of Anduran!"); - case CRYSTAL_BALL: return _("You come upon a caravan of gypsies who are feasting and fortifying their bodies with mead. They call you forward and say \"If you prove that you can dance the Rama-Buta, we will reward you.\" You don't know it, but try anyway. They laugh hysterically, but admire your bravery, giving you a Crystal Ball."); - case HEART_FIRE: return _("You enter a recently burned glade and come upon a Fire Elemental sitting atop a rock. It looks up, its flaming face contorted in a look of severe pain. It then tosses a glowing object at you. You put up your hands to block it, but it passes right through them and sears itself into your chest."); - case HEART_ICE: return _("Suddenly, a biting coldness engulfs your body. You seize up, falling from your horse. The pain subsides, but you still feel as if your chest is frozen. As you pick yourself up off of the ground, you hear hearty laughter. You turn around just in time to see a Frost Giant run off into the woods and disappear."); - case HELMET_ANDURAN: return _("You spy a gleaming object poking up out of the ground. You send a member of your party over to investigate. He comes back with a golden helmet in his hands. You realize that it must be the helmet of the legendary Anduran, the only man who was known to wear solid gold armor."); - case HOLY_HAMMER: return _("You come upon a battle where a Paladin has been mortally wounded by a group of Zombies. He asks you to take his hammer and finish what he started. As you pick it up, it begins to hum, and then everything becomes a blur. The Zombies lie dead, the hammer dripping with blood. You strap it to your belt."); - case LEGENDARY_SCEPTER: return _("Upon cresting a small hill, you come upon a ridiculous looking sight. A Sprite is attempting to carry a Scepter that is almost as big as it is. Trying not to laugh, you ask, \"Need help?\" The Sprite glares at you and answers: \"You think this is funny? Fine. You can carry it. I much prefer flying anyway.\""); - case MASTHEAD: return _("An old seaman tells you a tale of an enchanted masthead that he used in his youth to rally his crew during times of trouble. He then hands you a faded map that shows where he hid it. After much exploring, you find it stashed underneath a nearby dock."); - case SPHERE_NEGATION: return _("You stop to help a Peasant catch a runaway mare. To show his gratitude, he hands you a tiny sphere. As soon as you grasp it, you feel the magical energy drain from your limbs..."); - case STAFF_WIZARDRY: return _("While out scaring up game, your troops find a mysterious staff levitating about three feet off of the ground. They hand it to you, and you notice an inscription. It reads: \"Brains best brawn and magic beats might. Heed my words, and you'll win every fight.\""); - case SWORD_BREAKER: return _("A former Captain of the Guard admires your quest and gives you the enchanted Sword Breaker that he relied on during his tour of duty."); - case SWORD_ANDURAN: return _("A Troll stops you and says: \"Pay me 5,000 gold, or the Sword of Anduran will slay you where you stand.\" You refuse. The troll grabs the sword hanging from its belt, screams in pain, and runs away. Picking up the fabled sword, you give thanks that half-witted Trolls tend to grab the wrong end of sharp objects."); - case SPADE_NECROMANCY: return _("A dirty shovel has been thrust into a dirt mound nearby. Upon investigation, you discover it to be the enchanted shovel of the Gravediggers, long thought lost by mortals."); - - default: break; - } - - return NULL; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/resource/artifact.h b/project/jni/application/fheroes2/src/fheroes2/resource/artifact.h deleted file mode 100644 index 66941dc8e..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/resource/artifact.h +++ /dev/null @@ -1,194 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2ARTIFACT_H -#define H2ARTIFACT_H - -#include "gamedefs.h" - -class Artifact -{ -public: - enum artifact_t - { - ULTIMATE_BOOK, - ULTIMATE_SWORD, - ULTIMATE_CLOAK, - ULTIMATE_WAND, - ULTIMATE_SHIELD, - ULTIMATE_STAFF, - ULTIMATE_CROWN, - GOLDEN_GOOSE, - ARCANE_NECKLACE, - CASTER_BRACELET, - MAGE_RING, - WITCHES_BROACH, - MEDAL_VALOR, - MEDAL_COURAGE, - MEDAL_HONOR, - MEDAL_DISTINCTION, - FIZBIN_MISFORTUNE, - THUNDER_MACE, - ARMORED_GAUNTLETS, - DEFENDER_HELM, - GIANT_FLAIL, - BALLISTA, - STEALTH_SHIELD, - DRAGON_SWORD, - POWER_AXE, - DIVINE_BREASTPLATE, - MINOR_SCROLL, - MAJOR_SCROLL, - SUPERIOR_SCROLL, - FOREMOST_SCROLL, - ENDLESS_SACK_GOLD, - ENDLESS_BAG_GOLD, - ENDLESS_PURSE_GOLD, - NOMAD_BOOTS_MOBILITY, - TRAVELER_BOOTS_MOBILITY, - RABBIT_FOOT, - GOLDEN_HORSESHOE, - GAMBLER_LUCKY_COIN, - FOUR_LEAF_CLOVER, - TRUE_COMPASS_MOBILITY, - SAILORS_ASTROLABE_MOBILITY, - EVIL_EYE, - ENCHANTED_HOURGLASS, - GOLD_WATCH, - SKULLCAP, - ICE_CLOAK, - FIRE_CLOAK, - LIGHTNING_HELM, - EVERCOLD_ICICLE, - EVERHOT_LAVA_ROCK, - LIGHTNING_ROD, - SNAKE_RING, - ANKH, - BOOK_ELEMENTS, - ELEMENTAL_RING, - HOLY_PENDANT, - PENDANT_FREE_WILL, - PENDANT_LIFE, - SERENITY_PENDANT, - SEEING_EYE_PENDANT, - KINETIC_PENDANT, - PENDANT_DEATH, - WAND_NEGATION, - GOLDEN_BOW, - TELESCOPE, - STATESMAN_QUILL, - WIZARD_HAT, - POWER_RING, - AMMO_CART, - TAX_LIEN, - HIDEOUS_MASK, - ENDLESS_POUCH_SULFUR, - ENDLESS_VIAL_MERCURY, - ENDLESS_POUCH_GEMS, - ENDLESS_CORD_WOOD, - ENDLESS_CART_ORE, - ENDLESS_POUCH_CRYSTAL, - SPIKED_HELM, - SPIKED_SHIELD, - WHITE_PEARL, - BLACK_PEARL, - - MAGIC_BOOK, - - DUMMY1, - DUMMY2, - DUMMY3, - DUMMY4, - - SPELL_SCROLL, - ARM_MARTYR, - BREASTPLATE_ANDURAN, - BROACH_SHIELDING, - BATTLE_GARB, - CRYSTAL_BALL, - HEART_FIRE, - HEART_ICE, - HELMET_ANDURAN, - HOLY_HAMMER, - LEGENDARY_SCEPTER, - MASTHEAD, - SPHERE_NEGATION, - STAFF_WIZARDRY, - SWORD_BREAKER, - SWORD_ANDURAN, - SPADE_NECROMANCY, - - UNKNOWN - }; - - Artifact(); - Artifact(artifact_t); - - bool operator== (artifact_t) const; - bool operator!= (artifact_t) const; - artifact_t operator() (void) const; - artifact_t GetID(void) const; - - const char* GetName(void) const; - const char* GetDescription(void) const; - - void Set(artifact_t); - - bool isUltimate(void) const; - bool isValid(void) const; - - /* objnarti.icn */ - u8 GetIndexSprite(void) const; - /* artfx.icn */ - u8 GetIndexSprite32(void) const; - /* artifact.icn */ - u8 GetIndexSprite64(void) const; - - void SetExt(u8); - u8 GetExt(void) const; - - static artifact_t RandUltimate(void); - static artifact_t Rand(bool uniq = true); - static artifact_t Rand1(bool uniq = true); - static artifact_t Rand2(bool uniq = true); - static artifact_t Rand3(bool uniq = true); - - static const char* GetName(artifact_t); - static const char* GetDescription(artifact_t); - - static artifact_t FromInt(u16); - static artifact_t FromIndexSprite(u8); - - /* objnarti.icn */ - static u8 IndexSprite(artifact_t); - /* artfx.icn */ - static u8 IndexSprite32(artifact_t); - /* artifact.icn */ - static u8 IndexSprite64(artifact_t); - - static const char* GetScenario(artifact_t); - -private: - artifact_t id; - u8 ext; /* spell for scrolls, and other */ -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/resource/maps_text.cpp b/project/jni/application/fheroes2/src/fheroes2/resource/maps_text.cpp deleted file mode 100644 index efef2e3cd..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/resource/maps_text.cpp +++ /dev/null @@ -1,940 +0,0 @@ -/* - * message strings - * from original maps files! (do not edit this) - - * - * Part of the Free Heroes2 Engine: - * http://sourceforge.net/projects/fheroes2 - */ - -#include "gamedefs.h" - -#ifdef MAPS_MESSAGES - -const char* maps_messages[] = { -_("425 bottles of beer on the wall, 425 bottles of beer! If one of those bottles should happen to fall, there'll be..."), -_("A balanced scenario with lots of resources and land to explore."), -_("A bandit army of gorgons jump you without warning. they stone your entire army demand 500 gold before they will release your comrads. Realizing that it is much cheeper to pay then rebuild your army you part with the gold."), -_("Abandon All Hope!"), -_("Abandon All Hope Ye That Enter Here"), -_("A bit of crystal!"), -_("A bit of mercury!"), -_("A bit of sulfur!"), -_("Above you looms the ancient Ice Palace. Dimly remembered myth speaks of a Prince who rejected the advances of the Winter Goddess, and thus he and his domain were cursed to remain shrouded in ice, hidden in a forgotten corner of the world. It is said that he can only be rescued by a hero who is both clever and bold. Are you that one? Do you dare enter this frozen domain?"), -_("A cache of crystal!"), -_("A cache of gems!"), -_("A cache of gold!"), -_("A cache of mercury!"), -_("A cache of sulfur!"), -_("A chance to end a bitter war has finally arrived as a new resource-laden land has been discovered."), -_("A chunk of gold!"), -_("A chunk of ore!"), -_("A couple of gems!"), -_("\"Act of Desperation\""), -_("A desert isle rich in resources rewards the quick. Just be sure to watch your back!"), -_("A dolphin playfully jumps into the air."), -_("A Dragon, A Cyclops, or an Undead. King of the Centaurs, His name is ....?"), -_("A flight of dragons circles overhead."), -_("A flock of seagulls circle overhead."), -_("A friendly dolphin splashes alongside the ship."), -_("After a long search of the island, I have discovered that there is no way for me to escape without help. I can not steal a ship from one of the coastal castles, and I dare not venture into the desert unless I wish to become Dragon food. Should anyone find this, I beg of you, please send a ship and get me off this cursed island! -Sir Christian"), -_("After centuries of friendship, the Wizards have suddenly decided to stop sharing their Library with the rest of the world. This can't be good!"), -_("After many years of peace, you discover that your sworn enemy from across the sea has chosen to invade your homeland by raising up the ocean floor to bridge the distance! You must not let them gain a foothold on this continent, in fact, your King has ordered you to establish a foothold on theirs! To make matters worse, two of your OWN towns have thrown in their lots with the enemy..."), -_("After you return from a scouting trip, your Seneschal hurries to greet you. \"My Lord, in your absence I signed an agreement in your name with a Master Merchant. If we supply him with the resources he needs, through trading, he can return the resources to us in a week or so, plus some additional ones.\" The Seneschal eyes you anxiously. You hesitate, then nod slowly, \"Good, we can use more resources>\""), -_("A ghostly pirate ship appears and sails on by."), -_("A Gift from your King, and a note that reads \"Use these resources wisely, It's all we have left\"."), -_("A gift of gold, m'lord, from the people of Enroth, to the people of Enroth. Good luck, and may God save true King Roland!"), -_("A glint by a tree catches your eye..."), -_("A gold cache!"), -_("A gold chunk!"), -_("A gold nugget!"), -_("A great Black dragon stands before you. It speaks in a suprisingly soft voice, saying, \"The elves believe they have sent another hero to reclaim their prize. I believe they have sent me another meal.\""), -_("A group of peasant farmers approaches you, \"We are in dire need of your assistance. Our castle to the north has been overrun and our Lord killed. Please help us regain our homes! There are still women and children there! Take what we have to help!\""), -_("A group of peasant farmers approach you, \"We are in dire need of your assistance. Our castle to the east has been overrun and our Lord killed. Please help us regain our homes! There are still women and children there! Take what we have to help!\""), -_("A group of peasant farmers approach you, \"We are in dire need of your assistance. Our castle to the east has been overrun and our Lord killed. Please help us regain our homes! There are still women and children there! Take what we have to help!\""), -_("A group of peasant farmers approach you, We are in dire need of your assistance. Our castle to the northeast has been overrun and our Lord killed. Please help us regain our homes! There are still women and children there! Take what we have to help!\""), -_("A handful of gems!"), -_("Ah, you stumble across something buried in the sand. As you dig it up you discover a small pile of gems and crystal."), -_("A Knight and Necromancer team up against the Barbarian and Sorceress. (Blue and Green vs Red and Yellow)"), -_("Alamar"), -_("A large contingent of the king's guard approaches you. \"Ahh, we have finally caught up to you. The king requires tribute from all of his vassals and you have been negligent far too long.\""), -_("A large map with lots of resources and treasure. Exploration and victory will require many heroes."), -_("A legion of peasants stands between you and this unclaimed island."), -_("Algary"), -_("A little bit closer..."), -_("All mines are grouped by type. Trade is your only hope."), -_("A lump of crystal!"), -_("A lump of gold!"), -_("A lump of mercury!"), -_("A man appears from behind the sand dune. \"At last,\" he says, \"Someone has come to rescue me! I am forever grateful. Alas all I have to offer you in return are these souvenirs from my wrecked ship.\""), -_("A man is laying on the ground, near death. He looks to you and speaks, \"Please help my companions! Please... they can't...cough...get away from...cough...the drag...\" With that, he dies."), -_("A merchant caravan arrives, bringing gold and supplies, however, no one can seem to remember where they came from. You silently praise this anonymous benefactor and continue your duties."), -_("a mirror"), -_("An albatross flies ahead of the ship for a while"), -_("Anduran"), -_("An enemy from across the sea has seized half your towns. Can you put aside your own feud with your brother to fight this common enemy?"), -_("\"Annexation\""), -_("An old elf is sitting on a rock in a glen, pounding on the shackles on his feet with a stone. You help him remove them and ask him his tale. \"I'm a deserter from Drakonia's army. She has enslaved all the elves to support her madness. She must be stopped.\" Then he slips into the woods without a sound, leaving behind just his cloak."), -_("Antioch"), -_("A piece of crystal!"), -_("A pile of crystal!"), -_("A pile of gems!"), -_("A pile of gold!"), -_("A plague of undead is upon us. Who will unite the living against the dead?"), -_("\"Apocalypse\""), -_("A quantity of crystal!"), -_("A quantity of mercury!"), -_("A quantity of sulfur!"), -_("Archibald"), -_("Archibald has also sent an army to find the Crown, you must find it first or all is lost."), -_("Archibald is hiding at the end of the river."), -_("A resource rich valley keeps the Wizard and the Necromancer apart. Your opponent's army will arrive in 3 months so hurry."), -_("Arm of the Crusader"), -_("Arm of the Cyclops"), -_("Arm of the Dragon"), -_("Arm of the Phoenix"), -_("Arm of the Titan"), -_("Arr' Here be pirates gold buried."), -_("A shipment of wood has arrived from your kingdom!"), -_("A splash in the seaweed alerts you to a mermaid waving in a friendly manner. \"Oh, I thought you were Ahab.\" She is surprised, but quickly composes herself. \"Well, if you meet him, give him these treasures I have collected.\""), -_("Assassins tried to kill our ally."), -_("Astircaer"), -_("A stranded Wizard with only a small force must conquer an entire continent of hostile forces."), -_("A supply ship has arrived from the homeland! You send word home that all is well."), -_("As you approach the barrier, you see the old elf you helped free. This time, however, you see that he is wearing a cape of fine weave, and a wooden crown is on his head. He sees your forces, and says \"Take this sword, and with it, strike down Drakonia and help free my people.\" The old elf then strides regally into the woods."), -_("As you approach the gates of the Ice Palace, one of your troops points in terror. You watch in awe as great slabs of ice separate from the castle walls with loud cracking reports and crash to the ground. Soon the ice is gone and the sun begins to peak through the gloom. The deathly silence that must have ruled these lands for centuries ends as birds begin to sing. From inside you hear the sounds of life."), -_("As you approach the tent, the leader of the nomads comes out to greet you. He says, \"It was prophecied many years ago that a great hero would come to greet us in our sacred valley, and we would prosper afterwords. Now it has come to pass, and we offer you these gifts as tokens of our thanks.\""), -_("As you approach, you hear whispered mentions of \"the wild barbarian who passed this way months before\". One of the villagers approaches you and hands you an object, saying \"The wild one dropped this. You must be his kin. Therefore I give it to you. But beware! Many in the village will not be as friendly as I.\""), -_("As you break your fast your sage rushes in, \"Good news, my lord! I have translated the message. Two great heroes were imprisoned many years ago. They lie sleeping - still guarded by magic barriers and monsters. My lord, they lie nearby- in between our ally and us. If we could free them, they would surely aid us against our enemies! The password to the first magic barrier can be learned at the Aqua Traveller's Tent.\""), -_("As you enter the small clearing, you see a familiar figure talking to a group of halflings and soldiers. You stay awhile and listen to his speech. \"The time to throw off these chains of tyranny is now! We must strike at the heart of her empire, and destroy the evil that she has brought to our land.\" As the old elf finishes speaking, he gets up from his mossy seat and once again, blends into the woods with incredible grace."), -_("As you lay down to nap after a long battle, you notice a lucky four-leaf clover."), -_("As you make your way through the last of the golemn debris, a group of halflings runs towards you carrying fruit and flowers. \"Thank you so much!\" Their leader exclaims, \"We've been trapped in here for ever! Come by our homes, we'll pack up and go with you!\""), -_("As you make your way to the shrine, some very thin and hollow-eyed men come out of the flower patch and stare at you. Seeing that you want the gold, one of them says to you \"Hey, man, if you're, like, so lusty for earthly wealth, then, like, have this too.\" You graciously take what they have offered and back out of the clearing."), -_("As you prepare your lands to fight the onslaught from the South, a curious message appears on your table in the Great Hall of your Castle. Written in some ancient language, none but your sage can make any sense of it. She promises to have the words deciphered by tomorrow..."), -_("A three hour tour, a three hour tour..."), -_("A tiny gnome points to a chunk of crystal you otherwise would have overlooked!"), -_("Atlantium"), -_("At last, the king is dead. For years you have planned his demise, but now it is done, and there is no heir to take his place, though the Knights to the south believe that they are the rightful successors. A wealth in wood (to the south) and ore (in the northern mountains) provides you with trade goods, and your isolation has allowed you to prepare your forces of darkness for this day. Go, now, and fulfill your destiny!"), -_("At the base of the mountain you see something that glitters. You discover an ancient pile of offerings to the gods."), -_("Avalon"), -_("Avone"), -_("A wild magic has allowed a bridge to form between two lands... Your one hope is to capture castle \"Black Fang\"."), -_("Barbarian's castle lies to the south."), -_("Barbarians from the north threaten all civilization. Can you repel the hordes?"), -_("\"Barbarian Wars\""), -_("Barrowton"), -_("Basenji"), -_("Bayside"), -_("Baywatch"), -_("Because the Darkscale Valley is so barren, the Emperor will be sending wood to you every week. Use it wisely, for it is all you shall have."), -_("Before questing for the orb of negation, you must first crush the local opposition. After the Sorceresses are removed from the earth, go east where legend says the orb lies. You may expect a convoy of supplies in a week or so to aid your conquest."), -_("Before you may pass, the spirit guardian of this valley demands tribute."), -_("Being held...."), -_("Beltway"), -_("\"Betrayal!\""), -_("Beware -- Entering Hyrda Country"), -_("Beware for whom the bell trolls."), -_("Beware of Pirates!"), -_("Beware of thieves!"), -_("Beware of traps ahead."), -_("Beware of Warlocks"), -_("Beware the deadly swamps!"), -_("Beware the Domain of Dragons"), -_("Beware the Dragon Leader"), -_("Beware the edge of the world!"), -_("Beware the moors and stick to the roads."), -_("Beware the rocks"), -_("Beware the sirens!!!"), -_("Beware the sirens!"), -_("Beware the whiporwill..."), -_("Beware, the whirlpool may not take you into a friendly embrace."), -_("Beyond here be Dragons!"), -_("Beyond the door, there be Dragons. BEWARE!"), -_("Big Oak"), -_("Blackburn"), -_("Blackfang"), -_("Black Fang"), -_("Black Oak"), -_("Blackridge"), -_("Blacksford"), -_("Black Vein"), -_("Blackwind"), -_("Bloodreign"), -_("Boats my be needed to access some parts of this peninsula."), -_("Boats Sold Here Inquire Within"), -_("BoneVille"), -_("Borderlands"), -_("Bridge out!"), -_("Bridge Out!"), -_("Brindamoor"), -_("Broken Alliance"), -_("Brownston"), -_("Buried Treasure!"), -_("Burlock"), -_("Burton"), -_("Capture the necromancer's dreaded castle \"Death Gate\" and free the land from the undead plague."), -_("Capture the town on the island off the southeast shore in order to construct a boat and travel back towards the mainland."), -_("\"Carator Mines\""), -_("Cathcart"), -_("Ceallach"), -_("Chandler"), -_("Chilton"), -_("Chronos"), -_("Come and...."), -_("Compared to the rest of the villages in this land, this village seems grand, but in any other land it would seem poor. From here you can see the tall spires of the Warlock's tower of Dragons."), -_("Complete"), -_("Condemned!"), -_("Congratulations! After navigating the treacherous coast, you have established trade between the north and south."), -_("Corackston"), -_("Corlagon"), -_("\"Country Lords\""), -_("Crossroads"), -_("Crossroads North"), -_("Crossroads South"), -_("Dainwin"), -_("Danger a whirlpool destroyed my ship."), -_("Danger, Dragons abound!"), -_("DANGER! QUICKSAND!"), -_("Danger! Troll bridge ahead!"), -_("Danger - Turn Back Now"), -_("Dark clouds loom overhead as you enter this valley."), -_("Dead Pine"), -_("Dear Diary, I found a mermaid today. She was floating in a patch of seaweed next to a rock. A very friendly sort of creature too! Gave me all sorts of lovely gems and jewelry! She said to come back again sometime for more of the sea riches. Wow. Ahab"), -_("Deathgate"), -_("DeathGate"), -_("Decisions"), -_("\"Defender\""), -_("Destroy the Barbarians who are attacking the southern border of your kingdom! Recover your towns and then invade the jungle kingdom."), -_("Detour! Mountain pass to the East has been known to have avalanches! For your own safety, follow the road South."), -_("Detour! Troll bridge ahead!"), -_("Dirt"), -_("DirtWater"), -_("Dominion"), -_("Do Not Enter!"), -_("Do not remove coins from fountain."), -_("Dragadune"), -_("Dragonburg"), -_("Dragon City"), -_("Dragon City lies beyond the Scorpion Hills."), -_("Dragon Hill"), -_("\"Dragon Master\""), -_("Dragon Rider"), -_("Dragons Everywhere!"), -_("Dragon's Eye"), -_("Dragontooth"), -_("Dragon Town"), -_("Dragonville"), -_("Dragon Wars"), -_("Dragon Watch"), -_("Drakonia"), -_("Drakoran"), -_("Dwarfhall"), -_("Dwarfhall, Domain of the dwarf King."), -_("Dwarf Hall, domain of the dwarf King."), -_("Eatio"), -_("Edgewood"), -_("Elk's Head"), -_("Elowyn"), -_("Enroth"), -_("Entering high in the desert"), -_("Entering Praires of the Middlelands"), -_("Entering the desert high"), -_("Entering the high desert"), -_("Entering the higher desert"), -_("Entering the Valley of Magic"), -_("Erliquin"), -_("Evil Igor"), -_("Fadlan"), -_("Fantasy Island."), -_("Farlien"), -_("Federal express, when it absolutely positively has to be there turn one."), -_("fedx comp"), -_("Fedx for comp"), -_("Fenton"), -_("Fetid Elm"), -_("Final message from Overlord. \"The royal executioners are on their way. My gold, the land or your head- it's your choice.\""), -_("Find and defeat the Pirate Leader!"), -_("Find and destroy the evil beings who rule the wastelands."), -_("Find the center island."), -_("Find the Ultimate Artifact and be proclaimed King, or smash the opposition and take control."), -_("Find Your Wayward Son who is rumored to be living in the desolate lands. Do it within 8 weeks or it will be of no help to your family."), -_("Fire King"), -_("\"First Blood\""), -_("Five heroes vie for control of a familiar land."), -_("Fool's Gold"), -_("For a total of 400,000 gold your opponents will become \"loyal\" subjects, otherwise... let them eat cake!"), -_("For centuries, the Wizards of the North have maintained a vast library for all the world to share. Now, however, they have closed their doors, and issued declarations of war to each of the other rulers of the land. To make matters worse, rather than ally with you to face the Wizards, each of the others have decided to go forth on their own in an effort to conquer this land for themselves! Prepare your forces, commander, for you now stand alone."), -_("\"Force of Arms\""), -_("For decades you have studied, learned, and allowed yourself to be ruled by that pitiful excuse for a king, knowing that one day the time would come for you to sit on the throne. That time is now, for the king is dead and without an heir. You have the advantage of isolation from the rest of the kingdom, but beware the miles of coastline that could leave you vulnerable to attack. Go, now, and wipe your enemies from this land!"), -_("Forder Oaks"), -_("Forestria"), -_("For Honor"), -_("For information about Ye Rich lands to the south, speak to Alponse at the Golden Goose Tavern. Excellent views, plentiful water."), -_("Forsaken Lands"), -_("For sale."), -_("Fortress Isle"), -_("For years, you have existed peacefully in the Forest of Dreams, knowing that your king was the kindest and strongest ruler the land had seen in centuries. Now, however, his reign is at an end, and there is no heir to succeed him. You realize that a power struggle is coming, and that you must brace yourself for war, and prevent those who would harm this land from coming into power!"), -_("For years, you've been able to keep your subjects \"appeased.\" Now however, you discover not only that your entire kingdom has turned against you, but most of your outer towns have fallen to the different factions. To make matters worse, all your gold suddenly seems to be missing from the treasury!"), -_("Fountainhead"), -_("Four kingdoms race to capture the island of Sharkania."), -_("Four lakes have castles, three have treasure."), -_("Four players must work together to assault the Wizards' Stronghold."), -_("Frozenpeak"), -_("Full House"), -_("Gain the aid of the elves. They will not allow trees to be chopped down, so we will send you wood every 2 weeks. You have 7 months!"), -_("Gallavant"), -_("Galveston"), -_("Garamok"), -_("Gate"), -_("Gate to the Isle of Knowledge"), -_("Gate to The Isle of Knowledge"), -_("Gaurdian"), -_("Gavonshire"), -_("Giants"), -_("Glastonbury"), -_("Go away!"), -_("GO AWAY!"), -_("Goblin Island"), -_("Goblin King"), -_("Go Home!"), -_("Go north to find the lost gold-mine."), -_("Good vs. Evil"), -_("Gorgomar"), -_("\"Greater Glory\""), -_("Greed"), -_("Green bonus stuff"), -_("Green gets stuff"), -_("Greenroot"), -_("Green's Allowance"), -_("Green's Groceries"), -_("green stuff"), -_("Green stuff"), -_("Greywind"), -_("Grim"), -_("Grrr, Blazzer, Grrupt. Be gone with you!"), -_("Guardian War"), -_("Gungtooth"), -_("Hail Unicorns!"), -_("Hampshire"), -_("Have fun storming the castle!"), -_("Havenwood"), -_("Hawkins"), -_("Help!"), -_("Help me...."), -_("Help peasant farmers regain their castle and land, else they'll take your crops."), -_("Hero's Hall"), -_("High in the snowy crags, you meet an old witch who, in return for a trinket of yours, gives you a powerful magical object she used to use as a footstool before she was exiled into the mountains by her own townspeople."), -_("Hillstone"), -_("Hilltop"), -_("Hilltown"), -_("Horizon"), -_("Hot Spot"), -_("Hungry dragons await. Welcome, food."), -_("Hurry, no time to wait. This way to the dock."), -_("Hurry up! Few days are left before the enemy's army arrives."), -_("I am...."), -_("I am one of the few remaining survivors of the wrecked pleasure ship, Exhorbitance. I think we'll all be dead of hunger soon, for we are out of caviar. We ate the chef yesterday."), -_("Ibn Fadlan"), -_("Ice Palace"), -_("Ice Prince"), -_("Icy lands ahead."), -_("I didn't do it!"), -_("If three heroes could dig six holes in three days, how long would it take six heroes to dig twelve holes?"), -_("If you free a hero, they may help..."), -_("If you value your lives, for God's sake, Don't go through this whirlpool!"), -_("Income for Yellow."), -_("In the hole you find a chunk of ore!"), -_("In the stream you find an old compass!"), -_("In this glen live some very naughty halflings. Stay Away!"), -_("In two more weeks, if you have not located Joseph, your kingdom will surely lose its current battle with Harondale."), -_("I see you, you see me."), -_("Is it something I said? Go back and I will forget the whole thing."), -_("IslandHome"), -_("Island of the Elves"), -_("Island of the meek"), -_("Island of Wolcott"), -_("Isle Maze"), -_("Isle of Knowledge"), -_("It has become apparent that if all your enemies were eliminated, you would have all the time you need to find the Ultimate Artifact."), -_("It is obvious that the mage that once was here had won many battles! There, upon his hand, is a most powerful ring!"), -_("It is rumored that a bridge of land used to exist between the two continents, but that a wild magic caused it to sink into the sea, taking with it all those who used to inhabit it. To try to raise this bridge is to invite a curse upon the world! The spirits of the dead will haunt us all!"), -_("It is said that King Zealot found the gods' artifact once and it let him rule for 100 years."), -_("It looks like there used to be an ore mine here but all you see now is a hole in the ground and some minerals scattered around."), -_("It's a battle for supremacy as the Blue and Green heroes take on Red and Orange in team competition!"), -_("It's windy at the top. Defend, Divide, and Conquer."), -_("IvanHome"), -_("Ivan lives in the desert."), -_("Ivory Gates"), -_("I, Wilgatus, besiege you - do not fight me for I am all powerful and will destroy you if you persue me. I will demonstrate my power."), -_("I Would Go That Way If I Were You."), -_("Jarkonas"), -_("Jarkonas VI"), -_("Jolly Roger was here"), -_("Joseph"), -_("Jungomar"), -_("Just 30 days left!"), -_("Just ONE week left!"), -_("Kalindra"), -_("Kastor"), -_("Keep going south"), -_("Keep Off The Grass!"), -_("Keep Out!"), -_("King John"), -_("King of Death"), -_("Knight's Trail."), -_("Knight stuff"), -_("Lakeside"), -_("Land's Edge"), -_("Land teleporters will get you to your destination sooner."), -_("Lankershire"), -_("Lavalor"), -_("Like, Stuff And Junk?"), -_("Living on the outskirts of the kingdom, you are considered an unwelcome outcast by the other leaders of the realm, though you always showed your support for the king. Now, however, the king is dead, and many of those who spoke out againt him seek to seize his throne for themselves. You have a vast desert at your back, rich with gems, and the advantage that many do not consider you a threat. Go, now, and show them how wrong they are!"), -_("Lladner Dock"), -_("Log go up... Log go down... Log go up... Log go down... OOoohhhhhhhh........"), -_("Lombard"), -_("Long live Roland the true King!"), -_("Long live Roland the true King."), -_("Look before you leap."), -_("Look out!"), -_("Lord Alberon"), -_("Lord Alberon calls you into his war room. He says, \"I am glad you have chosen to remain loyal to me, but this war is a terrible one for my kingdom. Already, the sorceress' towns to the Northeast have become unsure about their loyalties, and will not pledge allegiance to either side. This is hard on our cities as most of the wood in the land comes from these towns. We will need to recover their sawmills and take their towns by force.\""), -_("Lord Haart"), -_("Lord Halton"), -_("Lord Kreager"), -_("Lord, messages have begun pouring in from our spies in the other island courts. They have learned of a new volcanic island with vast amounts of reasources. Your Majesty, with these new reasources we could put an end to a century of war between the islands, and reunite them under your rightful rule."), -_("Lost Continent"), -_("Lost Gold- Mine"), -_("Lost Island."), -_("Lost Relic"), -_("Maelstrom of Deceit"), -_("Maelstrom of Misery"), -_("Magic"), -_("Magic Three"), -_("Many dust plumes rise from the floor of this small valley. You see various bands of nomads roaming about, and in the distant, the bright flames of their camp."), -_("Many guardians stand between you and your enemies, but anybody can sneak through the back door!"), -_("Many that have gone through this door have never returned."), -_("Many years ago, a couple of mages had a \"duel\" that forever changed the lake at the center of this continent. Hearty adventurers might find interesting treasure there!"), -_("Many years ago, a falling star crashed near here. Only now the area is safe enough to explore. Rumor has it a castle exist where the star fell."), -_("Many years ago, your father, the King, died in a freak hunting accident. Since then, you and your brother have jointly ruled his kingdom, but both of you have been seeking a way to seize the throne for yourself. You got your wish. Attackers from across the sea have captured more than half your towns and castles, effectively dividing the continent in two. Now is the time to repel these invaders and do away with your brother once and for all!"), -_("Marco"), -_("Marsh Home"), -_("Martine"), -_("Mayland"), -_("Meramec"), -_("Message from Archibald. \" Do not dare to return without my Crown.\""), -_("Message from Archibald. \" General, thank you for bringing me this lovely gift. I have decided to participate directly in the capture of my brother Roland. Since your military advice has taken us this far, I will follow your orders to the letter.\""), -_("Message from Overlord. \"STILL WAITING FOR MY GOLD!\""), -_("Message from Overlord. \"WHERE'S MY GOLD?\""), -_("Message from Roland. \"General, circumstances permit me to take a hand in the events of this final conflict. I have your spoils of war with me and I will follow your advice explicitly.\""), -_("Message from Roland. \"General, I have sent most of our troops and material ahead to the region of the final conflict with Archibald. Unfortunately, Lord Corlagon has cut us off from the rest of our army. I will be awaiting your victory in a castle across the west river. I should be safe from attack.\""), -_("Message from Roland. \" We cannot hope to defeat Archibald without the Crown, I'm counting on you.\""), -_("Middle Gate"), -_("Middleton"), -_("Middletown"), -_("Might vs. Magic"), -_("Mineral Wars"), -_("Mirkosov"), -_("mirror"), -_("Money For Red"), -_("MONEY, MONEY, MONEY!"), -_("Morale becomes even lower as the endless cliffs move past."), -_("More water than land, you'll still spend lots of time on foot as you search a literal horde of islands."), -_("Mountain king"), -_("Mountainview"), -_("Mr Ed"), -_("Mr. Yellow's Income"), -_("Murray's resort Isle!"), -_("Mutiny! The crew has dumped off my precious cargo into the sea! Thank goodness it floats - when I've rid of them, I'll come back to pick it up!"), -_("My leige, our scouts report three other lords are attacking from the south. They work in conjuction with each other to eliminate us! We must keep this castle and remove the threat of the enemy. We wish you luck!"), -_("My leige, we have established a foothold (which we cannot afford to lose) and all of our Heroes have joined us. The king has made us the offer to purchase this land for 200,000 gold or we may take it by force. The local lords have been fighting and each wants to be the one that defeats us. Now all the local armies have arrived on the beach, creating a state of complete Pandemonium!"), -_("My Treasure Is Buried Beneath Three Palm Trees"), -_("\"Necromancers!\""), -_("New Dawn"), -_("New Enemies"), -_("New Vertigo"), -_("Nightshadow"), -_("No Description"), -_("No Fishing!"), -_("No gems, crystal, or mercury for red."), -_("None of the four leaders like being stuck in a land that has only one season."), -_("NO, Not That Way. This Way."), -_("No one has ever made it out of the deadly swamps alive!"), -_("Noraston"), -_("North Road"), -_("North vs. South"), -_("No stuff for red"), -_("No sulfer fer Yella."), -_("No swimming."), -_("Notice- Those who put messages in bottles will be tortured."), -_("No Trespassing"), -_("No tresspath... No tree... No thresh... GO AWAY!"), -_("Now leaving Swamplands of the Eternial"), -_("Obsidian"), -_("Of the necromancers...."), -_("Ogrehild"), -_("Olympus"), -_("One of the seers in your castle comes to you in the morning with urgent news. Your one time comrade, the wizard Joseph, and his armies have been imprisoned in a jail nearby. His power would surely aid you in your quest to reclaim the library, you think to yourself. Perhaps there is a way to rescue him..."), -_("One of your aides reports that the Castle of Farlien is located on the northeast spur of this island, and is a stronghold for the enemy. He urges you to take it out as soon as possible, and then move onto other islands."), -_("One of your \"allies\" has joined Archibald. You now face an opponent with three castles to your one. Good luck!"), -_("One of your \"Allies\" has joined Roland. You are now facing three castles, all belonging to the enemy. Good luck!"), -_("One of your loyal goblins has brought you an armload of crystal!"), -_("One of your loyal subjects, a fairy tells you where to find a cache of mercury!"), -_("One of your scouts reports a tiny cave nearby. Upon investigating, you discover a small cache of goods. In the dirt by them is etched 'Ivan'."), -_("One of your troops stubs its paw on something buried here. After a few hours of digging you unearth a cache of treasure!"), -_("Only a month remains in which to find Joseph."), -_("On quite days, Nubbie the sea monster can be seen!"), -_("Orange stuff"), -_("Orcville"), -_("Ostoroth"), -_("Other than the dragons, the elves don't have any enemies."), -_("Our ally was greatly weakened when his resources were plundered."), -_("\"Our Finest Hour\""), -_("Our reinforcements were lost in a storm, we salvaged all we could!"), -_("Our spies have discovered that the barbarian hordes are now receiving support from kraeger! You must hurry and find the third piece before your forces here are crushed!"), -_("Overlord"), -_("Pandemonium"), -_("Paper can gain you what wood and sail cannot."), -_("Password found by Crystals to the South."), -_("Peacekeeper"), -_("\"Peasants!\""), -_("Peasants"), -_("Peasantsville"), -_("Perenor"), -_("Pet Cemetary"), -_("Pick one of four Knights in this large and inhospitable land."), -_("Pig's Eye"), -_("Pinehurst"), -_("Pirate Cove"), -_("Pirate's Cove"), -_("Pirate Utopia"), -_("Pirites strike and take the gold from you holds."), -_("Pixie"), -_("Play the Knight or Barbarian in an alliance in this classic duel against the four spell casters. (Blue and Green vs Red)"), -_("Please...."), -_("Plenty of resources and lots of ground to cover. Watch out for Orange and Purple!"), -_("Portals"), -_("Portsmith"), -_("POSION - DO NOT DRINK"), -_("Powerful magic lies southwest of here in the Valley of the Kings."), -_("Prisoner on...."), -_("Pyramid"), -_("Quick Silver"), -_("Raste"), -_("Realm of the Undead. Fresh blood welcome."), -_("Red bonus"), -_("Red player sympathizes with the undead cause."), -_("Red's Connection"), -_("Redshield"), -_("Red's Lunch Money"), -_("Red's Rubles"), -_("Red stuff"), -_("Regrettably, you have no castle with which to begin your assault. Fortunately, however, Kraeger's forces are weak here in the south, and you have bribed a rebel necromancer to aid you in the beginning of your conquest."), -_("Reinforcements have arrived, Gold from the homelands!"), -_("Remains of a long since dead wizard have attracted an ancient artifact. This artifact has now attached itself to you!"), -_("Remember, you're searching for the Ultimate Artifact... don't get distracted!"), -_("Rendall Koski was here. 1997. Northampton, Massachusetts There is a powerful artifact in the southeastern corner of the world. Go for it, explorer!"), -_("Reports from your spies tell of enemies on the march. As you rush to the castle courtyard to prepare your armies, you are intercepted by your Chaplain. \"My Lord, I have received word that we should send what Heroes we can to the Isle of Knowledge. The Scholars there have agreed to teach them so they will be strong for the battles ahead of us.\" You thank the Chaplain for the information and head thoughtfully into the courtyard."), -_("Rescue your crazy Uncle Ivan. Find him within 4 months or it will be no help to your kingdom."), -_("Restricted Area, Do Not Enter!"), -_("Rest stop."), -_("Retake the Castle of Ivory Gates."), -_("Revolution"), -_("Right thinking - he who takes the riskes deserves the rewards."), -_("River Crossing"), -_("Road Ends"), -_("Road to Isle of Knowledge"), -_("Road to the Isle of Knowledge"), -_("Robbers have looted your treasury and you have lost valuable resources."), -_("Robbers have looted your treasury, stealing valuable resources."), -_("Roc Haven"), -_("Rogar"), -_("Roland"), -_("Roscomon"), -_("Rotten Birch"), -_("Rumors abound and your faithful hero Sandro is now highly regarded by the masses. Should Sandro desert you, all will be lost."), -_("Sandcaster"), -_("Sandro"), -_("Sands of Time"), -_("Sansobar"), -_("\"Save the Dwarves\""), -_("Scabsdale"), -_("Scorched Earth"), -_("Scouts have reported a town to the North. They have also heard some disturbing news. Their seems to be a war raging in this area."), -_("Scouts report the enemy's stronghold lies to the Southwest. Our swift arrival has caught them by surprise. If you move quickly their resistance will be minimal."), -_("Scouts report the notorious necromancer \"Wyrm\" has been sighted to the northeast."), -_("Scummy"), -_("Searching in the dust of this abandoned campsite, you find a magic scroll."), -_("Seasons Change"), -_("Secret Mountain Pass"), -_("Seek out the Ultimate Artifact to be victorious in this strangely shaped land."), -_("Seek the great library, for only with the guidance of the musty tomes therin will you find the means to reveal and bind the fount to your will."), -_("Seven Lakes"), -_("Sharkania"), -_("Sheltemburg"), -_("Sherman"), -_("Shipwrecked!"), -_("Should this message ever reach home, please know that this has become a hostile place since the King's death. No less than six factions are at war with each other, each seeking to be the King's successor. Beware especially of the Barbarians and the Necromancers who control the north, their regions are easily defended and they have a wealth of gold and gems. Do not venture to this land without a sizeable force. -Sir Christian"), -_("Sirein"), -_("Six factions have established a foothold on a huge, unexplored continent. Can you eliminate the other five?"), -_("Six heroes with large armies prepare to slug it out for total domination!"), -_("Skirmish"), -_("\"Slay the Dwarves\""), -_("Slippery when wet."), -_("Slugfest"), -_("Snagged on a thorny bush, you discover a scrap of cloth. The design on it looks like the coat of arms of Ivan's house!"), -_("Snowdrop"), -_("Somebody has stuffed a pile of gems in the ditch!"), -_("Some crystal!"), -_("Some gems!"), -_("Someone has stolen 100 wood and 77 ore from you. Ah, that's nothing. Let's keep going."), -_("Someone has stolen gold and resources from the palace treasury! You suspect your enemies, but you can't know for certain."), -_("Someone is playing a pan flute around here."), -_("Someone notices a piece of parchment lying behind a clump of grass. You pick it up. It looks to be a page from a journal, and it reads, \"...made it past the first guardians. Hopefully will reach the ancient desert city soon. Only hope my forces are strong enough to survive...\""), -_("Some ore!"), -_("Some sulfur!"), -_("Some unlucky adventurers have been captured and imprisoned in these lands."), -_("Sorceress Forest. Show respect for nature!"), -_("Sorpigal"), -_("South Mill"), -_("So you think you're smart?"), -_("Spector"), -_("Spell Casters"), -_("Spies report Roland has sent a hero to search for the Crown. If he finds it first, all is lost!"), -_("Spirit City"), -_("Spy Tower - see what your competition is doing!"), -_("Stairs"), -_("Start with five castles! How could you lose!? Oh yeah, everyone else starts with five, too."), -_("Stick to the road!"), -_("Stromgild"), -_("Stromhild"), -_("Stronghold"), -_("Stuff for red"), -_("Stuff for Yellow"), -_("Stuff For Yellow"), -_("Subbaculcha"), -_("Sundune"), -_("Surf and Turf"), -_("Swimming near the kelp is a pod of dolphins."), -_("Tacma"), -_("Tchudes"), -_("Teleporters"), -_("Terra Firma"), -_("Terrain Wars"), -_("The alliance has crumbled and all are at war. Lots of resources but little time to prepare."), -_("The ancient King Zealot had the artifact of the gods and then hid it in his old age so that it could not be used by others."), -_("The Back Door"), -_("The Barbarian's lands are being invaded. Are you strong enough to resist the invasion?"), -_("The castle of Drakonran in the east has been taken by the barbarians! Two other towns to the west have also been taken, but the barbarian armies were fairly decimated in the process."), -_("The center island is rumored to harbor great spells."), -_("The Citadel"), -_("The cities of the plains."), -_("The Clearing"), -_("The convoy has at long last arrived. Regretably, it has been beset by bandits on its journey here, and has far less supplies than we had hoped. Make your way south, for our spies have found rich mines there."), -_("The convoy should have been here by now! Let us hope that it is safe and still on its way."), -_("The country lords have allied and pooled their resources into one command. Not only have they massed their forces in the north, but they have sent a knight to the west to steal your supplies. Scouts report a castle to the east that would be ideal as a base of operations."), -_("The crew are unworthy! I am not going down with the ship! -The Captain"), -_("\"The Crown\""), -_("The day you have feared has finally arrived. The king, who you have faithfully served, has died, leaving no heir to his throne. As his captain, you feel that this job should now be yours, but several factions even now are preparing for conquest. You are at the center of the trade routes, having the sea to the south and the great forest to the north. Go, now, Commander, and claim what is rightfully yours!"), -_("The diplomats who were sent here ahead of you report that the elves will only cooperate with you if you will recover the golden bow for them. It was stolen by their enemies, the Dragons and hidden behind magic barriers."), -_("The Eastern Town."), -_("The edge of the world is your edge. But prepare to be prepared."), -_("The Emerald Isle"), -_("The Enchanted Forest."), -_("The End of the World is Nigh!"), -_("The End of the World is Nigh"), -_("The Epic battle against Your Rival! Eliminate everything! Total Warfare! Don't Lose your first hero!"), -_("The Fire King is an ally to the dragons, and will help a friend of theirs."), -_("The First One To Take Astircaer Wins!"), -_("The first piece of the artifact now lies in the hands of the Unholy Order of Warlocks. You must annihilate them, and their allies to the north. They will surely give us what we seek in exchange for their feeble lives."), -_("The Fortune of Infamous Uae was buried on one of these islands. She died without ever revealing it. Find it before the other cutthroats."), -_("The four factions race to capture a mystical castle."), -_("The four spell casters face off with substantial starting armies. Can the crusaders keep the peace?"), -_("\"The Gauntlet\""), -_("The Gods have given you 6 months to prove yourself. Good or Evil - who shall prevail? (Blue,Green and Red vs Yellow, Orange and Purple)"), -_("The gods have granted this world a great artifact, to find it means victory."), -_("The Gods themselves will aid us in this War."), -_("The Gold Traveller's Tent is near the Aqua Taveller's Tent."), -_("The guardians of Dragon Isle reside in the jungle."), -_("The Ice Prince stands frozen in some forgotten corner of the world."), -_("The island...."), -_("The Island of Lost Reason"), -_("The islands have much wealth."), -_("The Isle of Armoria"), -_("The key to success is rubbing enough lamps."), -_("The King has declared you his hier apparent and champion. You must seek out and destroy your common enemy, Wilgatus and his Castle, Mirkosov, the source of his power."), -_("The King is dead, his kingdom has been shattered, and six leaders seek to seize power for themselves."), -_("The Kingly Wastes"), -_("The Kings Road."), -_("The King will sell you this land for 200,000 gold or you can take it by force. The choice is yours."), -_("The land of Heroes II."), -_("The Lost Castle of the Ancients"), -_("The mage wars have caused a great turmoil. This island has become a central flux of magical power. Be wary all those that enter upon here."), -_("The mage wars have caused great turmoil. This island has become a central flux of magical power. Be wary all those that enter upon here."), -_("The Master Merchant arrives and takes the resources he needs for trade. Plus a little gold for expenses..."), -_("The Master Merchant arrives and takes the resources he needs for trading. Plus a little more gold for expenses..."), -_("The Master Merchant arrives at your Castle. He tells you tall tales of travel, full of outrageous lies. He also gives you, your share of the profits..."), -_("The Master Merchant arrives back at your Castle. He tells you tall tales of faraway places full of outrageous lies. He also gives you, your share of the profits..."), -_("The Medusas have the password and they can be found just to the west."), -_("The more there is the less you see."), -_("The North Road to Roland's castle."), -_("The note in this bottle has become mostly indecipherable. All you can make out are references to deadly pirates, and hidden gold mines."), -_("The Other Side"), -_("The Overlord has given you 4 months to conquer this land or deliver to him the sum of 150,000 gold."), -_("The people on the Isle of Knowledge are taking up a collection to aid us."), -_("The Proving Grounds"), -_("The Queen's Road."), -_("The Realm of Air is barred, but you may appeal here for help."), -_("There are remnants of a mighty battle fought here, not too long ago. It looks as if whoever came this way may have made this their final stop."), -_("There are three enemy castles to the north. Capture them in the name of Roland the true king!"), -_("The Red Tide of War rolls North. Stopping the flood seems hopeless. Yet, Honor demands you and your ally die trying."), -_("There is hidden treasure north of the Green Lord's Ore Mine."), -_("There is hidden treasure south of the Blue Lord's Sawmill."), -_("There's a warm wind blowing from the south."), -_("There's a Wizard living in the north who is behind this peasant revolt."), -_("The Retreat of the Alchemist Doctor Yu"), -_("There used to be a mine here, but it has long since run out of ore. You are only able to scavenge 5 units of ore from the old site."), -_("There was a shipreck in the far east waters recently."), -_("The River Styx"), -_("The roars of several dragons echo from the towers."), -_("The Rock Store."), -_("The Royal Gardens."), -_("The Scholars, Priests, and Priestesses of the Isle have given you what they can to help you against your enemies."), -_("The Scholars, Priests, and Priestesses of the Isle have given you what they can to help you defend against your enemies."), -_("These doors are a risk the likes of which you do not know."), -_("These lands are beholden to Lord Kraeger."), -_("These lands are desolate and for the most part devoid of resources. Not even the bravest heroes dare to venture into them, and plants are rare and precious here. Who knows what else awaits?"), -_("The Southern Witch is biding her time. She will strike when your armies are weak."), -_("the stairs"), -_("The Table in the Great Hall of the Castle is Haunted."), -_("The third piece of the artifact is somewhere to the north, that much we know. We are still unsure of its exact location, but our spies are out gathering information. The forces in this area are too strong to be completely subjugated, so take what you can and hold on to it tightly."), -_("The troops have sworn their allegiance, but should lose a battle they will lose faith and our cause will be lost."), -_("The Valley of Aruk."), -_("The Valley of Magic holds many surprises. You discover an old pair of boots sticking out of the sand."), -_("The Valley of Tresures"), -_("The Wasteland"), -_("The way of magic"), -_("The way of might"), -_("The way of numbers"), -_("The western town."), -_("The winds howl in mourning around the shipwreck."), -_("The wizard has an island in the southeast."), -_("The Wizards who have captured the Necromancers' town have wasted no time in building defenses designed to stop you, and their last castle has just been completed. Fortunately only a Captain of the Guard and a small garrison are currently present. If you hurry, you should be able to capture the castle before they have a chance to reinforce it!"), -_("The wood has arrived."), -_("The writing on this sign is too faded to read."), -_("The Yellow Lord has the Ultimate Artifact."), -_("The Yellow Lord is a hothead who will attack before his allies can send him aid."), -_("They say there's mermaids in these waters..."), -_("This area is rich in resources. Explore, but beware, a castle left undefended will quickly fall."), -_("This area must be secured for the sake of the Empire. Our spies have reported a discord between The kingdom of the knights to the north, and that of the oppressive sorceresses to the northeast. Perhaps this feud can be exploited for our gain..."), -_("This bottle is empty."), -_("This is the last week you have to find the rebel wizard Joseph! Good Luck in your quest."), -_("This land and all others are now under the sole ownership of Ibn Fadlan, the Undead King. Any disregard for his magesty's soverign rule is to be punished by death most horrendous."), -_("This land has been claimed by the nation of Neroli. Interlopers are UNWELCOME."), -_("This rugged land will have rivals fighting the terrain as well as each other."), -_("This rundown village looks like it was once the epicenter of an enormous, but now ruined, city. Under a pile of rubble you find an object which looks like it has lain there for ages."), -_("This spot overlooks an old quarry. This was one of the only places in the world where ore could be taken right out of the ground. Unfortunately the jungle has reclaimed the quarry and it is unusable. You collect the last of the ore and depart."), -_("This twisted maze of sorceress towns has three factions struggling for sole control. Use your resources wisely!"), -_("This village appears to be in little better shape than the first one you saw. As you approach the village an old man hands you a slip of paper, with the following message, \"Joseph lives in the town of IslandHome.\""), -_("This village is in extremely poor shape. There is no chance of getting more than some of the lesser creatures here."), -_("This way to the Necromancer Forest."), -_("Those who seek knowledge are welcome to the city of Chronos."), -_("Three Warlocks in the land of Dragons. Lose thy home and all will be lost. Conquer thy enemies and the land shall forever be yours!"), -_("Timberhill"), -_("Time for a refreshing drink."), -_("Time is running out! The enemy's reinforcements are almost here."), -_("To pass you must pay troll."), -_("TreeHome"), -_("Trespassers will be EATEN!"), -_("Trilobar"), -_("Troy"), -_("Tundara"), -_("Turn back, friend, while you still can!"), -_("Turn Back Now!"), -_("Turn Back Now or all will be LOST!"), -_("Turn Back or DIE!"), -_("Turn Back or else!"), -_("Turn back, you fool."), -_("\"Turning Point\""), -_("Uae was the scurviest, pirate ye'd never wanta see. In all her years of murdering and thieving she amassed so much ill-gotten booty that she couldn't carry it around in her galleon. Besides, even the meanest can't stay awake all the time. Legend tells that she hid it so well, she was thinking that she just might forget where it was. So she left clues around the islands, carved in stone. Well, she's dead now. It's up to you to recover her legacy."), -_("Uncle Ivan"), -_("Uncle Leo"), -_("Uncle Milty"), -_("Undead Armies"), -_("Unholy Alliance"), -_("Unite the Tribes. Don't lose your main hero, the first Descendant."), -_("Valley of Death"), -_("Valley Of The Damned"), -_("Valley of the Kings."), -_("Vaultius"), -_("Vertigo"), -_("Vikings!"), -_("Viper's Nest"), -_("Vulcania"), -_("Warrior Knight"), -_("Wastelands"), -_("Watch out for Purple!"), -_("Waystop"), -_("\"We are at the edge of the world!\" they scream. \"What are we doing here?\""), -_("Weddington"), -_("Weed Patch"), -_("We found a weakness my lord. Capture castle Black Fang and victory is ours."), -_("We have just learned that the artifact is on an island north of this continent. However, there does not appear to be any means to get there. Stay very alert for any possible way across the narrow channel."), -_("Welcome back general. Have you finished the conquest of the northern lands? What? you still have not finished your mission! Get back there and teach those rebels a lesson!"), -_("Welcome to Li'l Alctatraz! Vistors NOT welcome."), -_("Welcome to Power Island. He who controls this Isle controls the Seven Lakes!"), -_("Welcome to the Sandbar."), -_("Welcome to the sandy Isle."), -_("Welcome to the sorceress' guild."), -_("Welcome to the Spiral Isles"), -_("Welcome to the wounderous Kitisland range. Eruptions each day, beware of dragons."), -_("Welcome to Windfall Island!"), -_("Welcome to your DOOM!"), -_("We'll join you - for the right price."), -_("Well placed bribes have won you a stronghold near the warring Barbarians. Be advised that given their proximity an unguarded castle is an open invitation to defeat."), -_("Westfork"), -_("Westmoor"), -_("We told you not to drink!"), -_("What are you doing here?"), -_("What cannot be seen but only heard, and will not speak until spoken to?"), -_("What everyday word is most often pronounced incorrectly?"), -_("What goes up and down but never moves?"), -_("What good fortune! You've discovered a long-abandoned settlement. To your surprise, you discover that the previous inhabitants left some of their resources behind when they departed!"), -_("What is always coming but never arrives?"), -_("What is the Sum of all Numbers from 1 to 200?"), -_("What is time spent poorly?"), -_("What's another word for pirate treasure?"), -_("What's behind door number one?"), -_("What's this? A pile of gems?"), -_("What's this? Someone has left a pile of wood here!"), -_("What team won Super Bowl XXI and Super Bowl XXV? (Hint... a Wizard might have these troops in his army)"), -_("What turns everything around but does not move?"), -_("What walks in the morning on four legs, two in the afternoon and three in the evening?"), -_("What? What's this? Something at the bottom of this pool..."), -_("When you're ready, take the teleport to the Island's Hot Spot!"), -_("When you think yourself invincible, walk through this gate. Even then, prepare to meet your bitter end."), -_("Where am I?"), -_("While away seeking the Ultimate Artifact, Kastor's kingdom is invaded!"), -_("While traveling a mesenger meets you on the road. His message tells of a new ally from an island far to the south. This ally can not offer forces to your battle but has agreed to send some support in the form of gold and crystal."), -_("Whiteshield"), -_("Whittingham"), -_("Who am I?"), -_("Who am I?... Where am I?... Oh no! My Ship! Well it's consigned to the ghosts of my dead crew now, at least I still have my lucky rabbits foot."), -_("Who is the true King?"), -_("\"Why have we come this way?\" asks the first mate. You have no answer."), -_("Wicked Warlock Way"), -_("Wilasher"), -_("Wildabar"), -_("Wilgatus"), -_("Willow"), -_("Windfall Isle"), -_("Winterkill"), -_("Winterlands"), -_("Witch Hunt"), -_("With the year long eruption of Mt. Kitisland, your three worst enemies now have a ground bridge to your eastern contenent."), -_("Wizardwood. Magicians welcome!"), -_("Woodhaven"), -_("Wood's Lord"), -_("Woodstock"), -_("Woodville"), -_("Wormed Ash"), -_("Wow, somebody has left a pile of wood here!"), -_("Wyrm"), -_("Xabran"), -_("Yellow gets some stuff"), -_("Yellow's Steady Cash"), -_("Yellow stuff"), -_("Yellow's Yarbols"), -_("Ye old fish liver oil."), -_("Yorksford"), -_("You and your ally's families were given custody of The Isle of Knowledge. Other Lords feel the time has come for new guardians..."), -_("You are a fool to come here!"), -_("You are fighting on the side of your king!"), -_("You are fighting on the side of your sister!"), -_("You are now entering the domain of Prince Roland. Have a nice day."), -_("You are now entering the domain of Prince Roland. Have a pleasant stay."), -_("You bribe the entrance guards of this dingy prison camp. They agree to look the other way for a little while."), -_("You can only reach your enemies via teleporters, but each jump is a leap of faith."), -_("You cautiously ride through the trees, looking out for enemy assaults, when suddenly, the old elf is beside you. \"Your quest is almost at an end, my friend. All that remains is for you to lay seige to these last few castles. The fate of my people rests upon your final battles here. May the gods be with you as well.\" He turns to leave, but you ask him his name before he is gone. Over his shoulder, as he is leaving he says \"I am Ilthanis, king of the elves.\""), -_("You come across the dead remains of what was appearantly a powerful wizard! You wonder if it's safe to continue."), -_("You face three opponents in this scenario. Capture their castles and their heroes to prove your worthiness to Archibald."), -_("You find a beautiful helm buried in the lava. As you move to put it on your head it turns into the Hideous mask and now you realize that no creature will join you."), -_("You find a gleaming gold medalion buried in the snow. As you move to put it on it changes to the Fizbin of Misfortune."), -_("You find an old signpost in the midst of a thicket that reads \"Warlock Wood, West. Barbarian Fields, East.\""), -_("You find a note in the bottle! It reads, \"My ship has been wrecked by the notorious pirates in this area! I am stranded on a small and barren island. Please, I beg you to come and rescue me!\""), -_("You found something!"), -_("You found Treasure!"), -_("You have been ordered here to claim this land in the name of your King and recover any riches that you might find. However, five other Kings and Queens have also sent their heroes to this land, so you must watch out for them as well as the natives!"), -_("You have found what someone else has lost..."), -_("You have hired a barbarian of great power to aid you in this, your last quest. His origins are unknown to you, but you sense strong nobility beneath the furs and dirt that cover him. In addition, the famous explorer, Marco the wizard, is rumored to have wrecked his ship in this new land. Finding him would prove to be a much needed boon to your cause."), -_("You have just 8 weeks to build your army and conquer a town on the other side of a distant river. There are three paths to take, which will you choose?"), -_("You have just 8 weeks to build your army and conquer a town on the other side of a distant river. There are three paths to take, which will you choose?"), -_("You have received a message from Archibald. \"General, these peasants deserve punishment. Put them to the sword and let Corlagon have his way with them.\""), -_("You have received a message from Archibald. \" HOW DARE YOU BETRAY ME! I will see your head on the block alongside your new master's once I have won."), -_("You have received a message from Roland. \" I am shocked! I had thought better of you, but I was terribly wrong. Now you'll have to live with your dark decision for the rest of your life.\""), -_("You have recieved a shipment of supplies from your kingdom!"), -_("You have recieved a shipment of supplies from your kingdom! There is a note attached, \"These are all we could afford to send you from our treasuries, as the war with Harondale is taxing us greatly. We will send more in two weeks.\""), -_("You have six months to destroy the Necromancer Stronghold in the heart of the valley."), -_("You have washed up on the beach after being shipwrecked. Your goal is to find a way home."), -_("You hear a low rumble, look up and see an avalanche! You dive onto a large patch of grass to avoid it. While dusting yourself off, you consider yourself quite lucky to be alive. Luckier still to find a Four-Leaf Clover stuck on your nose."), -_("You hear a rumor from a peasant who lives in the town of Waystop. He says, \"The pirates control most of the sulfur mines in this area. They use it for the cannons on their bigger boats. If you want a mine, you'll have to defeat them.\""), -_("You hear melodic strains of elvish music as you enter this clearing."), -_("You must, like, forsake your earthly wealth and, like, join us on the island of the lotus eaters."), -_("You must search the world for your mortal enemy, Wilgatus. Can you find him before its too late?"), -_("You notice some runes hastily scrawled into a rock by your feet, They look like the initials of Uncle Ivan!"), -_("You notice that mines and resources in the elvish lands are few, and you send word to your kingdom that you will need extra supplies. They should respond within a fortnight."), -_("Your advance scouts come riding back to you with the following news. They believe they have found signs that Uncle Ivan was in this general area, and that he made his way to the north many months ago. Also they say there is a town nearby and many resources to the east."), -_("Your advisor approaches you, \"My liege, something must be done about these peasants! They still refuse to work. At this rate you won't have anything to put in your daughter's dowry!\""), -_("Your advisor approaches you smiling greatly, \"My liege! The peasants are making money in the market, and are finally paying taxes!\""), -_("Your advisor approaches you with a long face, \"My liege, the peasant's numbers are growing steadily. All they do is take, take, take! We are beginning to suffer dearly because of them.\""), -_("Your advisor approaches you with some startling information, \"My liege, the peasants are draining us. They do nothing, and take everything! We must get them home. Your own citizens are beginning to suffer!\""), -_("Your arrival here was a surprise to those sworn to guard Dragon Isle, and you were able to quickly capture one of their castles. Use caution, though, for two other guardians remain in this jungle."), -_("Your castle, founded inside the center of a mile wide crater, is besieged by those who desire your mineral wealth."), -_("Your castle is the last outpost in the area, Don't lose it!"), -_("Your crew begins to grumble."), -_("Your crew seriously entertains thoughts of mutiny. Your nights are sleepless."), -_("You're almost there!"), -_("You, recieve word that you have been robbed."), -_("You're getting colder."), -_("You're getting warmer."), -_("You're here! Oh, thank you thank you thank you! I'm in the jail east of the castle. Please hurry!"), -_("Your expedition has taken a turn for the worse... you now have no way to get home!"), -_("Your forces are thinly spread in an effort to defend all the dwarf towns (which may not be transformed into castles). Consolidate your forces and smite the enemy before the towns fall."), -_("Your horse stumbles and throws you from the saddle. When you awaken you find that you have hit your head on the Fizbin of Misfortune."), -_("Your isolation from the rest of the kingdom has largely kept you out of the political struggles, but now with the king's death, and lack of an heir, you see a golden opportunity to seize the throne for yourself. Just remember that you have relied largely on trade for several key resources, especially sulfur, but with a little planning this land can be yours. Go, now, and show these peasants how to rule!"), -_("Your king has sent supplies to aid the war effort."), -_("Your opponents are allied against you and each is twice as powerful as his predecessor! Is it possible to win?"), -_("Your Queen sent you here to explore this newly discovered territory, but a freak storm scattered your fleet and left you stranded. You gather the survivors and form a small settlement, naming it New Vertigo. This place is your home now, and survival is your highest priority, but remember, if you are captured or killed, it's over!"), -_("Your rival, the kingdom of Harondale, is attacking your weak border towns! Recover from their first strike and crush them completely."), -_("Your Scouts report talking to a young knight, a squire to the two sleeping heroes. The squire is trapped by the Aqua Magic Barriers and a group of fallen Paladins. He says the two heroes, Dainwin and Ceallach, have awakened but are still trapped by a Gold Magical Barrier and asks your aid in freeing them."), -_("Your Scouts report that the Aqua Traveller's Tent is located along The North Road."), -_("Your scouts return with grim news. The natives of this land are currently at war with each other, and they like outsiders even less than they like each other! Congratulations, Commander, you're at war!"), -_("Your sister calls you before her altar in the morning. \"I have important news,\" she says, \"The barbarian kingdoms which border this land have agreed to lend us some of their castles and warriors in return for a share of the spoils. I hope victory comes swiftly, but your presence gives me strength to stand until whatever end awaits.\""), -_("Your subjects contribute to your war effort!"), -_("Your town is undefended and your heroes are scattered. Do you attack or defend?"), -_("Your treasury has been looted by robbers and you have lost valuable resources."), -_("Your troops begin to wonder about your sanity."), -_("You run aground on the rocks and have to use some wood to fix your boat."), -_("You see a family of refugees making their way from the beach. You ask them about their plight and they tell you that they are from a once great city called Moss Side. They tell you that the castle was destroyed in a great conflagration, and they fled for fear of their lives."), -_("You see an old man bringing water towards the stables. Recognizing him as the mystic, you attempt to thank him for his gift with some gold. He refuses, but says to you instead, \"There are riddles guarding the source of the fount's power, and the dragons know the answers. Make your way through their lair, and you shall know victory.\""), -_("You see an old mystic perched on a rock. You walk towards him to see if he has any words for you on your quest, and he says \"First I see you as a great conquerer of the lands of men. Secondly, I see you as a mighty ruler of vast armies, well loved by your troops. Thirdly, I see you as a slayer of legions of dragons, your body bathed in their fire. Lastly, I see you standing on the shores of the fount, unable to cross.\" Then the Mystic fades away."), -_("You see something that could just be the elusive Nubbie!"), -_("You see the mast of ancient ship here. On further investigation you find that the ships holds are full of gems. The hours pass as your crue liberates the treasure."), -_("You see the remains of a burned out sawmill here. All you can salvage is some ofwood left for scrap."), -_("You see the remains of an old sawmill, but it is obvious that you will not be able to make it work again."), -_("You see the remains of an old sawmill just to realize that it will no longer produce. You gather the ramains and move on."), -_("You send this letter back to the king,\"A month has passed and we have not discovered the wizard Joseph. I only hope that we are able to locate him in time to aid us in our struggle.\""), -_("You should turn back."), -_("You stumble upon an old man who proclaims you Lord of the Realm, hands you his boots and wonders into the mountains mumbling something about being late for an important date."), -_("You stumple across three small rocks piled on top of each other and decide to dig undernear them. There you find an old weather-beaten bag of gems."), -_("You uncover a compass in the grass!"), -_("You've been warned!"), -_("You've received a message from Roland. \"In the absence of a strong leader, the local lords have fallen to fighting. Uniting this area is critical to our cause, so we must not fail. Leaving your castle undefended in this highly contested region will surely lead to defeat. I'm counting on you.\""), -_("You've received a message from the guild. \"Thank God you've arrived! We're under seige from two enemies from the north and one from across the sea. Please save us, you're our only hope.\""), -_("You've ruled with an iron fist (and an army of undead), but now your kingdom has turned against you!"), -_("You've saved a group of miners from the dragons. One of them approaches you, \"Thank you so much for saving us! We found this sulfer and sword in the mine, then those dragons chased us! I don't know how much longer we could survive!\""), -_("You will clash quickly on this small head-to-head map, so stay on your toes!"), -_("You will need a stronger army than that, mortal, to step through this portal."), -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/resource/resource.cpp b/project/jni/application/fheroes2/src/fheroes2/resource/resource.cpp deleted file mode 100644 index 73f9108e9..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/resource/resource.cpp +++ /dev/null @@ -1,394 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "mp2.h" -#include "world.h" -#include "agg.h" -#include "settings.h" -#include "resource.h" - -Resource::funds_t::funds_t(u8 rs, u32 count) : wood(0), mercury(0), ore(0), sulfur(0), crystal(0), gems(0), gold(0) -{ - switch(rs) - { - case ORE: ore = count; break; - case WOOD: wood = count; break; - case MERCURY: mercury = count;break; - case SULFUR: sulfur = count; break; - case GEMS: gems = count; break; - case CRYSTAL: crystal = count;break; - case GOLD: gold = count; break; - - default: DEBUG(DBG_GAME , DBG_WARN, "Resource::funds_t::funds_t: unknown resource"); break; - } -} - -Resource::resource_t Resource::Rand(void) -{ - switch(Rand::Get(1, 6)) - { - case 1: return Resource::WOOD; - case 2: return Resource::MERCURY; - case 3: return Resource::ORE; - case 4: return Resource::SULFUR; - case 5: return Resource::CRYSTAL; - case 6: return Resource::GEMS; - //case 7: return Resource::GOLD; exclude - default: break; - } - - return Resource::WOOD; -} - -Resource::resource_t Resource::FromIndexSprite(u8 index) -{ - switch(index) - { - case 1: return WOOD; - case 3: return MERCURY; - case 5: return ORE; - case 7: return SULFUR; - case 9: return CRYSTAL; - case 11: return GEMS; - case 13: return GOLD; - - default: break; - } - - return UNKNOWN; -} - -// operator funds_t + -const Resource::funds_t Resource::funds_t::operator+ (const Resource::funds_t & pm) const -{ - Resource::funds_t res; - - res.wood = wood + pm.wood; - res.mercury = mercury + pm.mercury; - res.ore = ore + pm.ore; - res.sulfur = sulfur + pm.sulfur; - res.crystal = crystal + pm.crystal; - res.gems = gems + pm.gems; - res.gold = gold + pm.gold; - - return res; -} - -const Resource::funds_t & Resource::funds_t::operator+= (const Resource::funds_t & pm) -{ - wood += pm.wood; - mercury += pm.mercury; - ore += pm.ore; - sulfur += pm.sulfur; - crystal += pm.crystal; - gems += pm.gems; - gold += pm.gold; - - return *this; -} - -// operator funds_t - -const Resource::funds_t Resource::funds_t::operator- (const Resource::funds_t & pm) const -{ - Resource::funds_t res; - - res.wood = wood - pm.wood; - res.mercury = mercury - pm.mercury; - res.ore = ore - pm.ore; - res.sulfur = sulfur - pm.sulfur; - res.crystal = crystal - pm.crystal; - res.gems = gems - pm.gems; - res.gold = gold - pm.gold; - - return res; -} - -const Resource::funds_t & Resource::funds_t::operator-= (const Resource::funds_t & pm) -{ - wood -= pm.wood; - mercury -= pm.mercury; - ore -= pm.ore; - sulfur -= pm.sulfur; - crystal -= pm.crystal; - gems -= pm.gems; - gold -= pm.gold; - - return *this; -} - -// operator funds_t * -const Resource::funds_t Resource::funds_t::operator* (u32 mul) const -{ - Resource::funds_t res; - - res.wood = wood * mul; - res.mercury = mercury * mul; - res.ore = ore * mul; - res.sulfur = sulfur * mul; - res.crystal = crystal * mul; - res.gems = gems * mul; - res.gold = gold * mul; - - return res; -} - -const Resource::funds_t & Resource::funds_t::operator*= (u32 mul) -{ - wood *= mul; - mercury *= mul; - ore *= mul; - sulfur *= mul; - crystal *= mul; - gems *= mul; - gold *= mul; - - return *this; -} - -// operator funds_t < -bool Resource::funds_t::operator< (const funds_t & pm) const -{ - return wood < pm.wood && - mercury < pm.mercury && - ore < pm.ore && - sulfur < pm.sulfur && - crystal < pm.crystal && - gems < pm.gems && - gold < pm.gold; -} - -// operator funds_t <= -bool Resource::funds_t::operator<= (const funds_t & pm) const -{ - return wood <= pm.wood && - mercury <= pm.mercury && - ore <= pm.ore && - sulfur <= pm.sulfur && - crystal <= pm.crystal && - gems <= pm.gems && - gold <= pm.gold; -} - -// operator funds_t > -bool Resource::funds_t::operator> (const funds_t & pm) const -{ - return wood > pm.wood || - mercury > pm.mercury || - ore > pm.ore || - sulfur > pm.sulfur || - crystal > pm.crystal || - gems > pm.gems || - gold > pm.gold; -} - -// operator funds_t >= -bool Resource::funds_t::operator>= (const funds_t & pm) const -{ - return wood >= pm.wood || - mercury >= pm.mercury || - ore >= pm.ore || - sulfur >= pm.sulfur || - crystal >= pm.crystal || - gems >= pm.gems || - gold >= pm.gold; -} - -/* name resource */ -const char* Resource::String(u8 resource) -{ - const char* res[] = { "Unknown", _("Wood"), _("Mercury"), _("Ore"), _("Sulfur"), _("Crystal"), _("Gems"), _("Gold") }; - - switch(resource){ - case Resource::WOOD: return res[1]; - case Resource::MERCURY: return res[2]; - case Resource::ORE: return res[3]; - case Resource::SULFUR: return res[4]; - case Resource::CRYSTAL: return res[5]; - case Resource::GEMS: return res[6]; - case Resource::GOLD: return res[7]; - default: break; - } - - return res[0]; -} - -/* return index sprite objnrsrc.icn */ -u8 Resource::GetIndexSprite(u8 resource) -{ - switch(resource){ - case Resource::WOOD: return 1; - case Resource::MERCURY: return 3; - case Resource::ORE: return 5; - case Resource::SULFUR: return 7; - case Resource::CRYSTAL: return 9; - case Resource::GEMS: return 11; - case Resource::GOLD: return 13; - default: - DEBUG(DBG_GAME , DBG_WARN, "Resource::GetIndexSprite: unknown resource"); - } - - return 0; -} - -/* return index sprite resource.icn */ -u8 Resource::GetIndexSprite2(u8 resource) -{ - switch(resource){ - case Resource::WOOD: return 0; - case Resource::MERCURY: return 1; - case Resource::ORE: return 2; - case Resource::SULFUR: return 3; - case Resource::CRYSTAL: return 4; - case Resource::GEMS: return 5; - case Resource::GOLD: return 6; - default: - DEBUG(DBG_GAME , DBG_WARN, "Resource::GetIndexSprite2: unknown resource"); - } - - return 0; -} - -u8 Resource::funds_t::GetValidItems(void) const -{ - u8 result = 0; - - if(wood) ++result; - if(ore) ++result; - if(mercury) ++result; - if(sulfur) ++result; - if(crystal) ++result; - if(gems) ++result; - if(gold) ++result; - - return result; -} - -void Resource::funds_t::Reset(void) -{ - wood = 0; - ore = 0; - mercury = 0; - sulfur = 0; - crystal = 0; - gems = 0; - gold = 0; -} - -Resource::BoxSprite::BoxSprite(const funds_t & f, u16 w) : Rect(0, 0, w, 0), rs(f) -{ - const u8 count = rs.GetValidItems(); - h = 4 > count ? 45 : (7 > count ? 90 : 135); -} - -const Rect & Resource::BoxSprite::GetArea(void) const -{ - return *this; -} - -void Resource::BoxSprite::SetPos(s16 px, s16 py) -{ - x = px; - y = py; -} - -void RedrawResourceSprite(const Surface & sf, const Point & pos, - u8 count, u16 width, u8 offset, s32 value) -{ - Display & display = Display::Get(); - Point dst_pt; - std::string str; - Text text; - - dst_pt.x = pos.x + width / 2 + count * width; - dst_pt.y = pos.y + offset; - - display.Blit(sf, dst_pt.x - sf.w() / 2, dst_pt.y - sf.h()); - - String::AddInt(str, value); - text.Set(str, Font::SMALL); - text.Blit(dst_pt.x - text.w() / 2, dst_pt.y + 2); -} - -void Resource::BoxSprite::Redraw(void) const -{ - const u8 valid_resource = rs.GetValidItems(); - if(0 == valid_resource) return; - - u16 width = 2 < valid_resource ? w / 3 : w / valid_resource; - - u8 count = 0; - u8 offset = 35; - - if(rs.wood) - { - const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, 0); - RedrawResourceSprite(sprite, Point(x, y), count, width, offset, rs.wood); - ++count; - } - - if(rs.ore) - { - const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, 2); - RedrawResourceSprite(sprite, Point(x, y), count, width, offset, rs.ore); - ++count; - } - - if(rs.mercury) - { - const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, 1); - RedrawResourceSprite(sprite, Point(x, y), count, width, offset, rs.mercury); - ++count; - } - - if(2 < count){ count = 0; offset += 45; } - - if(rs.sulfur) - { - const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, 3); - RedrawResourceSprite(sprite, Point(x, y), count, width, offset, rs.sulfur); - ++count; - } - - if(2 < count){ count = 0; offset += 45; } - if(rs.crystal) - { - const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, 4); - RedrawResourceSprite(sprite, Point(x, y), count, width, offset, rs.crystal); - ++count; - } - - if(2 < count){ count = 0; offset += 45; } - if(rs.gems) - { - const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, 5); - RedrawResourceSprite(sprite, Point(x, y), count, width, offset, rs.gems); - ++count; - } - - if(2 < count){ count = 0; offset += 45; } - if(rs.gold) - { - const Sprite & sprite = AGG::GetICN(ICN::RESOURCE, 6); - if(! count) width = w; - RedrawResourceSprite(sprite, Point(x, y), count, width, offset, rs.gold); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/resource/resource.h b/project/jni/application/fheroes2/src/fheroes2/resource/resource.h deleted file mode 100644 index b9eb0563b..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/resource/resource.h +++ /dev/null @@ -1,96 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2RESOURCE_H -#define H2RESOURCE_H - -#include -#include -#include "gamedefs.h" - -namespace Resource -{ - enum resource_t - { - UNKNOWN = 0x00, - WOOD = 0x01, - MERCURY = 0x02, - ORE = 0x04, - SULFUR = 0x08, - CRYSTAL = 0x10, - GEMS = 0x20, - GOLD = 0x40 - }; - - struct funds_t - { - funds_t() : wood(0), mercury(0), ore(0), sulfur(0), crystal(0), gems(0), gold(0) {}; - funds_t(u8 rs, u32 count); - - const funds_t operator+ (const funds_t &pm) const; - const funds_t operator* (u32 mul) const; - const funds_t operator- (const funds_t &pm) const; - const funds_t & operator+= (const funds_t &pm); - const funds_t & operator*= (u32 mul); - const funds_t & operator-= (const funds_t &pm); - - bool operator< (const funds_t &pm) const; - bool operator<= (const funds_t &pm) const; - bool operator> (const funds_t &pm) const; - bool operator>= (const funds_t &pm) const; - - u8 GetValidItems(void) const; - void Reset(void); - - s32 wood; - s32 mercury; - s32 ore; - s32 sulfur; - s32 crystal; - s32 gems; - s32 gold; - }; - - const char* String(u8 resource); - - resource_t Rand(void); - resource_t FromIndexSprite(u8 index); - - /* return index sprite objnrsrc.icn */ - u8 GetIndexSprite(u8 resource); - - /* return index sprite resource.icn */ - u8 GetIndexSprite2(u8 resource); - - class BoxSprite : protected Rect - { - public: - BoxSprite(const funds_t &, u16); - - const Rect & GetArea(void) const; - void SetPos(s16, s16); - void Redraw(void) const; - - const funds_t & rs; - }; -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/spell/spell.cpp b/project/jni/application/fheroes2/src/fheroes2/spell/spell.cpp deleted file mode 100644 index b2bc244ce..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/spell/spell.cpp +++ /dev/null @@ -1,887 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "heroes_base.h" -#include "artifact.h" -#include "settings.h" -#include "spell.h" -#include "army.h" - -#ifdef WITH_XML -#include "xmlccwrap.h" -#endif - -struct spellstats_t -{ - const char* name; - u8 mana; - u8 sprite; - u8 extra; - const char* description; -}; - -u16 Spell::dd_distance = 0; -u16 Spell::dd_sp = 0; -u16 Spell::dd_hp = 0; - -static spellstats_t spells[] = { - // name mana spr value description - { "Unknown", 0, 0, 0, "Unknown spell." }, - { _("Fireball"), 9, 8, 10, _("Causes a giant fireball to strike the selected area, damaging all nearby creatures.") }, - { _("Fireblast"), 15, 9, 10, _("An improved version of fireball, fireblast affects two hexes around the center point of the spell, rather than one.") }, - { _("Lightning Bolt"), 7, 4, 25, _("Causes a bolt of electrical energy to strike the selected creature.") }, - { _("Chain Lightning"), 15, 5, 40, _("Causes a bolt of electrical energy to strike a selected creature, then strike the nearest creature with half damage, then strike the NEXT nearest creature with half again damage, and so on, until it becomes too weak to be harmful. Warning: This spell can hit your own creatures!") }, - { _("Teleport"), 9, 10, 0, _("Teleports the creature you select to any open position on the battlefield.") }, - { _("Cure"), 6, 6, 5, _("Removes all negative spells cast upon one of your units, and restores up to %{count} HP per level of spell power.") }, - { _("Mass Cure"), 15, 2, 5, _("Removes all negative spells cast upon your forces, and restores up to %{count} HP per level of spell power, per creature.") }, - { _("Resurrect"), 12, 13, 50, _("Resurrects creatures from a damaged or dead unit until end of combat.") }, - { _("Resurrect True"), 15, 12, 50, _("Resurrects creatures from a damaged or dead unit permanently.") }, - // extra: 0, because also used Speed:GetOriginal (see Battle2::Stats::GetSpeed) - { _("Haste"), 3, 14, 0, _("Increases the speed of any creature by %{count}.") }, - { _("Mass Haste"), 10, 14, 0, _("Increases the speed of all of your creatures by %{count}.") }, - { _("spell|Slow"), 3, 1, 0, _("Slows target to half movement rate.") }, - { _("Mass Slow"), 15, 1, 0, _("Slows all enemies to half movement rate.") }, - // - { _("Blind "), 6, 21, 0, _("Clouds the affected creatures' eyes, preventing them from moving.") }, - { _("Bless"), 3, 7, 0, _("Causes the selected creatures to inflict maximum damage.") }, - { _("Mass Bless"), 12, 7, 0, _("Causes all of your units to inflict maximum damage.") }, - { _("Stoneskin"), 3, 31, 3, _("Magically increases the defense skill of the selected creatures.") }, - { _("Steelskin"), 6, 30, 5, _("Increases the defense skill of the targeted creatures. This is an improved version of Stoneskin.") }, - { _("Curse"), 3, 3, 0, _("Causes the selected creatures to inflict minimum damage.") }, - { _("Mass Curse"), 12, 3, 0, _("Causes all enemy troops to inflict minimum damage.") }, - { _("Holy Word"), 9, 22, 10, _("Damages all undead in the battle.") }, - { _("Holy Shout"), 12, 23, 20, _("Damages all undead in the battle. This is an improved version of Holy Word.") }, - { _("Anti-Magic"), 7, 17, 0, _("Prevents harmful magic against the selected creatures.") }, - { _("Dispel Magic"), 5, 18, 0, _("Removes all magic spells from a single target.") }, - { _("Mass Dispel"), 12, 18, 0, _("Removes all magic spells from all creatures.") }, - { _("Magic Arrow"), 3, 38, 10, _("Causes a magic arrow to strike the selected target.") }, - { _("Berserker"), 12, 19, 0, _("Causes a creature to attack its nearest neighbor.") }, - { _("Armageddon"), 20, 16, 50, _("Holy terror strikes the battlefield, causing severe damage to all creatures.") }, - { _("Elemental Storm"), 15, 11, 25, _("Magical elements pour down on the battlefield, damaging all creatures.") }, - { _("Meteor Shower"), 15, 24, 25, _("A rain of rocks strikes an area of the battlefield, damaging all nearby creatures.") }, - { _("Paralyze"), 9, 20, 0, _("The targeted creatures are paralyzed, unable to move or retaliate.") }, - { _("Hypnotize"), 15, 37, 25, _("Brings a single enemy unit under your control for one combat round if its hits are less than %{count} times the caster's spell power.") }, - { _("Cold Ray"), 6, 36, 20, _("Drains body heat from a single enemy unit.") }, - { _("Cold Ring"), 9, 35, 10, _("Drains body heat from all units surrounding the center point, but not including the center point.") }, - { _("Disrupting Ray"), 7, 34, 3, _("Reduces the defense rating of an enemy unit by three.") }, - { _("Death Ripple"), 6, 28, 5, _("Damages all living (non-undead) units in the battle.") }, - { _("Death Wave"), 10, 29, 10, _("Damages all living (non-undead) units in the battle. This spell is an improved version of Death Ripple.") }, - { _("Dragon Slayer"), 6, 32, 5, _("Greatly increases a unit's attack skill vs. Dragons.") }, - { _("Blood Lust"), 3, 27, 3, _("Increases a unit's attack skill.") }, - { _("Animate Dead"), 10, 25, 50, _("Resurrects creatures from a damaged or dead undead unit permanently.") }, - { _("Mirror Image"), 25, 26, 0, _("Creates an illusionary unit that duplicates one of your existing units. This illusionary unit does the same damages as the original, but will vanish if it takes any damage.") }, - { _("Shield"), 3, 15, 2, _("Halves damage received from ranged attacks for a single unit.") }, - { _("Mass Shield"), 7, 15, 0, _("Halves damage received from ranged attacks for all of your units.") }, - { _("Summon Earth Elemental"), 30, 56, 3, _("Summons Earth Elementals to fight for your army.") }, - { _("Summon Air Elemental"), 30, 57, 3, _("Summons Air Elementals to fight for your army.") }, - { _("Summon Fire Elemental"), 30, 58, 3, _("Summons Fire Elementals to fight for your army.") }, - { _("Summon Water Elemental"), 30, 59, 3, _("Summons Water Elementals to fight for your army.") }, - { _("Earthquake"), 15, 33, 0, _("Damages castle walls.") }, - { _("View Mines"), 1, 39, 0, _("Causes all mines across the land to become visible.") }, - { _("View Resources"), 1, 40, 0, _("Causes all resources across the land to become visible.") }, - { _("View Artifacts"), 2, 41, 0, _("Causes all artifacts across the land to become visible.") }, - { _("View Towns"), 2, 42, 0, _("Causes all towns and castles across the land to become visible.") }, - { _("View Heroes"), 2, 43, 0, _("Causes all Heroes across the land to become visible.") }, - { _("View All"), 3, 44, 0, _("Causes the entire land to become visible.") }, - { _("Identify Hero"), 3, 45, 0, _("Allows the caster to view detailed information on enemy Heroes.") }, - { _("Summon Boat"), 5, 46, 0, _("Summons the nearest unoccupied, friendly boat to an adjacent shore location. A friendly boat is one which you just built or were the most recent player to occupy.") }, - { _("Dimension Door"), 10, 47, 0, _("Allows the caster to magically transport to a nearby location.") }, - { _("Town Gate"), 10, 48, 0, _("Returns the caster to any town or castle currently owned.") }, - { _("Town Portal"), 20, 49, 0, _("Returns the hero to the town or castle of choice, provided it is controlled by you.") }, - { _("Visions"), 6, 50, 3, _("Visions predicts the likely outcome of an encounter with a neutral army camp.") }, - { _("Haunt"), 8, 51, 4, _("Haunts a mine you control with Ghosts. This mine stops producing resources. (If I can't keep it, nobody will!)") }, - { _("Set Earth Guardian"), 15, 52, 4, _("Sets Earth Elementals to guard a mine against enemy armies.") }, - { _("Set Air Guardian"), 15, 53, 4, _("Sets Air Elementals to guard a mine against enemy armies.") }, - { _("Set Fire Guardian"), 15, 54, 4, _("Sets Fire Elementals to guard a mine against enemy armies.") }, - { _("Set Water Guardian"), 15, 55, 4, _("Sets Water Elementals to guard a mine against enemy armies.") }, - { _("Stone"), 0, 0, 0, _("Stone spell from Medusa.") }, -}; - -void Spell::UpdateStats(const std::string & spec) -{ -#ifdef WITH_XML - // parse spells.xml - TiXmlDocument doc; - const TiXmlElement* xml_spells = NULL; - spellstats_t* ptr = &spells[0]; - - if(doc.LoadFile(spec.c_str()) && - NULL != (xml_spells = doc.FirstChildElement("spells"))) - { - const TiXmlElement* xml_spell = xml_spells->FirstChildElement("spell"); - for(; xml_spell; xml_spell = xml_spell->NextSiblingElement("spell")) - { - int value; - - xml_spell->Attribute("skip", &value); - if(0 == value) - { - xml_spell->Attribute("cost", &value); if(value) ptr->mana = value; - xml_spell->Attribute("extra", &value); if(value) ptr->extra = value; - } - - // load dimension door params - if((ptr - &spells[0]) == DIMENSIONDOOR) - { - xml_spell->Attribute("distance", &value); dd_distance = value; - xml_spell->Attribute("sp", &value); dd_sp = value; - xml_spell->Attribute("hp", &value); dd_hp = value; - } - - ++ptr; - - // out of range - if((ptr - &spells[0]) >= STONE) break; - } - } - else - VERBOSE(spec << ": " << doc.ErrorDesc()); -#endif -} - -Spell::Spell() : id(NONE) -{ -} - -Spell::Spell(spell_t s) : id(s) -{ -} - -Spell::Spell(u8 s) : id(FromInt(s)) -{ -} - -bool Spell::operator== (u8 s) const -{ - return s == id; -} - -bool Spell::operator!= (u8 s) const -{ - return id != s; -} - -Spell::spell_t Spell::operator() (void) const -{ - return id; -} - -Spell::spell_t Spell::GetID(void) const -{ - return id; -} - -void Spell::Set(spell_t s) -{ - id = s; -} - -const char* Spell::GetName(void) const -{ - return GetName(id); -} - -const char* Spell::GetDescription(void) const -{ - return GetDescription(id); -} - -u8 Spell::GetCostManaPoints(void) const -{ - return CostManaPoints(id); -} - -u8 Spell::GetLevel(void) const -{ - return Level(id); -} - -bool Spell::isCombat(void) const -{ - return isCombat(id); -} - -bool Spell::isAdventure(void) const -{ - return !isCombat(id); -} - -bool Spell::isDamage(void) const -{ - return isDamage(id); -} - -u8 Spell::GetDamage(void) const -{ - return Damage(id); -} - -bool Spell::isMindInfluence(void) const -{ - return isMindInfluence(id); -} - - -/* ---------- */ - - -u8 Spell::GetIndexSprite(void) const -{ - return IndexSprite(id); -} - -u8 Spell::GetInlIndexSprite(void) const -{ - return InlIndexSprite(id); -} - -Spell::spell_t Spell::FromInt(u8 index) -{ - return index > STONE ? NONE : static_cast(index); -} - -u8 Spell::CostManaPoints(spell_t spell, const HeroBase* hero) -{ - if(hero) - { - switch(spell) - { - case BLESS: - case MASSBLESS: - if(hero->HasArtifact(Artifact::SNAKE_RING)) return spells[spell].mana / 2; - break; - - case SUMMONEELEMENT: - case SUMMONAELEMENT: - case SUMMONFELEMENT: - case SUMMONWELEMENT: - if(hero->HasArtifact(Artifact::ELEMENTAL_RING)) return spells[spell].mana / 2; - break; - - case CURSE: - case MASSCURSE: - if(hero->HasArtifact(Artifact::EVIL_EYE)) return spells[spell].mana / 2; - break; - - default: break; - } - - if(isMindInfluence(spell) && hero->HasArtifact(Artifact::SKULLCAP)) return spells[spell].mana / 2; - } - - return spells[spell].mana; -} - -u8 Spell::Level(u8 spell) -{ - switch(spell) - { - case BLESS: - case BLOODLUST: - case CURE: - case CURSE: - case DISPEL: - case HASTE: - case ARROW: - case SHIELD: - case SLOW: - case STONESKIN: - - case VIEWMINES: - case VIEWRESOURCES: - return 1; - - case BLIND: - case COLDRAY: - case DEATHRIPPLE: - case DISRUPTINGRAY: - case DRAGONSLAYER: - case LIGHTNINGBOLT: - case STEELSKIN: - - case HAUNT: - case SUMMONBOAT: - case VIEWARTIFACTS: - case VISIONS: - return 2; - - case ANIMATEDEAD: - case ANTIMAGIC: - case COLDRING: - case DEATHWAVE: - case EARTHQUAKE: - case FIREBALL: - case HOLYWORD: - case MASSBLESS: - case MASSCURSE: - case MASSDISPEL: - case MASSHASTE: - case PARALYZE: - case TELEPORT: - - case IDENTIFYHERO: - case VIEWHEROES: - case VIEWTOWNS: - return 3; - - case BERSERKER: - case CHAINLIGHTNING: - case ELEMENTALSTORM: - case FIREBLAST: - case HOLYSHOUT: - case MASSCURE: - case MASSSHIELD: - case MASSSLOW: - case METEORSHOWER: - case RESURRECT: - - case SETEGUARDIAN: - case SETAGUARDIAN: - case SETFGUARDIAN: - case SETWGUARDIAN: - case TOWNGATE: - case VIEWALL: - return 4; - - case ARMAGEDDON: - case HYPNOTIZE: - case MIRRORIMAGE: - case RESURRECTTRUE: - case SUMMONEELEMENT: - case SUMMONAELEMENT: - case SUMMONFELEMENT: - case SUMMONWELEMENT: - - case DIMENSIONDOOR: - case TOWNPORTAL: - return 5; - - default: break; - } - - return 0; -} - -bool Spell::isCombat(u8 spell) -{ - switch(spell) - { - case NONE: - case VIEWMINES: - case VIEWRESOURCES: - case VIEWARTIFACTS: - case VIEWTOWNS: - case VIEWHEROES: - case VIEWALL: - case IDENTIFYHERO: - case SUMMONBOAT: - case DIMENSIONDOOR: - case TOWNGATE: - case TOWNPORTAL: - case VISIONS: - case HAUNT: - case SETEGUARDIAN: - case SETAGUARDIAN: - case SETFGUARDIAN: - case SETWGUARDIAN: return false; - default: break; - } - return true; -} - -u8 Spell::Damage(u8 spell) -{ - switch(spell) - { - case ARROW: - case FIREBALL: - case FIREBLAST: - case LIGHTNINGBOLT: - case COLDRING: - case DEATHWAVE: - case HOLYWORD: - case CHAINLIGHTNING: - case ARMAGEDDON: - case ELEMENTALSTORM: - case METEORSHOWER: - case COLDRAY: - case HOLYSHOUT: - case DEATHRIPPLE: - return spells[spell].extra; - - default: break; - } - - return 0; -} - -bool Spell::isDamage(u8 spell) -{ - return Damage(spell); -} - -u8 Spell::Restore(u8 spell) -{ - switch(spell) - { - case Spell::CURE: - case Spell::MASSCURE: - return spells[spell].extra; - - default: break; - } - - return Resurrect(spell); -} - -u8 Spell::Resurrect(u8 spell) -{ - switch(spell) - { - case Spell::ANIMATEDEAD: - case Spell::RESURRECT: - case Spell::RESURRECTTRUE: - return spells[spell].extra; - - default: break; - } - - return 0; -} - -bool Spell::isRestore(u8 spell) -{ - return Restore(spell); -} - -bool Spell::isResurrect(u8 spell) -{ - return Resurrect(spell); -} - -u8 Spell::IndexSprite(spell_t spell) -{ - return spells[spell].sprite; -} - -u8 Spell::InlIndexSprite(u8 spell) -{ - switch(spell) - { - case HASTE: - case MASSHASTE: return 0; - case SLOW: - case MASSSLOW: return 1; - case BLIND: return 2; - case BLESS: - case MASSBLESS: return 3; - case CURSE: - case MASSCURSE: return 4; - case BERSERKER: return 5; - case PARALYZE: return 6; - case HYPNOTIZE: return 7; - case DRAGONSLAYER: return 8; - case BLOODLUST: return 9; - case SHIELD: - case MASSSHIELD: return 10; - case STONE: return 11; - case ANTIMAGIC: return 12; - case STONESKIN: return 13; - case STEELSKIN: return 14; - default: break; - } - - return 0; -} - -u8 Spell::GetExtraValue(spell_t spell) -{ - return spells[spell].extra; -} - -const char* Spell::GetName(spell_t spell) -{ - return _(spells[spell].name); -} - -const char* Spell::GetDescription(spell_t spell) -{ - return _(spells[spell].description); -} - -Spell::spell_t Spell::RandCombat(u8 lvl) -{ - if(1 == lvl) - switch(Rand::Get(1, 10)) - { - case 1: return BLESS; - case 2: return BLOODLUST; - case 3: return CURE; - case 4: return CURSE; - case 5: return DISPEL; - case 6: return HASTE; - case 7: return ARROW; - case 8: return SHIELD; - case 9: return SLOW; - case 10: return STONESKIN; - default: break; - } - else - if(2 == lvl) - switch(Rand::Get(1, 7)) - { - case 1: return BLIND; - case 2: return COLDRAY; - case 3: return DEATHRIPPLE; - case 4: return DISRUPTINGRAY; - case 5: return DRAGONSLAYER; - case 6: return LIGHTNINGBOLT; - case 7: return STEELSKIN; - default: break; - } - else - if(3 == lvl) - switch(Rand::Get(1, 13)) - { - case 1: return ANIMATEDEAD; - case 2: return ANTIMAGIC; - case 3: return COLDRING; - case 4: return DEATHWAVE; - case 5: return EARTHQUAKE; - case 6: return FIREBALL; - case 7: return HOLYWORD; - case 8: return MASSBLESS; - case 9: return MASSCURSE; - case 10: return MASSDISPEL; - case 11: return MASSHASTE; - case 12: return PARALYZE; - case 13: return TELEPORT; - default: break; - } - else - if(4 == lvl) - switch(Rand::Get(1, 10)) - { - case 1: return BERSERKER; - case 2: return CHAINLIGHTNING; - case 3: return ELEMENTALSTORM; - case 4: return FIREBLAST; - case 5: return HOLYSHOUT; - case 6: return MASSCURE; - case 7: return MASSSHIELD; - case 8: return MASSSLOW; - case 9: return METEORSHOWER; - case 10: return RESURRECT; - default: break; - } - else - if(5 == lvl) - switch(Rand::Get(1, 8)) - { - case 1: return ARMAGEDDON; - case 2: return HYPNOTIZE; - case 3: return MIRRORIMAGE; - case 4: return RESURRECTTRUE; - case 5: return SUMMONEELEMENT; - case 6: return SUMMONAELEMENT; - case 7: return SUMMONFELEMENT; - case 8: return SUMMONWELEMENT; - default: break; - } - - return Spell::NONE; -} - -Spell::spell_t Spell::RandAdventure(u8 lvl) -{ - if(1 == lvl) - switch(Rand::Get(1, 2)) - { - case 1: return VIEWMINES; - case 2: return VIEWRESOURCES; - default: break; - } - else - if(2 == lvl) - switch(Rand::Get(1, 4)) - { - case 1: return HAUNT; - case 2: return SUMMONBOAT; - case 3: return VIEWARTIFACTS; - case 4: return VISIONS; - default: break; - } - else - if(3 == lvl) - switch(Rand::Get(1, 3)) - { - case 1: return IDENTIFYHERO; - case 2: return VIEWHEROES; - case 3: return VIEWTOWNS; - default: break; - } - else - if(4 == lvl) - switch(Rand::Get(1, 6)) - { - case 1: return SETEGUARDIAN; - case 2: return SETAGUARDIAN; - case 3: return SETFGUARDIAN; - case 4: return SETWGUARDIAN; - case 5: return TOWNGATE; - case 6: return VIEWALL; - - default: break; - } - else - if(5 == lvl) - switch(Rand::Get(1, 2)) - { - case 1: return DIMENSIONDOOR; - case 2: return TOWNPORTAL; - default: break; - } - - return Spell::NONE; -} - -bool Spell::isMindInfluence(u8 spell) -{ - switch(spell) - { - case BLIND: - case PARALYZE: - case BERSERKER: - case HYPNOTIZE: return true; - - default: break; - } - - return false; -} - -bool Spell::isUndeadOnly(u8 spell) -{ - switch(spell) - { - case ANIMATEDEAD: - case HOLYWORD: - case HOLYSHOUT: - return true; - - default: break; - } - - return false; -} - -bool Spell::isALiveOnly(u8 spell) -{ - switch(spell) - { - case BLESS: - case MASSBLESS: - case CURSE: - case MASSCURSE: - case DEATHRIPPLE: - case DEATHWAVE: - case RESURRECT: - case RESURRECTTRUE: - return true; - - default: break; - } - - return false; -} - -bool Spell::isApplyWithoutFocusObject(u8 spell) -{ - if(isMassActions(spell) || isSummon(spell)) - return true; - else - switch(spell) - { - case DEATHRIPPLE: - case DEATHWAVE: - case EARTHQUAKE: - case HOLYWORD: - case HOLYSHOUT: - case ARMAGEDDON: - case ELEMENTALSTORM: - return true; - - default: break; - } - - return false; -} - -bool Spell::isSummon(u8 spell) -{ - switch(spell) - { - case SUMMONEELEMENT: - case SUMMONAELEMENT: - case SUMMONFELEMENT: - case SUMMONWELEMENT: - return true; - - default: break; - } - - return false; -} - -bool Spell::isApplyToAnyTroops(u8 spell) -{ - switch(spell) - { - case DISPEL: - case MASSDISPEL: - return true; - - default: break; - } - - return false; -} - -bool Spell::isApplyToFriends(u8 spell) -{ - switch(spell) - { - case BLESS: - case BLOODLUST: - case CURE: - case HASTE: - case SHIELD: - case STONESKIN: - case DRAGONSLAYER: - case STEELSKIN: - case ANIMATEDEAD: - case ANTIMAGIC: - case TELEPORT: - case RESURRECT: - case MIRRORIMAGE: - case RESURRECTTRUE: - - case MASSBLESS: - case MASSCURE: - case MASSHASTE: - case MASSSHIELD: - return true; - - default: break; - } - - return false; -} - -bool Spell::isMassActions(u8 spell) -{ - switch(spell) - { - case MASSCURE: - case MASSHASTE: - case MASSSLOW: - case MASSBLESS: - case MASSCURSE: - case MASSDISPEL: - case MASSSHIELD: - return true; - - default: break; - } - - return false; -} - -bool Spell::isApplyToEnemies(u8 spell) -{ - switch(spell) - { - case MASSSLOW: - case MASSCURSE: - - case CURSE: - case ARROW: - case SLOW: - case BLIND: - case COLDRAY: - case DISRUPTINGRAY: - case LIGHTNINGBOLT: - case CHAINLIGHTNING: - case PARALYZE: - case BERSERKER: - case HYPNOTIZE: - return true; - - default: break; - } - - return false; -} - -bool Spell::isRaceCompatible(u8 spell, u8 race) -{ - switch(spell) - { - case MASSCURE: - case MASSBLESS: - case HOLYSHOUT: - case HOLYWORD: - case BLESS: - case CURE: - if(Race::NECR == race) return false; - break; - - case DEATHWAVE: - case DEATHRIPPLE: - case ANIMATEDEAD: - if(Race::NECR != race) return false; - break; - - default: - break; - } - - return true; -} - -u8 Spell::CalculateDimensionDoorDistance(u8 current_sp, u32 total_hp) -{ - if(dd_distance && dd_hp && dd_sp && total_hp) - { - const u16 res = (dd_distance * current_sp * dd_hp) / (dd_sp * total_hp); - return res ? (res < 255 ? res : 255) : 1; - } - // original h2 variant - return 14; -} - -bool Spell::AllowWithWisdom(u8 sp, u8 wisdom) -{ - return ((4 < Spell::Level(sp) && Skill::Level::EXPERT > wisdom) || - (3 < Spell::Level(sp) && Skill::Level::ADVANCED > wisdom) || - (2 < Spell::Level(sp) && Skill::Level::BASIC > wisdom) ? false : true); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/spell/spell.h b/project/jni/application/fheroes2/src/fheroes2/spell/spell.h deleted file mode 100644 index 56eabf7ed..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/spell/spell.h +++ /dev/null @@ -1,180 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2SPELL_H -#define H2SPELL_H - -#include -#include "gamedefs.h" - -class HeroBase; - -class Spell -{ -public: - enum spell_t - { - NONE = 0, - FIREBALL, - FIREBLAST, - LIGHTNINGBOLT, - CHAINLIGHTNING, - TELEPORT, - CURE, - MASSCURE, - RESURRECT, - RESURRECTTRUE, - HASTE, - MASSHASTE, - SLOW, - MASSSLOW, - BLIND, - BLESS, - MASSBLESS, - STONESKIN, - STEELSKIN, - CURSE, - MASSCURSE, - HOLYWORD, - HOLYSHOUT, - ANTIMAGIC, - DISPEL, - MASSDISPEL, - ARROW, - BERSERKER, - ARMAGEDDON, - ELEMENTALSTORM, - METEORSHOWER, - PARALYZE, - HYPNOTIZE, - COLDRAY, - COLDRING, - DISRUPTINGRAY, - DEATHRIPPLE, - DEATHWAVE, - DRAGONSLAYER, - BLOODLUST, - ANIMATEDEAD, - MIRRORIMAGE, - SHIELD, - MASSSHIELD, - SUMMONEELEMENT, - SUMMONAELEMENT, - SUMMONFELEMENT, - SUMMONWELEMENT, - EARTHQUAKE, - VIEWMINES, - VIEWRESOURCES, - VIEWARTIFACTS, - VIEWTOWNS, - VIEWHEROES, - VIEWALL, - IDENTIFYHERO, - SUMMONBOAT, - DIMENSIONDOOR, - TOWNGATE, - TOWNPORTAL, - VISIONS, - HAUNT, - SETEGUARDIAN, - SETAGUARDIAN, - SETFGUARDIAN, - SETWGUARDIAN, - - STONE - }; - - Spell(); - Spell(spell_t); - Spell(u8); - - bool operator== (u8) const; - bool operator!= (u8) const; - spell_t operator() (void) const; - spell_t GetID(void) const; - - void Set(spell_t); - - const char* GetName(void) const; - const char* GetDescription(void) const; - - u8 GetCostManaPoints(void) const; - u8 GetLevel(void) const; - u8 GetDamage(void) const; - bool isCombat(void) const; - bool isAdventure(void) const; - bool isDamage(void) const; - bool isMindInfluence(void) const; - - /* return index sprite spells.icn */ - u8 GetIndexSprite(void) const; - /* return index in spellinl.icn */ - u8 GetInlIndexSprite(void) const; - - static spell_t FromInt(u8); - static u8 Level(u8); - static bool isCombat(u8); - static u8 Damage(u8); - static u8 Restore(u8); - static u8 Resurrect(u8); - static bool isDamage(u8); - static bool isRestore(u8); - static bool isResurrect(u8); - static bool isMindInfluence(u8); - static bool isUndeadOnly(u8); - static bool isALiveOnly(u8); - static bool isSummon(u8); - - static bool isApplyWithoutFocusObject(u8); - static bool isApplyToAnyTroops(u8); - static bool isApplyToFriends(u8); - static bool isApplyToEnemies(u8); - static bool isMassActions(u8); - static bool isRaceCompatible(u8 spell, u8 race); - - static bool AllowWithWisdom(u8 spell, u8 wisdom); - - /* return index sprite spells.icn */ - static u8 IndexSprite(spell_t); - /* return index in spellinl.icn */ - static u8 InlIndexSprite(u8); - - static u8 CostManaPoints(spell_t, const HeroBase* hero = NULL); - static u8 GetExtraValue(spell_t); - static const char* GetName(spell_t); - static const char* GetDescription(spell_t); - - static spell_t RandCombat(u8); - static spell_t RandAdventure(u8); - - static void UpdateStats(const std::string &); - static u8 CalculateDimensionDoorDistance(u8 current_sp, u32 total_hp); - -private: - spell_t id; - - static u16 dd_distance; - static u16 dd_sp; - static u16 dd_hp; -}; - -#endif - diff --git a/project/jni/application/fheroes2/src/fheroes2/spell/spell_book.cpp b/project/jni/application/fheroes2/src/fheroes2/spell/spell_book.cpp deleted file mode 100644 index bc24ae551..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/spell/spell_book.cpp +++ /dev/null @@ -1,415 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "agg.h" -#include "cursor.h" -#include "spell_book.h" -#include "dialog.h" -#include "heroes_base.h" -#include "skill.h" -#include "settings.h" - -#define SPELL_PER_PAGE 6 -#define SPELL_PER_PAGE_SMALL 2 - -struct SpellFiltered : std::binary_function -{ - bool operator() (Spell::spell_t s, SpellBook::filter_t f) const { return ((SpellBook::ADVN & f) && Spell::isCombat(s)) || ((SpellBook::CMBT & f) && !Spell::isCombat(s)); }; -}; - -void SpellBookSetFilter(const BagArtifacts &, const std::vector &, std::vector &, SpellBook::filter_t); -void SpellBookRedrawLists(const std::vector &, std::vector &, const size_t, const Point &, u16, const SpellBook::filter_t only, const HeroBase & hero); -void SpellBookRedrawSpells(const std::vector &, std::vector &, const size_t, s16, s16, const HeroBase & hero); -void SpellBookRedrawMP(const Point &, u16); - -bool SortingSpell(const Spell::spell_t spell1, const Spell::spell_t spell2) -{ - return (!Spell::isCombat(spell1) && Spell::isCombat(spell1)) || - (std::string(Spell::GetName(spell1)) < std::string(Spell::GetName(spell2))); -} - -SpellBook::SpellBook() : active(false) -{ -} - -void SpellBook::Activate(void) -{ - active = true; - spells.clear(); -} - -Spell::spell_t SpellBook::Open(const HeroBase & hero, const filter_t filt, bool canselect) const -{ - if(!active) - { - Dialog::Message("", _("No spell to cast."), Font::BIG, Dialog::OK); - return Spell::NONE; - } - - std::vector spells2; - spells2.reserve(spells.size()); - - Display & display = Display::Get(); - Cursor & cursor = Cursor::Get(); - bool small = Settings::Get().QVGA(); - - const Cursor::themes_t oldcursor = cursor.Themes(); - - const Sprite & r_list = AGG::GetICN(ICN::BOOK, 0); - const Sprite & l_list = AGG::GetICN(ICN::BOOK, 0, true); - - filter_t filter = filt; - SpellBookSetFilter(hero.GetBagArtifacts(), spells, spells2, filter); - - if(canselect && spells2.empty()) - { - Dialog::Message("", _("No spell to cast."), Font::BIG, Dialog::OK); - return Spell::NONE; - } - - // sorting results - std::sort(spells2.begin(), spells2.end(), SortingSpell); - - size_t current_index = 0; - - cursor.Hide(); - cursor.SetThemes(Cursor::POINTER); - - const Sprite & bookmark_info = AGG::GetICN(ICN::BOOK, 6); - const Sprite & bookmark_advn = AGG::GetICN(ICN::BOOK, 3); - const Sprite & bookmark_cmbt = AGG::GetICN(ICN::BOOK, 4); - const Sprite & bookmark_clos = AGG::GetICN(ICN::BOOK, 5); - - const Rect pos((display.w() - (r_list.w() + l_list.w())) / 2, (display.h() - r_list.h()) / 2, r_list.w() + l_list.w(), r_list.h() + 70); - Background back(pos); - back.Save(); - - const Rect prev_list(pos.x + (small ? 15 : 30), pos.y + (small ? 4 : 8), (small ? 15 : 30), (small ? 12 : 25)); - const Rect next_list(pos.x + (small ? 205 : 410), pos.y + (small ? 4: 8), (small ? 15 : 30), (small ? 12 :25)); - - const Rect info_rt(pos.x + (small ? 64 : 125), pos.y + (small ? 137: 275), bookmark_info.w(), bookmark_info.h()); - const Rect advn_rt(pos.x + (small ? 135: 270), pos.y + (small ? 135: 270), bookmark_advn.w(), bookmark_advn.h()); - const Rect cmbt_rt(pos.x + (small ? 152: 304), pos.y + (small ? 138: 278), bookmark_cmbt.w(), bookmark_cmbt.h()); - const Rect clos_rt(pos.x + (small ? 210: 420), pos.y + (small ? 142: 284), bookmark_clos.w(), bookmark_clos.h()); - - Spell::spell_t curspell = Spell::NONE; - - std::vector coords; - coords.reserve(small ? SPELL_PER_PAGE_SMALL * 2 : SPELL_PER_PAGE * 2); - - SpellBookRedrawLists(spells2, coords, current_index, pos, hero.GetSpellPoints(), filt, hero); - - cursor.Show(); - display.Flip(); - - LocalEvent & le = LocalEvent::Get(); - - // message loop - while(le.HandleEvents()) - { - if(le.MouseClickLeft(prev_list) && current_index) - { - cursor.Hide(); - current_index -= small ? SPELL_PER_PAGE_SMALL * 2 : SPELL_PER_PAGE * 2; - SpellBookRedrawLists(spells2, coords, current_index, pos, hero.GetSpellPoints(), filt, hero); - cursor.Show(); - display.Flip(); - } - else - if(le.MouseClickLeft(next_list) && spells2.size() > (current_index + (small ? SPELL_PER_PAGE_SMALL * 2 : SPELL_PER_PAGE * 2))) - { - cursor.Hide(); - current_index += small ? SPELL_PER_PAGE_SMALL * 2 : SPELL_PER_PAGE * 2; - SpellBookRedrawLists(spells2, coords, current_index, pos, hero.GetSpellPoints(), filt, hero); - cursor.Show(); - display.Flip(); - } - else - if((le.MouseClickLeft(info_rt)) || - (le.MousePressRight(info_rt))) - { - std::string str = _("Your hero has %{point} spell points remaining"); - String::Replace(str, "%{point}", hero.GetSpellPoints()); - str += " spell points remaining"; - cursor.Hide(); - Dialog::Message("", str, Font::BIG, Dialog::OK); - cursor.Show(); - display.Flip(); - } - else - if(le.MouseClickLeft(advn_rt) && filter != ADVN && filt != CMBT) - { - cursor.Hide(); - filter = ADVN; - current_index = 0; - SpellBookSetFilter(hero.GetBagArtifacts(), spells, spells2, filter); - SpellBookRedrawLists(spells2, coords, current_index, pos, hero.GetSpellPoints(), filt, hero); - cursor.Show(); - display.Flip(); - } - else - if(le.MouseClickLeft(cmbt_rt) && filter != CMBT && filt != ADVN) - { - cursor.Hide(); - filter = CMBT; - current_index = 0; - SpellBookSetFilter(hero.GetBagArtifacts(), spells, spells2, filter); - SpellBookRedrawLists(spells2, coords, current_index, pos, hero.GetSpellPoints(), filt, hero); - cursor.Show(); - display.Flip(); - } - else - if(le.MouseClickLeft(clos_rt) || - Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break; - else - if(le.MouseClickLeft(pos)) - { - std::vector::const_iterator it = std::find_if(coords.begin(), coords.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())); - if(it != coords.end()) - { - Spell::spell_t spell = spells2.at(it - coords.begin() + current_index); - - if(canselect) - { - if(spell != Spell::NONE) - { - if(hero.HaveSpellPoints(Spell::CostManaPoints(spell, &hero))) - { - curspell = spell; - break; - } - else - { - cursor.Hide(); - std::string str = _("That spell costs %{mana} mana. You only have %{point} mana, so you can't cast the spell."); - String::Replace(str, "%{mana}", Spell::CostManaPoints(spell, &hero)); - String::Replace(str, "%{point}", hero.GetSpellPoints()); - Dialog::Message("", str, Font::BIG, Dialog::OK); - cursor.Show(); - display.Flip(); - } - } - } - else - if(spell != Spell::NONE) - { - cursor.Hide(); - Dialog::SpellInfo(spell, true); - cursor.Show(); - display.Flip(); - } - } - } - - if(le.MousePressRight(pos)) - { - std::vector::const_iterator it = std::find_if(coords.begin(), coords.end(), std::bind2nd(RectIncludePoint(), le.GetMouseCursor())); - if(it != coords.end()) - { - Spell::spell_t spell = spells2.at(it - coords.begin() + current_index); - if(spell != Spell::NONE) - { - cursor.Hide(); - Dialog::SpellInfo(spell, false); - cursor.Show(); - display.Flip(); - } - } - } - } - - cursor.Hide(); - back.Restore(); - cursor.SetThemes(oldcursor); - cursor.Show(); - display.Flip(); - - return curspell; -} - -void SpellBookSetFilter(const BagArtifacts & bag, const std::vector & spells, std::vector & v, SpellBook::filter_t filter) -{ - v = spells; - - // added heroes spell scrolls - BagArtifacts::const_iterator it1 = bag.begin(); - BagArtifacts::const_iterator it2 = bag.end(); - for(; it1 != it2; ++it1) - { - switch((*it1).GetID()) - { - case Artifact::SPELL_SCROLL: - { - const Spell::spell_t scroll = Spell::FromInt((*it1).GetExt()); - if(Spell::NONE != scroll && v.end() == std::find(v.begin(), v.end(), scroll)) - v.push_back(scroll); - } - break; - - case Artifact::CRYSTAL_BALL: - if(Settings::Get().ExtArtifactCrystalBall()) - { - if(v.end() == std::find(v.begin(), v.end(), Spell::IDENTIFYHERO)) - v.push_back(Spell::IDENTIFYHERO); - if(v.end() == std::find(v.begin(), v.end(), Spell::VISIONS)) - v.push_back(Spell::VISIONS); - } - break; - - case Artifact::BATTLE_GARB: - if(v.end() == std::find(v.begin(), v.end(), Spell::TOWNPORTAL)) - v.push_back(Spell::TOWNPORTAL); - break; - - default: break; - } - } - - if(filter != SpellBook::ALL) - { - std::vector::iterator it = std::remove_if(v.begin(), v.end(), std::bind2nd(SpellFiltered(), filter)); - if(v.end() != it) v.resize(it - v.begin()); - } -} - -void SpellBookRedrawMP(const Point & dst, u16 mp) -{ - bool small = Settings::Get().QVGA(); - - Point tp(dst.x + (small ? 5 : 11), dst.y + (small ? 1 : 9)); - std::string mps; - if(0 == mp) - { - mps = "0"; - Text text(mps, Font::SMALL); - text.Blit(tp.x - text.w() / 2, tp.y); - } - else - for(int i = 100; i >= 1; i /= 10) if(mp >= i) - { - mps.clear(); - String::AddInt(mps, (mp % (i * 10)) / i); - Text text(mps, Font::SMALL); - text.Blit(tp.x - text.w() / 2, tp.y); - tp.y += (small ? -2 : 0) + text.h(); - } -} - -void SpellBookRedrawLists(const std::vector & spells, std::vector & coords, const size_t cur, const Point & pt, u16 sp, const SpellBook::filter_t only, const HeroBase & hero) -{ - Display & display = Display::Get(); - bool small = Settings::Get().QVGA(); - - const Sprite & r_list = AGG::GetICN(ICN::BOOK, 0); - const Sprite & l_list = AGG::GetICN(ICN::BOOK, 0, true); - const Sprite & bookmark_info = AGG::GetICN(ICN::BOOK, 6); - const Sprite & bookmark_advn = AGG::GetICN(ICN::BOOK, 3); - const Sprite & bookmark_cmbt = AGG::GetICN(ICN::BOOK, 4); - const Sprite & bookmark_clos = AGG::GetICN(ICN::BOOK, 5); - - const Rect info_rt(pt.x + (small ? 64 : 125), pt.y + (small ? 137: 275), bookmark_info.w(), bookmark_info.h()); - const Rect advn_rt(pt.x + (small ? 135: 270), pt.y + (small ? 135: 270), bookmark_advn.w(), bookmark_advn.h()); - const Rect cmbt_rt(pt.x + (small ? 152: 304), pt.y + (small ? 138: 278), bookmark_cmbt.w(), bookmark_cmbt.h()); - const Rect clos_rt(pt.x + (small ? 210: 420), pt.y + (small ? 142: 284), bookmark_clos.w(), bookmark_clos.h()); - - display.Blit(l_list, pt.x, pt.y); - display.Blit(r_list, pt.x + l_list.w(), pt.y); - display.Blit(bookmark_info, info_rt); - if(SpellBook::CMBT != only) - display.Blit(bookmark_advn, advn_rt); - if(SpellBook::ADVN != only) - display.Blit(bookmark_cmbt, cmbt_rt); - display.Blit(bookmark_clos, clos_rt); - - if(coords.size()) coords.clear(); - - SpellBookRedrawMP(info_rt, sp); - SpellBookRedrawSpells(spells, coords, cur, pt.x, pt.y, hero); - SpellBookRedrawSpells(spells, coords, cur + (small ? SPELL_PER_PAGE_SMALL : SPELL_PER_PAGE), pt.x + (small ? 110 : 220), pt.y, hero); -} - -void SpellBookRedrawSpells(const std::vector & spells, std::vector & coords, const size_t cur, s16 px, s16 py, const HeroBase & hero) -{ - Display & display = Display::Get(); - bool small = Settings::Get().QVGA(); - - u16 ox = 0; - u16 oy = 0; - - for(u8 ii = 0; ii < (small ? SPELL_PER_PAGE_SMALL : SPELL_PER_PAGE); ++ii) if(spells.size() > cur + ii) - { - if(small) - { - if(0 == (ii % SPELL_PER_PAGE_SMALL)) - { - oy = 25; - ox = 60; - } - } - else - { - if(0 == (ii % (SPELL_PER_PAGE / 2))) - { - oy = 50; - ox += 80; - } - } - - const Spell::spell_t & spell = spells[ii + cur]; - const Sprite & icon = AGG::GetICN(ICN::SPELLS, Spell::IndexSprite(spell)); - const Rect rect(px + ox - icon.w() / 2, py + oy - icon.h() / 2, icon.w(), icon.h() + 10); - - display.Blit(icon, rect.x, rect.y); - - // multiple icons for mass spells - if(!small) - switch(spell) - { - case Spell::MASSBLESS: - case Spell::MASSCURE: - case Spell::MASSHASTE: - case Spell::MASSSLOW: - case Spell::MASSCURSE: - case Spell::MASSDISPEL: - case Spell::MASSSHIELD: - display.Blit(icon, rect.x - 10, rect.y + 8); - display.Blit(icon, rect.x + 10, rect.y + 8); - break; - - default: break; - } - - std::string str(Spell::GetName(spell)); - str.append(" ["); - String::AddInt(str, Spell::CostManaPoints(spell, &hero)); - str.append("]"); - - TextBox box(str, Font::SMALL, (small ? 94 : 80)); - box.Blit(px + ox - (small ? 47 : 40), py + oy + (small ? 22 : 25)); - - oy += small ? 65 : 80; - - coords.push_back(rect); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/spell/spell_book.h b/project/jni/application/fheroes2/src/fheroes2/spell/spell_book.h deleted file mode 100644 index 8762cf3b0..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/spell/spell_book.h +++ /dev/null @@ -1,53 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2SPELLBOOK_H -#define H2SPELLBOOK_H - -#include "gamedefs.h" -#include "spell_storage.h" - -class HeroBase; - -class SpellBook : public SpellStorage -{ -public: - enum filter_t - { - ADVN = 0x01, - CMBT = 0x02, - ALL = ADVN | CMBT - }; - - SpellBook(void); - - Spell::spell_t Open(const HeroBase &, filter_t filt, bool canselect) const; - void Activate(void); - bool isActive(void) const { return active; } - -private: - friend class Game::IO; - - bool active; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/spell/spell_storage.cpp b/project/jni/application/fheroes2/src/fheroes2/spell/spell_storage.cpp deleted file mode 100644 index b1b06efb7..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/spell/spell_storage.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include "skill.h" -#include "spell_storage.h" - -struct SpellEqualLevel : std::binary_function -{ - bool operator() (Spell::spell_t s, u8 l) const { return Spell::Level(s) == l; }; -}; - -SpellStorage::SpellStorage() -{ - spells.reserve(67); -} - -u8 SpellStorage::Size(u8 lvl) const -{ - switch(lvl) - { - case 1: return std::count_if(spells.begin(), spells.end(), std::bind2nd(SpellEqualLevel(), 1)); - case 2: return std::count_if(spells.begin(), spells.end(), std::bind2nd(SpellEqualLevel(), 2)); - case 3: return std::count_if(spells.begin(), spells.end(), std::bind2nd(SpellEqualLevel(), 3)); - case 4: return std::count_if(spells.begin(), spells.end(), std::bind2nd(SpellEqualLevel(), 4)); - case 5: return std::count_if(spells.begin(), spells.end(), std::bind2nd(SpellEqualLevel(), 5)); - - default: break; - } - - return spells.size(); -} - -void SpellStorage::GetSpells(std::vector & v, u8 lvl) const -{ - std::vector::const_iterator it1 = spells.begin(); - std::vector::const_iterator it2 = spells.end(); - for(; it1 != it2; ++it1) if(lvl == Spell::Level(*it1)) v.push_back(*it1); -} - -void SpellStorage::Append(const Spell::spell_t sp, u8 wisdom) -{ - if(spells.end() == std::find(spells.begin(), spells.end(), sp) && Spell::AllowWithWisdom(sp, wisdom)) - spells.push_back(sp); -} - -void SpellStorage::Append(const Spell::spell_t sp) -{ - if(spells.end() == std::find(spells.begin(), spells.end(), sp)) - spells.push_back(sp); -} - -bool SpellStorage::isPresentSpell(Spell::spell_t spell) const -{ - return spells.end() != std::find(spells.begin(), spells.end(), spell); -} diff --git a/project/jni/application/fheroes2/src/fheroes2/spell/spell_storage.h b/project/jni/application/fheroes2/src/fheroes2/spell/spell_storage.h deleted file mode 100644 index 0a908cb22..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/spell/spell_storage.h +++ /dev/null @@ -1,49 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2SPELLSTORAGE_H -#define H2SPELLSTORAGE_H - -#include -#include "spell.h" -#include "game_io.h" -#include "gamedefs.h" - -class SpellStorage -{ -public: - SpellStorage(); - - u8 Size(u8 lvl = 0) const; - - void GetSpells(std::vector &, u8) const; - void Append(const Spell::spell_t sp, u8 wisdom); - void Append(const Spell::spell_t sp); - bool isPresentSpell(Spell::spell_t) const; - -/* protected: */ - friend class Game::IO; - - std::vector spells; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/system/bitmodes.h b/project/jni/application/fheroes2/src/fheroes2/system/bitmodes.h deleted file mode 100644 index 2da0ce841..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/system/bitmodes.h +++ /dev/null @@ -1,46 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2BITMODES_H -#define H2BITMODES_H - -#include "gamedefs.h" - -#define MODES_ALL 0xFFFFFFFF - -class BitModes -{ -public: - BitModes() : modes(0) {}; - - u32 operator() (void) const { return modes; } - void SetModes(u32 f) { modes |= f; } - void ResetModes(u32 f) { modes &= ~f; } - void ToggleModes(u32 f) { modes ^= f; } - - bool Modes(u32 f) const { return (modes & f); } - -protected: - u32 modes; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/system/dir.cpp b/project/jni/application/fheroes2/src/fheroes2/system/dir.cpp deleted file mode 100644 index 8f73c767f..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/system/dir.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include -#include "gamedefs.h" -#include "settings.h" -#include "dir.h" - -Dir::Dir() -{ -} - -void Dir::Read(const std::string &path, const std::string &filter, bool sensitive) -{ - // read directory - DIR *dp; - struct dirent *ep; - struct stat fs; - - dp = opendir(path.c_str()); - - DEBUG(DBG_ENGINE , DBG_INFO, "Dir::Read: " << (filter.size() ? path + " (" + filter + ")" : path)); - - if(dp) - { - while(NULL != (ep = readdir(dp))) - { - const std::string fullname(path + SEPARATOR + ep->d_name); - - // if not regular file - if(stat(fullname.c_str(), &fs) || !S_ISREG(fs.st_mode)) continue; - - if(filter.size()) - { - std::string filename(ep->d_name); - - if(sensitive) - { - if(std::string::npos == filename.find(filter)) continue; - } - else - { - std::string filterlow(filter); - String::Lower(filterlow); - String::Lower(filename); - - if(std::string::npos == filename.find(filterlow)) continue; - } - } - - push_back(fullname); - } - closedir(dp); - } -} diff --git a/project/jni/application/fheroes2/src/fheroes2/system/dir.h b/project/jni/application/fheroes2/src/fheroes2/system/dir.h deleted file mode 100644 index 92609bc04..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/system/dir.h +++ /dev/null @@ -1,36 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2DIR_H -#define H2DIR_H - -#include -#include - -class Dir : public std::list -{ -public: - Dir(); - - void Read(const std::string &path, const std::string &filter = "", bool sensitive = true); -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/system/gamedefs.cpp b/project/jni/application/fheroes2/src/fheroes2/system/gamedefs.cpp deleted file mode 100644 index 0110bb768..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/system/gamedefs.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "gamedefs.h" - -const char* strip_context(const char* c) -{ - const char* p = c; - - while(p && *p && *p++ != '|'); - - return p && *p ? p : c; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/system/gamedefs.h b/project/jni/application/fheroes2/src/fheroes2/system/gamedefs.h deleted file mode 100644 index c232cc3f1..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/system/gamedefs.h +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef H2GAMEDEFS_H -#define H2GAMEDEFS_H - -#include "engine.h" - -#define MAJOR_VERSION 0 -#define MINOR_VERSION 6 - -const char* strip_context(const char* c); - -#ifdef WITH_TTF -#include -#define _(s) strip_context(gettext(s)) -#else -#define _(s) strip_context(s) -#define ngettext(s1, s2, c) (c == 1 ? s1 : s2) -#endif - -#define GETTEXT_PACKAGE "fheroes2" - -// hardcore defines: kingdom -#define KINGDOMMAX 6 - -// hardcore defines: world -#define MAXCASTLES 72 -#define DAYOFWEEK 7 -#define WEEKOFMONTH 4 - -// hardcore defines: castle -#define CASTLEMAXMONSTER 6 - -// hardcore defines: heroes -#define HEROESMAXARTIFACT 14 -#define HEROESMAXSKILL 8 -#define HEROESMAXCOUNT 71 - -// hardcore defines: skill -#define MAXPRIMARYSKILL 4 -#define MAXSECONDARYSKILL 14 - -// hardcore defines: army -#define ARMYMAXTROOPS 5 - -// hardcore defines: interface -#define RADARWIDTH 144 -#define BORDERWIDTH 16 - -// ai/hero speed -#define DEFAULT_SPEED_DELAY 5 - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/system/settings.cpp b/project/jni/application/fheroes2/src/fheroes2/system/settings.cpp deleted file mode 100644 index ca2e828bb..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/system/settings.cpp +++ /dev/null @@ -1,1427 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include -#include -#include "maps.h" -#include "tinyconfig.h" -#include "settings.h" - -#define DEFAULT_PORT 5154 -#define DEFAULT_DEBUG (DBG_ENGINE | DBG_GAME | DBG_BATTLE | DBG_AI | DBG_NETWORK | DBG_WARN) - -enum -{ - GLOBAL_LOADGAME = 0x00000001, - GLOBAL_PRICELOYALTY = 0x00000004, - - GLOBAL_POCKETPC = 0x00000010, - GLOBAL_DEDICATEDSERVER = 0x00000020, - GLOBAL_LOCALCLIENT = 0x00000040, - - GLOBAL_SHOWCPANEL = 0x00000100, - GLOBAL_SHOWRADAR = 0x00000200, - GLOBAL_SHOWICONS = 0x00000400, - GLOBAL_SHOWBUTTONS = 0x00000800, - GLOBAL_SHOWSTATUS = 0x00001000, - - GLOBAL_AUTOBATTLE = 0x00010000, - - GLOBAL_FONTRENDERBLENDED = 0x00020000, - GLOBAL_FULLSCREEN = 0x00400000, - GLOBAL_USESWSURFACE = 0x00800000, - - GLOBAL_SOUND = 0x01000000, - GLOBAL_MUSIC_EXT = 0x02000000, - GLOBAL_MUSIC_CD = 0x04000000, - GLOBAL_MUSIC_MIDI = 0x08000000, - - GLOBAL_EDITOR = 0x20000000, - GLOBAL_USEUNICODE = 0x40000000, - GLOBAL_ALTRESOURCE = 0x80000000, - - GLOBAL_MUSIC = GLOBAL_MUSIC_CD | GLOBAL_MUSIC_EXT | GLOBAL_MUSIC_MIDI -}; - -struct settings_t -{ - u32 id; - const char* str; - - bool operator== (const std::string & s) const { return str && s == str; }; - bool operator== (u32 i) const { return id && id == i; }; -}; - -// external settings -static const settings_t settingsGeneral[] = -{ - { GLOBAL_SOUND, "sound", }, - { GLOBAL_MUSIC_MIDI, "music", }, - { GLOBAL_FULLSCREEN, "fullscreen", }, - { GLOBAL_FULLSCREEN, "full screen", }, - { GLOBAL_USEUNICODE, "unicode", }, - { GLOBAL_ALTRESOURCE, "alt resource", }, - { GLOBAL_POCKETPC, "pocketpc", }, - { GLOBAL_POCKETPC, "pocket pc", }, - { GLOBAL_USESWSURFACE,"use swsurface only",}, - { 0, NULL, }, -}; - -// internal settings -static const settings_t settingsFHeroes2[] = -{ - { Settings::GAME_SAVE_REWRITE_CONFIRM, _("game: always confirm for rewrite savefile"), }, - { Settings::GAME_ALSO_CONFIRM_AUTOSAVE, _("game: also confirm autosave"), }, - { Settings::GAME_REMEMBER_LAST_FOCUS, _("game: remember last focus"), }, - { Settings::GAME_REMEMBER_LAST_FILENAME, _("game: remember last filename"), }, - { Settings::WORLD_SHOW_VISITED_CONTENT, _("world: show visited content from objects"), }, - { Settings::WORLD_SCOUTING_EXTENDED, _("world: scouting skill show extended content info"), }, - { Settings::WORLD_ABANDONED_MINE_RANDOM, _("world: abandoned mine random resource"), }, - { Settings::WORLD_SAVE_MONSTER_BATTLE, _("world: save count monster after battle"), }, - { Settings::WORLD_ALLOW_SET_GUARDIAN, _("world: allow set guardian to objects"), }, - { Settings::WORLD_NOREQ_FOR_ARTIFACTS, _("world: no in-built requirements or guardians for placed artifacts"), }, - { Settings::WORLD_ONLY_FIRST_MONSTER_ATTACK,_("world: only the first monster will attack (H2 bug)."), }, - { Settings::WORLD_EYE_EAGLE_AS_SCHOLAR, _("world: Eagle Eye also works like Scholar in H3."), }, - { Settings::WORLD_BUY_BOOK_FROM_SHRINES, _("world: allow buy a spellbook from Shrines"), }, - { Settings::WORLD_ARTIFACT_CRYSTAL_BALL, _("artifact: Crystal Ball also added Identify Hero and Visions spells"), }, - { Settings::CASTLE_ALLOW_BUY_FROM_WELL, _("castle: allow buy from well"), }, - { Settings::HEROES_LEARN_SPELLS_WITH_DAY, _("heroes: learn new spells with day"), }, - { Settings::HEROES_FORCE_RACE_FROM_TYPE, _("heroes: fixed race with custom portrait"), }, - { Settings::HEROES_COST_DEPENDED_FROM_LEVEL,_("heroes: recruit cost to be dependent on hero level"),}, - { Settings::HEROES_REMEMBER_POINTS_RETREAT, _("heroes: remember MP/SP for retreat/surrender result"),}, - { Settings::HEROES_SURRENDERING_GIVE_EXP, _("heroes: surrendering gives some experience"), }, - { Settings::HEROES_RECALCULATE_MOVEMENT, _("heroes: recalculate movement points after creatures movement"), }, - { Settings::UNIONS_ALLOW_HERO_MEETINGS, _("unions: allow meeting heroes"), }, - { Settings::UNIONS_ALLOW_CASTLE_VISITING, _("unions: allow castle visiting"), }, - { Settings::UNIONS_ALLOW_VIEW_MAPS, _("unions: allow view maps"), }, - { Settings::BATTLE_SHOW_DAMAGE, _("battle: show damage info"), }, - { Settings::BATTLE_TROOP_DIRECTION, _("battle: troop direction to move"), }, - { Settings::BATTLE_SOFT_WAITING, _("battle: soft wait troop"), }, - { Settings::BATTLE_SHOW_GRID, _("battle: show grid"), }, - { Settings::BATTLE_SHOW_MOUSE_SHADOW, _("battle: show mouse shadow"), }, - { Settings::BATTLE_SHOW_MOVE_SHADOW, _("battle: show move shadow"), }, - { Settings::BATTLE_OBJECTS_ARCHERS_PENALTY, _("battle: high objects are an obstacle for archers"), }, - { Settings::BATTLE_MERGE_ARMIES, _("battle: merge armies for hero from castle"), }, - { Settings::BATTLE_ARCHMAGE_RESIST_BAD_SPELL,_("battle: archmage can resists (20%) bad spells"), }, - { Settings::BATTLE_MAGIC_TROOP_RESIST, _("battle: magical creature resists (20%) the same magic"),}, - { Settings::BATTLE_SKIP_INCREASE_DEFENSE, _("battle: skip increase +2 defense"), }, - { Settings::GAME_SHOW_SYSTEM_INFO, _("game: show system info"), }, - { Settings::GAME_AUTOSAVE_ON, _("game: autosave on"), }, - { Settings::GAME_USE_FADE, _("game: use fade"), }, - { Settings::GAME_SHOW_SDL_LOGO, _("game: show SDL logo"), }, - { Settings::GAME_EVIL_INTERFACE, _("game: use evil interface"), }, - { Settings::GAME_DYNAMIC_INTERFACE, _("game: also use dynamic interface for castles"), }, - { Settings::GAME_HIDE_INTERFACE, _("game: hide interface"), }, - { Settings::POCKETPC_HIDE_CURSOR, _("pocketpc: hide cursor"), }, - { Settings::POCKETPC_TAP_MODE, _("pocketpc: tap mode"), }, - { Settings::POCKETPC_LOW_MEMORY, _("pocketpc: low memory"), }, - - { 0, NULL }, -}; - -/* constructor */ -Settings::Settings() : major_version(MAJOR_VERSION), minor_version(MINOR_VERSION), -#ifdef SVN_REVISION - svn_version(SVN_REVISION), -#endif - debug(DEFAULT_DEBUG), video_mode(0, 0), game_difficulty(Difficulty::NORMAL), - my_color(Color::GRAY), cur_color(Color::GRAY), path_data_directory("data"), - font_normal("dejavusans.ttf"), font_small("dejavusans.ttf"), force_lang("en"), size_normal(15), size_small(10), - sound_volume(6), music_volume(6), heroes_speed(DEFAULT_SPEED_DELAY), ai_speed(DEFAULT_SPEED_DELAY), scroll_speed(SCROLL_NORMAL), battle_speed(DEFAULT_SPEED_DELAY), - game_type(0), players_colors(0), preferably_count_players(0), port(DEFAULT_PORT), memory_limit(0) -{ - build_version = "version: "; - String::AddInt(build_version, MAJOR_VERSION); - build_version += "."; - String::AddInt(build_version, MINOR_VERSION); - if(svn_version.size()) - { - build_version += "." + svn_version; - } - - // default maps dir - list_maps_directory.push_back("maps"); - - ExtSetModes(GAME_SHOW_SDL_LOGO); - ExtSetModes(GAME_AUTOSAVE_ON); - - opt_global.SetModes(GLOBAL_SHOWRADAR); - opt_global.SetModes(GLOBAL_SHOWICONS); - opt_global.SetModes(GLOBAL_SHOWBUTTONS); - opt_global.SetModes(GLOBAL_SHOWSTATUS); -} - -Settings::~Settings() -{ - BinarySave(); -} - -Settings & Settings::Get(void) -{ - static Settings conf; - - return conf; -} - -bool Settings::Read(const std::string & filename) -{ - Tiny::Config config; - const Tiny::Entry* entry = NULL; - config.SetSeparator('='); - config.SetComment('#'); - if(! config.Load(filename.c_str())) return false; - - LocalEvent & le = LocalEvent::Get(); - - // debug - entry = config.Find("debug"); - if(NULL == entry) - debug = DEFAULT_DEBUG; - else - debug = entry->IntParams(); - - // opt_globals - const settings_t* ptr = settingsGeneral; - while(ptr->id) - { - entry = config.Find(ptr->str); - if(entry) - { - if(0 == entry->IntParams()) - opt_global.ResetModes(ptr->id); - else - opt_global.SetModes(ptr->id); - } - ++ptr; - } - - // maps directories - config.GetParams("maps", list_maps_directory); - list_maps_directory.sort(); - list_maps_directory.unique(); - - // data directory - entry = config.Find("data"); - if(entry) path_data_directory = entry->StrParams(); - - // unicode - if(Unicode()) - { - entry = config.Find("lang"); - if(entry) force_lang = entry->StrParams(); - - entry = config.Find("fonts normal"); - if(entry) font_normal = entry->StrParams(); - - entry = config.Find("fonts small"); - if(entry) font_small = entry->StrParams(); - - entry = config.Find("fonts normal size"); - if(entry) size_normal = entry->IntParams(); - - entry = config.Find("fonts small size"); - if(entry) size_small = entry->IntParams(); - - entry = config.Find("fonts render"); - if(entry && entry->StrParams() == "blended") opt_global.SetModes(GLOBAL_FONTRENDERBLENDED); - } - - // music - entry = config.Find("music"); - if(entry) - { - if(entry->StrParams() == "midi") - { - opt_global.ResetModes(GLOBAL_MUSIC); - opt_global.SetModes(GLOBAL_MUSIC_MIDI); - } - else - if(entry->StrParams() == "cd") - { - opt_global.ResetModes(GLOBAL_MUSIC); - opt_global.SetModes(GLOBAL_MUSIC_CD); - } - else - if(entry->StrParams() == "ext") - { - opt_global.ResetModes(GLOBAL_MUSIC); - opt_global.SetModes(GLOBAL_MUSIC_EXT); - } - } - - // sound volume - entry = config.Find("sound volume"); - if(entry) - { - sound_volume = entry->IntParams(); - if(sound_volume > 10) sound_volume = 10; - } - - // music volume - entry = config.Find("music volume"); - if(entry) - { - music_volume = entry->IntParams(); - if(music_volume > 10) music_volume = 10; - } - - // playmus command - entry = config.Find("playmus command"); - if(entry) playmus_command = entry->StrParams(); - - // memory limit - entry = config.Find("memory limit"); - if(entry) memory_limit = entry->IntParams(); - - // default depth - entry = config.Find("default depth"); - if(entry) Surface::SetDefaultDepth(entry->IntParams()); - - // move speed - entry = config.Find("ai speed"); - if(entry) - { - ai_speed = entry->IntParams(); - if(10 < ai_speed) ai_speed = 10; - } - - entry = config.Find("heroes speed"); - if(entry) - { - heroes_speed = entry->IntParams(); - if(10 < heroes_speed) heroes_speed = 10; - } - - // scroll speed - entry = config.Find("scroll speed"); - if(entry) - { - switch(entry->IntParams()) - { - case 1: scroll_speed = SCROLL_SLOW; break; - case 2: scroll_speed = SCROLL_NORMAL; break; - case 3: scroll_speed = SCROLL_FAST1; break; - case 4: scroll_speed = SCROLL_FAST2; break; - default: scroll_speed = SCROLL_NORMAL; break; - } - } - - entry = config.Find("battle speed"); - if(entry) - { - battle_speed = entry->IntParams(); - if(10 < battle_speed) battle_speed = 10; - } - - // network port - port = DEFAULT_PORT; - entry = config.Find("port"); - if(entry) port = entry->IntParams(); - - // videodriver - entry = config.Find("videodriver"); - if(entry) video_driver = entry->StrParams(); - - // pocketpc - if(PocketPC()) - { - entry = config.Find("pointer offset x"); - if(entry) le.SetMouseOffsetX(entry->IntParams()); - - entry = config.Find("pointer offset y"); - if(entry) le.SetMouseOffsetY(entry->IntParams()); - - entry = config.Find("tap delay"); - if(entry) le.SetTapDelayForRightClickEmulation(entry->IntParams()); - } - - // videomode - entry = config.Find("videomode"); - if(entry) - { - // default - video_mode.w = 640; - video_mode.h = 480; - - std::string value(entry->StrParams()); - String::Lower(value); - const size_t pos = value.find('x'); - - if(std::string::npos != pos) - { - std::string width(value.substr(0, pos)); - std::string height(value.substr(pos + 1, value.length() - pos - 1)); - - video_mode.w = String::ToInt(width); - video_mode.h = String::ToInt(height); - } - else - if(value == "auto") - { - video_mode.w = 0; - video_mode.h = 0; - } - else DEBUG(DBG_ENGINE , DBG_WARN, "Settings::Read: " << "unknown video mode: " << value); - } - -#ifdef WITHOUT_MOUSE - entry = config.Find("emulate mouse"); - if(entry) - { - le.SetEmulateMouse(entry->IntParams()); - - entry = config.Find("emulate mouse step"); - if(entry) le.SetEmulateMouseStep(entry->IntParams()); - } -#endif - -#ifndef WITH_TTF - opt_global.ResetModes(GLOBAL_USEUNICODE); -#endif - - if(font_normal.empty() || font_small.empty()) opt_global.ResetModes(GLOBAL_USEUNICODE); - -#ifdef BUILD_RELEASE - debug &= 0x000F; - debug |= (DBG_ENGINE | DBG_GAME | DBG_BATTLE | DBG_AI | DBG_NETWORK); -#endif - - BinaryLoad(); - - if(video_driver.size()) - String::Lower(video_driver); - - if(video_mode.w && video_mode.h) PostLoad(); - - if(opt_global.Modes(GLOBAL_POCKETPC)) - { - entry = config.Find("fullscreen"); - if(!entry || entry->StrParams() != "off") - opt_global.SetModes(GLOBAL_FULLSCREEN); - } - - return true; -} - -void Settings::PostLoad(void) -{ - if(QVGA()) - { - opt_global.SetModes(GLOBAL_POCKETPC); - ExtSetModes(GAME_HIDE_INTERFACE); - } - - if(! opt_global.Modes(GLOBAL_POCKETPC)) - { - ExtResetModes(POCKETPC_HIDE_CURSOR); - ExtResetModes(POCKETPC_TAP_MODE); - ExtResetModes(POCKETPC_LOW_MEMORY); - } - - if(ExtModes(GAME_HIDE_INTERFACE)) - { - opt_global.SetModes(GLOBAL_SHOWCPANEL); - opt_global.ResetModes(GLOBAL_SHOWRADAR); - opt_global.ResetModes(GLOBAL_SHOWICONS); - opt_global.ResetModes(GLOBAL_SHOWBUTTONS); - opt_global.ResetModes(GLOBAL_SHOWSTATUS); - } -} - -void Settings::SetAutoVideoMode(void) -{ - Size size; - - switch(Display::GetMaxMode(size, PocketPC())) - { - case 0: - return; - - case -1: - video_mode.w = 1024; - video_mode.h = 768; - return; - - default: break; - } - - video_mode.w = size.w; - video_mode.h = size.h; - - PostLoad(); -} - -bool Settings::Save(const std::string & filename) const -{ - if(filename.empty()) return false; - - std::ofstream file(filename.c_str()); - - if(!file.is_open()) return false; - - Dump(file); - - file.close(); - - return true; -} - -void Settings::Dump(std::ostream & stream) const -{ - std::string str; - - String::AddInt(str, major_version); - str += "."; - String::AddInt(str, minor_version); - str += "." + svn_version; - - stream << std::endl; - stream << "# fheroes2 dump config, version " << str << std::endl; - - if(path_data_directory.size()) stream << "data = " << path_data_directory << std::endl; - - ListMapsDirectory::const_iterator it1 = list_maps_directory.begin(); - ListMapsDirectory::const_iterator it2 = list_maps_directory.end(); - - for(; it1 != it2; ++it1) - stream << "maps = " << *it1 << std::endl; - - if(video_mode.w && video_mode.h) - { - str.clear(); - String::AddInt(str, video_mode.w); - str += "x"; - String::AddInt(str, video_mode.h); - } - else - str = "auto"; - - stream << "videomode = " << str << std::endl; - stream << "sound = " << (opt_global.Modes(GLOBAL_SOUND) ? "on" : "off") << std::endl; - stream << "music = " << (opt_global.Modes(GLOBAL_MUSIC_CD) ? "cd" : (opt_global.Modes(GLOBAL_MUSIC_MIDI) ? "midi" : (opt_global.Modes(GLOBAL_MUSIC_EXT) ? "ext" : "off"))) << std::endl; - stream << "sound volume = " << static_cast(sound_volume) << std::endl; - stream << "music volume = " << static_cast(music_volume) << std::endl; - stream << "fullscreen = " << (opt_global.Modes(GLOBAL_FULLSCREEN) ? "on" : "off") << std::endl; - stream << "alt resource = " << (opt_global.Modes(GLOBAL_ALTRESOURCE) ? "on" : "off") << std::endl; - stream << "debug = " << (debug ? "on" : "off") << std::endl; - -#ifdef WITH_TTF - stream << "fonts normal = " << font_normal << std::endl; - stream << "fonts small = " << font_small << std::endl; - if(force_lang.size()) - stream << "lang = " << force_lang << std::endl; - stream << "fonts normal size = " << static_cast(size_normal) << std::endl; - stream << "fonts small size = " << static_cast(size_small) << std::endl; - stream << "unicode = " << (opt_global.Modes(GLOBAL_USEUNICODE) ? "on" : "off") << std::endl; -#endif - -#ifndef WITH_MIXER - stream << "playmus command = " << playmus_command << std::endl; -#endif - - if(video_driver.size()) stream << "videodriver = " << video_driver << std::endl; - - if(opt_global.Modes(GLOBAL_POCKETPC)) - stream << "pocket pc = on" << std::endl; - - stream << std::endl; -} - -/* read maps info */ -bool Settings::LoadFileMapsMP2(const std::string & file) -{ - if(! current_maps_file.ReadMP2(file)) return false; - - // get first color - my_color = Color::Get(Color::GetFirst(current_maps_file.human_colors)); - - // game difficulty - game_difficulty = Difficulty::NORMAL; - - preferably_count_players = Color::Count(current_maps_file.human_colors); - - return true; -} - -Maps::FileInfo & Settings::CurrentFileInfo(void) -{ - return current_maps_file; -} - -/* return major version */ -u8 Settings::MajorVersion(void) const { return major_version; } - -/* return minor version */ -u8 Settings::MinorVersion(void) const { return minor_version; } - -/* return debug */ -u16 Settings::Debug(void) const { return debug; } - -/* return game difficulty */ -Difficulty::difficulty_t Settings::GameDifficulty(void) const { return game_difficulty; } - -Color::color_t Settings::CurrentColor(void) const { return cur_color; } -Color::color_t Settings::MyColor(void) const { return my_color; } - -const std::string & Settings::SelectVideoDriver(void) const { return video_driver; } - -/* return fontname */ -const std::string & Settings::FontsNormal(void) const { return font_normal; } -const std::string & Settings::FontsSmall(void) const { return font_small; } -const std::string & Settings::ForceLang(void) const { return force_lang; } -u8 Settings::FontsNormalSize(void) const { return size_normal; } -u8 Settings::FontsSmallSize(void) const { return size_small; } -bool Settings::FontsRenderBlended(void) const { return opt_global.Modes(GLOBAL_FONTRENDERBLENDED); } - -const std::string & Settings::BuildVersion(void) const { return build_version; } - -/* return path to data directory */ -const std::string & Settings::DataDirectory(void) const { return path_data_directory; } - -/* return path to maps directory */ -const ListMapsDirectory & Settings::GetListMapsDirectory(void) const { return list_maps_directory; } - -/* return path to locales directory */ -const std::string & Settings::LocalPrefix(void) const { return local_prefix; } -const std::string & Settings::PlayMusCommand(void) const { return playmus_command; } - -bool Settings::MusicExt(void) const { return opt_global.Modes(GLOBAL_MUSIC_EXT); } -bool Settings::MusicMIDI(void) const { return opt_global.Modes(GLOBAL_MUSIC_MIDI); } -bool Settings::MusicCD(void) const { return opt_global.Modes(GLOBAL_MUSIC_CD); } - -/* return editor */ -bool Settings::Editor(void) const { return opt_global.Modes(GLOBAL_EDITOR); } - -/* return sound */ -bool Settings::Sound(void) const { return opt_global.Modes(GLOBAL_SOUND); } - -/* return music */ -bool Settings::Music(void) const { return opt_global.Modes(GLOBAL_MUSIC); } - -bool Settings::CDMusic(void) const { return opt_global.Modes(GLOBAL_MUSIC_CD | GLOBAL_MUSIC_EXT); } - -/* return move speed */ -u8 Settings::HeroesMoveSpeed(void) const { return heroes_speed; } -u8 Settings::AIMoveSpeed(void) const { return ai_speed; } -u8 Settings::BattleSpeed(void) const { return battle_speed; } - -/* return scroll speed */ -u8 Settings::ScrollSpeed(void) const { return scroll_speed; } - -/* set ai speed: 0 - 10 */ -void Settings::SetAIMoveSpeed(u8 speed) -{ - ai_speed = (10 <= speed ? 10 : speed); -} - -/* set hero speed: 0 - 10 */ -void Settings::SetHeroesMoveSpeed(u8 speed) -{ - heroes_speed = (10 <= speed ? 10 : speed); -} - -/* set battle speed: 0 - 10 */ -void Settings::SetBattleSpeed(u8 speed) -{ - battle_speed = (10 <= speed ? 10 : speed); -} - -/* set scroll speed: 1 - 4 */ -void Settings::SetScrollSpeed(u8 speed) -{ - switch(speed) - { - case SCROLL_SLOW: scroll_speed = SCROLL_SLOW; break; - case SCROLL_NORMAL:scroll_speed = SCROLL_NORMAL; break; - case SCROLL_FAST1: scroll_speed = SCROLL_FAST1; break; - case SCROLL_FAST2: scroll_speed = SCROLL_FAST2; break; - default: scroll_speed = SCROLL_NORMAL; break; - } -} - -/* return full screen */ -bool Settings::QVGA(void) const { return video_mode.w && video_mode.h && (video_mode.w < 640 || video_mode.h < 480); } - -bool Settings::UseAltResource(void) const { return opt_global.Modes(GLOBAL_ALTRESOURCE); } -bool Settings::PriceLoyaltyVersion(void) const { return opt_global.Modes(GLOBAL_PRICELOYALTY); } -bool Settings::LoadedGameVersion(void) const { return opt_global.Modes(GLOBAL_LOADGAME); } - -bool Settings::ShowControlPanel(void) const { return opt_global.Modes(GLOBAL_SHOWCPANEL); } -bool Settings::ShowRadar(void) const { return opt_global.Modes(GLOBAL_SHOWRADAR); } -bool Settings::ShowIcons(void) const { return opt_global.Modes(GLOBAL_SHOWICONS); } -bool Settings::ShowButtons(void) const { return opt_global.Modes(GLOBAL_SHOWBUTTONS); } -bool Settings::ShowStatus(void) const { return opt_global.Modes(GLOBAL_SHOWSTATUS); } - -/* unicode support */ -bool Settings::Unicode(void) const { return opt_global.Modes(GLOBAL_USEUNICODE); } - -bool Settings::PocketPC(void) const { return opt_global.Modes(GLOBAL_POCKETPC); } -bool Settings::NetworkDedicatedServer(void) const { return opt_global.Modes(GLOBAL_DEDICATEDSERVER); } -bool Settings::NetworkLocalClient(void) const { return opt_global.Modes(GLOBAL_LOCALCLIENT); } - -/* get video mode */ -const Size & Settings::VideoMode(void) const { return video_mode; } - -/* set level debug */ -void Settings::SetDebug(const u16 d) -{ - debug = d; -} - -/**/ -void Settings::SetGameDifficulty(const Difficulty::difficulty_t d) { game_difficulty = d; } - -void Settings::SetCurrentColor(const Color::color_t c) { cur_color = c; } -void Settings::SetMyColor(const Color::color_t c) { my_color = c; } - -u8 Settings::SoundVolume(void) const -{ - return sound_volume; -} - -u8 Settings::MusicVolume(void) const -{ - return music_volume; -} - -/* sound volume: 0 - 10 */ -void Settings::SetSoundVolume(const u8 v) -{ - sound_volume = 10 <= v ? 10 : v; -} - -/* music volume: 0 - 10 */ -void Settings::SetMusicVolume(const u8 v) -{ - music_volume = 10 <= v ? 10 : v; -} - -/* check game type */ -u8 Settings::GameType(void) const -{ - return game_type; -} - -/* set game type */ -void Settings::SetGameType(const Game::type_t type) -{ - game_type = type; -} - -/* get color players */ -u8 Settings::PlayersColors(void) const -{ - return players_colors; -} - -/* set game color players */ -void Settings::SetPlayersColors(u8 c) -{ - players_colors = c; -} - -bool Settings::AutoBattle(void) const -{ - return opt_global.Modes(GLOBAL_AUTOBATTLE); -} - -void Settings::SetPreferablyCountPlayers(u8 c) -{ - preferably_count_players = 6 < c ? 6 : c; -} - -u8 Settings::PreferablyCountPlayers(void) const -{ - return preferably_count_players; -} - -void Settings::SetLocalPrefix(const char* str) -{ - if(str) local_prefix = str; -} - -u16 Settings::GetPort(void) const -{ - return port; -} - -Race::race_t Settings::KingdomRace(u8 color) const -{ - return Race::Get(current_maps_file.KingdomRace(color)); -} - -void Settings::SetKingdomRace(u8 color, u8 race) -{ - switch(color) - { - case Color::BLUE: current_maps_file.races[0] = race; break; - case Color::GREEN: current_maps_file.races[1] = race; break; - case Color::RED: current_maps_file.races[2] = race; break; - case Color::YELLOW: current_maps_file.races[3] = race; break; - case Color::ORANGE: current_maps_file.races[4] = race; break; - case Color::PURPLE: current_maps_file.races[5] = race; break; - default: break; - } -} - -const std::string & Settings::MapsFile(void) const -{ - return current_maps_file.file; -} - -const std::string & Settings::MapsName(void) const -{ - return current_maps_file.name; -} - -const std::string & Settings::MapsDescription(void) const -{ - return current_maps_file.description; -} - -Difficulty::difficulty_t Settings::MapsDifficulty(void) const -{ - return Difficulty::Get(current_maps_file.difficulty); -} - -u16 Settings::MapsWidth(void) const -{ - return current_maps_file.size_w; -} - -u8 Settings::AllowColors(void) const -{ - return current_maps_file.human_colors; -} - -bool Settings::AllowColors(u8 f) const -{ - return current_maps_file.human_colors & f; -} - -Color::color_t Settings::FirstAllowColor(void) const -{ - if(current_maps_file.HumanOnlyColors()) - return Color::Get(Color::GetFirst(current_maps_file.HumanOnlyColors())); - - return Color::Get(Color::GetFirst(current_maps_file.human_colors)); -} - -bool Settings::AllowChangeRace(u8 f) const -{ - return current_maps_file.rnd_races & f; -} - -u8 Settings::KingdomColors(void) const -{ - return current_maps_file.kingdom_colors; -} - -bool Settings::KingdomColors(u8 f) const -{ - return current_maps_file.kingdom_colors & f; -} - -u8 Settings::AllowColorsCount(void) const -{ - return Color::Count(current_maps_file.human_colors); -} - -u8 Settings::KingdomColorsCount(void) const -{ - return Color::Count(current_maps_file.kingdom_colors); -} - -bool Settings::GameStartWithHeroes(void) const -{ - return current_maps_file.with_heroes; -} - -u16 Settings::ConditionWins(void) const -{ - return current_maps_file.ConditionWins(); -} - -u16 Settings::ConditionLoss(void) const -{ - return current_maps_file.ConditionLoss(); -} - -bool Settings::WinsCompAlsoWins(void) const -{ - return current_maps_file.WinsCompAlsoWins(); -} - -bool Settings::WinsAllowNormalVictory(void) const -{ - return current_maps_file.WinsAllowNormalVictory(); -} - -Artifact::artifact_t Settings::WinsFindArtifact(void) const -{ - return current_maps_file.WinsFindArtifact(); -} - -bool Settings::WinsFindUltimateArtifact(void) const -{ - return current_maps_file.WinsFindUltimateArtifact(); -} - -u16 Settings::WinsSidePart(void) const -{ - return current_maps_file.WinsSidePart(); -} - -u32 Settings::WinsAccumulateGold(void) const -{ - return current_maps_file.WinsAccumulateGold(); -} - -u32 Settings::WinsMapsIndexObject(void) const -{ - return current_maps_file.WinsMapsIndexObject(); -} - -u32 Settings::LossMapsIndexObject(void) const -{ - return current_maps_file.LossMapsIndexObject(); -} - -u16 Settings::LossCountDays(void) const -{ - return current_maps_file.LossCountDays(); -} - -u8 Settings::GetUnions(u8 cl) const -{ - switch(cl) - { - case Color::BLUE: return current_maps_file.unions[0]; - case Color::GREEN: return current_maps_file.unions[1]; - case Color::RED: return current_maps_file.unions[2]; - case Color::YELLOW: return current_maps_file.unions[3]; - case Color::ORANGE: return current_maps_file.unions[4]; - case Color::PURPLE: return current_maps_file.unions[5]; - default: break; - } - - return 0; -} - -bool Settings::IsUnions(u8 cl1, u8 cl2) const -{ - if(cl1 == cl2) return true; - else - switch(cl1) - { - case Color::BLUE: return (current_maps_file.unions[0] & cl2); - case Color::GREEN: return (current_maps_file.unions[1] & cl2); - case Color::RED: return (current_maps_file.unions[2] & cl2); - case Color::YELLOW: return (current_maps_file.unions[3] & cl2); - case Color::ORANGE: return (current_maps_file.unions[4] & cl2); - case Color::PURPLE: return (current_maps_file.unions[5] & cl2); - default: break; - } - - return false; -} - -void Settings::FixKingdomRandomRace(void) -{ - for(Color::color_t color = Color::BLUE; color != Color::GRAY; ++color) if(KingdomColors(color)) - { - if(Race::RAND == KingdomRace(color)) SetKingdomRace(color, Race::Rand()); - DEBUG(DBG_GAME , DBG_INFO, "Settings::FixKingdomRandomRace: " << Color::String(color) << ": " << Race::String(KingdomRace(color))); - } -} - -void Settings::SetEditor(void) -{ - opt_global.SetModes(GLOBAL_EDITOR); -} - -void Settings::SetUnicode(bool f) -{ - f ? opt_global.SetModes(GLOBAL_USEUNICODE) : opt_global.ResetModes(GLOBAL_USEUNICODE); -} - -void Settings::SetPriceLoyaltyVersion(void) -{ - opt_global.SetModes(GLOBAL_PRICELOYALTY); -} - -void Settings::SetAutoBattle(bool f) -{ - f ? opt_global.SetModes(GLOBAL_AUTOBATTLE) : opt_global.ResetModes(GLOBAL_AUTOBATTLE); -} - -void Settings::SetEvilInterface(bool f) -{ - f ? ExtSetModes(GAME_EVIL_INTERFACE) : ExtResetModes(GAME_EVIL_INTERFACE); -} - -void Settings::SetBattleGrid(bool f) -{ - f ? ExtSetModes(BATTLE_SHOW_GRID) : ExtResetModes(BATTLE_SHOW_GRID); -} - -void Settings::SetBattleMovementShaded(bool f) -{ - f ? ExtSetModes(BATTLE_SHOW_MOVE_SHADOW) : ExtResetModes(BATTLE_SHOW_MOVE_SHADOW); -} - -void Settings::SetBattleMouseShaded(bool f) -{ - f ? ExtSetModes(BATTLE_SHOW_MOUSE_SHADOW) : ExtResetModes(BATTLE_SHOW_MOUSE_SHADOW); -} - -void Settings::ResetSound(void) -{ - opt_global.ResetModes(GLOBAL_SOUND); -} - -void Settings::ResetMusic(void) -{ - opt_global.ResetModes(GLOBAL_MUSIC); -} - -void Settings::SetLoadedGameVersion(bool f) -{ - f ? opt_global.SetModes(GLOBAL_LOADGAME) : opt_global.ResetModes(GLOBAL_LOADGAME); -} - -void Settings::SetShowPanel(bool f) -{ - f ? opt_global.SetModes(GLOBAL_SHOWCPANEL) : opt_global.ResetModes(GLOBAL_SHOWCPANEL); -} - -void Settings::SetShowRadar(bool f) -{ - f ? opt_global.SetModes(GLOBAL_SHOWRADAR) : opt_global.ResetModes(GLOBAL_SHOWRADAR); -} - -void Settings::SetShowIcons(bool f) -{ - f ? opt_global.SetModes(GLOBAL_SHOWICONS) : opt_global.ResetModes(GLOBAL_SHOWICONS); -} - -void Settings::SetShowButtons(bool f) -{ - f ? opt_global.SetModes(GLOBAL_SHOWBUTTONS) : opt_global.ResetModes(GLOBAL_SHOWBUTTONS); -} - -void Settings::SetShowStatus(bool f) -{ - f ? opt_global.SetModes(GLOBAL_SHOWSTATUS) : opt_global.ResetModes(GLOBAL_SHOWSTATUS); -} - -void Settings::SetNetworkLocalClient(bool f) -{ - f ? opt_global.SetModes(GLOBAL_LOCALCLIENT) : opt_global.ResetModes(GLOBAL_LOCALCLIENT); -} - -void Settings::SetNetworkDedicatedServer(bool f) -{ - f ? opt_global.SetModes(GLOBAL_DEDICATEDSERVER) : opt_global.ResetModes(GLOBAL_DEDICATEDSERVER); -} - -bool Settings::ExtModes(u32 f) const -{ - const u32 mask = 0x0FFFFFFF; - switch(f >> 28) - { - case 0x01: return opt_game.Modes(f & mask); - case 0x02: return opt_world.Modes(f & mask); - case 0x04: return opt_battle.Modes(f & mask); - default: break; - } - return false; -} - -const char* Settings::ExtName(u32 f) const -{ - const settings_t* ptr = std::find(settingsFHeroes2, - settingsFHeroes2 + sizeof(settingsFHeroes2) / sizeof(settings_t) - 1, f); - - return ptr ? _(ptr->str) : NULL; -} - -void Settings::ExtSetModes(u32 f) -{ - const u32 mask = 0x0FFFFFFF; - switch(f >> 28) - { - case 0x01: opt_game.SetModes(f & mask); break; - case 0x02: opt_world.SetModes(f & mask); break; - case 0x04: opt_battle.SetModes(f & mask); break; - default: break; - } -} - -void Settings::ExtResetModes(u32 f) -{ - const u32 mask = 0x0FFFFFFF; - switch(f >> 28) - { - case 0x01: opt_game.ResetModes(f & mask); break; - case 0x02: opt_world.ResetModes(f & mask); break; - case 0x04: opt_battle.ResetModes(f & mask); break; - default: break; - } -} - -bool Settings::ExtAllowBuyFromWell(void) const -{ - return ExtModes(CASTLE_ALLOW_BUY_FROM_WELL); -} - -bool Settings::ExtShowVisitedContent(void) const -{ - return ExtModes(WORLD_SHOW_VISITED_CONTENT); -} - -bool Settings::ExtScouteExtended(void) const -{ - return ExtModes(WORLD_SCOUTING_EXTENDED); -} - -bool Settings::ExtRememberLastFocus(void) const -{ - return ExtModes(GAME_REMEMBER_LAST_FOCUS); -} - -bool Settings::ExtAbandonedMineRandom(void) const -{ - return ExtModes(WORLD_ABANDONED_MINE_RANDOM); -} - -bool Settings::ExtSaveMonsterBattle(void) const -{ - return ExtModes(WORLD_SAVE_MONSTER_BATTLE); -} - -bool Settings::ExtAllowSetGuardian(void) const -{ - return ExtModes(WORLD_ALLOW_SET_GUARDIAN); -} - -bool Settings::ExtNoRequirementsForArtifacts(void) const -{ - return ExtModes(WORLD_NOREQ_FOR_ARTIFACTS); -} - -bool Settings::ExtArtifactCrystalBall(void) const -{ - return ExtModes(WORLD_ARTIFACT_CRYSTAL_BALL); -} - -bool Settings::ExtOnlyFirstMonsterAttack(void) const -{ - return ExtModes(WORLD_ONLY_FIRST_MONSTER_ATTACK); -} - -bool Settings::ExtEyeEagleAsScholar(void) const -{ - return ExtModes(WORLD_EYE_EAGLE_AS_SCHOLAR); -} - -bool Settings::ExtBuySpellBookFromShrine(void) const -{ - return ExtModes(WORLD_BUY_BOOK_FROM_SHRINES); -} - -bool Settings::ExtHeroRecruitCostDependedFromLevel(void) const -{ - return ExtModes(HEROES_COST_DEPENDED_FROM_LEVEL); -} - -bool Settings::ExtRememberPointsForHeroRetreating(void) const -{ - return ExtModes(HEROES_REMEMBER_POINTS_RETREAT); -} - -bool Settings::ExtHeroSurrenderingGiveExp(void) const -{ - return ExtModes(HEROES_SURRENDERING_GIVE_EXP); -} - -bool Settings::ExtHeroRecalculateMovement(void) const -{ - return ExtModes(HEROES_RECALCULATE_MOVEMENT); -} - -bool Settings::ExtLearnSpellsWithDay(void) const -{ - return ExtModes(HEROES_LEARN_SPELLS_WITH_DAY); -} - -bool Settings::ExtForceSelectRaceFromType(void) const -{ - return ExtModes(HEROES_FORCE_RACE_FROM_TYPE); -} - -bool Settings::ExtUnionsAllowCastleVisiting(void) const -{ - return ExtModes(UNIONS_ALLOW_CASTLE_VISITING); -} - -bool Settings::ExtUnionsAllowHeroesMeetings(void) const -{ - return ExtModes(UNIONS_ALLOW_HERO_MEETINGS); -} - -bool Settings::ExtUnionsAllowViewMaps(void) const -{ - return ExtModes(UNIONS_ALLOW_VIEW_MAPS); -} - -bool Settings::ExtBattleShowDamage(void) const -{ - return ExtModes(BATTLE_SHOW_DAMAGE); -} - -bool Settings::ExtBattleTroopDirection(void) const -{ - return ExtModes(BATTLE_TROOP_DIRECTION); -} - -bool Settings::ExtBattleSkipIncreaseDefense(void) const -{ - return ExtModes(BATTLE_SKIP_INCREASE_DEFENSE); -} - -bool Settings::ExtBattleSoftWait(void) const -{ - return ExtModes(BATTLE_SOFT_WAITING); -} - -bool Settings::ExtBattleShowGrid(void) const -{ - return ExtModes(BATTLE_SHOW_GRID); -} - -bool Settings::ExtBattleShowMouseShadow(void) const -{ - return ExtModes(BATTLE_SHOW_MOUSE_SHADOW); -} - -bool Settings::ExtBattleShowMoveShadow(void) const -{ - return ExtModes(BATTLE_SHOW_MOVE_SHADOW); -} - -bool Settings::ExtBattleObjectsArchersPenalty(void) const -{ - return ExtModes(BATTLE_OBJECTS_ARCHERS_PENALTY); -} - -bool Settings::ExtBattleMergeArmies(void) const -{ - return ExtModes(BATTLE_MERGE_ARMIES); -} - -bool Settings::ExtBattleArchmageCanResistBadMagic(void) const -{ - return ExtModes(BATTLE_ARCHMAGE_RESIST_BAD_SPELL); -} - -bool Settings::ExtBattleMagicTroopCanResist(void) const -{ - return ExtModes(BATTLE_MAGIC_TROOP_RESIST); -} - -bool Settings::ExtRewriteConfirm(void) const -{ - return ExtModes(GAME_SAVE_REWRITE_CONFIRM); -} - -bool Settings::ExtAutosaveConfirm(void) const -{ - return ExtModes(GAME_ALSO_CONFIRM_AUTOSAVE); -} - -bool Settings::ExtHideCursor(void) const -{ - return ExtModes(POCKETPC_HIDE_CURSOR); -} - -bool Settings::ExtShowSystemInfo(void) const -{ - return ExtModes(GAME_SHOW_SYSTEM_INFO); -} - -bool Settings::ExtAutoSaveOn(void) const -{ - return ExtModes(GAME_AUTOSAVE_ON); -} - -bool Settings::ExtRememberLastFilename(void) const -{ - return ExtModes(GAME_REMEMBER_LAST_FILENAME); -} - -bool Settings::ExtUseFade(void) const -{ - return ExtModes(GAME_USE_FADE); -} - -bool Settings::ExtShowSDL(void) const -{ - return ExtModes(GAME_SHOW_SDL_LOGO); -} - -bool Settings::EvilInterface(void) const -{ - return ExtModes(GAME_EVIL_INTERFACE); -} - -bool Settings::DynamicInterface(void) const -{ - return ExtModes(GAME_DYNAMIC_INTERFACE); -} - -bool Settings::HideInterface(void) const -{ - return ExtModes(GAME_HIDE_INTERFACE); -} - -bool Settings::ExtLowMemory(void) const -{ - return ExtModes(POCKETPC_LOW_MEMORY); -} - -bool Settings::ExtTapMode(void) const -{ - return ExtModes(POCKETPC_TAP_MODE); -} - -const Point & Settings::PosRadar(void) const { return pos_radr; } -const Point & Settings::PosButtons(void) const { return pos_bttn; } -const Point & Settings::PosIcons(void) const { return pos_icon; } -const Point & Settings::PosStatus(void) const { return pos_stat; } - -void Settings::SetPosRadar(const Point & pt) { pos_radr = pt; } -void Settings::SetPosButtons(const Point & pt) { pos_bttn = pt; } -void Settings::SetPosIcons(const Point & pt) { pos_icon = pt; } -void Settings::SetPosStatus(const Point & pt) { pos_stat = pt; } - -void Settings::BinarySave(void) const -{ - const std::string binary = local_prefix + SEPARATOR + "fheroes2.bin"; - QueueMessage msg; - - // version - msg.Push(static_cast(CURRENT_FORMAT_VERSION)); - - // options - msg.Push(opt_game()); - msg.Push(opt_world()); - msg.Push(opt_battle()); - - // radar position - msg.Push(pos_radr.x); - msg.Push(pos_radr.y); - - // buttons position - msg.Push(pos_bttn.x); - msg.Push(pos_bttn.y); - - // icons position - msg.Push(pos_icon.x); - msg.Push(pos_icon.y); - - // status position - msg.Push(pos_stat.x); - msg.Push(pos_stat.y); - - msg.Save(binary.c_str()); -} - -void Settings::BinaryLoad(void) -{ - const std::string binary = local_prefix + SEPARATOR + "fheroes2.bin"; - - if(FilePresent(binary)) - { - QueueMessage msg; - u32 byte32; - u16 byte16, version; - - msg.Load(binary.c_str()); - - opt_game.ResetModes(MODES_ALL); - opt_world.ResetModes(MODES_ALL); - opt_battle.ResetModes(MODES_ALL); - - msg.Pop(version); - - msg.Pop(byte32); - opt_game.SetModes(byte32); - - msg.Pop(byte32); - opt_world.SetModes(byte32); - - msg.Pop(byte32); - opt_battle.SetModes(byte32); - - msg.Pop(byte16); - pos_radr.x = byte16; - msg.Pop(byte16); - pos_radr.y = byte16; - - msg.Pop(byte16); - pos_bttn.x = byte16; - msg.Pop(byte16); - pos_bttn.y = byte16; - - msg.Pop(byte16); - pos_icon.x = byte16; - msg.Pop(byte16); - pos_icon.y = byte16; - - msg.Pop(byte16); - pos_stat.x = byte16; - msg.Pop(byte16); - pos_stat.y = byte16; - } -} - -void Settings::SetMemoryLimit(u32 limit) -{ - memory_limit = limit; -} - -u32 Settings::MemoryLimit(void) const -{ - return memory_limit; -} - -u32 Settings::DisplayFlags(void) const -{ - u32 flags = opt_global.Modes(GLOBAL_USESWSURFACE) ? SDL_SWSURFACE : SDL_SWSURFACE | SDL_HWSURFACE; - if(opt_global.Modes(GLOBAL_FULLSCREEN)) flags |= SDL_FULLSCREEN; - #ifdef ANDROID - flags = SDL_SWSURFACE; - #endif - - return flags; -} diff --git a/project/jni/application/fheroes2/src/fheroes2/system/settings.h b/project/jni/application/fheroes2/src/fheroes2/system/settings.h deleted file mode 100644 index d2d1e2f3e..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/system/settings.h +++ /dev/null @@ -1,417 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2SETTINGS_H -#define H2SETTINGS_H - -#include -#include -#include -#include -#include -#include "gamedefs.h" -#include "difficulty.h" -#include "race.h" -#include "color.h" -#include "maps_fileinfo.h" -#include "game.h" -#include "game_io.h" -#include "bitmodes.h" -#ifdef ANDROID -#include -#endif - -#define FORMAT_VERSION_2031 0x07EF -#define FORMAT_VERSION_1978 0x07BA -#define FORMAT_VERSION_1966 0x07AE -#define CURRENT_FORMAT_VERSION FORMAT_VERSION_2031 -#define LAST_FORMAT_VERSION FORMAT_VERSION_1966 - -#define ListMapsDirectory std::list - -enum -{ - DBG_WARN = 0x0001, - DBG_INFO = 0x0002, - DBG_TRACE = 0x0004, - - DBG_ENGINE = 0x0010, - DBG_GAME = 0x0020, - DBG_BATTLE = 0x0040, - DBG_AI = 0x0080, - DBG_NETWORK = 0x0100, - - - DBG_DEVEL = 0x8000 -}; - -enum -{ - SCROLL_SLOW = 4, - SCROLL_NORMAL = 8, - SCROLL_FAST1 = 16, - SCROLL_FAST2 = 32 -}; - -#ifdef __SYMBIAN32__ -#define VERBOSE(x) -#define DEBUG(x, y, z) -#elif defined(ANDROID) -#define VERBOSE(x) { std::ostringstream osss; osss << x; __android_log_print(ANDROID_LOG_INFO, "FHeroes", "%s", osss.str().c_str()); } -#define DEBUG(x, y, z) if(IS_DEBUG((x), (y))) VERBOSE(z) -#else -#define VERBOSE(x) std::cout << x << std::endl -#define DEBUG(x, y, z) if(IS_DEBUG((x), (y))) VERBOSE(z) -#endif - -#define IS_DEVEL() (DBG_DEVEL & Settings::Get().Debug()) -#define IS_DEBUG(x, y) (((x) & Settings::Get().Debug()) && ((0x000F & (y)) <= (0x000F & Settings::Get().Debug()))) - -class Settings -{ -public: - enum - { - //GAME_UNUSED = 0x10000010, - GAME_REMEMBER_LAST_FOCUS = 0x10000020, - GAME_SAVE_REWRITE_CONFIRM = 0x10000040, - //GAME_UNUSED = 0x10000080, - GAME_SHOW_SYSTEM_INFO = 0x10000100, - GAME_AUTOSAVE_ON = 0x10000200, - GAME_USE_FADE = 0x10000400, - GAME_SHOW_SDL_LOGO = 0x10000800, - GAME_EVIL_INTERFACE = 0x10001000, - GAME_HIDE_INTERFACE = 0x10002000, - GAME_ALSO_CONFIRM_AUTOSAVE = 0x10004000, - GAME_REMEMBER_LAST_FILENAME = 0x10008000, - GAME_DYNAMIC_INTERFACE = 0x10010000, - POCKETPC_HIDE_CURSOR = 0x10400000, - POCKETPC_LOW_MEMORY = 0x10800000, - POCKETPC_TAP_MODE = 0x11000000, - - WORLD_SHOW_VISITED_CONTENT = 0x20000001, - WORLD_ABANDONED_MINE_RANDOM = 0x20000002, - WORLD_SAVE_MONSTER_BATTLE = 0x20000004, - WORLD_ALLOW_SET_GUARDIAN = 0x20000008, - WORLD_NOREQ_FOR_ARTIFACTS = 0x20000010, - WORLD_ARTIFACT_CRYSTAL_BALL = 0x20000020, - WORLD_SCOUTING_EXTENDED = 0x20000040, - WORLD_ONLY_FIRST_MONSTER_ATTACK = 0x20000080, - WORLD_EYE_EAGLE_AS_SCHOLAR = 0x20000100, - WORLD_BUY_BOOK_FROM_SHRINES = 0x20000200, - UNIONS_ALLOW_HERO_MEETINGS = 0x20001000, - UNIONS_ALLOW_CASTLE_VISITING = 0x20002000, - UNIONS_ALLOW_VIEW_MAPS = 0x20004000, - CASTLE_ALLOW_BUY_FROM_WELL = 0x20100000, - HEROES_LEARN_SPELLS_WITH_DAY = 0x20200000, - HEROES_FORCE_RACE_FROM_TYPE = 0x20400000, - HEROES_COST_DEPENDED_FROM_LEVEL = 0x20800000, - HEROES_REMEMBER_POINTS_RETREAT = 0x21000000, - HEROES_SURRENDERING_GIVE_EXP = 0x22000000, - HEROES_RECALCULATE_MOVEMENT = 0x24000000, - - BATTLE_ARCHMAGE_RESIST_BAD_SPELL= 0x40001000, - BATTLE_MAGIC_TROOP_RESIST = 0x40002000, - BATTLE_SHOW_DAMAGE = 0x40004000, - BATTLE_TROOP_DIRECTION = 0x40008000, - BATTLE_SOFT_WAITING = 0x40010000, - BATTLE_SHOW_GRID = 0x40020000, - BATTLE_SHOW_MOUSE_SHADOW = 0x40040000, - BATTLE_SHOW_MOVE_SHADOW = 0x40080000, - BATTLE_MERGE_ARMIES = 0x40100000, - BATTLE_SKIP_INCREASE_DEFENSE = 0x40200000, - BATTLE_OBJECTS_ARCHERS_PENALTY = 0x42000000, - - SETTINGS_LAST - }; - - static Settings & Get(void); - - bool Read(const std::string & filename); - bool Save(const std::string & filename) const; - - void Dump(std::ostream & stream = std::cout) const; - bool LoadFileMapsMP2(const std::string & file); - Maps::FileInfo & CurrentFileInfo(void); - - u8 MajorVersion(void) const; - u8 MinorVersion(void) const; - u16 Debug(void) const; - u8 HeroesMoveSpeed(void) const; - u8 AIMoveSpeed(void) const; - u8 BattleSpeed(void) const; - u8 ScrollSpeed(void) const; - u32 MemoryLimit(void) const; - - const std::string & BuildVersion(void) const; - const std::string & DataDirectory(void) const; - const std::string & LocalPrefix(void) const; - const std::string & PlayMusCommand(void) const; - const std::string & SelectVideoDriver(void) const; - - const ListMapsDirectory & GetListMapsDirectory(void) const; - - Difficulty::difficulty_t GameDifficulty(void) const; - - const std::string & ForceLang(void) const; - const std::string & FontsNormal(void) const; - const std::string & FontsSmall(void) const; - u8 FontsNormalSize(void) const; - u8 FontsSmallSize(void) const; - bool FontsRenderBlended(void) const; - - const Point & PosRadar(void) const; - const Point & PosButtons(void) const; - const Point & PosIcons(void) const; - const Point & PosStatus(void) const; - - void SetPosRadar(const Point &); - void SetPosButtons(const Point &); - void SetPosIcons(const Point &); - void SetPosStatus(const Point &); - - u32 DisplayFlags(void) const; - - bool QVGA(void) const; - bool Editor(void) const; - bool Sound(void) const; - bool Music(void) const; - bool CDMusic(void) const; - bool ShowControlPanel(void) const; - bool ShowRadar(void) const; - bool ShowIcons(void) const; - bool ShowButtons(void) const; - bool ShowStatus(void) const; - bool Unicode(void) const; - bool PocketPC(void) const; - bool UseAltResource(void) const; - bool AutoBattle(void) const; - bool PriceLoyaltyVersion(void) const; - bool LoadedGameVersion(void) const; - bool MusicExt(void) const; - bool MusicMIDI(void) const; - bool MusicCD(void) const; - void BinarySave(void) const; - void BinaryLoad(void); - - bool ExtModes(u32) const; - void ExtSetModes(u32); - void ExtResetModes(u32); - const char* ExtName(u32) const; - bool ExtAllowBuyFromWell(void) const; - bool ExtShowVisitedContent(void) const; - bool ExtScouteExtended(void) const; - bool ExtRememberLastFocus(void) const; - bool ExtRememberLastFilename(void) const; - bool ExtAbandonedMineRandom(void) const; - bool ExtSaveMonsterBattle(void) const; - bool ExtAllowSetGuardian(void) const; - bool ExtNoRequirementsForArtifacts(void) const; - bool ExtArtifactCrystalBall(void) const; - bool ExtLearnSpellsWithDay(void) const; - bool ExtForceSelectRaceFromType(void) const; - bool ExtOnlyFirstMonsterAttack(void) const; - bool ExtEyeEagleAsScholar(void) const; - bool ExtBuySpellBookFromShrine(void) const; - bool ExtHeroRecruitCostDependedFromLevel(void) const; - bool ExtRememberPointsForHeroRetreating(void) const; - bool ExtHeroSurrenderingGiveExp(void) const; - bool ExtHeroRecalculateMovement(void) const; - bool ExtUnionsAllowCastleVisiting(void) const; - bool ExtUnionsAllowHeroesMeetings(void) const; - bool ExtUnionsAllowViewMaps(void) const; - bool ExtBattleShowDamage(void) const; - bool ExtBattleTroopDirection(void) const; - bool ExtBattleSoftWait(void) const; - bool ExtBattleMagicTroopCanResist(void) const; - bool ExtBattleArchmageCanResistBadMagic(void) const; - bool ExtBattleObjectsArchersPenalty(void) const; - bool ExtBattleMergeArmies(void) const; - bool ExtBattleSkipIncreaseDefense(void) const; - bool ExtRewriteConfirm(void) const; - bool ExtAutosaveConfirm(void) const; - bool ExtHideCursor(void) const; - bool ExtBattleShowGrid(void) const; - bool ExtBattleShowMouseShadow(void) const; - bool ExtBattleShowMoveShadow(void) const; - bool ExtShowSystemInfo(void) const; - bool ExtAutoSaveOn(void) const; - bool ExtUseFade(void) const; - bool ExtShowSDL(void) const; - bool ExtLowMemory(void) const; - bool ExtTapMode(void) const; - bool EvilInterface(void) const; - bool DynamicInterface(void) const; - bool HideInterface(void) const; - - bool NetworkDedicatedServer(void) const; - bool NetworkLocalClient(void) const; - - const Size & VideoMode(void) const; - void SetAutoVideoMode(void); - - u8 SoundVolume(void) const; - u8 MusicVolume(void) const; - - void SetDebug(const u16 d); - void SetEditor(void); - void SetUnicode(bool); - void SetPriceLoyaltyVersion(void); - void SetGameDifficulty(const Difficulty::difficulty_t d); - void SetEvilInterface(bool); - void SetAutoBattle(bool); - void SetBattleGrid(bool); - void SetBattleMovementShaded(bool); - void SetBattleMouseShaded(bool); - void SetLoadedGameVersion(bool); - void SetShowPanel(bool); - void SetShowRadar(bool); - void SetShowIcons(bool); - void SetShowButtons(bool); - void SetShowStatus(bool); - void SetNetworkLocalClient(bool); - void SetNetworkDedicatedServer(bool); - void SetMemoryLimit(u32); - void SetAIMoveSpeed(u8); - void SetScrollSpeed(u8); - void SetHeroesMoveSpeed(u8); - void SetBattleSpeed(u8); - - void SetSoundVolume(const u8 v); - void SetMusicVolume(const u8 v); - void ResetSound(void); - void ResetMusic(void); - - u8 GameType(void) const; - void SetGameType(const Game::type_t type); - - u8 GetUnions(u8 cl1) const; - bool IsUnions(u8 cl1, u8 cl2) const; - Color::color_t CurrentColor(void) const; - Color::color_t MyColor(void) const; - void SetCurrentColor(const Color::color_t c); - void SetMyColor(const Color::color_t c); - u8 PlayersColors(void) const; - void SetPlayersColors(u8 c); - u8 PreferablyCountPlayers(void) const; - void SetPreferablyCountPlayers(u8 c); - - void SetLocalPrefix(const char*); - - u16 GetPort(void) const; - - // from maps info - Race::race_t KingdomRace(u8) const; - void SetKingdomRace(u8, u8); - void FixKingdomRandomRace(void); - const std::string & MapsFile(void) const; - const std::string & MapsName(void) const; - const std::string & MapsDescription(void) const; - Difficulty::difficulty_t MapsDifficulty(void) const; - u16 MapsWidth(void) const; - bool AllowColors(u8) const; - u8 AllowColors(void) const; - Color::color_t FirstAllowColor(void) const; - bool KingdomColors(u8) const; - u8 KingdomColors(void) const; - bool AllowChangeRace(u8) const; - u8 AllowColorsCount(void) const; - u8 KingdomColorsCount(void) const; - bool GameStartWithHeroes(void) const; - u16 ConditionWins(void) const; - u16 ConditionLoss(void) const; - bool WinsCompAlsoWins(void) const; - bool WinsAllowNormalVictory(void) const; - Artifact::artifact_t WinsFindArtifact(void) const; - bool WinsFindUltimateArtifact(void) const; - u16 WinsSidePart(void) const; - u32 WinsAccumulateGold(void) const; - u32 WinsMapsIndexObject(void) const; - u32 LossMapsIndexObject(void) const; - u16 LossCountDays(void) const; - -protected: - void Parse(const std::string & left, const std::string & right); - void PostLoad(void); - -private: - friend class Game::IO; - - Settings(); - ~Settings(); - - BitModes opt_global; - - BitModes opt_game; - BitModes opt_battle; - BitModes opt_world; - - const u8 major_version; - const u8 minor_version; - std::string svn_version; - u16 debug; - - Size video_mode; - - Difficulty::difficulty_t game_difficulty; - Color::color_t my_color; - Color::color_t cur_color; - - std::string build_version; - std::string path_data_directory; - std::string local_prefix; - - ListMapsDirectory list_maps_directory; - - std::string font_normal; - std::string font_small; - std::string force_lang; - u8 size_normal; - u8 size_small; - - Maps::FileInfo current_maps_file; - - u8 sound_volume; - u8 music_volume; - u8 heroes_speed; - u8 ai_speed; - u8 scroll_speed; - u8 battle_speed; - - u8 game_type; - u8 players_colors; - u8 preferably_count_players; - - std::string playmus_command; - std::string video_driver; - - u16 port; - - u32 memory_limit; - - Point pos_radr; - Point pos_bttn; - Point pos_icon; - Point pos_stat; -}; - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/test/test.cpp b/project/jni/application/fheroes2/src/fheroes2/test/test.cpp deleted file mode 100644 index 445684d11..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/test/test.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "agg.h" -#include "settings.h" -#include "gamedefs.h" -#include "battle2.h" -#include "world.h" -#include "army.h" -#include "castle.h" -#include "kingdom.h" -#include "heroes.h" -#include "test.h" - -#ifndef BUILD_RELEASE - -void RunTest1(void); -void RunTest2(void); -void RunTest3(void); - -void TestMonsterSprite(void); - -void Test::Run(int num) -{ - switch(num) - { - case 1: RunTest1(); break; - case 2: RunTest2(); break; - case 3: RunTest3(); break; - - case 9: TestMonsterSprite(); break; - - default: DEBUG(DBG_ENGINE , DBG_WARN, "Test::Run: unknown test."); break; - } -} - -void RunTest1(void) -{ - VERBOSE("Run Test1"); -} - -void RunTest2(void) -{ - VERBOSE("Run Test2"); -} - -void RunTest3(void) -{ - VERBOSE("Run Test3"); - Settings & conf = Settings::Get(); - //conf.SetPlayers(Color::BLUE|Color::GREEN); - - world.LoadMaps("/opt/projects/fh2/maps/beltway.mp2"); - - Heroes & hero1 = *world.GetHeroes(Heroes::SANDYSANDY); - Heroes & hero2 = *world.GetHeroes(Heroes::BAX); - - Kingdom & kingdom1 = world.GetKingdom(Color::RED); - Kingdom & kingdom2 = world.GetKingdom(Color::YELLOW); - - conf.SetMyColor(Color::RED); - - hero1.SetSpellPoints(150); - - kingdom1.SetControl(Game::LOCAL); - kingdom2.SetControl(Game::LOCAL); - - if(kingdom1.GetCastles().size()) - hero1.Recruit(kingdom1.GetColor(), Point(20, 20)); - hero2.Recruit(kingdom2.GetColor(), Point(20, 21)); - - Army::army_t & army1 = hero1.GetArmy(); - - Castle* castle = kingdom2.GetCastles().at(0); - castle->BuyBuilding(BUILD_CAPTAIN); - castle->ActionNewDay(); - castle->BuyBuilding(BUILD_MAGEGUILD1); - - //Army::army_t army2; - //Army::army_t & army2 = hero2.GetArmy(); - Army::army_t & army2 = castle->GetArmy(); - - army1.Clear(); - //army1.JoinTroop(Monster::PHOENIX, 10); - //army1.JoinTroop(Monster::RANGER, 80); - army1.At(0) = Army::Troop(Monster::ROYAL_MUMMY, 50); - //army1.JoinTroop(Monster::GARGOYLE, 100); - - //army1.JoinTroop(Monster::Rand(Monster::LEVEL1), 30); - //army1.JoinTroop(Monster::Rand(Monster::LEVEL2), 20); - //army1.JoinTroop(Monster::Rand(Monster::LEVEL3), 10); - - army2.Clear(); -// army2.At(0) = Army::Troop(Monster::OGRE, 1); - army2.At(0) = Army::Troop(Monster::DWARF, 2); - army2.At(1) = Army::Troop(Monster::DWARF, 2); - army2.At(2) = Army::Troop(Monster::DWARF, 2); - army2.At(3) = Army::Troop(Monster::DWARF, 2); - army2.At(4) = Army::Troop(Monster::DWARF, 2); -// army2.JoinTroop(static_cast(1), 10); -// army2.JoinTroop(static_cast(4), 10); -// army2.JoinTroop(static_cast(6), 10); -// army2.JoinTroop(static_cast(8), 10); - -// kingdom2.Dump(); - - Battle2::Loader(army1, army2, castle->GetIndex()); -} - -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/test/test.h b/project/jni/application/fheroes2/src/fheroes2/test/test.h deleted file mode 100644 index 468113402..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/test/test.h +++ /dev/null @@ -1,34 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef H2TEST_H -#define H2TEST_H - -#ifndef BUILD_RELEASE - -namespace Test -{ - void Run(int); -} - -#endif -#endif diff --git a/project/jni/application/fheroes2/src/fheroes2/test/test_monstersprite.cpp b/project/jni/application/fheroes2/src/fheroes2/test/test_monstersprite.cpp deleted file mode 100644 index 1ec7676dc..000000000 --- a/project/jni/application/fheroes2/src/fheroes2/test/test_monstersprite.cpp +++ /dev/null @@ -1,194 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2009 by Andrey Afletdinov * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "gamedefs.h" -#include "agg.h" -#include "cursor.h" -#include "game.h" -#include "statusbar.h" -#include "dialog.h" -#include "monster.h" -#include "button.h" -#include "army_troop.h" -#include "battle_stats.h" - -#ifndef BUILD_RELEASE - -void TestMonsterSprite(void) -{ - // cursor - Cursor & cursor = Cursor::Get(); - cursor.Hide(); - cursor.SetThemes(Cursor::POINTER); - - //Monster monster(Monster::PEASANT); - Army::Troop troop(Monster::PEASANT, 1); - troop.BattleInit(); - const Battle2::Stats & b = *troop.GetBattleStats(); - Background back; - Rect pos; - - Display & display = Display::Get(); - LocalEvent & le = LocalEvent::Get(); - - std::string str; - - StatusBar speed_bar; - StatusBar count_bar; - StatusBar start_bar; - StatusBar frame_bar; - StatusBar info_bar; - - start_bar.SetCenter(100, display.h() - 15); - count_bar.SetCenter(200, display.h() - 15); - speed_bar.SetCenter(300, display.h() - 15); - frame_bar.SetCenter(400, display.h() - 15); - info_bar.SetCenter(550, display.h() - 15); - - u32 ticket = 0; - - u8 start = 0; - u8 count = AGG::GetICNCount(b.ICNFile()); - u8 frame = 0; - u8 speed = 100; - - str.clear(); - String::AddInt(str, frame); - frame_bar.ShowMessage("frame: " + str); - - str.clear(); - String::AddInt(str, speed); - speed_bar.ShowMessage("speed: " + str); - - str.clear(); - String::AddInt(str, start); - start_bar.ShowMessage("start: " + str); - - str.clear(); - String::AddInt(str, count); - count_bar.ShowMessage("count: " + str); - - cursor.Show(); - display.Flip(); - - // mainmenu loop - while(le.HandleEvents()) - { - if(Game::HotKeyPress(Game::EVENT_DEFAULT_EXIT)) break; - - if(le.MouseClickLeft(pos)) - { - u32 mons = troop(); - if(Dialog::SelectCount("Monster", Monster::PEASANT, Monster::WATER_ELEMENT, mons)) - { - cursor.Hide(); - troop.SetMonster(Monster::FromInt(mons)); - start = 0; - count = AGG::GetICNCount(b.ICNFile()); - frame = 0; - cursor.Show(); - display.Flip(); - } - } - - if(le.MouseClickLeft(start_bar.GetRect())) - { - u32 start2 = start; - if(Dialog::SelectCount("Start", 0, AGG::GetICNCount(b.ICNFile()) - 1, start2)) - { - cursor.Hide(); - start = start2; - if(start + count > AGG::GetICNCount(b.ICNFile())) count = AGG::GetICNCount(b.ICNFile()) - start; - str.clear(); - String::AddInt(str, start); - start_bar.ShowMessage("start: " + str); - cursor.Show(); - display.Flip(); - } - } - - if(le.MouseClickLeft(count_bar.GetRect())) - { - u32 count2 = count; - if(Dialog::SelectCount("Count", 1, AGG::GetICNCount(b.ICNFile()), count2)) - { - cursor.Hide(); - count = count2; - frame = start; - str.clear(); - String::AddInt(str, count); - count_bar.ShowMessage("count: " + str); - cursor.Show(); - display.Flip(); - } - } - - if(le.MouseClickLeft(speed_bar.GetRect())) - { - u32 speed2 = speed; - if(Dialog::SelectCount("Speed", 1, 50, speed2)) - { - cursor.Hide(); - speed = speed2; - frame = start; - str.clear(); - String::AddInt(str, speed); - speed_bar.ShowMessage("speed: " + str); - cursor.Show(); - display.Flip(); - } - } - - if(0 == (ticket % speed)) - { - cursor.Hide(); - const Sprite & sprite = AGG::GetICN(b.ICNFile(), frame); - pos.x = 320 + sprite.x(); - pos.y = 240 + sprite.y(); - pos.w = sprite.w(); - pos.h = sprite.h(); - back.Restore(); - back.Save(pos); - display.Blit(sprite, pos); - - str.clear(); - String::AddInt(str, frame); - frame_bar.ShowMessage("frame: " + str); - - str = "ox: "; - String::AddInt(str, sprite.x()); - str += ", oy: "; - String::AddInt(str, sprite.y()); - info_bar.ShowMessage(str); - - cursor.Show(); - display.Flip(); - - ++frame; - if(frame >= start + count) frame = start; - } - - ++ticket; - } -} - -#endif diff --git a/project/jni/application/fheroes2/src/xmlccwrap/gzstream.cpp b/project/jni/application/fheroes2/src/xmlccwrap/gzstream.cpp deleted file mode 100644 index 491983359..000000000 --- a/project/jni/application/fheroes2/src/xmlccwrap/gzstream.cpp +++ /dev/null @@ -1,165 +0,0 @@ -// ============================================================================ -// gzstream, C++ iostream classes wrapping the zlib compression library. -// Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library 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 -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// ============================================================================ -// -// File : gzstream.C -// Revision : $Revision: 1.7 $ -// Revision_date : $Date: 2003/01/08 14:41:27 $ -// Author(s) : Deepak Bandyopadhyay, Lutz Kettner -// -// Standard streambuf implementation following Nicolai Josuttis, "The -// Standard C++ Library". -// ============================================================================ - -#include "gzstream.h" -#include -#include // for memcpy - -#ifdef GZSTREAM_NAMESPACE -namespace GZSTREAM_NAMESPACE { -#endif - -// ---------------------------------------------------------------------------- -// Internal classes to implement gzstream. See header file for user classes. -// ---------------------------------------------------------------------------- - -// -------------------------------------- -// class gzstreambuf: -// -------------------------------------- - -gzstreambuf* gzstreambuf::open( const char* name, int open_mode) { - if ( is_open()) - return (gzstreambuf*)0; - mode = open_mode; - // no append nor read/write mode - if ((mode & std::ios::ate) || (mode & std::ios::app) - || ((mode & std::ios::in) && (mode & std::ios::out))) - return (gzstreambuf*)0; - char fmode[10]; - char* fmodeptr = fmode; - if ( mode & std::ios::in) - *fmodeptr++ = 'r'; - else if ( mode & std::ios::out) - *fmodeptr++ = 'w'; - *fmodeptr++ = 'b'; - *fmodeptr = '\0'; - file = gzopen( name, fmode); - if (file == 0) - return (gzstreambuf*)0; - opened = 1; - return this; -} - -gzstreambuf * gzstreambuf::close() { - if ( is_open()) { - sync(); - opened = 0; - if ( gzclose( file) == Z_OK) - return this; - } - return (gzstreambuf*)0; -} - -int gzstreambuf::underflow() { // used for input buffer only - if ( gptr() && ( gptr() < egptr())) - return * reinterpret_cast( gptr()); - - if ( ! (mode & std::ios::in) || ! opened) - return EOF; - // Josuttis' implementation of inbuf - int n_putback = gptr() - eback(); - if ( n_putback > 4) - n_putback = 4; - std::memcpy( buffer + (4 - n_putback), gptr() - n_putback, n_putback); - - int num = gzread( file, buffer+4, bufferSize-4); - if (num <= 0) // ERROR or EOF - return EOF; - - // reset buffer pointers - setg( buffer + (4 - n_putback), // beginning of putback area - buffer + 4, // read position - buffer + 4 + num); // end of buffer - - // return next character - return * reinterpret_cast( gptr()); -} - -int gzstreambuf::flush_buffer() { - // Separate the writing of the buffer from overflow() and - // sync() operation. - int w = pptr() - pbase(); - if ( gzwrite( file, pbase(), w) != w) - return EOF; - pbump( -w); - return w; -} - -int gzstreambuf::overflow( int c) { // used for output buffer only - if ( ! ( mode & std::ios::out) || ! opened) - return EOF; - if (c != EOF) { - *pptr() = c; - pbump(1); - } - if ( flush_buffer() == EOF) - return EOF; - return c; -} - -int gzstreambuf::sync() { - // Changed to use flush_buffer() instead of overflow( EOF) - // which caused improper behavior with std::endl and flush(), - // bug reported by Vincent Ricard. - if ( pptr() && pptr() > pbase()) { - if ( flush_buffer() == EOF) - return -1; - } - return 0; -} - -// -------------------------------------- -// class gzstreambase: -// -------------------------------------- - -gzstreambase::gzstreambase( const char* name, int mode) { - init( &buf); - open( name, mode); -} - -gzstreambase::~gzstreambase() { - buf.close(); -} - -void gzstreambase::open( const char* name, int open_mode) { - if ( ! buf.open( name, open_mode)) - clear( rdstate() | std::ios::badbit); -} - -void gzstreambase::close() { - if ( buf.is_open()) - if ( ! buf.close()) - clear( rdstate() | std::ios::badbit); -} - -#ifdef GZSTREAM_NAMESPACE -} // namespace GZSTREAM_NAMESPACE -#endif - -// ============================================================================ -// EOF // diff --git a/project/jni/application/fheroes2/src/xmlccwrap/gzstream.h b/project/jni/application/fheroes2/src/xmlccwrap/gzstream.h deleted file mode 100644 index 13e631281..000000000 --- a/project/jni/application/fheroes2/src/xmlccwrap/gzstream.h +++ /dev/null @@ -1,122 +0,0 @@ -// ============================================================================ -// gzstream, C++ iostream classes wrapping the zlib compression library. -// Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library 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 -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -// ============================================================================ -// -// File : gzstream.h -// Revision : $Revision: 1.5 $ -// Revision_date : $Date: 2002/04/26 23:30:15 $ -// Author(s) : Deepak Bandyopadhyay, Lutz Kettner -// -// Standard streambuf implementation following Nicolai Josuttis, "The -// Standard C++ Library". -// ============================================================================ - -#ifndef GZSTREAM_H -#define GZSTREAM_H 1 - -// standard C++ with new header file names and std:: namespace -#include -#include -#include -#include - -#ifdef GZSTREAM_NAMESPACE -namespace GZSTREAM_NAMESPACE { -#endif - -// ---------------------------------------------------------------------------- -// Internal classes to implement gzstream. See below for user classes. -// ---------------------------------------------------------------------------- - -class gzstreambuf : public std::streambuf { -private: - static const int bufferSize = 47+256; // size of data buff - // totals 512 bytes under g++ for igzstream at the end. - - gzFile file; // file handle for compressed file - char buffer[bufferSize]; // data buffer - char opened; // open/close state of stream - int mode; // I/O mode - - int flush_buffer(); -public: - gzstreambuf() : opened(0) { - setp( buffer, buffer + (bufferSize-1)); - setg( buffer + 4, // beginning of putback area - buffer + 4, // read position - buffer + 4); // end position - // ASSERT: both input & output capabilities will not be used together - } - int is_open() { return opened; } - gzstreambuf* open( const char* name, int open_mode); - gzstreambuf* close(); - ~gzstreambuf() { close(); } - - virtual int overflow( int c = EOF); - virtual int underflow(); - virtual int sync(); -}; - -class gzstreambase : virtual public std::ios { -protected: - gzstreambuf buf; -public: - gzstreambase() { init(&buf); } - gzstreambase( const char* name, int open_mode); - ~gzstreambase(); - void open( const char* name, int open_mode); - void close(); - gzstreambuf* rdbuf() { return &buf; } -}; - -// ---------------------------------------------------------------------------- -// User classes. Use igzstream and ogzstream analogously to ifstream and -// ofstream respectively. They read and write files based on the gz* -// function interface of the zlib. Files are compatible with gzip compression. -// ---------------------------------------------------------------------------- - -class igzstream : public gzstreambase, public std::istream { -public: - igzstream() : std::istream( &buf) {} - igzstream( const char* name, int open_mode = std::ios::in) - : gzstreambase( name, open_mode), std::istream( &buf) {} - gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); } - void open( const char* name, int open_mode = std::ios::in) { - gzstreambase::open( name, open_mode); - } -}; - -class ogzstream : public gzstreambase, public std::ostream { -public: - ogzstream() : std::ostream( &buf) {} - ogzstream( const char* name, int mode = std::ios::out) - : gzstreambase( name, mode), std::ostream( &buf) {} - gzstreambuf* rdbuf() { return gzstreambase::rdbuf(); } - void open( const char* name, int open_mode = std::ios::out) { - gzstreambase::open( name, open_mode); - } -}; - -#ifdef GZSTREAM_NAMESPACE -} // namespace GZSTREAM_NAMESPACE -#endif - -#endif // GZSTREAM_H -// ============================================================================ -// EOF // - diff --git a/project/jni/application/fheroes2/src/xmlccwrap/tinystr.cpp b/project/jni/application/fheroes2/src/xmlccwrap/tinystr.cpp deleted file mode 100644 index 681250714..000000000 --- a/project/jni/application/fheroes2/src/xmlccwrap/tinystr.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* -www.sourceforge.net/projects/tinyxml -Original file by Yves Berquin. - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - -/* - * THIS FILE WAS ALTERED BY Tyge Løvset, 7. April 2005. - */ - - -#ifndef TIXML_USE_STL - -#include "tinystr.h" - -// Error value for find primitive -const TiXmlString::size_type TiXmlString::npos = static_cast< TiXmlString::size_type >(-1); - - -// Null rep. -TiXmlString::Rep TiXmlString::nullrep_ = { 0, 0, { '\0' } }; - - -void TiXmlString::reserve (size_type cap) -{ - if (cap > capacity()) - { - TiXmlString tmp; - tmp.init(length(), cap); - memcpy(tmp.start(), data(), length()); - swap(tmp); - } -} - - -TiXmlString& TiXmlString::assign(const char* str, size_type len) -{ - size_type cap = capacity(); - if (len > cap || cap > 3*(len + 8)) - { - TiXmlString tmp; - tmp.init(len); - memcpy(tmp.start(), str, len); - swap(tmp); - } - else - { - memmove(start(), str, len); - set_size(len); - } - return *this; -} - - -TiXmlString& TiXmlString::append(const char* str, size_type len) -{ - size_type newsize = length() + len; - if (newsize > capacity()) - { - reserve (newsize + capacity()); - } - memmove(finish(), str, len); - set_size(newsize); - return *this; -} - - -TiXmlString operator + (const TiXmlString & a, const TiXmlString & b) -{ - TiXmlString tmp; - tmp.reserve(a.length() + b.length()); - tmp += a; - tmp += b; - return tmp; -} - -TiXmlString operator + (const TiXmlString & a, const char* b) -{ - TiXmlString tmp; - TiXmlString::size_type b_len = static_cast( strlen(b) ); - tmp.reserve(a.length() + b_len); - tmp += a; - tmp.append(b, b_len); - return tmp; -} - -TiXmlString operator + (const char* a, const TiXmlString & b) -{ - TiXmlString tmp; - TiXmlString::size_type a_len = static_cast( strlen(a) ); - tmp.reserve(a_len + b.length()); - tmp.append(a, a_len); - tmp += b; - return tmp; -} - - -#endif // TIXML_USE_STL diff --git a/project/jni/application/fheroes2/src/xmlccwrap/tinystr.h b/project/jni/application/fheroes2/src/xmlccwrap/tinystr.h deleted file mode 100644 index 3c2aa9d54..000000000 --- a/project/jni/application/fheroes2/src/xmlccwrap/tinystr.h +++ /dev/null @@ -1,319 +0,0 @@ -/* -www.sourceforge.net/projects/tinyxml -Original file by Yves Berquin. - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - -/* - * THIS FILE WAS ALTERED BY Tyge Lovset, 7. April 2005. - * - * - completely rewritten. compact, clean, and fast implementation. - * - sizeof(TiXmlString) = pointer size (4 bytes on 32-bit systems) - * - fixed reserve() to work as per specification. - * - fixed buggy compares operator==(), operator<(), and operator>() - * - fixed operator+=() to take a const ref argument, following spec. - * - added "copy" constructor with length, and most compare operators. - * - added swap(), clear(), size(), capacity(), operator+(). - */ - -#ifndef TIXML_USE_STL - -#ifndef TIXML_STRING_INCLUDED -#define TIXML_STRING_INCLUDED - -#include -#include - -/* The support for explicit isn't that universal, and it isn't really - required - it is used to check that the TiXmlString class isn't incorrectly - used. Be nice to old compilers and macro it here: -*/ -#if defined(_MSC_VER) && (_MSC_VER >= 1200 ) - // Microsoft visual studio, version 6 and higher. - #define TIXML_EXPLICIT explicit -#elif defined(__GNUC__) && (__GNUC__ >= 3 ) - // GCC version 3 and higher.s - #define TIXML_EXPLICIT explicit -#else - #define TIXML_EXPLICIT -#endif - - -/* - TiXmlString is an emulation of a subset of the std::string template. - Its purpose is to allow compiling TinyXML on compilers with no or poor STL support. - Only the member functions relevant to the TinyXML project have been implemented. - The buffer allocation is made by a simplistic power of 2 like mechanism : if we increase - a string and there's no more room, we allocate a buffer twice as big as we need. -*/ -class TiXmlString -{ - public : - // The size type used - typedef size_t size_type; - - // Error value for find primitive - static const size_type npos; // = -1; - - - // TiXmlString empty constructor - TiXmlString () : rep_(&nullrep_) - { - } - - // TiXmlString copy constructor - TiXmlString ( const TiXmlString & copy) : rep_(0) - { - init(copy.length()); - memcpy(start(), copy.data(), length()); - } - - // TiXmlString constructor, based on a string - TIXML_EXPLICIT TiXmlString ( const char * copy) : rep_(0) - { - init( static_cast( strlen(copy) )); - memcpy(start(), copy, length()); - } - - // TiXmlString constructor, based on a string - TIXML_EXPLICIT TiXmlString ( const char * str, size_type len) : rep_(0) - { - init(len); - memcpy(start(), str, len); - } - - // TiXmlString destructor - ~TiXmlString () - { - quit(); - } - - // = operator - TiXmlString& operator = (const char * copy) - { - return assign( copy, (size_type)strlen(copy)); - } - - // = operator - TiXmlString& operator = (const TiXmlString & copy) - { - return assign(copy.start(), copy.length()); - } - - - // += operator. Maps to append - TiXmlString& operator += (const char * suffix) - { - return append(suffix, static_cast( strlen(suffix) )); - } - - // += operator. Maps to append - TiXmlString& operator += (char single) - { - return append(&single, 1); - } - - // += operator. Maps to append - TiXmlString& operator += (const TiXmlString & suffix) - { - return append(suffix.data(), suffix.length()); - } - - - // Convert a TiXmlString into a null-terminated char * - const char * c_str () const { return rep_->str; } - - // Convert a TiXmlString into a char * (need not be null terminated). - const char * data () const { return rep_->str; } - - // Return the length of a TiXmlString - size_type length () const { return rep_->size; } - - // Alias for length() - size_type size () const { return rep_->size; } - - // Checks if a TiXmlString is empty - bool empty () const { return rep_->size == 0; } - - // Return capacity of string - size_type capacity () const { return rep_->capacity; } - - - // single char extraction - const char& at (size_type index) const - { - assert( index < length() ); - return rep_->str[ index ]; - } - - // [] operator - char& operator [] (size_type index) const - { - assert( index < length() ); - return rep_->str[ index ]; - } - - // find a char in a string. Return TiXmlString::npos if not found - size_type find (char lookup) const - { - return find(lookup, 0); - } - - // find a char in a string from an offset. Return TiXmlString::npos if not found - size_type find (char tofind, size_type offset) const - { - if (offset >= length()) return npos; - - for (const char* p = c_str() + offset; *p != '\0'; ++p) - { - if (*p == tofind) return static_cast< size_type >( p - c_str() ); - } - return npos; - } - - void clear () - { - //Lee: - //The original was just too strange, though correct: - // TiXmlString().swap(*this); - //Instead use the quit & re-init: - quit(); - init(0,0); - } - - /* Function to reserve a big amount of data when we know we'll need it. Be aware that this - function DOES NOT clear the content of the TiXmlString if any exists. - */ - void reserve (size_type cap); - - TiXmlString& assign (const char* str, size_type len); - - TiXmlString& append (const char* str, size_type len); - - void swap (TiXmlString& other) - { - Rep* r = rep_; - rep_ = other.rep_; - other.rep_ = r; - } - - private: - - void init(size_type sz) { init(sz, sz); } - void set_size(size_type sz) { rep_->str[ rep_->size = sz ] = '\0'; } - char* start() const { return rep_->str; } - char* finish() const { return rep_->str + rep_->size; } - - struct Rep - { - size_type size, capacity; - char str[1]; - }; - - void init(size_type sz, size_type cap) - { - if (cap) - { - // Lee: the original form: - // rep_ = static_cast(operator new(sizeof(Rep) + cap)); - // doesn't work in some cases of new being overloaded. Switching - // to the normal allocation, although use an 'int' for systems - // that are overly picky about structure alignment. - const size_type bytesNeeded = sizeof(Rep) + cap; - const size_type intsNeeded = ( bytesNeeded + sizeof(int) - 1 ) / sizeof( int ); - rep_ = reinterpret_cast( new int[ intsNeeded ] ); - - rep_->str[ rep_->size = sz ] = '\0'; - rep_->capacity = cap; - } - else - { - rep_ = &nullrep_; - } - } - - void quit() - { - if (rep_ != &nullrep_) - { - // The rep_ is really an array of ints. (see the allocator, above). - // Cast it back before delete, so the compiler won't incorrectly call destructors. - delete [] ( reinterpret_cast( rep_ ) ); - } - } - - Rep * rep_; - static Rep nullrep_; - -} ; - - -inline bool operator == (const TiXmlString & a, const TiXmlString & b) -{ - return ( a.length() == b.length() ) // optimization on some platforms - && ( strcmp(a.c_str(), b.c_str()) == 0 ); // actual compare -} -inline bool operator < (const TiXmlString & a, const TiXmlString & b) -{ - return strcmp(a.c_str(), b.c_str()) < 0; -} - -inline bool operator != (const TiXmlString & a, const TiXmlString & b) { return !(a == b); } -inline bool operator > (const TiXmlString & a, const TiXmlString & b) { return b < a; } -inline bool operator <= (const TiXmlString & a, const TiXmlString & b) { return !(b < a); } -inline bool operator >= (const TiXmlString & a, const TiXmlString & b) { return !(a < b); } - -inline bool operator == (const TiXmlString & a, const char* b) { return strcmp(a.c_str(), b) == 0; } -inline bool operator == (const char* a, const TiXmlString & b) { return b == a; } -inline bool operator != (const TiXmlString & a, const char* b) { return !(a == b); } -inline bool operator != (const char* a, const TiXmlString & b) { return !(b == a); } - -TiXmlString operator + (const TiXmlString & a, const TiXmlString & b); -TiXmlString operator + (const TiXmlString & a, const char* b); -TiXmlString operator + (const char* a, const TiXmlString & b); - - -/* - TiXmlOutStream is an emulation of std::ostream. It is based on TiXmlString. - Only the operators that we need for TinyXML have been developped. -*/ -class TiXmlOutStream : public TiXmlString -{ -public : - - // TiXmlOutStream << operator. - TiXmlOutStream & operator << (const TiXmlString & in) - { - *this += in; - return *this; - } - - // TiXmlOutStream << operator. - TiXmlOutStream & operator << (const char * in) - { - *this += in; - return *this; - } - -} ; - -#endif // TIXML_STRING_INCLUDED -#endif // TIXML_USE_STL diff --git a/project/jni/application/fheroes2/src/xmlccwrap/tinyxml.cpp b/project/jni/application/fheroes2/src/xmlccwrap/tinyxml.cpp deleted file mode 100644 index 83690bd99..000000000 --- a/project/jni/application/fheroes2/src/xmlccwrap/tinyxml.cpp +++ /dev/null @@ -1,1888 +0,0 @@ -/* -www.sourceforge.net/projects/tinyxml -Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - -#include - -#ifdef TIXML_USE_STL -#include -#include -#endif - -#include "tinyxml.h" - - -bool TiXmlBase::condenseWhiteSpace = true; - -// Microsoft compiler security -FILE* TiXmlFOpen( const char* filename, const char* mode ) -{ - #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) - FILE* fp = 0; - errno_t err = fopen_s( &fp, filename, mode ); - if ( !err && fp ) - return fp; - return 0; - #else - return fopen( filename, mode ); - #endif -} - -void TiXmlBase::EncodeString( const TIXML_STRING& str, TIXML_STRING* outString ) -{ - int i=0; - - while( i<(int)str.length() ) - { - unsigned char c = (unsigned char) str[i]; - - if ( c == '&' - && i < ( (int)str.length() - 2 ) - && str[i+1] == '#' - && str[i+2] == 'x' ) - { - // Hexadecimal character reference. - // Pass through unchanged. - // © -- copyright symbol, for example. - // - // The -1 is a bug fix from Rob Laveaux. It keeps - // an overflow from happening if there is no ';'. - // There are actually 2 ways to exit this loop - - // while fails (error case) and break (semicolon found). - // However, there is no mechanism (currently) for - // this function to return an error. - while ( i<(int)str.length()-1 ) - { - outString->append( str.c_str() + i, 1 ); - ++i; - if ( str[i] == ';' ) - break; - } - } - else if ( c == '&' ) - { - outString->append( entity[0].str, entity[0].strLength ); - ++i; - } - else if ( c == '<' ) - { - outString->append( entity[1].str, entity[1].strLength ); - ++i; - } - else if ( c == '>' ) - { - outString->append( entity[2].str, entity[2].strLength ); - ++i; - } - else if ( c == '\"' ) - { - outString->append( entity[3].str, entity[3].strLength ); - ++i; - } - else if ( c == '\'' ) - { - outString->append( entity[4].str, entity[4].strLength ); - ++i; - } - else if ( c < 32 ) - { - // Easy pass at non-alpha/numeric/symbol - // Below 32 is symbolic. - char buf[ 32 ]; - - #if defined(TIXML_SNPRINTF) - TIXML_SNPRINTF( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); - #else - sprintf( buf, "&#x%02X;", (unsigned) ( c & 0xff ) ); - #endif - - //*ME: warning C4267: convert 'size_t' to 'int' - //*ME: Int-Cast to make compiler happy ... - outString->append( buf, (int)strlen( buf ) ); - ++i; - } - else - { - //char realc = (char) c; - //outString->append( &realc, 1 ); - *outString += (char) c; // somewhat more efficient function call. - ++i; - } - } -} - - -TiXmlNode::TiXmlNode( NodeType _type ) : TiXmlBase() -{ - parent = 0; - type = _type; - firstChild = 0; - lastChild = 0; - prev = 0; - next = 0; -} - - -TiXmlNode::~TiXmlNode() -{ - TiXmlNode* node = firstChild; - TiXmlNode* temp = 0; - - while ( node ) - { - temp = node; - node = node->next; - delete temp; - } -} - - -void TiXmlNode::CopyTo( TiXmlNode* target ) const -{ - target->SetValue (value.c_str() ); - target->userData = userData; -} - - -void TiXmlNode::Clear() -{ - TiXmlNode* node = firstChild; - TiXmlNode* temp = 0; - - while ( node ) - { - temp = node; - node = node->next; - delete temp; - } - - firstChild = 0; - lastChild = 0; -} - - -TiXmlNode* TiXmlNode::LinkEndChild( TiXmlNode* node ) -{ - assert( node->parent == 0 || node->parent == this ); - assert( node->GetDocument() == 0 || node->GetDocument() == this->GetDocument() ); - - if ( node->Type() == TiXmlNode::DOCUMENT ) - { - delete node; - if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - node->parent = this; - - node->prev = lastChild; - node->next = 0; - - if ( lastChild ) - lastChild->next = node; - else - firstChild = node; // it was an empty list. - - lastChild = node; - return node; -} - - -TiXmlNode* TiXmlNode::InsertEndChild( const TiXmlNode& addThis ) -{ - if ( addThis.Type() == TiXmlNode::DOCUMENT ) - { - if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - TiXmlNode* node = addThis.Clone(); - if ( !node ) - return 0; - - return LinkEndChild( node ); -} - - -TiXmlNode* TiXmlNode::InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ) -{ - if ( !beforeThis || beforeThis->parent != this ) { - return 0; - } - if ( addThis.Type() == TiXmlNode::DOCUMENT ) - { - if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - TiXmlNode* node = addThis.Clone(); - if ( !node ) - return 0; - node->parent = this; - - node->next = beforeThis; - node->prev = beforeThis->prev; - if ( beforeThis->prev ) - { - beforeThis->prev->next = node; - } - else - { - assert( firstChild == beforeThis ); - firstChild = node; - } - beforeThis->prev = node; - return node; -} - - -TiXmlNode* TiXmlNode::InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ) -{ - if ( !afterThis || afterThis->parent != this ) { - return 0; - } - if ( addThis.Type() == TiXmlNode::DOCUMENT ) - { - if ( GetDocument() ) GetDocument()->SetError( TIXML_ERROR_DOCUMENT_TOP_ONLY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - TiXmlNode* node = addThis.Clone(); - if ( !node ) - return 0; - node->parent = this; - - node->prev = afterThis; - node->next = afterThis->next; - if ( afterThis->next ) - { - afterThis->next->prev = node; - } - else - { - assert( lastChild == afterThis ); - lastChild = node; - } - afterThis->next = node; - return node; -} - - -TiXmlNode* TiXmlNode::ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ) -{ - if ( replaceThis->parent != this ) - return 0; - - TiXmlNode* node = withThis.Clone(); - if ( !node ) - return 0; - - node->next = replaceThis->next; - node->prev = replaceThis->prev; - - if ( replaceThis->next ) - replaceThis->next->prev = node; - else - lastChild = node; - - if ( replaceThis->prev ) - replaceThis->prev->next = node; - else - firstChild = node; - - delete replaceThis; - node->parent = this; - return node; -} - - -bool TiXmlNode::RemoveChild( TiXmlNode* removeThis ) -{ - if ( removeThis->parent != this ) - { - assert( 0 ); - return false; - } - - if ( removeThis->next ) - removeThis->next->prev = removeThis->prev; - else - lastChild = removeThis->prev; - - if ( removeThis->prev ) - removeThis->prev->next = removeThis->next; - else - firstChild = removeThis->next; - - delete removeThis; - return true; -} - -const TiXmlNode* TiXmlNode::FirstChild( const char * _value ) const -{ - const TiXmlNode* node; - for ( node = firstChild; node; node = node->next ) - { - if ( strcmp( node->Value(), _value ) == 0 ) - return node; - } - return 0; -} - - -const TiXmlNode* TiXmlNode::LastChild( const char * _value ) const -{ - const TiXmlNode* node; - for ( node = lastChild; node; node = node->prev ) - { - if ( strcmp( node->Value(), _value ) == 0 ) - return node; - } - return 0; -} - - -const TiXmlNode* TiXmlNode::IterateChildren( const TiXmlNode* previous ) const -{ - if ( !previous ) - { - return FirstChild(); - } - else - { - assert( previous->parent == this ); - return previous->NextSibling(); - } -} - - -const TiXmlNode* TiXmlNode::IterateChildren( const char * val, const TiXmlNode* previous ) const -{ - if ( !previous ) - { - return FirstChild( val ); - } - else - { - assert( previous->parent == this ); - return previous->NextSibling( val ); - } -} - - -const TiXmlNode* TiXmlNode::NextSibling( const char * _value ) const -{ - const TiXmlNode* node; - for ( node = next; node; node = node->next ) - { - if ( strcmp( node->Value(), _value ) == 0 ) - return node; - } - return 0; -} - - -const TiXmlNode* TiXmlNode::PreviousSibling( const char * _value ) const -{ - const TiXmlNode* node; - for ( node = prev; node; node = node->prev ) - { - if ( strcmp( node->Value(), _value ) == 0 ) - return node; - } - return 0; -} - - -void TiXmlElement::RemoveAttribute( const char * name ) -{ - #ifdef TIXML_USE_STL - TIXML_STRING str( name ); - TiXmlAttribute* node = attributeSet.Find( str ); - #else - TiXmlAttribute* node = attributeSet.Find( name ); - #endif - if ( node ) - { - attributeSet.Remove( node ); - delete node; - } -} - -const TiXmlElement* TiXmlNode::FirstChildElement() const -{ - const TiXmlNode* node; - - for ( node = FirstChild(); - node; - node = node->NextSibling() ) - { - if ( node->ToElement() ) - return node->ToElement(); - } - return 0; -} - - -const TiXmlElement* TiXmlNode::FirstChildElement( const char * _value ) const -{ - const TiXmlNode* node; - - for ( node = FirstChild( _value ); - node; - node = node->NextSibling( _value ) ) - { - if ( node->ToElement() ) - return node->ToElement(); - } - return 0; -} - - -const TiXmlElement* TiXmlNode::NextSiblingElement() const -{ - const TiXmlNode* node; - - for ( node = NextSibling(); - node; - node = node->NextSibling() ) - { - if ( node->ToElement() ) - return node->ToElement(); - } - return 0; -} - - -const TiXmlElement* TiXmlNode::NextSiblingElement( const char * _value ) const -{ - const TiXmlNode* node; - - for ( node = NextSibling( _value ); - node; - node = node->NextSibling( _value ) ) - { - if ( node->ToElement() ) - return node->ToElement(); - } - return 0; -} - - -const TiXmlDocument* TiXmlNode::GetDocument() const -{ - const TiXmlNode* node; - - for( node = this; node; node = node->parent ) - { - if ( node->ToDocument() ) - return node->ToDocument(); - } - return 0; -} - - -TiXmlElement::TiXmlElement (const char * _value) - : TiXmlNode( TiXmlNode::ELEMENT ) -{ - firstChild = lastChild = 0; - value = _value; -} - - -#ifdef TIXML_USE_STL -TiXmlElement::TiXmlElement( const std::string& _value ) - : TiXmlNode( TiXmlNode::ELEMENT ) -{ - firstChild = lastChild = 0; - value = _value; -} -#endif - - -TiXmlElement::TiXmlElement( const TiXmlElement& copy) - : TiXmlNode( TiXmlNode::ELEMENT ) -{ - firstChild = lastChild = 0; - copy.CopyTo( this ); -} - - -void TiXmlElement::operator=( const TiXmlElement& base ) -{ - ClearThis(); - base.CopyTo( this ); -} - - -TiXmlElement::~TiXmlElement() -{ - ClearThis(); -} - - -void TiXmlElement::ClearThis() -{ - Clear(); - while( attributeSet.First() ) - { - TiXmlAttribute* node = attributeSet.First(); - attributeSet.Remove( node ); - delete node; - } -} - - -const char* TiXmlElement::Attribute( const char* name ) const -{ - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( node ) - return node->Value(); - return 0; -} - - -#ifdef TIXML_USE_STL -const std::string* TiXmlElement::Attribute( const std::string& name ) const -{ - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( node ) - return &node->ValueStr(); - return 0; -} -#endif - - -const char* TiXmlElement::Attribute( const char* name, int* i ) const -{ - const char* s = Attribute( name ); - if ( i ) - { - if ( s ) { - *i = atoi( s ); - } - else { - *i = 0; - } - } - return s; -} - - -#ifdef TIXML_USE_STL -const std::string* TiXmlElement::Attribute( const std::string& name, int* i ) const -{ - const std::string* s = Attribute( name ); - if ( i ) - { - if ( s ) { - *i = atoi( s->c_str() ); - } - else { - *i = 0; - } - } - return s; -} -#endif - - -const char* TiXmlElement::Attribute( const char* name, double* d ) const -{ - const char* s = Attribute( name ); - if ( d ) - { - if ( s ) { - *d = atof( s ); - } - else { - *d = 0; - } - } - return s; -} - - -#ifdef TIXML_USE_STL -const std::string* TiXmlElement::Attribute( const std::string& name, double* d ) const -{ - const std::string* s = Attribute( name ); - if ( d ) - { - if ( s ) { - *d = atof( s->c_str() ); - } - else { - *d = 0; - } - } - return s; -} -#endif - - -int TiXmlElement::QueryIntAttribute( const char* name, int* ival ) const -{ - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - return node->QueryIntValue( ival ); -} - - -#ifdef TIXML_USE_STL -int TiXmlElement::QueryIntAttribute( const std::string& name, int* ival ) const -{ - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - return node->QueryIntValue( ival ); -} -#endif - - -int TiXmlElement::QueryDoubleAttribute( const char* name, double* dval ) const -{ - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - return node->QueryDoubleValue( dval ); -} - - -#ifdef TIXML_USE_STL -int TiXmlElement::QueryDoubleAttribute( const std::string& name, double* dval ) const -{ - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - return node->QueryDoubleValue( dval ); -} -#endif - - -void TiXmlElement::SetAttribute( const char * name, int val ) -{ - char buf[64]; - #if defined(TIXML_SNPRINTF) - TIXML_SNPRINTF( buf, sizeof(buf), "%d", val ); - #else - sprintf( buf, "%d", val ); - #endif - SetAttribute( name, buf ); -} - - -#ifdef TIXML_USE_STL -void TiXmlElement::SetAttribute( const std::string& name, int val ) -{ - std::ostringstream oss; - oss << val; - SetAttribute( name, oss.str() ); -} -#endif - - -void TiXmlElement::SetDoubleAttribute( const char * name, double val ) -{ - char buf[256]; - #if defined(TIXML_SNPRINTF) - TIXML_SNPRINTF( buf, sizeof(buf), "%f", val ); - #else - sprintf( buf, "%f", val ); - #endif - SetAttribute( name, buf ); -} - - -void TiXmlElement::SetAttribute( const char * cname, const char * cvalue ) -{ - #ifdef TIXML_USE_STL - TIXML_STRING _name( cname ); - TIXML_STRING _value( cvalue ); - #else - const char* _name = cname; - const char* _value = cvalue; - #endif - - TiXmlAttribute* node = attributeSet.Find( _name ); - if ( node ) - { - node->SetValue( _value ); - return; - } - - TiXmlAttribute* attrib = new TiXmlAttribute( cname, cvalue ); - if ( attrib ) - { - attributeSet.Add( attrib ); - } - else - { - TiXmlDocument* document = GetDocument(); - if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN ); - } -} - - -#ifdef TIXML_USE_STL -void TiXmlElement::SetAttribute( const std::string& name, const std::string& _value ) -{ - TiXmlAttribute* node = attributeSet.Find( name ); - if ( node ) - { - node->SetValue( _value ); - return; - } - - TiXmlAttribute* attrib = new TiXmlAttribute( name, _value ); - if ( attrib ) - { - attributeSet.Add( attrib ); - } - else - { - TiXmlDocument* document = GetDocument(); - if ( document ) document->SetError( TIXML_ERROR_OUT_OF_MEMORY, 0, 0, TIXML_ENCODING_UNKNOWN ); - } -} -#endif - - -void TiXmlElement::Print( FILE* cfile, int depth ) const -{ - int i; - assert( cfile ); - for ( i=0; iNext() ) - { - fprintf( cfile, " " ); - attrib->Print( cfile, depth ); - } - - // There are 3 different formatting approaches: - // 1) An element without children is printed as a node - // 2) An element with only a text child is printed as text - // 3) An element with children is printed on multiple lines. - TiXmlNode* node; - if ( !firstChild ) - { - fprintf( cfile, " />" ); - } - else if ( firstChild == lastChild && firstChild->ToText() ) - { - fprintf( cfile, ">" ); - firstChild->Print( cfile, depth + 1 ); - fprintf( cfile, "", value.c_str() ); - } - else - { - fprintf( cfile, ">" ); - - for ( node = firstChild; node; node=node->NextSibling() ) - { - if ( !node->ToText() ) - { - fprintf( cfile, "\n" ); - } - node->Print( cfile, depth+1 ); - } - fprintf( cfile, "\n" ); - for( i=0; i", value.c_str() ); - } -} - - -void TiXmlElement::CopyTo( TiXmlElement* target ) const -{ - // superclass: - TiXmlNode::CopyTo( target ); - - // Element class: - // Clone the attributes, then clone the children. - const TiXmlAttribute* attribute = 0; - for( attribute = attributeSet.First(); - attribute; - attribute = attribute->Next() ) - { - target->SetAttribute( attribute->Name(), attribute->Value() ); - } - - TiXmlNode* node = 0; - for ( node = firstChild; node; node = node->NextSibling() ) - { - target->LinkEndChild( node->Clone() ); - } -} - -bool TiXmlElement::Accept( TiXmlVisitor* visitor ) const -{ - if ( visitor->VisitEnter( *this, attributeSet.First() ) ) - { - for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) - { - if ( !node->Accept( visitor ) ) - break; - } - } - return visitor->VisitExit( *this ); -} - - -TiXmlNode* TiXmlElement::Clone() const -{ - TiXmlElement* clone = new TiXmlElement( Value() ); - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -const char* TiXmlElement::GetText() const -{ - const TiXmlNode* child = this->FirstChild(); - if ( child ) { - const TiXmlText* childText = child->ToText(); - if ( childText ) { - return childText->Value(); - } - } - return 0; -} - - -TiXmlDocument::TiXmlDocument() : TiXmlNode( TiXmlNode::DOCUMENT ) -{ - tabsize = 4; - useMicrosoftBOM = false; - ClearError(); -} - -TiXmlDocument::TiXmlDocument( const char * documentName ) : TiXmlNode( TiXmlNode::DOCUMENT ) -{ - tabsize = 4; - useMicrosoftBOM = false; - value = documentName; - ClearError(); -} - - -#ifdef TIXML_USE_STL -TiXmlDocument::TiXmlDocument( const std::string& documentName ) : TiXmlNode( TiXmlNode::DOCUMENT ) -{ - tabsize = 4; - useMicrosoftBOM = false; - value = documentName; - ClearError(); -} -#endif - - -TiXmlDocument::TiXmlDocument( const TiXmlDocument& copy ) : TiXmlNode( TiXmlNode::DOCUMENT ) -{ - copy.CopyTo( this ); -} - - -void TiXmlDocument::operator=( const TiXmlDocument& copy ) -{ - Clear(); - copy.CopyTo( this ); -} - - -bool TiXmlDocument::LoadFile( TiXmlEncoding encoding ) -{ - // See STL_STRING_BUG below. - //StringToBuffer buf( value ); - - return LoadFile( Value(), encoding ); -} - - -bool TiXmlDocument::SaveFile() const -{ - // See STL_STRING_BUG below. -// StringToBuffer buf( value ); -// -// if ( buf.buffer && SaveFile( buf.buffer ) ) -// return true; -// -// return false; - return SaveFile( Value() ); -} - -bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding ) -{ - // There was a really terrifying little bug here. The code: - // value = filename - // in the STL case, cause the assignment method of the std::string to - // be called. What is strange, is that the std::string had the same - // address as it's c_str() method, and so bad things happen. Looks - // like a bug in the Microsoft STL implementation. - // Add an extra string to avoid the crash. - TIXML_STRING filename( _filename ); - value = filename; - - // reading in binary mode so that tinyxml can normalize the EOL - FILE* file = TiXmlFOpen( value.c_str (), "rb" ); - - if ( file ) - { - bool result = LoadFile( file, encoding ); - fclose( file ); - return result; - } - else - { - SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); - return false; - } -} - -bool TiXmlDocument::LoadFile( FILE* file, TiXmlEncoding encoding ) -{ - if ( !file ) - { - SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); - return false; - } - - // Delete the existing data: - Clear(); - location.Clear(); - - // Get the file size, so we can pre-allocate the string. HUGE speed impact. - long length = 0; - fseek( file, 0, SEEK_END ); - length = ftell( file ); - fseek( file, 0, SEEK_SET ); - - // Strange case, but good to handle up front. - if ( length <= 0 ) - { - SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return false; - } - - // If we have a file, assume it is all one big XML file, and read it in. - // The document parser may decide the document ends sooner than the entire file, however. - TIXML_STRING data; - data.reserve( length ); - - // Subtle bug here. TinyXml did use fgets. But from the XML spec: - // 2.11 End-of-Line Handling - // - // - // ...the XML processor MUST behave as if it normalized all line breaks in external - // parsed entities (including the document entity) on input, before parsing, by translating - // both the two-character sequence #xD #xA and any #xD that is not followed by #xA to - // a single #xA character. - // - // - // It is not clear fgets does that, and certainly isn't clear it works cross platform. - // Generally, you expect fgets to translate from the convention of the OS to the c/unix - // convention, and not work generally. - - /* - while( fgets( buf, sizeof(buf), file ) ) - { - data += buf; - } - */ - - char* buf = new char[ length+1 ]; - buf[0] = 0; - - if ( fread( buf, length, 1, file ) != 1 ) { - delete [] buf; - SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); - return false; - } - - const char* lastPos = buf; - const char* p = buf; - - buf[length] = 0; - while( *p ) { - assert( p < (buf+length) ); - if ( *p == 0xa ) { - // Newline character. No special rules for this. Append all the characters - // since the last string, and include the newline. - data.append( lastPos, (p-lastPos+1) ); // append, include the newline - ++p; // move past the newline - lastPos = p; // and point to the new buffer (may be 0) - assert( p <= (buf+length) ); - } - else if ( *p == 0xd ) { - // Carriage return. Append what we have so far, then - // handle moving forward in the buffer. - if ( (p-lastPos) > 0 ) { - data.append( lastPos, p-lastPos ); // do not add the CR - } - data += (char)0xa; // a proper newline - - if ( *(p+1) == 0xa ) { - // Carriage return - new line sequence - p += 2; - lastPos = p; - assert( p <= (buf+length) ); - } - else { - // it was followed by something else...that is presumably characters again. - ++p; - lastPos = p; - assert( p <= (buf+length) ); - } - } - else { - ++p; - } - } - // Handle any left over characters. - if ( p-lastPos ) { - data.append( lastPos, p-lastPos ); - } - delete [] buf; - buf = 0; - - Parse( data.c_str(), 0, encoding ); - - if ( Error() ) - return false; - else - return true; -} - - -bool TiXmlDocument::SaveFile( const char * filename ) const -{ - // The old c stuff lives on... - FILE* fp = TiXmlFOpen( filename, "w" ); - if ( fp ) - { - bool result = SaveFile( fp ); - fclose( fp ); - return result; - } - return false; -} - - -bool TiXmlDocument::SaveFile( FILE* fp ) const -{ - if ( useMicrosoftBOM ) - { - const unsigned char TIXML_UTF_LEAD_0 = 0xefU; - const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; - const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; - - fputc( TIXML_UTF_LEAD_0, fp ); - fputc( TIXML_UTF_LEAD_1, fp ); - fputc( TIXML_UTF_LEAD_2, fp ); - } - Print( fp, 0 ); - return (ferror(fp) == 0); -} - - -void TiXmlDocument::CopyTo( TiXmlDocument* target ) const -{ - TiXmlNode::CopyTo( target ); - - target->error = error; - target->errorId = errorId; - target->errorDesc = errorDesc; - target->tabsize = tabsize; - target->errorLocation = errorLocation; - target->useMicrosoftBOM = useMicrosoftBOM; - - TiXmlNode* node = 0; - for ( node = firstChild; node; node = node->NextSibling() ) - { - target->LinkEndChild( node->Clone() ); - } -} - - -TiXmlNode* TiXmlDocument::Clone() const -{ - TiXmlDocument* clone = new TiXmlDocument(); - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -void TiXmlDocument::Print( FILE* cfile, int depth ) const -{ - assert( cfile ); - for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) - { - node->Print( cfile, depth ); - fprintf( cfile, "\n" ); - } -} - - -bool TiXmlDocument::Accept( TiXmlVisitor* visitor ) const -{ - if ( visitor->VisitEnter( *this ) ) - { - for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() ) - { - if ( !node->Accept( visitor ) ) - break; - } - } - return visitor->VisitExit( *this ); -} - - -const TiXmlAttribute* TiXmlAttribute::Next() const -{ - // We are using knowledge of the sentinel. The sentinel - // have a value or name. - if ( next->value.empty() && next->name.empty() ) - return 0; - return next; -} - -/* -TiXmlAttribute* TiXmlAttribute::Next() -{ - // We are using knowledge of the sentinel. The sentinel - // have a value or name. - if ( next->value.empty() && next->name.empty() ) - return 0; - return next; -} -*/ - -const TiXmlAttribute* TiXmlAttribute::Previous() const -{ - // We are using knowledge of the sentinel. The sentinel - // have a value or name. - if ( prev->value.empty() && prev->name.empty() ) - return 0; - return prev; -} - -/* -TiXmlAttribute* TiXmlAttribute::Previous() -{ - // We are using knowledge of the sentinel. The sentinel - // have a value or name. - if ( prev->value.empty() && prev->name.empty() ) - return 0; - return prev; -} -*/ - -void TiXmlAttribute::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const -{ - TIXML_STRING n, v; - - EncodeString( name, &n ); - EncodeString( value, &v ); - - if (value.find ('\"') == TIXML_STRING::npos) { - if ( cfile ) { - fprintf (cfile, "%s=\"%s\"", n.c_str(), v.c_str() ); - } - if ( str ) { - (*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\""; - } - } - else { - if ( cfile ) { - fprintf (cfile, "%s='%s'", n.c_str(), v.c_str() ); - } - if ( str ) { - (*str) += n; (*str) += "='"; (*str) += v; (*str) += "'"; - } - } -} - - -int TiXmlAttribute::QueryIntValue( int* ival ) const -{ - if ( TIXML_SSCANF( value.c_str(), "%d", ival ) == 1 ) - return TIXML_SUCCESS; - return TIXML_WRONG_TYPE; -} - -int TiXmlAttribute::QueryDoubleValue( double* dval ) const -{ - if ( TIXML_SSCANF( value.c_str(), "%lf", dval ) == 1 ) - return TIXML_SUCCESS; - return TIXML_WRONG_TYPE; -} - -void TiXmlAttribute::SetIntValue( int _value ) -{ - char buf [64]; - #if defined(TIXML_SNPRINTF) - TIXML_SNPRINTF(buf, sizeof(buf), "%d", _value); - #else - sprintf (buf, "%d", _value); - #endif - SetValue (buf); -} - -void TiXmlAttribute::SetDoubleValue( double _value ) -{ - char buf [256]; - #if defined(TIXML_SNPRINTF) - TIXML_SNPRINTF( buf, sizeof(buf), "%g", _value); - #else - sprintf (buf, "%g", _value); - #endif - SetValue (buf); -} - -int TiXmlAttribute::IntValue() const -{ - return atoi (value.c_str ()); -} - -double TiXmlAttribute::DoubleValue() const -{ - return atof (value.c_str ()); -} - - -TiXmlComment::TiXmlComment( const TiXmlComment& copy ) : TiXmlNode( TiXmlNode::COMMENT ) -{ - copy.CopyTo( this ); -} - - -void TiXmlComment::operator=( const TiXmlComment& base ) -{ - Clear(); - base.CopyTo( this ); -} - - -void TiXmlComment::Print( FILE* cfile, int depth ) const -{ - assert( cfile ); - for ( int i=0; i", value.c_str() ); -} - - -void TiXmlComment::CopyTo( TiXmlComment* target ) const -{ - TiXmlNode::CopyTo( target ); -} - - -bool TiXmlComment::Accept( TiXmlVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -TiXmlNode* TiXmlComment::Clone() const -{ - TiXmlComment* clone = new TiXmlComment(); - - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -void TiXmlText::Print( FILE* cfile, int depth ) const -{ - assert( cfile ); - if ( cdata ) - { - int i; - fprintf( cfile, "\n" ); - for ( i=0; i\n", value.c_str() ); // unformatted output - } - else - { - TIXML_STRING buffer; - EncodeString( value, &buffer ); - fprintf( cfile, "%s", buffer.c_str() ); - } -} - - -void TiXmlText::CopyTo( TiXmlText* target ) const -{ - TiXmlNode::CopyTo( target ); - target->cdata = cdata; -} - - -bool TiXmlText::Accept( TiXmlVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -TiXmlNode* TiXmlText::Clone() const -{ - TiXmlText* clone = 0; - clone = new TiXmlText( "" ); - - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -TiXmlDeclaration::TiXmlDeclaration( const char * _version, - const char * _encoding, - const char * _standalone ) - : TiXmlNode( TiXmlNode::DECLARATION ) -{ - version = _version; - encoding = _encoding; - standalone = _standalone; -} - - -#ifdef TIXML_USE_STL -TiXmlDeclaration::TiXmlDeclaration( const std::string& _version, - const std::string& _encoding, - const std::string& _standalone ) - : TiXmlNode( TiXmlNode::DECLARATION ) -{ - version = _version; - encoding = _encoding; - standalone = _standalone; -} -#endif - - -TiXmlDeclaration::TiXmlDeclaration( const TiXmlDeclaration& copy ) - : TiXmlNode( TiXmlNode::DECLARATION ) -{ - copy.CopyTo( this ); -} - - -void TiXmlDeclaration::operator=( const TiXmlDeclaration& copy ) -{ - Clear(); - copy.CopyTo( this ); -} - - -void TiXmlDeclaration::Print( FILE* cfile, int /*depth*/, TIXML_STRING* str ) const -{ - if ( cfile ) fprintf( cfile, "" ); - if ( str ) (*str) += "?>"; -} - - -void TiXmlDeclaration::CopyTo( TiXmlDeclaration* target ) const -{ - TiXmlNode::CopyTo( target ); - - target->version = version; - target->encoding = encoding; - target->standalone = standalone; -} - - -bool TiXmlDeclaration::Accept( TiXmlVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -TiXmlNode* TiXmlDeclaration::Clone() const -{ - TiXmlDeclaration* clone = new TiXmlDeclaration(); - - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -void TiXmlUnknown::Print( FILE* cfile, int depth ) const -{ - for ( int i=0; i", value.c_str() ); -} - - -void TiXmlUnknown::CopyTo( TiXmlUnknown* target ) const -{ - TiXmlNode::CopyTo( target ); -} - - -bool TiXmlUnknown::Accept( TiXmlVisitor* visitor ) const -{ - return visitor->Visit( *this ); -} - - -TiXmlNode* TiXmlUnknown::Clone() const -{ - TiXmlUnknown* clone = new TiXmlUnknown(); - - if ( !clone ) - return 0; - - CopyTo( clone ); - return clone; -} - - -TiXmlAttributeSet::TiXmlAttributeSet() -{ - sentinel.next = &sentinel; - sentinel.prev = &sentinel; -} - - -TiXmlAttributeSet::~TiXmlAttributeSet() -{ - assert( sentinel.next == &sentinel ); - assert( sentinel.prev == &sentinel ); -} - - -void TiXmlAttributeSet::Add( TiXmlAttribute* addMe ) -{ - #ifdef TIXML_USE_STL - assert( !Find( TIXML_STRING( addMe->Name() ) ) ); // Shouldn't be multiply adding to the set. - #else - assert( !Find( addMe->Name() ) ); // Shouldn't be multiply adding to the set. - #endif - - addMe->next = &sentinel; - addMe->prev = sentinel.prev; - - sentinel.prev->next = addMe; - sentinel.prev = addMe; -} - -void TiXmlAttributeSet::Remove( TiXmlAttribute* removeMe ) -{ - TiXmlAttribute* node; - - for( node = sentinel.next; node != &sentinel; node = node->next ) - { - if ( node == removeMe ) - { - node->prev->next = node->next; - node->next->prev = node->prev; - node->next = 0; - node->prev = 0; - return; - } - } - assert( 0 ); // we tried to remove a non-linked attribute. -} - - -#ifdef TIXML_USE_STL -const TiXmlAttribute* TiXmlAttributeSet::Find( const std::string& name ) const -{ - for( const TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) - { - if ( node->name == name ) - return node; - } - return 0; -} - -/* -TiXmlAttribute* TiXmlAttributeSet::Find( const std::string& name ) -{ - for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) - { - if ( node->name == name ) - return node; - } - return 0; -} -*/ -#endif - - -const TiXmlAttribute* TiXmlAttributeSet::Find( const char* name ) const -{ - for( const TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) - { - if ( strcmp( node->name.c_str(), name ) == 0 ) - return node; - } - return 0; -} - -/* -TiXmlAttribute* TiXmlAttributeSet::Find( const char* name ) -{ - for( TiXmlAttribute* node = sentinel.next; node != &sentinel; node = node->next ) - { - if ( strcmp( node->name.c_str(), name ) == 0 ) - return node; - } - return 0; -} -*/ - -#ifdef TIXML_USE_STL -std::istream& operator>> (std::istream & in, TiXmlNode & base) -{ - TIXML_STRING tag; - tag.reserve( 8 * 1000 ); - base.StreamIn( &in, &tag ); - - base.Parse( tag.c_str(), 0, TIXML_DEFAULT_ENCODING ); - return in; -} -#endif - - -#ifdef TIXML_USE_STL -std::ostream& operator<< (std::ostream & out, const TiXmlNode & base) -{ - TiXmlPrinter printer; - printer.SetStreamPrinting(); - base.Accept( &printer ); - out << printer.Str(); - - return out; -} - - -std::string& operator<< (std::string& out, const TiXmlNode& base ) -{ - TiXmlPrinter printer; - printer.SetStreamPrinting(); - base.Accept( &printer ); - out.append( printer.Str() ); - - return out; -} -#endif - - -TiXmlHandle TiXmlHandle::FirstChild() const -{ - if ( node ) - { - TiXmlNode* child = node->FirstChild(); - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::FirstChild( const char * value ) const -{ - if ( node ) - { - TiXmlNode* child = node->FirstChild( value ); - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::FirstChildElement() const -{ - if ( node ) - { - TiXmlElement* child = node->FirstChildElement(); - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::FirstChildElement( const char * value ) const -{ - if ( node ) - { - TiXmlElement* child = node->FirstChildElement( value ); - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::Child( int count ) const -{ - if ( node ) - { - int i; - TiXmlNode* child = node->FirstChild(); - for ( i=0; - child && iNextSibling(), ++i ) - { - // nothing - } - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::Child( const char* value, int count ) const -{ - if ( node ) - { - int i; - TiXmlNode* child = node->FirstChild( value ); - for ( i=0; - child && iNextSibling( value ), ++i ) - { - // nothing - } - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::ChildElement( int count ) const -{ - if ( node ) - { - int i; - TiXmlElement* child = node->FirstChildElement(); - for ( i=0; - child && iNextSiblingElement(), ++i ) - { - // nothing - } - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -TiXmlHandle TiXmlHandle::ChildElement( const char* value, int count ) const -{ - if ( node ) - { - int i; - TiXmlElement* child = node->FirstChildElement( value ); - for ( i=0; - child && iNextSiblingElement( value ), ++i ) - { - // nothing - } - if ( child ) - return TiXmlHandle( child ); - } - return TiXmlHandle( 0 ); -} - - -bool TiXmlPrinter::VisitEnter( const TiXmlDocument& ) -{ - return true; -} - -bool TiXmlPrinter::VisitExit( const TiXmlDocument& ) -{ - return true; -} - -bool TiXmlPrinter::VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ) -{ - DoIndent(); - buffer += "<"; - buffer += element.Value(); - - for( const TiXmlAttribute* attrib = firstAttribute; attrib; attrib = attrib->Next() ) - { - buffer += " "; - attrib->Print( 0, 0, &buffer ); - } - - if ( !element.FirstChild() ) - { - buffer += " />"; - DoLineBreak(); - } - else - { - buffer += ">"; - if ( element.FirstChild()->ToText() - && element.LastChild() == element.FirstChild() - && element.FirstChild()->ToText()->CDATA() == false ) - { - simpleTextPrint = true; - // no DoLineBreak()! - } - else - { - DoLineBreak(); - } - } - ++depth; - return true; -} - - -bool TiXmlPrinter::VisitExit( const TiXmlElement& element ) -{ - --depth; - if ( !element.FirstChild() ) - { - // nothing. - } - else - { - if ( simpleTextPrint ) - { - simpleTextPrint = false; - } - else - { - DoIndent(); - } - buffer += ""; - DoLineBreak(); - } - return true; -} - - -bool TiXmlPrinter::Visit( const TiXmlText& text ) -{ - if ( text.CDATA() ) - { - DoIndent(); - buffer += ""; - DoLineBreak(); - } - else if ( simpleTextPrint ) - { - TIXML_STRING str; - TiXmlBase::EncodeString( text.ValueTStr(), &str ); - buffer += str; - } - else - { - DoIndent(); - TIXML_STRING str; - TiXmlBase::EncodeString( text.ValueTStr(), &str ); - buffer += str; - DoLineBreak(); - } - return true; -} - - -bool TiXmlPrinter::Visit( const TiXmlDeclaration& declaration ) -{ - DoIndent(); - declaration.Print( 0, 0, &buffer ); - DoLineBreak(); - return true; -} - - -bool TiXmlPrinter::Visit( const TiXmlComment& comment ) -{ - DoIndent(); - buffer += ""; - DoLineBreak(); - return true; -} - - -bool TiXmlPrinter::Visit( const TiXmlUnknown& unknown ) -{ - DoIndent(); - buffer += "<"; - buffer += unknown.Value(); - buffer += ">"; - DoLineBreak(); - return true; -} - diff --git a/project/jni/application/fheroes2/src/xmlccwrap/tinyxml.h b/project/jni/application/fheroes2/src/xmlccwrap/tinyxml.h deleted file mode 100644 index c6f40cc27..000000000 --- a/project/jni/application/fheroes2/src/xmlccwrap/tinyxml.h +++ /dev/null @@ -1,1802 +0,0 @@ -/* -www.sourceforge.net/projects/tinyxml -Original code (2.0 and earlier )copyright (c) 2000-2006 Lee Thomason (www.grinninglizard.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - - -#ifndef TINYXML_INCLUDED -#define TINYXML_INCLUDED - -#ifdef _MSC_VER -#pragma warning( push ) -#pragma warning( disable : 4530 ) -#pragma warning( disable : 4786 ) -#endif - -#include -#include -#include -#include -#include - -// Help out windows: -#if defined( _DEBUG ) && !defined( DEBUG ) -#define DEBUG -#endif - -#ifdef TIXML_USE_STL - #include - #include - #include - #define TIXML_STRING std::string -#else - #include "tinystr.h" - #define TIXML_STRING TiXmlString -#endif - -// Deprecated library function hell. Compilers want to use the -// new safe versions. This probably doesn't fully address the problem, -// but it gets closer. There are too many compilers for me to fully -// test. If you get compilation troubles, undefine TIXML_SAFE -#define TIXML_SAFE - -#ifdef TIXML_SAFE - #if defined(_MSC_VER) && (_MSC_VER >= 1400 ) - // Microsoft visual studio, version 2005 and higher. - #define TIXML_SNPRINTF _snprintf_s - #define TIXML_SNSCANF _snscanf_s - #define TIXML_SSCANF sscanf_s - #elif defined(_MSC_VER) && (_MSC_VER >= 1200 ) - // Microsoft visual studio, version 6 and higher. - //#pragma message( "Using _sn* functions." ) - #define TIXML_SNPRINTF _snprintf - #define TIXML_SNSCANF _snscanf - #define TIXML_SSCANF sscanf - #elif defined(__GNUC__) && (__GNUC__ >= 3 ) - // GCC version 3 and higher.s - //#warning( "Using sn* functions." ) - #define TIXML_SNPRINTF snprintf - #define TIXML_SNSCANF snscanf - #define TIXML_SSCANF sscanf - #else - #define TIXML_SSCANF sscanf - #endif -#endif - -class TiXmlDocument; -class TiXmlElement; -class TiXmlComment; -class TiXmlUnknown; -class TiXmlAttribute; -class TiXmlText; -class TiXmlDeclaration; -class TiXmlParsingData; - -const int TIXML_MAJOR_VERSION = 2; -const int TIXML_MINOR_VERSION = 5; -const int TIXML_PATCH_VERSION = 3; - -/* Internal structure for tracking location of items - in the XML file. -*/ -struct TiXmlCursor -{ - TiXmlCursor() { Clear(); } - void Clear() { row = col = -1; } - - int row; // 0 based. - int col; // 0 based. -}; - - -/** - If you call the Accept() method, it requires being passed a TiXmlVisitor - class to handle callbacks. For nodes that contain other nodes (Document, Element) - you will get called with a VisitEnter/VisitExit pair. Nodes that are always leaves - are simple called with Visit(). - - If you return 'true' from a Visit method, recursive parsing will continue. If you return - false, no children of this node or its sibilings will be Visited. - - All flavors of Visit methods have a default implementation that returns 'true' (continue - visiting). You need to only override methods that are interesting to you. - - Generally Accept() is called on the TiXmlDocument, although all nodes suppert Visiting. - - You should never change the document from a callback. - - @sa TiXmlNode::Accept() -*/ -class TiXmlVisitor -{ -public: - virtual ~TiXmlVisitor() {} - - /// Visit a document. - virtual bool VisitEnter( const TiXmlDocument& /*doc*/ ) { return true; } - /// Visit a document. - virtual bool VisitExit( const TiXmlDocument& /*doc*/ ) { return true; } - - /// Visit an element. - virtual bool VisitEnter( const TiXmlElement& /*element*/, const TiXmlAttribute* /*firstAttribute*/ ) { return true; } - /// Visit an element. - virtual bool VisitExit( const TiXmlElement& /*element*/ ) { return true; } - - /// Visit a declaration - virtual bool Visit( const TiXmlDeclaration& /*declaration*/ ) { return true; } - /// Visit a text node - virtual bool Visit( const TiXmlText& /*text*/ ) { return true; } - /// Visit a comment node - virtual bool Visit( const TiXmlComment& /*comment*/ ) { return true; } - /// Visit an unknow node - virtual bool Visit( const TiXmlUnknown& /*unknown*/ ) { return true; } -}; - -// Only used by Attribute::Query functions -enum -{ - TIXML_SUCCESS, - TIXML_NO_ATTRIBUTE, - TIXML_WRONG_TYPE -}; - - -// Used by the parsing routines. -enum TiXmlEncoding -{ - TIXML_ENCODING_UNKNOWN, - TIXML_ENCODING_UTF8, - TIXML_ENCODING_LEGACY -}; - -const TiXmlEncoding TIXML_DEFAULT_ENCODING = TIXML_ENCODING_UNKNOWN; - -/** TiXmlBase is a base class for every class in TinyXml. - It does little except to establish that TinyXml classes - can be printed and provide some utility functions. - - In XML, the document and elements can contain - other elements and other types of nodes. - - @verbatim - A Document can contain: Element (container or leaf) - Comment (leaf) - Unknown (leaf) - Declaration( leaf ) - - An Element can contain: Element (container or leaf) - Text (leaf) - Attributes (not on tree) - Comment (leaf) - Unknown (leaf) - - A Decleration contains: Attributes (not on tree) - @endverbatim -*/ -class TiXmlBase -{ - friend class TiXmlNode; - friend class TiXmlElement; - friend class TiXmlDocument; - -public: - TiXmlBase() : userData(0) {} - virtual ~TiXmlBase() {} - - /** All TinyXml classes can print themselves to a filestream - or the string class (TiXmlString in non-STL mode, std::string - in STL mode.) Either or both cfile and str can be null. - - This is a formatted print, and will insert - tabs and newlines. - - (For an unformatted stream, use the << operator.) - */ - virtual void Print( FILE* cfile, int depth ) const = 0; - - /** The world does not agree on whether white space should be kept or - not. In order to make everyone happy, these global, static functions - are provided to set whether or not TinyXml will condense all white space - into a single space or not. The default is to condense. Note changing this - value is not thread safe. - */ - static void SetCondenseWhiteSpace( bool condense ) { condenseWhiteSpace = condense; } - - /// Return the current white space setting. - static bool IsWhiteSpaceCondensed() { return condenseWhiteSpace; } - - /** Return the position, in the original source file, of this node or attribute. - The row and column are 1-based. (That is the first row and first column is - 1,1). If the returns values are 0 or less, then the parser does not have - a row and column value. - - Generally, the row and column value will be set when the TiXmlDocument::Load(), - TiXmlDocument::LoadFile(), or any TiXmlNode::Parse() is called. It will NOT be set - when the DOM was created from operator>>. - - The values reflect the initial load. Once the DOM is modified programmatically - (by adding or changing nodes and attributes) the new values will NOT update to - reflect changes in the document. - - There is a minor performance cost to computing the row and column. Computation - can be disabled if TiXmlDocument::SetTabSize() is called with 0 as the value. - - @sa TiXmlDocument::SetTabSize() - */ - int Row() const { return location.row + 1; } - int Column() const { return location.col + 1; } ///< See Row() - - void SetUserData( void* user ) { userData = user; } ///< Set a pointer to arbitrary user data. - void* GetUserData() { return userData; } ///< Get a pointer to arbitrary user data. - const void* GetUserData() const { return userData; } ///< Get a pointer to arbitrary user data. - - // Table that returs, for a given lead byte, the total number of bytes - // in the UTF-8 sequence. - static const int utf8ByteTable[256]; - - virtual const char* Parse( const char* p, - TiXmlParsingData* data, - TiXmlEncoding encoding /*= TIXML_ENCODING_UNKNOWN */ ) = 0; - - /** Expands entities in a string. Note this should not contian the tag's '<', '>', etc, - or they will be transformed into entities! - */ - static void EncodeString( const TIXML_STRING& str, TIXML_STRING* out ); - - enum - { - TIXML_NO_ERROR = 0, - TIXML_ERROR, - TIXML_ERROR_OPENING_FILE, - TIXML_ERROR_OUT_OF_MEMORY, - TIXML_ERROR_PARSING_ELEMENT, - TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, - TIXML_ERROR_READING_ELEMENT_VALUE, - TIXML_ERROR_READING_ATTRIBUTES, - TIXML_ERROR_PARSING_EMPTY, - TIXML_ERROR_READING_END_TAG, - TIXML_ERROR_PARSING_UNKNOWN, - TIXML_ERROR_PARSING_COMMENT, - TIXML_ERROR_PARSING_DECLARATION, - TIXML_ERROR_DOCUMENT_EMPTY, - TIXML_ERROR_EMBEDDED_NULL, - TIXML_ERROR_PARSING_CDATA, - TIXML_ERROR_DOCUMENT_TOP_ONLY, - - TIXML_ERROR_STRING_COUNT - }; - -protected: - - static const char* SkipWhiteSpace( const char*, TiXmlEncoding encoding ); - inline static bool IsWhiteSpace( char c ) - { - return ( isspace( (unsigned char) c ) || c == '\n' || c == '\r' ); - } - inline static bool IsWhiteSpace( int c ) - { - if ( c < 256 ) - return IsWhiteSpace( (char) c ); - return false; // Again, only truly correct for English/Latin...but usually works. - } - - #ifdef TIXML_USE_STL - static bool StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ); - static bool StreamTo( std::istream * in, int character, TIXML_STRING * tag ); - #endif - - /* Reads an XML name into the string provided. Returns - a pointer just past the last character of the name, - or 0 if the function has an error. - */ - static const char* ReadName( const char* p, TIXML_STRING* name, TiXmlEncoding encoding ); - - /* Reads text. Returns a pointer past the given end tag. - Wickedly complex options, but it keeps the (sensitive) code in one place. - */ - static const char* ReadText( const char* in, // where to start - TIXML_STRING* text, // the string read - bool ignoreWhiteSpace, // whether to keep the white space - const char* endTag, // what ends this text - bool ignoreCase, // whether to ignore case in the end tag - TiXmlEncoding encoding ); // the current encoding - - // If an entity has been found, transform it into a character. - static const char* GetEntity( const char* in, char* value, int* length, TiXmlEncoding encoding ); - - // Get a character, while interpreting entities. - // The length can be from 0 to 4 bytes. - inline static const char* GetChar( const char* p, char* _value, int* length, TiXmlEncoding encoding ) - { - assert( p ); - if ( encoding == TIXML_ENCODING_UTF8 ) - { - *length = utf8ByteTable[ *((const unsigned char*)p) ]; - assert( *length >= 0 && *length < 5 ); - } - else - { - *length = 1; - } - - if ( *length == 1 ) - { - if ( *p == '&' ) - return GetEntity( p, _value, length, encoding ); - *_value = *p; - return p+1; - } - else if ( *length ) - { - //strncpy( _value, p, *length ); // lots of compilers don't like this function (unsafe), - // and the null terminator isn't needed - for( int i=0; p[i] && i<*length; ++i ) { - _value[i] = p[i]; - } - return p + (*length); - } - else - { - // Not valid text. - return 0; - } - } - - // Return true if the next characters in the stream are any of the endTag sequences. - // Ignore case only works for english, and should only be relied on when comparing - // to English words: StringEqual( p, "version", true ) is fine. - static bool StringEqual( const char* p, - const char* endTag, - bool ignoreCase, - TiXmlEncoding encoding ); - - static const char* errorString[ TIXML_ERROR_STRING_COUNT ]; - - TiXmlCursor location; - - /// Field containing a generic user pointer - void* userData; - - // None of these methods are reliable for any language except English. - // Good for approximation, not great for accuracy. - static int IsAlpha( unsigned char anyByte, TiXmlEncoding encoding ); - static int IsAlphaNum( unsigned char anyByte, TiXmlEncoding encoding ); - inline static int ToLower( int v, TiXmlEncoding encoding ) - { - if ( encoding == TIXML_ENCODING_UTF8 ) - { - if ( v < 128 ) return tolower( v ); - return v; - } - else - { - return tolower( v ); - } - } - static void ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ); - -private: - TiXmlBase( const TiXmlBase& ); // not implemented. - void operator=( const TiXmlBase& base ); // not allowed. - - struct Entity - { - const char* str; - unsigned int strLength; - char chr; - }; - enum - { - NUM_ENTITY = 5, - MAX_ENTITY_LENGTH = 6 - - }; - static Entity entity[ NUM_ENTITY ]; - static bool condenseWhiteSpace; -}; - - -/** The parent class for everything in the Document Object Model. - (Except for attributes). - Nodes have siblings, a parent, and children. A node can be - in a document, or stand on its own. The type of a TiXmlNode - can be queried, and it can be cast to its more defined type. -*/ -class TiXmlNode : public TiXmlBase -{ - friend class TiXmlDocument; - friend class TiXmlElement; - -public: - #ifdef TIXML_USE_STL - - /** An input stream operator, for every class. Tolerant of newlines and - formatting, but doesn't expect them. - */ - friend std::istream& operator >> (std::istream& in, TiXmlNode& base); - - /** An output stream operator, for every class. Note that this outputs - without any newlines or formatting, as opposed to Print(), which - includes tabs and new lines. - - The operator<< and operator>> are not completely symmetric. Writing - a node to a stream is very well defined. You'll get a nice stream - of output, without any extra whitespace or newlines. - - But reading is not as well defined. (As it always is.) If you create - a TiXmlElement (for example) and read that from an input stream, - the text needs to define an element or junk will result. This is - true of all input streams, but it's worth keeping in mind. - - A TiXmlDocument will read nodes until it reads a root element, and - all the children of that root element. - */ - friend std::ostream& operator<< (std::ostream& out, const TiXmlNode& base); - - /// Appends the XML node or attribute to a std::string. - friend std::string& operator<< (std::string& out, const TiXmlNode& base ); - - #endif - - /** The types of XML nodes supported by TinyXml. (All the - unsupported types are picked up by UNKNOWN.) - */ - enum NodeType - { - DOCUMENT, - ELEMENT, - COMMENT, - UNKNOWN, - TEXT, - DECLARATION, - TYPECOUNT - }; - - virtual ~TiXmlNode(); - - /** The meaning of 'value' changes for the specific type of - TiXmlNode. - @verbatim - Document: filename of the xml file - Element: name of the element - Comment: the comment text - Unknown: the tag contents - Text: the text string - @endverbatim - - The subclasses will wrap this function. - */ - const char *Value() const { return value.c_str (); } - - #ifdef TIXML_USE_STL - /** Return Value() as a std::string. If you only use STL, - this is more efficient than calling Value(). - Only available in STL mode. - */ - const std::string& ValueStr() const { return value; } - #endif - - const TIXML_STRING& ValueTStr() const { return value; } - - /** Changes the value of the node. Defined as: - @verbatim - Document: filename of the xml file - Element: name of the element - Comment: the comment text - Unknown: the tag contents - Text: the text string - @endverbatim - */ - void SetValue(const char * _value) { value = _value;} - - #ifdef TIXML_USE_STL - /// STL std::string form. - void SetValue( const std::string& _value ) { value = _value; } - #endif - - /// Delete all the children of this node. Does not affect 'this'. - void Clear(); - - /// One step up the DOM. - TiXmlNode* Parent() { return parent; } - const TiXmlNode* Parent() const { return parent; } - - const TiXmlNode* FirstChild() const { return firstChild; } ///< The first child of this node. Will be null if there are no children. - TiXmlNode* FirstChild() { return firstChild; } - const TiXmlNode* FirstChild( const char * value ) const; ///< The first child of this node with the matching 'value'. Will be null if none found. - /// The first child of this node with the matching 'value'. Will be null if none found. - TiXmlNode* FirstChild( const char * _value ) { - // Call through to the const version - safe since nothing is changed. Exiting syntax: cast this to a const (always safe) - // call the method, cast the return back to non-const. - return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->FirstChild( _value )); - } - const TiXmlNode* LastChild() const { return lastChild; } /// The last child of this node. Will be null if there are no children. - TiXmlNode* LastChild() { return lastChild; } - - const TiXmlNode* LastChild( const char * value ) const; /// The last child of this node matching 'value'. Will be null if there are no children. - TiXmlNode* LastChild( const char * _value ) { - return const_cast< TiXmlNode* > ((const_cast< const TiXmlNode* >(this))->LastChild( _value )); - } - - #ifdef TIXML_USE_STL - const TiXmlNode* FirstChild( const std::string& _value ) const { return FirstChild (_value.c_str ()); } ///< STL std::string form. - TiXmlNode* FirstChild( const std::string& _value ) { return FirstChild (_value.c_str ()); } ///< STL std::string form. - const TiXmlNode* LastChild( const std::string& _value ) const { return LastChild (_value.c_str ()); } ///< STL std::string form. - TiXmlNode* LastChild( const std::string& _value ) { return LastChild (_value.c_str ()); } ///< STL std::string form. - #endif - - /** An alternate way to walk the children of a node. - One way to iterate over nodes is: - @verbatim - for( child = parent->FirstChild(); child; child = child->NextSibling() ) - @endverbatim - - IterateChildren does the same thing with the syntax: - @verbatim - child = 0; - while( child = parent->IterateChildren( child ) ) - @endverbatim - - IterateChildren takes the previous child as input and finds - the next one. If the previous child is null, it returns the - first. IterateChildren will return null when done. - */ - const TiXmlNode* IterateChildren( const TiXmlNode* previous ) const; - TiXmlNode* IterateChildren( const TiXmlNode* previous ) { - return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( previous ) ); - } - - /// This flavor of IterateChildren searches for children with a particular 'value' - const TiXmlNode* IterateChildren( const char * value, const TiXmlNode* previous ) const; - TiXmlNode* IterateChildren( const char * _value, const TiXmlNode* previous ) { - return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->IterateChildren( _value, previous ) ); - } - - #ifdef TIXML_USE_STL - const TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) const { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. - TiXmlNode* IterateChildren( const std::string& _value, const TiXmlNode* previous ) { return IterateChildren (_value.c_str (), previous); } ///< STL std::string form. - #endif - - /** Add a new node related to this. Adds a child past the LastChild. - Returns a pointer to the new object or NULL if an error occured. - */ - TiXmlNode* InsertEndChild( const TiXmlNode& addThis ); - - - /** Add a new node related to this. Adds a child past the LastChild. - - NOTE: the node to be added is passed by pointer, and will be - henceforth owned (and deleted) by tinyXml. This method is efficient - and avoids an extra copy, but should be used with care as it - uses a different memory model than the other insert functions. - - @sa InsertEndChild - */ - TiXmlNode* LinkEndChild( TiXmlNode* addThis ); - - /** Add a new node related to this. Adds a child before the specified child. - Returns a pointer to the new object or NULL if an error occured. - */ - TiXmlNode* InsertBeforeChild( TiXmlNode* beforeThis, const TiXmlNode& addThis ); - - /** Add a new node related to this. Adds a child after the specified child. - Returns a pointer to the new object or NULL if an error occured. - */ - TiXmlNode* InsertAfterChild( TiXmlNode* afterThis, const TiXmlNode& addThis ); - - /** Replace a child of this node. - Returns a pointer to the new object or NULL if an error occured. - */ - TiXmlNode* ReplaceChild( TiXmlNode* replaceThis, const TiXmlNode& withThis ); - - /// Delete a child of this node. - bool RemoveChild( TiXmlNode* removeThis ); - - /// Navigate to a sibling node. - const TiXmlNode* PreviousSibling() const { return prev; } - TiXmlNode* PreviousSibling() { return prev; } - - /// Navigate to a sibling node. - const TiXmlNode* PreviousSibling( const char * ) const; - TiXmlNode* PreviousSibling( const char *_prev ) { - return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->PreviousSibling( _prev ) ); - } - - #ifdef TIXML_USE_STL - const TiXmlNode* PreviousSibling( const std::string& _value ) const { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. - TiXmlNode* PreviousSibling( const std::string& _value ) { return PreviousSibling (_value.c_str ()); } ///< STL std::string form. - const TiXmlNode* NextSibling( const std::string& _value) const { return NextSibling (_value.c_str ()); } ///< STL std::string form. - TiXmlNode* NextSibling( const std::string& _value) { return NextSibling (_value.c_str ()); } ///< STL std::string form. - #endif - - /// Navigate to a sibling node. - const TiXmlNode* NextSibling() const { return next; } - TiXmlNode* NextSibling() { return next; } - - /// Navigate to a sibling node with the given 'value'. - const TiXmlNode* NextSibling( const char * ) const; - TiXmlNode* NextSibling( const char* _next ) { - return const_cast< TiXmlNode* >( (const_cast< const TiXmlNode* >(this))->NextSibling( _next ) ); - } - - /** Convenience function to get through elements. - Calls NextSibling and ToElement. Will skip all non-Element - nodes. Returns 0 if there is not another element. - */ - const TiXmlElement* NextSiblingElement() const; - TiXmlElement* NextSiblingElement() { - return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement() ); - } - - /** Convenience function to get through elements. - Calls NextSibling and ToElement. Will skip all non-Element - nodes. Returns 0 if there is not another element. - */ - const TiXmlElement* NextSiblingElement( const char * ) const; - TiXmlElement* NextSiblingElement( const char *_next ) { - return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->NextSiblingElement( _next ) ); - } - - #ifdef TIXML_USE_STL - const TiXmlElement* NextSiblingElement( const std::string& _value) const { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. - TiXmlElement* NextSiblingElement( const std::string& _value) { return NextSiblingElement (_value.c_str ()); } ///< STL std::string form. - #endif - - /// Convenience function to get through elements. - const TiXmlElement* FirstChildElement() const; - TiXmlElement* FirstChildElement() { - return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement() ); - } - - /// Convenience function to get through elements. - const TiXmlElement* FirstChildElement( const char * _value ) const; - TiXmlElement* FirstChildElement( const char * _value ) { - return const_cast< TiXmlElement* >( (const_cast< const TiXmlNode* >(this))->FirstChildElement( _value ) ); - } - - #ifdef TIXML_USE_STL - const TiXmlElement* FirstChildElement( const std::string& _value ) const { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. - TiXmlElement* FirstChildElement( const std::string& _value ) { return FirstChildElement (_value.c_str ()); } ///< STL std::string form. - #endif - - /** Query the type (as an enumerated value, above) of this node. - The possible types are: DOCUMENT, ELEMENT, COMMENT, - UNKNOWN, TEXT, and DECLARATION. - */ - int Type() const { return type; } - - /** Return a pointer to the Document this node lives in. - Returns null if not in a document. - */ - const TiXmlDocument* GetDocument() const; - TiXmlDocument* GetDocument() { - return const_cast< TiXmlDocument* >( (const_cast< const TiXmlNode* >(this))->GetDocument() ); - } - - /// Returns true if this node has no children. - bool NoChildren() const { return !firstChild; } - - virtual const TiXmlDocument* ToDocument() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlElement* ToElement() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlComment* ToComment() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlUnknown* ToUnknown() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlText* ToText() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual const TiXmlDeclaration* ToDeclaration() const { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - - virtual TiXmlDocument* ToDocument() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlElement* ToElement() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlComment* ToComment() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlUnknown* ToUnknown() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlText* ToText() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - virtual TiXmlDeclaration* ToDeclaration() { return 0; } ///< Cast to a more defined type. Will return null if not of the requested type. - - /** Create an exact duplicate of this node and return it. The memory must be deleted - by the caller. - */ - virtual TiXmlNode* Clone() const = 0; - - /** Accept a hierchical visit the nodes in the TinyXML DOM. Every node in the - XML tree will be conditionally visited and the host will be called back - via the TiXmlVisitor interface. - - This is essentially a SAX interface for TinyXML. (Note however it doesn't re-parse - the XML for the callbacks, so the performance of TinyXML is unchanged by using this - interface versus any other.) - - The interface has been based on ideas from: - - - http://www.saxproject.org/ - - http://c2.com/cgi/wiki?HierarchicalVisitorPattern - - Which are both good references for "visiting". - - An example of using Accept(): - @verbatim - TiXmlPrinter printer; - tinyxmlDoc.Accept( &printer ); - const char* xmlcstr = printer.CStr(); - @endverbatim - */ - virtual bool Accept( TiXmlVisitor* visitor ) const = 0; - -protected: - TiXmlNode( NodeType _type ); - - // Copy to the allocated object. Shared functionality between Clone, Copy constructor, - // and the assignment operator. - void CopyTo( TiXmlNode* target ) const; - - #ifdef TIXML_USE_STL - // The real work of the input operator. - virtual void StreamIn( std::istream* in, TIXML_STRING* tag ) = 0; - #endif - - // Figure out what is at *p, and parse it. Returns null if it is not an xml node. - TiXmlNode* Identify( const char* start, TiXmlEncoding encoding ); - - TiXmlNode* parent; - NodeType type; - - TiXmlNode* firstChild; - TiXmlNode* lastChild; - - TIXML_STRING value; - - TiXmlNode* prev; - TiXmlNode* next; - -private: - TiXmlNode( const TiXmlNode& ); // not implemented. - void operator=( const TiXmlNode& base ); // not allowed. -}; - - -/** An attribute is a name-value pair. Elements have an arbitrary - number of attributes, each with a unique name. - - @note The attributes are not TiXmlNodes, since they are not - part of the tinyXML document object model. There are other - suggested ways to look at this problem. -*/ -class TiXmlAttribute : public TiXmlBase -{ - friend class TiXmlAttributeSet; - -public: - /// Construct an empty attribute. - TiXmlAttribute() : TiXmlBase() - { - document = 0; - prev = next = 0; - } - - #ifdef TIXML_USE_STL - /// std::string constructor. - TiXmlAttribute( const std::string& _name, const std::string& _value ) - { - name = _name; - value = _value; - document = 0; - prev = next = 0; - } - #endif - - /// Construct an attribute with a name and value. - TiXmlAttribute( const char * _name, const char * _value ) - { - name = _name; - value = _value; - document = 0; - prev = next = 0; - } - - const char* Name() const { return name.c_str(); } ///< Return the name of this attribute. - const char* Value() const { return value.c_str(); } ///< Return the value of this attribute. - #ifdef TIXML_USE_STL - const std::string& ValueStr() const { return value; } ///< Return the value of this attribute. - #endif - int IntValue() const; ///< Return the value of this attribute, converted to an integer. - double DoubleValue() const; ///< Return the value of this attribute, converted to a double. - - // Get the tinyxml string representation - const TIXML_STRING& NameTStr() const { return name; } - - /** QueryIntValue examines the value string. It is an alternative to the - IntValue() method with richer error checking. - If the value is an integer, it is stored in 'value' and - the call returns TIXML_SUCCESS. If it is not - an integer, it returns TIXML_WRONG_TYPE. - - A specialized but useful call. Note that for success it returns 0, - which is the opposite of almost all other TinyXml calls. - */ - int QueryIntValue( int* _value ) const; - /// QueryDoubleValue examines the value string. See QueryIntValue(). - int QueryDoubleValue( double* _value ) const; - - void SetName( const char* _name ) { name = _name; } ///< Set the name of this attribute. - void SetValue( const char* _value ) { value = _value; } ///< Set the value. - - void SetIntValue( int _value ); ///< Set the value from an integer. - void SetDoubleValue( double _value ); ///< Set the value from a double. - - #ifdef TIXML_USE_STL - /// STL std::string form. - void SetName( const std::string& _name ) { name = _name; } - /// STL std::string form. - void SetValue( const std::string& _value ) { value = _value; } - #endif - - /// Get the next sibling attribute in the DOM. Returns null at end. - const TiXmlAttribute* Next() const; - TiXmlAttribute* Next() { - return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Next() ); - } - - /// Get the previous sibling attribute in the DOM. Returns null at beginning. - const TiXmlAttribute* Previous() const; - TiXmlAttribute* Previous() { - return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttribute* >(this))->Previous() ); - } - - bool operator==( const TiXmlAttribute& rhs ) const { return rhs.name == name; } - bool operator<( const TiXmlAttribute& rhs ) const { return name < rhs.name; } - bool operator>( const TiXmlAttribute& rhs ) const { return name > rhs.name; } - - /* Attribute parsing starts: first letter of the name - returns: the next char after the value end quote - */ - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - // Prints this Attribute to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const { - Print( cfile, depth, 0 ); - } - void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; - - // [internal use] - // Set the document pointer so the attribute can report errors. - void SetDocument( TiXmlDocument* doc ) { document = doc; } - -private: - TiXmlAttribute( const TiXmlAttribute& ); // not implemented. - void operator=( const TiXmlAttribute& base ); // not allowed. - - TiXmlDocument* document; // A pointer back to a document, for error reporting. - TIXML_STRING name; - TIXML_STRING value; - TiXmlAttribute* prev; - TiXmlAttribute* next; -}; - - -/* A class used to manage a group of attributes. - It is only used internally, both by the ELEMENT and the DECLARATION. - - The set can be changed transparent to the Element and Declaration - classes that use it, but NOT transparent to the Attribute - which has to implement a next() and previous() method. Which makes - it a bit problematic and prevents the use of STL. - - This version is implemented with circular lists because: - - I like circular lists - - it demonstrates some independence from the (typical) doubly linked list. -*/ -class TiXmlAttributeSet -{ -public: - TiXmlAttributeSet(); - ~TiXmlAttributeSet(); - - void Add( TiXmlAttribute* attribute ); - void Remove( TiXmlAttribute* attribute ); - - const TiXmlAttribute* First() const { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } - TiXmlAttribute* First() { return ( sentinel.next == &sentinel ) ? 0 : sentinel.next; } - const TiXmlAttribute* Last() const { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } - TiXmlAttribute* Last() { return ( sentinel.prev == &sentinel ) ? 0 : sentinel.prev; } - - const TiXmlAttribute* Find( const char* _name ) const; - TiXmlAttribute* Find( const char* _name ) { - return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) ); - } - #ifdef TIXML_USE_STL - const TiXmlAttribute* Find( const std::string& _name ) const; - TiXmlAttribute* Find( const std::string& _name ) { - return const_cast< TiXmlAttribute* >( (const_cast< const TiXmlAttributeSet* >(this))->Find( _name ) ); - } - - #endif - -private: - //*ME: Because of hidden/disabled copy-construktor in TiXmlAttribute (sentinel-element), - //*ME: this class must be also use a hidden/disabled copy-constructor !!! - TiXmlAttributeSet( const TiXmlAttributeSet& ); // not allowed - void operator=( const TiXmlAttributeSet& ); // not allowed (as TiXmlAttribute) - - TiXmlAttribute sentinel; -}; - - -/** The element is a container class. It has a value, the element name, - and can contain other elements, text, comments, and unknowns. - Elements also contain an arbitrary number of attributes. -*/ -class TiXmlElement : public TiXmlNode -{ -public: - /// Construct an element. - TiXmlElement (const char * in_value); - - #ifdef TIXML_USE_STL - /// std::string constructor. - TiXmlElement( const std::string& _value ); - #endif - - TiXmlElement( const TiXmlElement& ); - - void operator=( const TiXmlElement& base ); - - virtual ~TiXmlElement(); - - /** Given an attribute name, Attribute() returns the value - for the attribute of that name, or null if none exists. - */ - const char* Attribute( const char* name ) const; - - /** Given an attribute name, Attribute() returns the value - for the attribute of that name, or null if none exists. - If the attribute exists and can be converted to an integer, - the integer value will be put in the return 'i', if 'i' - is non-null. - */ - const char* Attribute( const char* name, int* i ) const; - - /** Given an attribute name, Attribute() returns the value - for the attribute of that name, or null if none exists. - If the attribute exists and can be converted to an double, - the double value will be put in the return 'd', if 'd' - is non-null. - */ - const char* Attribute( const char* name, double* d ) const; - - /** QueryIntAttribute examines the attribute - it is an alternative to the - Attribute() method with richer error checking. - If the attribute is an integer, it is stored in 'value' and - the call returns TIXML_SUCCESS. If it is not - an integer, it returns TIXML_WRONG_TYPE. If the attribute - does not exist, then TIXML_NO_ATTRIBUTE is returned. - */ - int QueryIntAttribute( const char* name, int* _value ) const; - /// QueryDoubleAttribute examines the attribute - see QueryIntAttribute(). - int QueryDoubleAttribute( const char* name, double* _value ) const; - /// QueryFloatAttribute examines the attribute - see QueryIntAttribute(). - int QueryFloatAttribute( const char* name, float* _value ) const { - double d; - int result = QueryDoubleAttribute( name, &d ); - if ( result == TIXML_SUCCESS ) { - *_value = (float)d; - } - return result; - } - - #ifdef TIXML_USE_STL - /** Template form of the attribute query which will try to read the - attribute into the specified type. Very easy, very powerful, but - be careful to make sure to call this with the correct type. - - NOTE: This method doesn't work correctly for 'string' types. - - @return TIXML_SUCCESS, TIXML_WRONG_TYPE, or TIXML_NO_ATTRIBUTE - */ - template< typename T > int QueryValueAttribute( const std::string& name, T* outValue ) const - { - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - - std::stringstream sstream( node->ValueStr() ); - sstream >> *outValue; - if ( !sstream.fail() ) - return TIXML_SUCCESS; - return TIXML_WRONG_TYPE; - } - /* - This is - in theory - a bug fix for "QueryValueAtribute returns truncated std::string" - but template specialization is hard to get working cross-compiler. Leaving the bug for now. - - // The above will fail for std::string because the space character is used as a seperator. - // Specialize for strings. Bug [ 1695429 ] QueryValueAtribute returns truncated std::string - template<> int QueryValueAttribute( const std::string& name, std::string* outValue ) const - { - const TiXmlAttribute* node = attributeSet.Find( name ); - if ( !node ) - return TIXML_NO_ATTRIBUTE; - *outValue = node->ValueStr(); - return TIXML_SUCCESS; - } - */ - #endif - - /** Sets an attribute of name to a given value. The attribute - will be created if it does not exist, or changed if it does. - */ - void SetAttribute( const char* name, const char * _value ); - - #ifdef TIXML_USE_STL - const std::string* Attribute( const std::string& name ) const; - const std::string* Attribute( const std::string& name, int* i ) const; - const std::string* Attribute( const std::string& name, double* d ) const; - int QueryIntAttribute( const std::string& name, int* _value ) const; - int QueryDoubleAttribute( const std::string& name, double* _value ) const; - - /// STL std::string form. - void SetAttribute( const std::string& name, const std::string& _value ); - ///< STL std::string form. - void SetAttribute( const std::string& name, int _value ); - #endif - - /** Sets an attribute of name to a given value. The attribute - will be created if it does not exist, or changed if it does. - */ - void SetAttribute( const char * name, int value ); - - /** Sets an attribute of name to a given value. The attribute - will be created if it does not exist, or changed if it does. - */ - void SetDoubleAttribute( const char * name, double value ); - - /** Deletes an attribute with the given name. - */ - void RemoveAttribute( const char * name ); - #ifdef TIXML_USE_STL - void RemoveAttribute( const std::string& name ) { RemoveAttribute (name.c_str ()); } ///< STL std::string form. - #endif - - const TiXmlAttribute* FirstAttribute() const { return attributeSet.First(); } ///< Access the first attribute in this element. - TiXmlAttribute* FirstAttribute() { return attributeSet.First(); } - const TiXmlAttribute* LastAttribute() const { return attributeSet.Last(); } ///< Access the last attribute in this element. - TiXmlAttribute* LastAttribute() { return attributeSet.Last(); } - - /** Convenience function for easy access to the text inside an element. Although easy - and concise, GetText() is limited compared to getting the TiXmlText child - and accessing it directly. - - If the first child of 'this' is a TiXmlText, the GetText() - returns the character string of the Text node, else null is returned. - - This is a convenient method for getting the text of simple contained text: - @verbatim - This is text - const char* str = fooElement->GetText(); - @endverbatim - - 'str' will be a pointer to "This is text". - - Note that this function can be misleading. If the element foo was created from - this XML: - @verbatim - This is text - @endverbatim - - then the value of str would be null. The first child node isn't a text node, it is - another element. From this XML: - @verbatim - This is text - @endverbatim - GetText() will return "This is ". - - WARNING: GetText() accesses a child node - don't become confused with the - similarly named TiXmlHandle::Text() and TiXmlNode::ToText() which are - safe type casts on the referenced node. - */ - const char* GetText() const; - - /// Creates a new Element and returns it - the returned element is a copy. - virtual TiXmlNode* Clone() const; - // Print the Element to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const; - - /* Attribtue parsing starts: next char past '<' - returns: next char past '>' - */ - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlElement* ToElement() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlElement* ToElement() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* visitor ) const; - -protected: - - void CopyTo( TiXmlElement* target ) const; - void ClearThis(); // like clear, but initializes 'this' object as well - - // Used to be public [internal use] - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - /* [internal use] - Reads the "value" of the element -- another element, or text. - This should terminate with the current end tag. - */ - const char* ReadValue( const char* in, TiXmlParsingData* prevData, TiXmlEncoding encoding ); - -private: - - TiXmlAttributeSet attributeSet; -}; - - -/** An XML comment. -*/ -class TiXmlComment : public TiXmlNode -{ -public: - /// Constructs an empty comment. - TiXmlComment() : TiXmlNode( TiXmlNode::COMMENT ) {} - /// Construct a comment from text. - TiXmlComment( const char* _value ) : TiXmlNode( TiXmlNode::COMMENT ) { - SetValue( _value ); - } - TiXmlComment( const TiXmlComment& ); - void operator=( const TiXmlComment& base ); - - virtual ~TiXmlComment() {} - - /// Returns a copy of this Comment. - virtual TiXmlNode* Clone() const; - // Write this Comment to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const; - - /* Attribtue parsing starts: at the ! of the !-- - returns: next char past '>' - */ - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlComment* ToComment() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlComment* ToComment() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* visitor ) const; - -protected: - void CopyTo( TiXmlComment* target ) const; - - // used to be public - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif -// virtual void StreamOut( TIXML_OSTREAM * out ) const; - -private: - -}; - - -/** XML text. A text node can have 2 ways to output the next. "normal" output - and CDATA. It will default to the mode it was parsed from the XML file and - you generally want to leave it alone, but you can change the output mode with - SetCDATA() and query it with CDATA(). -*/ -class TiXmlText : public TiXmlNode -{ - friend class TiXmlElement; -public: - /** Constructor for text element. By default, it is treated as - normal, encoded text. If you want it be output as a CDATA text - element, set the parameter _cdata to 'true' - */ - TiXmlText (const char * initValue ) : TiXmlNode (TiXmlNode::TEXT) - { - SetValue( initValue ); - cdata = false; - } - virtual ~TiXmlText() {} - - #ifdef TIXML_USE_STL - /// Constructor. - TiXmlText( const std::string& initValue ) : TiXmlNode (TiXmlNode::TEXT) - { - SetValue( initValue ); - cdata = false; - } - #endif - - TiXmlText( const TiXmlText& copy ) : TiXmlNode( TiXmlNode::TEXT ) { copy.CopyTo( this ); } - void operator=( const TiXmlText& base ) { base.CopyTo( this ); } - - // Write this text object to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const; - - /// Queries whether this represents text using a CDATA section. - bool CDATA() const { return cdata; } - /// Turns on or off a CDATA representation of text. - void SetCDATA( bool _cdata ) { cdata = _cdata; } - - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlText* ToText() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlText* ToText() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* content ) const; - -protected : - /// [internal use] Creates a new Element and returns it. - virtual TiXmlNode* Clone() const; - void CopyTo( TiXmlText* target ) const; - - bool Blank() const; // returns true if all white space and new lines - // [internal use] - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - -private: - bool cdata; // true if this should be input and output as a CDATA style text element -}; - - -/** In correct XML the declaration is the first entry in the file. - @verbatim - - @endverbatim - - TinyXml will happily read or write files without a declaration, - however. There are 3 possible attributes to the declaration: - version, encoding, and standalone. - - Note: In this version of the code, the attributes are - handled as special cases, not generic attributes, simply - because there can only be at most 3 and they are always the same. -*/ -class TiXmlDeclaration : public TiXmlNode -{ -public: - /// Construct an empty declaration. - TiXmlDeclaration() : TiXmlNode( TiXmlNode::DECLARATION ) {} - -#ifdef TIXML_USE_STL - /// Constructor. - TiXmlDeclaration( const std::string& _version, - const std::string& _encoding, - const std::string& _standalone ); -#endif - - /// Construct. - TiXmlDeclaration( const char* _version, - const char* _encoding, - const char* _standalone ); - - TiXmlDeclaration( const TiXmlDeclaration& copy ); - void operator=( const TiXmlDeclaration& copy ); - - virtual ~TiXmlDeclaration() {} - - /// Version. Will return an empty string if none was found. - const char *Version() const { return version.c_str (); } - /// Encoding. Will return an empty string if none was found. - const char *Encoding() const { return encoding.c_str (); } - /// Is this a standalone document? - const char *Standalone() const { return standalone.c_str (); } - - /// Creates a copy of this Declaration and returns it. - virtual TiXmlNode* Clone() const; - // Print this declaration to a FILE stream. - virtual void Print( FILE* cfile, int depth, TIXML_STRING* str ) const; - virtual void Print( FILE* cfile, int depth ) const { - Print( cfile, depth, 0 ); - } - - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlDeclaration* ToDeclaration() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlDeclaration* ToDeclaration() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* visitor ) const; - -protected: - void CopyTo( TiXmlDeclaration* target ) const; - // used to be public - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - -private: - - TIXML_STRING version; - TIXML_STRING encoding; - TIXML_STRING standalone; -}; - - -/** Any tag that tinyXml doesn't recognize is saved as an - unknown. It is a tag of text, but should not be modified. - It will be written back to the XML, unchanged, when the file - is saved. - - DTD tags get thrown into TiXmlUnknowns. -*/ -class TiXmlUnknown : public TiXmlNode -{ -public: - TiXmlUnknown() : TiXmlNode( TiXmlNode::UNKNOWN ) {} - virtual ~TiXmlUnknown() {} - - TiXmlUnknown( const TiXmlUnknown& copy ) : TiXmlNode( TiXmlNode::UNKNOWN ) { copy.CopyTo( this ); } - void operator=( const TiXmlUnknown& copy ) { copy.CopyTo( this ); } - - /// Creates a copy of this Unknown and returns it. - virtual TiXmlNode* Clone() const; - // Print this Unknown to a FILE stream. - virtual void Print( FILE* cfile, int depth ) const; - - virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ); - - virtual const TiXmlUnknown* ToUnknown() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlUnknown* ToUnknown() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* content ) const; - -protected: - void CopyTo( TiXmlUnknown* target ) const; - - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - -private: - -}; - - -/** Always the top level node. A document binds together all the - XML pieces. It can be saved, loaded, and printed to the screen. - The 'value' of a document node is the xml file name. -*/ -class TiXmlDocument : public TiXmlNode -{ -public: - /// Create an empty document, that has no name. - TiXmlDocument(); - /// Create a document with a name. The name of the document is also the filename of the xml. - TiXmlDocument( const char * documentName ); - - #ifdef TIXML_USE_STL - /// Constructor. - TiXmlDocument( const std::string& documentName ); - #endif - - TiXmlDocument( const TiXmlDocument& copy ); - void operator=( const TiXmlDocument& copy ); - - virtual ~TiXmlDocument() {} - - /** Load a file using the current document value. - Returns true if successful. Will delete any existing - document data before loading. - */ - bool LoadFile( TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); - /// Save a file using the current document value. Returns true if successful. - bool SaveFile() const; - /// Load a file using the given filename. Returns true if successful. - bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); - /// Save a file using the given filename. Returns true if successful. - bool SaveFile( const char * filename ) const; - /** Load a file using the given FILE*. Returns true if successful. Note that this method - doesn't stream - the entire object pointed at by the FILE* - will be interpreted as an XML file. TinyXML doesn't stream in XML from the current - file location. Streaming may be added in the future. - */ - bool LoadFile( FILE*, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); - /// Save a file using the given FILE*. Returns true if successful. - bool SaveFile( FILE* ) const; - - #ifdef TIXML_USE_STL - bool LoadFile( const std::string& filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ) ///< STL std::string version. - { -// StringToBuffer f( filename ); -// return ( f.buffer && LoadFile( f.buffer, encoding )); - return LoadFile( filename.c_str(), encoding ); - } - bool SaveFile( const std::string& filename ) const ///< STL std::string version. - { -// StringToBuffer f( filename ); -// return ( f.buffer && SaveFile( f.buffer )); - return SaveFile( filename.c_str() ); - } - #endif - - /** Parse the given null terminated block of xml data. Passing in an encoding to this - method (either TIXML_ENCODING_LEGACY or TIXML_ENCODING_UTF8 will force TinyXml - to use that encoding, regardless of what TinyXml might otherwise try to detect. - */ - virtual const char* Parse( const char* p, TiXmlParsingData* data = 0, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); - - /** Get the root element -- the only top level element -- of the document. - In well formed XML, there should only be one. TinyXml is tolerant of - multiple elements at the document level. - */ - const TiXmlElement* RootElement() const { return FirstChildElement(); } - TiXmlElement* RootElement() { return FirstChildElement(); } - - /** If an error occurs, Error will be set to true. Also, - - The ErrorId() will contain the integer identifier of the error (not generally useful) - - The ErrorDesc() method will return the name of the error. (very useful) - - The ErrorRow() and ErrorCol() will return the location of the error (if known) - */ - bool Error() const { return error; } - - /// Contains a textual (english) description of the error if one occurs. - const char * ErrorDesc() const { return errorDesc.c_str (); } - - /** Generally, you probably want the error string ( ErrorDesc() ). But if you - prefer the ErrorId, this function will fetch it. - */ - int ErrorId() const { return errorId; } - - /** Returns the location (if known) of the error. The first column is column 1, - and the first row is row 1. A value of 0 means the row and column wasn't applicable - (memory errors, for example, have no row/column) or the parser lost the error. (An - error in the error reporting, in that case.) - - @sa SetTabSize, Row, Column - */ - int ErrorRow() const { return errorLocation.row+1; } - int ErrorCol() const { return errorLocation.col+1; } ///< The column where the error occured. See ErrorRow() - - /** SetTabSize() allows the error reporting functions (ErrorRow() and ErrorCol()) - to report the correct values for row and column. It does not change the output - or input in any way. - - By calling this method, with a tab size - greater than 0, the row and column of each node and attribute is stored - when the file is loaded. Very useful for tracking the DOM back in to - the source file. - - The tab size is required for calculating the location of nodes. If not - set, the default of 4 is used. The tabsize is set per document. Setting - the tabsize to 0 disables row/column tracking. - - Note that row and column tracking is not supported when using operator>>. - - The tab size needs to be enabled before the parse or load. Correct usage: - @verbatim - TiXmlDocument doc; - doc.SetTabSize( 8 ); - doc.Load( "myfile.xml" ); - @endverbatim - - @sa Row, Column - */ - void SetTabSize( int _tabsize ) { tabsize = _tabsize; } - - int TabSize() const { return tabsize; } - - /** If you have handled the error, it can be reset with this call. The error - state is automatically cleared if you Parse a new XML block. - */ - void ClearError() { error = false; - errorId = 0; - errorDesc = ""; - errorLocation.row = errorLocation.col = 0; - //errorLocation.last = 0; - } - - /** Write the document to standard out using formatted printing ("pretty print"). */ - void Print() const { Print( stdout, 0 ); } - - /* Write the document to a string using formatted printing ("pretty print"). This - will allocate a character array (new char[]) and return it as a pointer. The - calling code pust call delete[] on the return char* to avoid a memory leak. - */ - //char* PrintToMemory() const; - - /// Print this Document to a FILE stream. - virtual void Print( FILE* cfile, int depth = 0 ) const; - // [internal use] - void SetError( int err, const char* errorLocation, TiXmlParsingData* prevData, TiXmlEncoding encoding ); - - virtual const TiXmlDocument* ToDocument() const { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - virtual TiXmlDocument* ToDocument() { return this; } ///< Cast to a more defined type. Will return null not of the requested type. - - /** Walk the XML tree visiting this node and all of its children. - */ - virtual bool Accept( TiXmlVisitor* content ) const; - -protected : - // [internal use] - virtual TiXmlNode* Clone() const; - #ifdef TIXML_USE_STL - virtual void StreamIn( std::istream * in, TIXML_STRING * tag ); - #endif - -private: - void CopyTo( TiXmlDocument* target ) const; - - bool error; - int errorId; - TIXML_STRING errorDesc; - int tabsize; - TiXmlCursor errorLocation; - bool useMicrosoftBOM; // the UTF-8 BOM were found when read. Note this, and try to write. -}; - - -/** - A TiXmlHandle is a class that wraps a node pointer with null checks; this is - an incredibly useful thing. Note that TiXmlHandle is not part of the TinyXml - DOM structure. It is a separate utility class. - - Take an example: - @verbatim - - - - - - - @endverbatim - - Assuming you want the value of "attributeB" in the 2nd "Child" element, it's very - easy to write a *lot* of code that looks like: - - @verbatim - TiXmlElement* root = document.FirstChildElement( "Document" ); - if ( root ) - { - TiXmlElement* element = root->FirstChildElement( "Element" ); - if ( element ) - { - TiXmlElement* child = element->FirstChildElement( "Child" ); - if ( child ) - { - TiXmlElement* child2 = child->NextSiblingElement( "Child" ); - if ( child2 ) - { - // Finally do something useful. - @endverbatim - - And that doesn't even cover "else" cases. TiXmlHandle addresses the verbosity - of such code. A TiXmlHandle checks for null pointers so it is perfectly safe - and correct to use: - - @verbatim - TiXmlHandle docHandle( &document ); - TiXmlElement* child2 = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", 1 ).ToElement(); - if ( child2 ) - { - // do something useful - @endverbatim - - Which is MUCH more concise and useful. - - It is also safe to copy handles - internally they are nothing more than node pointers. - @verbatim - TiXmlHandle handleCopy = handle; - @endverbatim - - What they should not be used for is iteration: - - @verbatim - int i=0; - while ( true ) - { - TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).Child( "Child", i ).ToElement(); - if ( !child ) - break; - // do something - ++i; - } - @endverbatim - - It seems reasonable, but it is in fact two embedded while loops. The Child method is - a linear walk to find the element, so this code would iterate much more than it needs - to. Instead, prefer: - - @verbatim - TiXmlElement* child = docHandle.FirstChild( "Document" ).FirstChild( "Element" ).FirstChild( "Child" ).ToElement(); - - for( child; child; child=child->NextSiblingElement() ) - { - // do something - } - @endverbatim -*/ -class TiXmlHandle -{ -public: - /// Create a handle from any node (at any depth of the tree.) This can be a null pointer. - TiXmlHandle( TiXmlNode* _node ) { this->node = _node; } - /// Copy constructor - TiXmlHandle( const TiXmlHandle& ref ) { this->node = ref.node; } - TiXmlHandle operator=( const TiXmlHandle& ref ) { this->node = ref.node; return *this; } - - /// Return a handle to the first child node. - TiXmlHandle FirstChild() const; - /// Return a handle to the first child node with the given name. - TiXmlHandle FirstChild( const char * value ) const; - /// Return a handle to the first child element. - TiXmlHandle FirstChildElement() const; - /// Return a handle to the first child element with the given name. - TiXmlHandle FirstChildElement( const char * value ) const; - - /** Return a handle to the "index" child with the given name. - The first child is 0, the second 1, etc. - */ - TiXmlHandle Child( const char* value, int index ) const; - /** Return a handle to the "index" child. - The first child is 0, the second 1, etc. - */ - TiXmlHandle Child( int index ) const; - /** Return a handle to the "index" child element with the given name. - The first child element is 0, the second 1, etc. Note that only TiXmlElements - are indexed: other types are not counted. - */ - TiXmlHandle ChildElement( const char* value, int index ) const; - /** Return a handle to the "index" child element. - The first child element is 0, the second 1, etc. Note that only TiXmlElements - are indexed: other types are not counted. - */ - TiXmlHandle ChildElement( int index ) const; - - #ifdef TIXML_USE_STL - TiXmlHandle FirstChild( const std::string& _value ) const { return FirstChild( _value.c_str() ); } - TiXmlHandle FirstChildElement( const std::string& _value ) const { return FirstChildElement( _value.c_str() ); } - - TiXmlHandle Child( const std::string& _value, int index ) const { return Child( _value.c_str(), index ); } - TiXmlHandle ChildElement( const std::string& _value, int index ) const { return ChildElement( _value.c_str(), index ); } - #endif - - /** Return the handle as a TiXmlNode. This may return null. - */ - TiXmlNode* ToNode() const { return node; } - /** Return the handle as a TiXmlElement. This may return null. - */ - TiXmlElement* ToElement() const { return ( ( node && node->ToElement() ) ? node->ToElement() : 0 ); } - /** Return the handle as a TiXmlText. This may return null. - */ - TiXmlText* ToText() const { return ( ( node && node->ToText() ) ? node->ToText() : 0 ); } - /** Return the handle as a TiXmlUnknown. This may return null. - */ - TiXmlUnknown* ToUnknown() const { return ( ( node && node->ToUnknown() ) ? node->ToUnknown() : 0 ); } - - /** @deprecated use ToNode. - Return the handle as a TiXmlNode. This may return null. - */ - TiXmlNode* Node() const { return ToNode(); } - /** @deprecated use ToElement. - Return the handle as a TiXmlElement. This may return null. - */ - TiXmlElement* Element() const { return ToElement(); } - /** @deprecated use ToText() - Return the handle as a TiXmlText. This may return null. - */ - TiXmlText* Text() const { return ToText(); } - /** @deprecated use ToUnknown() - Return the handle as a TiXmlUnknown. This may return null. - */ - TiXmlUnknown* Unknown() const { return ToUnknown(); } - -private: - TiXmlNode* node; -}; - - -/** Print to memory functionality. The TiXmlPrinter is useful when you need to: - - -# Print to memory (especially in non-STL mode) - -# Control formatting (line endings, etc.) - - When constructed, the TiXmlPrinter is in its default "pretty printing" mode. - Before calling Accept() you can call methods to control the printing - of the XML document. After TiXmlNode::Accept() is called, the printed document can - be accessed via the CStr(), Str(), and Size() methods. - - TiXmlPrinter uses the Visitor API. - @verbatim - TiXmlPrinter printer; - printer.SetIndent( "\t" ); - - doc.Accept( &printer ); - fprintf( stdout, "%s", printer.CStr() ); - @endverbatim -*/ -class TiXmlPrinter : public TiXmlVisitor -{ -public: - TiXmlPrinter() : depth( 0 ), simpleTextPrint( false ), - buffer(), indent( " " ), lineBreak( "\n" ) {} - - virtual bool VisitEnter( const TiXmlDocument& doc ); - virtual bool VisitExit( const TiXmlDocument& doc ); - - virtual bool VisitEnter( const TiXmlElement& element, const TiXmlAttribute* firstAttribute ); - virtual bool VisitExit( const TiXmlElement& element ); - - virtual bool Visit( const TiXmlDeclaration& declaration ); - virtual bool Visit( const TiXmlText& text ); - virtual bool Visit( const TiXmlComment& comment ); - virtual bool Visit( const TiXmlUnknown& unknown ); - - /** Set the indent characters for printing. By default 4 spaces - but tab (\t) is also useful, or null/empty string for no indentation. - */ - void SetIndent( const char* _indent ) { indent = _indent ? _indent : "" ; } - /// Query the indention string. - const char* Indent() { return indent.c_str(); } - /** Set the line breaking string. By default set to newline (\n). - Some operating systems prefer other characters, or can be - set to the null/empty string for no indenation. - */ - void SetLineBreak( const char* _lineBreak ) { lineBreak = _lineBreak ? _lineBreak : ""; } - /// Query the current line breaking string. - const char* LineBreak() { return lineBreak.c_str(); } - - /** Switch over to "stream printing" which is the most dense formatting without - linebreaks. Common when the XML is needed for network transmission. - */ - void SetStreamPrinting() { indent = ""; - lineBreak = ""; - } - /// Return the result. - const char* CStr() { return buffer.c_str(); } - /// Return the length of the result string. - size_t Size() { return buffer.size(); } - - #ifdef TIXML_USE_STL - /// Return the result. - const std::string& Str() { return buffer; } - #endif - -private: - void DoIndent() { - for( int i=0; i -#include - -#include "tinyxml.h" - -//#define DEBUG_PARSER -#if defined( DEBUG_PARSER ) -# if defined( DEBUG ) && defined( _MSC_VER ) -# include -# define TIXML_LOG OutputDebugString -# else -# define TIXML_LOG printf -# endif -#endif - -// Note tha "PutString" hardcodes the same list. This -// is less flexible than it appears. Changing the entries -// or order will break putstring. -TiXmlBase::Entity TiXmlBase::entity[ NUM_ENTITY ] = -{ - { "&", 5, '&' }, - { "<", 4, '<' }, - { ">", 4, '>' }, - { """, 6, '\"' }, - { "'", 6, '\'' } -}; - -// Bunch of unicode info at: -// http://www.unicode.org/faq/utf_bom.html -// Including the basic of this table, which determines the #bytes in the -// sequence from the lead byte. 1 placed for invalid sequences -- -// although the result will be junk, pass it through as much as possible. -// Beware of the non-characters in UTF-8: -// ef bb bf (Microsoft "lead bytes") -// ef bf be -// ef bf bf - -const unsigned char TIXML_UTF_LEAD_0 = 0xefU; -const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; -const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; - -const int TiXmlBase::utf8ByteTable[256] = -{ - // 0 1 2 3 4 5 6 7 8 9 a b c d e f - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x00 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x10 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x20 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x30 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x40 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x50 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x60 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x70 End of ASCII range - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x80 0x80 to 0xc1 invalid - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0x90 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xa0 - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 0xb0 - 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xc0 0xc2 to 0xdf 2 byte - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // 0xd0 - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, // 0xe0 0xe0 to 0xef 3 byte - 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // 0xf0 0xf0 to 0xf4 4 byte, 0xf5 and higher invalid -}; - - -void TiXmlBase::ConvertUTF32ToUTF8( unsigned long input, char* output, int* length ) -{ - const unsigned long BYTE_MASK = 0xBF; - const unsigned long BYTE_MARK = 0x80; - const unsigned long FIRST_BYTE_MARK[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC }; - - if (input < 0x80) - *length = 1; - else if ( input < 0x800 ) - *length = 2; - else if ( input < 0x10000 ) - *length = 3; - else if ( input < 0x200000 ) - *length = 4; - else - { *length = 0; return; } // This code won't covert this correctly anyway. - - output += *length; - - // Scary scary fall throughs. - switch (*length) - { - case 4: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 3: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 2: - --output; - *output = (char)((input | BYTE_MARK) & BYTE_MASK); - input >>= 6; - case 1: - --output; - *output = (char)(input | FIRST_BYTE_MARK[*length]); - } -} - - -/*static*/ int TiXmlBase::IsAlpha( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) -{ - // This will only work for low-ascii, everything else is assumed to be a valid - // letter. I'm not sure this is the best approach, but it is quite tricky trying - // to figure out alhabetical vs. not across encoding. So take a very - // conservative approach. - -// if ( encoding == TIXML_ENCODING_UTF8 ) -// { - if ( anyByte < 127 ) - return isalpha( anyByte ); - else - return 1; // What else to do? The unicode set is huge...get the english ones right. -// } -// else -// { -// return isalpha( anyByte ); -// } -} - - -/*static*/ int TiXmlBase::IsAlphaNum( unsigned char anyByte, TiXmlEncoding /*encoding*/ ) -{ - // This will only work for low-ascii, everything else is assumed to be a valid - // letter. I'm not sure this is the best approach, but it is quite tricky trying - // to figure out alhabetical vs. not across encoding. So take a very - // conservative approach. - -// if ( encoding == TIXML_ENCODING_UTF8 ) -// { - if ( anyByte < 127 ) - return isalnum( anyByte ); - else - return 1; // What else to do? The unicode set is huge...get the english ones right. -// } -// else -// { -// return isalnum( anyByte ); -// } -} - - -class TiXmlParsingData -{ - friend class TiXmlDocument; - public: - void Stamp( const char* now, TiXmlEncoding encoding ); - - const TiXmlCursor& Cursor() { return cursor; } - - private: - // Only used by the document! - TiXmlParsingData( const char* start, int _tabsize, int row, int col ) - { - assert( start ); - stamp = start; - tabsize = _tabsize; - cursor.row = row; - cursor.col = col; - } - - TiXmlCursor cursor; - const char* stamp; - int tabsize; -}; - - -void TiXmlParsingData::Stamp( const char* now, TiXmlEncoding encoding ) -{ - assert( now ); - - // Do nothing if the tabsize is 0. - if ( tabsize < 1 ) - { - return; - } - - // Get the current row, column. - int row = cursor.row; - int col = cursor.col; - const char* p = stamp; - assert( p ); - - while ( p < now ) - { - // Treat p as unsigned, so we have a happy compiler. - const unsigned char* pU = (const unsigned char*)p; - - // Code contributed by Fletcher Dunn: (modified by lee) - switch (*pU) { - case 0: - // We *should* never get here, but in case we do, don't - // advance past the terminating null character, ever - return; - - case '\r': - // bump down to the next line - ++row; - col = 0; - // Eat the character - ++p; - - // Check for \r\n sequence, and treat this as a single character - if (*p == '\n') { - ++p; - } - break; - - case '\n': - // bump down to the next line - ++row; - col = 0; - - // Eat the character - ++p; - - // Check for \n\r sequence, and treat this as a single - // character. (Yes, this bizarre thing does occur still - // on some arcane platforms...) - if (*p == '\r') { - ++p; - } - break; - - case '\t': - // Eat the character - ++p; - - // Skip to next tab stop - col = (col / tabsize + 1) * tabsize; - break; - - case TIXML_UTF_LEAD_0: - if ( encoding == TIXML_ENCODING_UTF8 ) - { - if ( *(p+1) && *(p+2) ) - { - // In these cases, don't advance the column. These are - // 0-width spaces. - if ( *(pU+1)==TIXML_UTF_LEAD_1 && *(pU+2)==TIXML_UTF_LEAD_2 ) - p += 3; - else if ( *(pU+1)==0xbfU && *(pU+2)==0xbeU ) - p += 3; - else if ( *(pU+1)==0xbfU && *(pU+2)==0xbfU ) - p += 3; - else - { p +=3; ++col; } // A normal character. - } - } - else - { - ++p; - ++col; - } - break; - - default: - if ( encoding == TIXML_ENCODING_UTF8 ) - { - // Eat the 1 to 4 byte utf8 character. - int step = TiXmlBase::utf8ByteTable[*((const unsigned char*)p)]; - if ( step == 0 ) - step = 1; // Error case from bad encoding, but handle gracefully. - p += step; - - // Just advance one column, of course. - ++col; - } - else - { - ++p; - ++col; - } - break; - } - } - cursor.row = row; - cursor.col = col; - assert( cursor.row >= -1 ); - assert( cursor.col >= -1 ); - stamp = p; - assert( stamp ); -} - - -const char* TiXmlBase::SkipWhiteSpace( const char* p, TiXmlEncoding encoding ) -{ - if ( !p || !*p ) - { - return 0; - } - if ( encoding == TIXML_ENCODING_UTF8 ) - { - while ( *p ) - { - const unsigned char* pU = (const unsigned char*)p; - - // Skip the stupid Microsoft UTF-8 Byte order marks - if ( *(pU+0)==TIXML_UTF_LEAD_0 - && *(pU+1)==TIXML_UTF_LEAD_1 - && *(pU+2)==TIXML_UTF_LEAD_2 ) - { - p += 3; - continue; - } - else if(*(pU+0)==TIXML_UTF_LEAD_0 - && *(pU+1)==0xbfU - && *(pU+2)==0xbeU ) - { - p += 3; - continue; - } - else if(*(pU+0)==TIXML_UTF_LEAD_0 - && *(pU+1)==0xbfU - && *(pU+2)==0xbfU ) - { - p += 3; - continue; - } - - if ( IsWhiteSpace( *p ) || *p == '\n' || *p =='\r' ) // Still using old rules for white space. - ++p; - else - break; - } - } - else - { - while ( *p && (IsWhiteSpace( *p ) || *p == '\n' || *p =='\r')) - ++p; - } - - return p; -} - -#ifdef TIXML_USE_STL -/*static*/ bool TiXmlBase::StreamWhiteSpace( std::istream * in, TIXML_STRING * tag ) -{ - for( ;; ) - { - if ( !in->good() ) return false; - - int c = in->peek(); - // At this scope, we can't get to a document. So fail silently. - if ( !IsWhiteSpace( c ) || c <= 0 ) - return true; - - *tag += (char) in->get(); - } -} - -/*static*/ bool TiXmlBase::StreamTo( std::istream * in, int character, TIXML_STRING * tag ) -{ - //assert( character > 0 && character < 128 ); // else it won't work in utf-8 - while ( in->good() ) - { - int c = in->peek(); - if ( c == character ) - return true; - if ( c <= 0 ) // Silent failure: can't get document at this scope - return false; - - in->get(); - *tag += (char) c; - } - return false; -} -#endif - -// One of TinyXML's more performance demanding functions. Try to keep the memory overhead down. The -// "assign" optimization removes over 10% of the execution time. -// -const char* TiXmlBase::ReadName( const char* p, TIXML_STRING * name, TiXmlEncoding encoding ) -{ - // Oddly, not supported on some comilers, - //name->clear(); - // So use this: - *name = ""; - assert( p ); - - // Names start with letters or underscores. - // Of course, in unicode, tinyxml has no idea what a letter *is*. The - // algorithm is generous. - // - // After that, they can be letters, underscores, numbers, - // hyphens, or colons. (Colons are valid ony for namespaces, - // but tinyxml can't tell namespaces from names.) - if ( p && *p - && ( IsAlpha( (unsigned char) *p, encoding ) || *p == '_' ) ) - { - const char* start = p; - while( p && *p - && ( IsAlphaNum( (unsigned char ) *p, encoding ) - || *p == '_' - || *p == '-' - || *p == '.' - || *p == ':' ) ) - { - //(*name) += *p; // expensive - ++p; - } - if ( p-start > 0 ) { - name->assign( start, p-start ); - } - return p; - } - return 0; -} - -const char* TiXmlBase::GetEntity( const char* p, char* value, int* length, TiXmlEncoding encoding ) -{ - // Presume an entity, and pull it out. - TIXML_STRING ent; - int i; - *length = 0; - - if ( *(p+1) && *(p+1) == '#' && *(p+2) ) - { - unsigned long ucs = 0; - ptrdiff_t delta = 0; - unsigned mult = 1; - - if ( *(p+2) == 'x' ) - { - // Hexadecimal. - if ( !*(p+3) ) return 0; - - const char* q = p+3; - q = strchr( q, ';' ); - - if ( !q || !*q ) return 0; - - delta = q-p; - --q; - - while ( *q != 'x' ) - { - if ( *q >= '0' && *q <= '9' ) - ucs += mult * (*q - '0'); - else if ( *q >= 'a' && *q <= 'f' ) - ucs += mult * (*q - 'a' + 10); - else if ( *q >= 'A' && *q <= 'F' ) - ucs += mult * (*q - 'A' + 10 ); - else - return 0; - mult *= 16; - --q; - } - } - else - { - // Decimal. - if ( !*(p+2) ) return 0; - - const char* q = p+2; - q = strchr( q, ';' ); - - if ( !q || !*q ) return 0; - - delta = q-p; - --q; - - while ( *q != '#' ) - { - if ( *q >= '0' && *q <= '9' ) - ucs += mult * (*q - '0'); - else - return 0; - mult *= 10; - --q; - } - } - if ( encoding == TIXML_ENCODING_UTF8 ) - { - // convert the UCS to UTF-8 - ConvertUTF32ToUTF8( ucs, value, length ); - } - else - { - *value = (char)ucs; - *length = 1; - } - return p + delta + 1; - } - - // Now try to match it. - for( i=0; iappend( cArr, len ); - } - } - else - { - bool whitespace = false; - - // Remove leading white space: - p = SkipWhiteSpace( p, encoding ); - while ( p && *p - && !StringEqual( p, endTag, caseInsensitive, encoding ) ) - { - if ( *p == '\r' || *p == '\n' ) - { - whitespace = true; - ++p; - } - else if ( IsWhiteSpace( *p ) ) - { - whitespace = true; - ++p; - } - else - { - // If we've found whitespace, add it before the - // new character. Any whitespace just becomes a space. - if ( whitespace ) - { - (*text) += ' '; - whitespace = false; - } - int len; - char cArr[4] = { 0, 0, 0, 0 }; - p = GetChar( p, cArr, &len, encoding ); - if ( len == 1 ) - (*text) += cArr[0]; // more efficient - else - text->append( cArr, len ); - } - } - } - if ( p ) - p += strlen( endTag ); - return p; -} - -#ifdef TIXML_USE_STL - -void TiXmlDocument::StreamIn( std::istream * in, TIXML_STRING * tag ) -{ - // The basic issue with a document is that we don't know what we're - // streaming. Read something presumed to be a tag (and hope), then - // identify it, and call the appropriate stream method on the tag. - // - // This "pre-streaming" will never read the closing ">" so the - // sub-tag can orient itself. - - if ( !StreamTo( in, '<', tag ) ) - { - SetError( TIXML_ERROR_PARSING_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return; - } - - while ( in->good() ) - { - int tagIndex = (int) tag->length(); - while ( in->good() && in->peek() != '>' ) - { - int c = in->get(); - if ( c <= 0 ) - { - SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); - break; - } - (*tag) += (char) c; - } - - if ( in->good() ) - { - // We now have something we presume to be a node of - // some sort. Identify it, and call the node to - // continue streaming. - TiXmlNode* node = Identify( tag->c_str() + tagIndex, TIXML_DEFAULT_ENCODING ); - - if ( node ) - { - node->StreamIn( in, tag ); - bool isElement = node->ToElement() != 0; - delete node; - node = 0; - - // If this is the root element, we're done. Parsing will be - // done by the >> operator. - if ( isElement ) - { - return; - } - } - else - { - SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); - return; - } - } - } - // We should have returned sooner. - SetError( TIXML_ERROR, 0, 0, TIXML_ENCODING_UNKNOWN ); -} - -#endif - -const char* TiXmlDocument::Parse( const char* p, TiXmlParsingData* prevData, TiXmlEncoding encoding ) -{ - ClearError(); - - // Parse away, at the document level. Since a document - // contains nothing but other tags, most of what happens - // here is skipping white space. - if ( !p || !*p ) - { - SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - // Note that, for a document, this needs to come - // before the while space skip, so that parsing - // starts from the pointer we are given. - location.Clear(); - if ( prevData ) - { - location.row = prevData->cursor.row; - location.col = prevData->cursor.col; - } - else - { - location.row = 0; - location.col = 0; - } - TiXmlParsingData data( p, TabSize(), location.row, location.col ); - location = data.Cursor(); - - if ( encoding == TIXML_ENCODING_UNKNOWN ) - { - // Check for the Microsoft UTF-8 lead bytes. - const unsigned char* pU = (const unsigned char*)p; - if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0 - && *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1 - && *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 ) - { - encoding = TIXML_ENCODING_UTF8; - useMicrosoftBOM = true; - } - } - - p = SkipWhiteSpace( p, encoding ); - if ( !p ) - { - SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); - return 0; - } - - while ( p && *p ) - { - TiXmlNode* node = Identify( p, encoding ); - if ( node ) - { - p = node->Parse( p, &data, encoding ); - LinkEndChild( node ); - } - else - { - break; - } - - // Did we get encoding info? - if ( encoding == TIXML_ENCODING_UNKNOWN - && node->ToDeclaration() ) - { - TiXmlDeclaration* dec = node->ToDeclaration(); - const char* enc = dec->Encoding(); - assert( enc ); - - if ( *enc == 0 ) - encoding = TIXML_ENCODING_UTF8; - else if ( StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) ) - encoding = TIXML_ENCODING_UTF8; - else if ( StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) ) - encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice - else - encoding = TIXML_ENCODING_LEGACY; - } - - p = SkipWhiteSpace( p, encoding ); - } - - // Was this empty? - if ( !firstChild ) { - SetError( TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding ); - return 0; - } - - // All is well. - return p; -} - -void TiXmlDocument::SetError( int err, const char* pError, TiXmlParsingData* data, TiXmlEncoding encoding ) -{ - // The first error in a chain is more accurate - don't set again! - if ( error ) - return; - - assert( err > 0 && err < TIXML_ERROR_STRING_COUNT ); - error = true; - errorId = err; - errorDesc = errorString[ errorId ]; - - errorLocation.Clear(); - if ( pError && data ) - { - data->Stamp( pError, encoding ); - errorLocation = data->Cursor(); - } -} - - -TiXmlNode* TiXmlNode::Identify( const char* p, TiXmlEncoding encoding ) -{ - TiXmlNode* returnNode = 0; - - p = SkipWhiteSpace( p, encoding ); - if( !p || !*p || *p != '<' ) - { - return 0; - } - - TiXmlDocument* doc = GetDocument(); - p = SkipWhiteSpace( p, encoding ); - - if ( !p || !*p ) - { - return 0; - } - - // What is this thing? - // - Elements start with a letter or underscore, but xml is reserved. - // - Comments: "; - - if ( !StringEqual( p, startTag, false, encoding ) ) - { - document->SetError( TIXML_ERROR_PARSING_COMMENT, p, data, encoding ); - return 0; - } - p += strlen( startTag ); - - // [ 1475201 ] TinyXML parses entities in comments - // Oops - ReadText doesn't work, because we don't want to parse the entities. - // p = ReadText( p, &value, false, endTag, false, encoding ); - // - // from the XML spec: - /* - [Definition: Comments may appear anywhere in a document outside other markup; in addition, - they may appear within the document type declaration at places allowed by the grammar. - They are not part of the document's character data; an XML processor MAY, but need not, - make it possible for an application to retrieve the text of comments. For compatibility, - the string "--" (double-hyphen) MUST NOT occur within comments.] Parameter entity - references MUST NOT be recognized within comments. - - An example of a comment: - - - */ - - value = ""; - // Keep all the white space. - while ( p && *p && !StringEqual( p, endTag, false, encoding ) ) - { - value.append( p, 1 ); - ++p; - } - if ( p ) - p += strlen( endTag ); - - return p; -} - - -const char* TiXmlAttribute::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) -{ - p = SkipWhiteSpace( p, encoding ); - if ( !p || !*p ) return 0; - -// int tabsize = 4; -// if ( document ) -// tabsize = document->TabSize(); - - if ( data ) - { - data->Stamp( p, encoding ); - location = data->Cursor(); - } - // Read the name, the '=' and the value. - const char* pErr = p; - p = ReadName( p, &name, encoding ); - if ( !p || !*p ) - { - if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding ); - return 0; - } - p = SkipWhiteSpace( p, encoding ); - if ( !p || !*p || *p != '=' ) - { - if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); - return 0; - } - - ++p; // skip '=' - p = SkipWhiteSpace( p, encoding ); - if ( !p || !*p ) - { - if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); - return 0; - } - - const char* end; - const char SINGLE_QUOTE = '\''; - const char DOUBLE_QUOTE = '\"'; - - if ( *p == SINGLE_QUOTE ) - { - ++p; - end = "\'"; // single quote in string - p = ReadText( p, &value, false, end, false, encoding ); - } - else if ( *p == DOUBLE_QUOTE ) - { - ++p; - end = "\""; // double quote in string - p = ReadText( p, &value, false, end, false, encoding ); - } - else - { - // All attribute values should be in single or double quotes. - // But this is such a common error that the parser will try - // its best, even without them. - value = ""; - while ( p && *p // existence - && !IsWhiteSpace( *p ) && *p != '\n' && *p != '\r' // whitespace - && *p != '/' && *p != '>' ) // tag end - { - if ( *p == SINGLE_QUOTE || *p == DOUBLE_QUOTE ) { - // [ 1451649 ] Attribute values with trailing quotes not handled correctly - // We did not have an opening quote but seem to have a - // closing one. Give up and throw an error. - if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, p, data, encoding ); - return 0; - } - value += *p; - ++p; - } - } - return p; -} - -#ifdef TIXML_USE_STL -void TiXmlText::StreamIn( std::istream * in, TIXML_STRING * tag ) -{ - while ( in->good() ) - { - int c = in->peek(); - if ( !cdata && (c == '<' ) ) - { - return; - } - if ( c <= 0 ) - { - TiXmlDocument* document = GetDocument(); - if ( document ) - document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); - return; - } - - (*tag) += (char) c; - in->get(); // "commits" the peek made above - - if ( cdata && c == '>' && tag->size() >= 3 ) { - size_t len = tag->size(); - if ( (*tag)[len-2] == ']' && (*tag)[len-3] == ']' ) { - // terminator of cdata. - return; - } - } - } -} -#endif - -const char* TiXmlText::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding ) -{ - value = ""; - TiXmlDocument* document = GetDocument(); - - if ( data ) - { - data->Stamp( p, encoding ); - location = data->Cursor(); - } - - const char* const startTag = ""; - - if ( cdata || StringEqual( p, startTag, false, encoding ) ) - { - cdata = true; - - if ( !StringEqual( p, startTag, false, encoding ) ) - { - document->SetError( TIXML_ERROR_PARSING_CDATA, p, data, encoding ); - return 0; - } - p += strlen( startTag ); - - // Keep all the white space, ignore the encoding, etc. - while ( p && *p - && !StringEqual( p, endTag, false, encoding ) - ) - { - value += *p; - ++p; - } - - TIXML_STRING dummy; - p = ReadText( p, &dummy, false, endTag, false, encoding ); - return p; - } - else - { - bool ignoreWhite = true; - - const char* end = "<"; - p = ReadText( p, &value, ignoreWhite, end, false, encoding ); - if ( p ) - return p-1; // don't truncate the '<' - return 0; - } -} - -#ifdef TIXML_USE_STL -void TiXmlDeclaration::StreamIn( std::istream * in, TIXML_STRING * tag ) -{ - while ( in->good() ) - { - int c = in->get(); - if ( c <= 0 ) - { - TiXmlDocument* document = GetDocument(); - if ( document ) - document->SetError( TIXML_ERROR_EMBEDDED_NULL, 0, 0, TIXML_ENCODING_UNKNOWN ); - return; - } - (*tag) += (char) c; - - if ( c == '>' ) - { - // All is well. - return; - } - } -} -#endif - -const char* TiXmlDeclaration::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding _encoding ) -{ - p = SkipWhiteSpace( p, _encoding ); - // Find the beginning, find the end, and look for - // the stuff in-between. - TiXmlDocument* document = GetDocument(); - if ( !p || !*p || !StringEqual( p, "SetError( TIXML_ERROR_PARSING_DECLARATION, 0, 0, _encoding ); - return 0; - } - if ( data ) - { - data->Stamp( p, _encoding ); - location = data->Cursor(); - } - p += 5; - - version = ""; - encoding = ""; - standalone = ""; - - while ( p && *p ) - { - if ( *p == '>' ) - { - ++p; - return p; - } - - p = SkipWhiteSpace( p, _encoding ); - if ( StringEqual( p, "version", true, _encoding ) ) - { - TiXmlAttribute attrib; - p = attrib.Parse( p, data, _encoding ); - version = attrib.Value(); - } - else if ( StringEqual( p, "encoding", true, _encoding ) ) - { - TiXmlAttribute attrib; - p = attrib.Parse( p, data, _encoding ); - encoding = attrib.Value(); - } - else if ( StringEqual( p, "standalone", true, _encoding ) ) - { - TiXmlAttribute attrib; - p = attrib.Parse( p, data, _encoding ); - standalone = attrib.Value(); - } - else - { - // Read over whatever it is. - while( p && *p && *p != '>' && !IsWhiteSpace( *p ) ) - ++p; - } - } - return 0; -} - -bool TiXmlText::Blank() const -{ - for ( unsigned i=0; i * - * * - * Part of the Free Heroes2 Engine: * - * http://sourceforge.net/projects/fheroes2 * - * * - * This program 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 * - * (at your option) any later version. * - * * - * This program 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 this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#ifndef XMLWRAP_H -#define XMLWRAP_H - -#include "tinyxml.h" -#include "gzstream.h" - -#endif