Przeglądaj źródła

Merge branch 'develop' of https://github.com/vcmi/vcmi into develop

DjWarmonger 10 lat temu
rodzic
commit
50b7b8e47b
53 zmienionych plików z 328 dodań i 1030 usunięć
  1. 0 23
      AI/BattleAI/BattleAI.cbp
  2. 1 29
      AI/EmptyAI/EmptyAI.cbp
  3. 0 28
      AI/FuzzyLite/FuzzyLite.cbp
  4. 0 24
      AI/StupidAI/StupidAI.cbp
  5. 0 28
      AI/VCAI/VCAI.cbp
  6. 14 21
      CMakeLists.txt
  7. 2 19
      client/CDefHandler.cpp
  8. 22 118
      client/CMT.cpp
  9. 1 4
      client/CMT.h
  10. 0 15
      client/CMusicHandler.cpp
  11. 9 49
      client/CPlayerInterface.cpp
  12. 3 10
      client/CPlayerInterface.h
  13. 0 10
      client/CPreGame.cpp
  14. 1 2
      client/CPreGame.h
  15. 0 49
      client/CVideoHandler.cpp
  16. 1 8
      client/CVideoHandler.h
  17. 0 2
      client/Graphics.cpp
  18. 0 41
      client/VCMI_client.cbp
  19. 5 3
      client/battle/CBattleAnimations.cpp
  20. 1 1
      client/battle/CBattleInterface.cpp
  21. 0 18
      client/battle/CCreatureAnimation.cpp
  22. 3 40
      client/gui/CAnimation.cpp
  23. 0 2
      client/gui/CCursorHandler.cpp
  24. 53 74
      client/gui/CGuiHandler.cpp
  25. 12 11
      client/gui/CGuiHandler.h
  26. 0 9
      client/gui/CIntObject.h
  27. 0 11
      client/gui/SDL_Compat.h
  28. 3 34
      client/gui/SDL_Extensions.cpp
  29. 1 37
      client/gui/SDL_Extensions.h
  30. 0 8
      client/gui/SDL_Pixels.h
  31. 0 20
      client/widgets/AdventureMapClasses.cpp
  32. 0 2
      client/widgets/AdventureMapClasses.h
  33. 0 5
      client/widgets/Buttons.cpp
  34. 2 27
      client/widgets/TextControls.cpp
  35. 0 4
      client/widgets/TextControls.h
  36. 5 8
      client/windows/CAdvmapInterface.cpp
  37. 1 1
      client/windows/CCreatureWindow.cpp
  38. 2 2
      client/windows/CSpellWindow.cpp
  39. 1 3
      client/windows/GUIClasses.cpp
  40. 18 18
      config/heroClasses.json
  41. 7 1
      config/objects/generic.json
  42. 17 3
      config/objects/moddables.json
  43. 3 0
      config/objects/rewardable.json
  44. 5 0
      config/schemas/objectTemplate.json
  45. 5 5
      lib/CGameState.cpp
  46. 0 11
      lib/HeroBonus.cpp
  47. 12 2
      lib/HeroBonus.h
  48. 16 29
      lib/NetPacksLib.cpp
  49. 0 35
      lib/VCMI_lib.cbp
  50. 0 29
      lib/minizip/minizip.cbp
  51. 102 56
      server/CGameHandler.cpp
  52. 0 29
      server/VCMI_server.cbp
  53. 0 12
      test/Test.cbp

+ 0 - 23
AI/BattleAI/BattleAI.cbp

@@ -29,29 +29,6 @@
 					<Add option="-s" />
 				</Linker>
 			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../BattleAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Debug/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-g" />
-				</Compiler>
-			</Target>
-			<Target title="Release-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../BattleAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Release/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-O2" />
-				</Compiler>
-				<Linker>
-					<Add option="-s" />
-				</Linker>
-			</Target>
 		</Build>
 		<Compiler>
 			<Add option="-pedantic" />

+ 1 - 29
AI/EmptyAI/EmptyAI.cbp

@@ -23,36 +23,8 @@
 				<Option type="3" />
 				<Option compiler="gcc" />
 				<Compiler>
-					<Add option="-fomit-frame-pointer" />
-					<Add option="-O3" />
+					<Add option="-O2" />
 				</Compiler>
-				<Linker>
-					<Add option="-s" />
-				</Linker>
-			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../EmptyAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Debug/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-ggdb" />
-				</Compiler>
-			</Target>
-			<Target title="Release-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../EmptyAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Release/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-fomit-frame-pointer" />
-					<Add option="-O3" />
-				</Compiler>
-				<Linker>
-					<Add option="-s" />
-				</Linker>
 			</Target>
 		</Build>
 		<Compiler>

+ 0 - 28
AI/FuzzyLite/FuzzyLite.cbp

@@ -34,34 +34,6 @@
 					<Add option="-s" />
 				</Linker>
 			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="bin/Debug/FuzzyLite" prefix_auto="1" extension_auto="1" />
-				<Option working_dir="" />
-				<Option object_output="obj/Debug/" />
-				<Option type="2" />
-				<Option compiler="gcc" />
-				<Option createDefFile="1" />
-				<Compiler>
-					<Add option="-g" />
-				</Compiler>
-			</Target>
-			<Target title="Release-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="bin/Release/FuzzyLite" prefix_auto="1" extension_auto="1" />
-				<Option working_dir="" />
-				<Option object_output="obj/Release/" />
-				<Option type="2" />
-				<Option compiler="gcc" />
-				<Option createDefFile="1" />
-				<Compiler>
-					<Add option="-fomit-frame-pointer" />
-					<Add option="-O2" />
-				</Compiler>
-				<Linker>
-					<Add option="-s" />
-				</Linker>
-			</Target>
 		</Build>
 		<Compiler>
 			<Add option="-Wextra" />

+ 0 - 24
AI/StupidAI/StupidAI.cbp

@@ -30,30 +30,6 @@
 					<Add option="-s" />
 				</Linker>
 			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../StupidAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Debug/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-ggdb" />
-				</Compiler>
-			</Target>
-			<Target title="Release-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../StupidAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Release/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-fomit-frame-pointer" />
-					<Add option="-O3" />
-				</Compiler>
-				<Linker>
-					<Add option="-s" />
-				</Linker>
-			</Target>
 		</Build>
 		<Compiler>
 			<Add option="-pedantic" />

+ 0 - 28
AI/VCAI/VCAI.cbp

@@ -34,34 +34,6 @@
 					<Add directory="../FuzzyLite/bin/Release" />
 				</Linker>
 			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../VCAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Debug/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-g" />
-				</Compiler>
-				<Linker>
-					<Add directory="../FuzzyLite/bin/Debug" />
-				</Linker>
-			</Target>
-			<Target title="Release-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../VCAI" imp_lib="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).a" def_file="$(TARGET_OUTPUT_DIR)$(TARGET_OUTPUT_BASENAME).def" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Release/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-fomit-frame-pointer" />
-					<Add option="-O3" />
-				</Compiler>
-				<Linker>
-					<Add option="-s" />
-					<Add directory="../FuzzyLite/bin/Release" />
-				</Linker>
-			</Target>
 		</Build>
 		<Compiler>
 			<Add option="-pedantic" />

+ 14 - 21
CMakeLists.txt

@@ -21,7 +21,6 @@ option(ENABLE_EDITOR "Enable compilation of map editor" OFF)
 option(ENABLE_LAUNCHER "Enable compilation of launcher" ON)
 option(ENABLE_TEST "Enable compilation of unit tests" OFF)
 option(ENABLE_PCH "Enable compilation using precompiled headers" ON)
-option(ENABLE_SDL2 "Use SDL2 for compilation instead of SDL 1.2" ON)
 
 ############################################
 #        Building section                  #
@@ -118,26 +117,20 @@ if (MINIZIP_FOUND)
     add_definitions(-DUSE_SYSTEM_MINIZIP)
 endif()
 
-if (ENABLE_SDL2)
-	find_package(SDL2 REQUIRED)
-	find_package(SDL2_image REQUIRED)
-	find_package(SDL2_mixer REQUIRED)
-	find_package(SDL2_ttf REQUIRED)
-
-	set(SDL_INCLUDE_DIR "${SDL2_INCLUDE_DIR}")
-	set(SDLTTF_INCLUDE_DIR "${SDL2_TTF_INCLUDE_DIR}")
-	set(SDLIMAGE_INCLUDE_DIR "${SDL2_IMAGE_INCLUDE_DIR}")
-	set(SDLMIXER_INCLUDE_DIR "${SDL2_MIXER_INCLUDE_DIR}")
-	set(SDL_LIBRARY "${SDL2_LIBRARY}")
-	set(SDLTTF_LIBRARY "${SDL2_TTF_LIBRARY}")
-	set(SDLIMAGE_LIBRARY "${SDL2_IMAGE_LIBRARY}")
-	set(SDLMIXER_LIBRARY "${SDL2_MIXER_LIBRARY}")
-else()
-	find_package(SDL REQUIRED)
-	find_package(SDL_image REQUIRED)
-	find_package(SDL_mixer REQUIRED)
-	find_package(SDL_ttf REQUIRED)
-endif()
+find_package(SDL2 REQUIRED)
+find_package(SDL2_image REQUIRED)
+find_package(SDL2_mixer REQUIRED)
+find_package(SDL2_ttf REQUIRED)
+
+set(SDL_INCLUDE_DIR "${SDL2_INCLUDE_DIR}")
+set(SDLTTF_INCLUDE_DIR "${SDL2_TTF_INCLUDE_DIR}")
+set(SDLIMAGE_INCLUDE_DIR "${SDL2_IMAGE_INCLUDE_DIR}")
+set(SDLMIXER_INCLUDE_DIR "${SDL2_MIXER_INCLUDE_DIR}")
+set(SDL_LIBRARY "${SDL2_LIBRARY}")
+set(SDLTTF_LIBRARY "${SDL2_TTF_LIBRARY}")
+set(SDLIMAGE_LIBRARY "${SDL2_IMAGE_LIBRARY}")
+set(SDLMIXER_LIBRARY "${SDL2_MIXER_LIBRARY}")
+
 include(cotire)
 
 if (ENABLE_EDITOR OR ENABLE_LAUNCHER)

+ 2 - 19
client/CDefHandler.cpp

@@ -181,24 +181,12 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co
 	BaseOffset += sizeof(SSpriteDef);
 	int BaseOffsetor = BaseOffset;
 
-	#ifdef VCMI_SDL1
-	for(int i=0; i<256; ++i)
-	{		
-		SDL_Color pr;
-		pr.r = palette[i].r;
-		pr.g = palette[i].g;
-		pr.b = palette[i].b;
-		pr.unused = palette[i].unused;
-		(*(ret->format->palette->colors+i))=pr;		
-	}
-	#else
 	if(SDL_SetPaletteColors(ret->format->palette,palette,0,256) != 0)
 	{
-		throw std::runtime_error("Unable to set palette");	
+		logGlobal->errorStream() << __FUNCTION__ <<": Unable to set palette";
+		logGlobal->errorStream() << SDL_GetError();		
 	}
 	
-	#endif
-
 	int ftcp=0;
 
 	// If there's a margin anywhere, just blank out the whole surface.
@@ -363,13 +351,8 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Co
 	}
 
 	SDL_Color ttcol = ret->format->palette->colors[0];
-	#ifdef VCMI_SDL1
-	Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.unused);	
-	SDL_SetColorKey(ret, SDL_SRCCOLORKEY, keycol);	
-	#else
 	Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.a);	
 	SDL_SetColorKey(ret, SDL_TRUE, keycol);	
-	#endif // 0
 
 	return ret;
 }

+ 22 - 118
client/CMT.cpp

@@ -69,12 +69,10 @@ std::string NAME = GameConstants::VCMI_VERSION + std::string(" (") + NAME_AFFIX
 CGuiHandler GH;
 static CClient *client=nullptr;
 
-#ifndef VCMI_SDL1
 int preferredDriverIndex = -1;
 SDL_Window * mainWindow = nullptr;
 SDL_Renderer * mainRenderer = nullptr;
 SDL_Texture * screenTexture = nullptr;
-#endif // VCMI_SDL1
 
 extern boost::thread_specific_ptr<bool> inGuiThread;
 
@@ -182,6 +180,18 @@ static void prog_help(const po::options_description &opts)
 // 	printf("  -v, --version     display version information and exit\n");
 }
 
+static void SDLLogCallback(void*           userdata,
+                           int             category,
+                           SDL_LogPriority priority,
+                           const char*     message)
+{
+	//todo: convert SDL log priority to vcmi log priority
+	//todo: make separate log domain for SDL
+	
+	logGlobal->debugStream() << "SDL(category " << category << "; priority " <<priority <<") "<<message;
+}
+
+
 #ifdef VCMI_APPLE
 void OSX_checkForUpdates();
 #endif
@@ -264,11 +274,6 @@ int main(int argc, char** argv)
 		gNoGUI = true;
 		vm.insert(std::pair<std::string, po::variable_value>("onlyAI", po::variable_value()));
 	}
-#ifdef VCMI_SDL1
-	//Set environment vars to make window centered. Sometimes work, sometimes not. :/
-	putenv((char*)"SDL_VIDEO_WINDOW_POS");
-	putenv((char*)"SDL_VIDEO_CENTERED=1");
-#endif
 
 	// Have effect on X11 system only (Linux).
 	// For whatever reason in fullscreen mode SDL takes "raw" mouse input from DGA X11 extension
@@ -338,11 +343,7 @@ int main(int argc, char** argv)
 
 	if(!gNoGUI)
 	{
-		#ifdef VCMI_SDL1
-		if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO))
-		#else
 		if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO|SDL_INIT_NOPARACHUTE))
-		#endif
 		{
 			logGlobal->errorStream()<<"Something was wrong: "<< SDL_GetError();
 			exit(-1);
@@ -350,7 +351,8 @@ int main(int argc, char** argv)
 		GH.mainFPSmng->init(); //(!)init here AFTER SDL_Init() while using SDL for FPS management
 		atexit(SDL_Quit);
 		
-		#ifndef VCMI_SDL1
+		SDL_LogSetOutputFunction(&SDLLogCallback, nullptr);
+		
 		int driversCount = SDL_GetNumRenderDrivers();
 		std::string preferredDriverName = video["driver"].String();
 		
@@ -371,7 +373,6 @@ int main(int argc, char** argv)
 			else
 				logGlobal->infoStream() << "\t" << driverName;
 		}			
-		#endif // VCMI_SDL1	
 		
 		config::CConfigHandler::GuiOptionsMap::key_type resPair(res["width"].Float(), res["height"].Float());
 		if (conf.guiOptions.count(resPair) == 0)
@@ -823,7 +824,6 @@ void dispose()
 
 static bool checkVideoMode(int monitorIndex, int w, int h, int& bpp, bool fullscreen)
 {
-	#ifndef VCMI_SDL1
 	SDL_DisplayMode mode;
 	const int modeCount = SDL_GetNumDisplayModes(monitorIndex);
 	for (int i = 0; i < modeCount; i++) {
@@ -833,13 +833,8 @@ static bool checkVideoMode(int monitorIndex, int w, int h, int& bpp, bool fullsc
 		}
 	}
 	return false;	
-	#else
-	bpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0));
-	return !(bpp==0);
-	#endif // VCMI_SDL1
 }
 
-#ifndef VCMI_SDL1
 static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
 {
 	// VCMI will only work with 2 or 4 bytes per pixel	
@@ -982,91 +977,14 @@ static bool recreateWindow(int w, int h, int bpp, bool fullscreen)
 		
 	return true;	
 }
-#endif
-
-
 
 //used only once during initialization
 static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo)
 {
-#ifdef VCMI_SDL1
-	
-	// VCMI will only work with 2, 3 or 4 bytes per pixel
-	vstd::amax(bpp, 16);
-	vstd::amin(bpp, 32);
-
-	// Try to use the best screen depth for the display
-	int suggestedBpp = SDL_VideoModeOK(w, h, bpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0));
-	if(suggestedBpp == 0)
-	{
-		logGlobal->errorStream() << "Error: SDL says that " << w << "x" << h << " resolution is not available!";
-		return;
-	}
-
-	bool bufOnScreen = (screenBuf == screen);
-
-	if(suggestedBpp != bpp)
-	{
-		logGlobal->infoStream() << boost::format("Using %s bpp (bits per pixel) for the video mode. Default or overridden setting was %s bpp.") % suggestedBpp % bpp;
-	}
-
-	//For some reason changing fullscreen via config window checkbox result in SDL_Quit event
-	if (resetVideo)
-	{
-		if(screen) //screen has been already initialized
-			SDL_QuitSubSystem(SDL_INIT_VIDEO);
-		SDL_InitSubSystem(SDL_INIT_VIDEO);
-	}
-
-	if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == nullptr)
-	{
-		logGlobal->errorStream() << "Requested screen resolution is not available (" << w << "x" << h << "x" << suggestedBpp << "bpp)";
-		throw std::runtime_error("Requested screen resolution is not available\n");
-	}
-
-	logGlobal->infoStream() << "New screen flags: " << screen->flags;
-
-	if(screen2)
-		SDL_FreeSurface(screen2);
-	screen2 = CSDL_Ext::copySurface(screen);
-	SDL_EnableUNICODE(1);
-	SDL_WM_SetCaption(NAME.c_str(),""); //set window title
-	SDL_ShowCursor(SDL_DISABLE);
-	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-
-#ifdef VCMI_WINDOWS
-	SDL_SysWMinfo wm;
-	SDL_VERSION(&wm.version);
-	int getwm = SDL_GetWMInfo(&wm);
-	if(getwm == 1)
-	{
-		int sw = GetSystemMetrics(SM_CXSCREEN),
-			sh = GetSystemMetrics(SM_CYSCREEN);
-		RECT curpos;
-		GetWindowRect(wm.window,&curpos);
-		int ourw = curpos.right - curpos.left,
-			ourh = curpos.bottom - curpos.top;
-		SetWindowPos(wm.window, 0, (sw - ourw)/2, (sh - ourh)/2, 0, 0, SWP_NOZORDER|SWP_NOSIZE);
-	}
-	else
-	{
-        logGlobal->warnStream() << "Something went wrong, getwm=" << getwm;
-        logGlobal->warnStream() << "SDL says: " << SDL_GetError();
-        logGlobal->warnStream() << "Window won't be centered.";
-	}
-#endif
-	//TODO: centering game window on other platforms (or does the environment do their job correctly there?)
-
-	screenBuf = bufOnScreen ? screen : screen2;
-	//setResolution = true;	
-	
-#else
-	
 	if(!recreateWindow(w,h,bpp,fullscreen))
 	{
 		throw std::runtime_error("Requested screen resolution is not available\n");
 	}	
-#endif // VCMI_SDL1
 }
 
 static void fullScreenChanged()
@@ -1078,19 +996,6 @@ static void fullScreenChanged()
 
 	auto bitsPerPixel = screen->format->BitsPerPixel;
 	
-	#ifdef VCMI_SDL1
-	bitsPerPixel = SDL_VideoModeOK(screen->w, screen->h, bitsPerPixel, SDL_SWSURFACE|(toFullscreen?SDL_FULLSCREEN:0));
-	if(bitsPerPixel == 0)
-	{
-        logGlobal->errorStream() << "Error: SDL says that " << screen->w << "x" << screen->h << " resolution is not available!";
-		return;
-	}
-
-	bool bufOnScreen = (screenBuf == screen);
-	screen = SDL_SetVideoMode(screen->w, screen->h, bitsPerPixel, SDL_SWSURFACE|(toFullscreen?SDL_FULLSCREEN:0));
-	screenBuf = bufOnScreen ? screen : screen2;
-	
-	#else
 	auto w = screen->w;
 	auto h = screen->h;
 	
@@ -1099,7 +1004,6 @@ static void fullScreenChanged()
 		//will return false and report error if video mode is not supported
 		return;	
 	}	
-	#endif
 	
 	GH.totalRedraw();
 }
@@ -1111,13 +1015,7 @@ static void handleEvent(SDL_Event & ev)
 		handleQuit();	
 		return;
 	}
-
-	#ifdef VCMI_SDL1
-	//FIXME: this should work even in pregame
-	else if(LOCPLINT && ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4)
-	#else
 	else if(ev.type == SDL_KEYDOWN && ev.key.keysym.sym==SDLK_F4)
-	#endif // VCMI_SDL1		
 	{
 		Settings full = settings.write["video"]["fullscreen"];
 		full->Bool() = !full->Bool();
@@ -1127,6 +1025,12 @@ static void handleEvent(SDL_Event & ev)
 	{
 		switch(ev.user.code)
 		{
+		case FORCE_QUIT:
+			{
+				handleQuit(false);	
+				return;			
+			}
+		    break;
 		case RETURN_TO_MAIN_MENU:
 			{
 				endGame();
@@ -1244,7 +1148,7 @@ void endGame()
 	vstd::clear_pointer(client);
 }
 
-void handleQuit()
+void handleQuit(bool ask/* = true*/)
 {
 	auto quitApplication = []()
 	{
@@ -1261,7 +1165,7 @@ void handleQuit()
 		exit(0);
 	};
 
-	if(client && LOCPLINT)
+	if(client && LOCPLINT && ask)
 	{
 		CCS->curh->changeGraphic(ECursor::ADVENTURE, 0);
 		LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[69], quitApplication, 0);

+ 1 - 4
client/CMT.h

@@ -1,6 +1,5 @@
 #pragma once
 
-#ifndef VCMI_SDL1
 #include <SDL_render.h>
 
 extern SDL_Texture * screenTexture;
@@ -8,8 +7,6 @@ extern SDL_Texture * screenTexture;
 extern SDL_Window * mainWindow;
 extern SDL_Renderer * mainRenderer;
 
-#endif // VCMI_SDL2
-
 extern SDL_Surface *screen;      // main screen surface
 extern SDL_Surface *screen2;     // and hlp surface (used to store not-active interfaces layer)
 extern SDL_Surface *screenBuf; // points to screen (if only advmapint is present) or screen2 (else) - should be used when updating controls which are not regularly redrawed
@@ -17,4 +14,4 @@ extern SDL_Surface *screenBuf; // points to screen (if only advmapint is present
 
 extern bool gNoGUI; //if true there is no client window and game is silently played between AIs
 
-void handleQuit();
+void handleQuit(bool ask = true);

+ 0 - 15
client/CMusicHandler.cpp

@@ -451,18 +451,6 @@ void MusicEntry::load(std::string musicURI)
 	data = CResourceHandler::get()->load(ResourceID(musicURI, EResType::MUSIC))->readAll();
 	musicFile = SDL_RWFromConstMem(data.first.get(), data.second);
 	
-	#ifdef VCMI_SDL1
-	music = Mix_LoadMUS_RW(musicFile);
-
-	if(!music)
-	{
-		SDL_FreeRW(musicFile);
-		musicFile = nullptr;
-		logGlobal->warnStream() << "Warning: Cannot open " << currentName << ": " << Mix_GetError();
-		return;
-	}
-
-	#else
 	music = Mix_LoadMUS_RW(musicFile, SDL_FALSE);
 
 	if(!music)
@@ -472,9 +460,6 @@ void MusicEntry::load(std::string musicURI)
 		logGlobal->warnStream() << "Warning: Cannot open " << currentName << ": " << Mix_GetError();
 		return;
 	}
-
-	#endif // 0
-
 }
 
 bool MusicEntry::play()

+ 9 - 49
client/CPlayerInterface.cpp

@@ -78,7 +78,6 @@ void processCommand(const std::string &message, CClient *&client);
 extern std::queue<SDL_Event> events;
 extern boost::mutex eventsM;
 boost::recursive_mutex * CPlayerInterface::pim = new boost::recursive_mutex;
-CondSh<bool> CPlayerInterface::terminate_cond;
 
 CPlayerInterface * LOCPLINT;
 
@@ -112,14 +111,13 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player)
 	makingTurn = false;
 	showingDialog = new CondSh<bool>(false);
 	cingconsole = new CInGameConsole;
-	terminate_cond.set(false);
+	GH.terminate_cond.set(false);
 	firstCall = 1; //if loading will be overwritten in serialize
 	autosaveCount = 0;
 	isAutoFightOn = false;
 
 	duringMovement = false;
-	ignoreEvents = false;
-	locked = false;
+	ignoreEvents = false;	
 }
 
 CPlayerInterface::~CPlayerInterface()
@@ -1545,16 +1543,11 @@ void CPlayerInterface::centerView (int3 pos, int focusTime)
 	if(focusTime)
 	{
 		GH.totalRedraw();
-		#ifdef VCMI_SDL1
-		CSDL_Ext::update(screen);
-		SDL_Delay(focusTime);
-		#else
 		{
 			auto unlockPim = vstd::makeUnlockGuard(*pim);
 			IgnoreEvents ignore(*this);
 			SDL_Delay(focusTime);
 		}
-		#endif
 	}
 }
 
@@ -1595,11 +1588,13 @@ void CPlayerInterface::setSelection(const CArmedInstance * obj)
 
 void CPlayerInterface::update()
 {
-	if (!locked)
-	{
-		logGlobal->errorStream() << "Non synchronized update of PlayerInterface";
+	// Make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request
+	boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
+	
+	// While mutexes were locked away we may be have stopped being the active interface	
+	if(LOCPLINT != this)
 		return;
-	}
+	
 	//if there are any waiting dialogs, show them
 	if((howManyPeople <= 1 || makingTurn) && !dialogs.empty() && !showingDialog->get())
 	{
@@ -1622,41 +1617,6 @@ void CPlayerInterface::update()
 		GH.totalRedraw();
 	else
 		GH.simpleRedraw();
-
-	if (settings["general"]["showfps"].Bool())
-		GH.drawFPSCounter();
-}
-
-void CPlayerInterface::runLocked(std::function<void()> functor)
-{
-	// Updating GUI requires locking pim mutex (that protects screen and GUI state).
-	// When ending the game, the pim mutex might be hold by other thread,
-	// that will notify us about the ending game by setting terminate_cond flag.
-
-	bool acquiredTheLockOnPim = false; //for tracking whether pim mutex locking succeeded
-	while(!terminate_cond.get() && !(acquiredTheLockOnPim = pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate
-		boost::this_thread::sleep(boost::posix_time::milliseconds(15));
-
-	if(!acquiredTheLockOnPim)
-	{
-		// We broke the while loop above and not because of mutex, so we must be terminating.
-		assert(terminate_cond.get());
-		return;
-	}
-
-	// If we are here, pim mutex has been successfully locked - let's store it in a safe RAII lock.
-	boost::unique_lock<boost::recursive_mutex> un(*pim, boost::adopt_lock);
-
-	// While mutexes were locked away we may be have stopped being the active interface
-	if(LOCPLINT != this)
-		return;
-
-	// Make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request
-	boost::shared_lock<boost::shared_mutex> gsLock(cb->getGsMutex());
-
-	locked = true;
-	functor();
-	locked = false;
 }
 
 int CPlayerInterface::getLastIndex( std::string namePrefix)
@@ -2138,7 +2098,7 @@ void CPlayerInterface::gameOver(PlayerColor player, const EVictoryLossCheckResul
 		{
 			if(adventureInt)
 			{
-				terminate_cond.setn(true);
+				GH.terminate_cond.setn(true);
 				adventureInt->deactivate();
 				if(GH.topInt() == adventureInt)
 					GH.popInt(adventureInt);

+ 3 - 10
client/CPlayerInterface.h

@@ -1,7 +1,6 @@
 #pragma once
 
 
-//#include "../lib/CondSh.h"
 #include "../lib/FunctionList.h"
 #include "../lib/CGameInterface.h"
 #include "../lib/NetPacksBase.h"
@@ -80,11 +79,12 @@ enum
 	RESTART_GAME,
 	RETURN_TO_MENU_LOAD,
 	FULLSCREEN_TOGGLED,
-	PREPARE_RESTART_CAMPAIGN
+	PREPARE_RESTART_CAMPAIGN,
+	FORCE_QUIT //quit client without question
 };
 
 /// Central class for managing user interface logic
-class CPlayerInterface : public CGameInterface, public ILockedUpdatable
+class CPlayerInterface : public CGameInterface, public IUpdateable
 {
 	const CArmedInstance * currentSelection;
 public:
@@ -135,7 +135,6 @@ public:
 	} spellbookSettings;
 
 	void update() override;
-	void runLocked(std::function<void()> functor) override;
 	void initializeHeroTownList();
 	int getLastIndex(std::string namePrefix);
 
@@ -270,10 +269,6 @@ public:
 	CPlayerInterface(PlayerColor Player);//c-tor
 	~CPlayerInterface();//d-tor
 
-	static CondSh<bool> terminate_cond; // confirm termination
-
-
-
 private:
 
 	template <typename Handler> void serializeTempl(Handler &h, const int version);
@@ -299,8 +294,6 @@ private:
 	bool duringMovement;
 	bool ignoreEvents;
 
-	bool locked;
-
 	void doMoveHero(const CGHeroInstance *h, CGPath path);
 };
 

+ 0 - 10
client/CPreGame.cpp

@@ -516,7 +516,6 @@ void CGPreGame::disposeGraphics()
 
 void CGPreGame::update()
 {
-	boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim);
 	if(CGP != this) //don't update if you are not a main interface
 		return;
 
@@ -538,15 +537,6 @@ void CGPreGame::update()
 	// /FIXME: find out why GH.listInt is empty to begin with
 	if (GH.topInt() != nullptr)
 		GH.topInt()->show(screen);
-
-	if (settings["general"]["showfps"].Bool())
-		GH.drawFPSCounter();
-}
-
-void CGPreGame::runLocked(std::function<void()> cb)
-{
-	boost::unique_lock<boost::recursive_mutex> lock(*CPlayerInterface::pim);
-	cb();	
 }
 
 void CGPreGame::openCampaignScreen(std::string name)

+ 1 - 2
client/CPreGame.h

@@ -597,7 +597,7 @@ private:
 };
 
 /// Handles background screen, loads graphics for victory/loss condition and random town or hero selection
-class CGPreGame : public CIntObject, public ILockedUpdatable
+class CGPreGame : public CIntObject, public IUpdateable
 {
 	void loadGraphics();
 	void disposeGraphics();
@@ -611,7 +611,6 @@ public:
 
 	~CGPreGame();
 	void update() override;
-	void runLocked(std::function<void()> cb) override;
 	void openSel(CMenuScreen::EState type, CMenuScreen::EMultiMode multi = CMenuScreen::SINGLE_PLAYER);
 
 	void openCampaignScreen(std::string name);

+ 0 - 49
client/CVideoHandler.cpp

@@ -53,11 +53,7 @@ CVideoPlayer::CVideoPlayer()
 	frame = nullptr;
 	codec = nullptr;
 	sws = nullptr;
-#ifdef VCMI_SDL1
-	overlay = nullptr;
-#else
 	texture = nullptr;
-#endif
 	dest = nullptr;
 	context = nullptr;
 
@@ -173,13 +169,7 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal
 	// Allocate a place to put our YUV image on that screen
 	if (useOverlay)
 	{
-#ifdef VCMI_SDL1
-		overlay = SDL_CreateYUVOverlay(pos.w, pos.h,
-									   SDL_YV12_OVERLAY, screen);
-#else
 		texture = SDL_CreateTexture( mainRenderer, SDL_PIXELFORMAT_IYUV, SDL_TEXTUREACCESS_STATIC, pos.w, pos.h);
-#endif
-
 	}
 	else
 	{
@@ -188,17 +178,11 @@ bool CVideoPlayer::open(std::string fname, bool loop, bool useOverlay, bool scal
 		destRect.w = pos.w;
 		destRect.h = pos.h;
 	}
-#ifdef VCMI_SDL1
-	if (overlay == nullptr && dest == nullptr)
-		return false;
 
-	if (overlay)
-#else
 	if (texture == nullptr && dest == nullptr)
 		return false;
 
 	if (texture)
-#endif
 	{ // Convert the image into YUV format that SDL uses
 		sws = sws_getContext(codecContext->width, codecContext->height, codecContext->pix_fmt, 
 							 pos.w, pos.h, PIX_FMT_YUV420P, 
@@ -284,23 +268,6 @@ bool CVideoPlayer::nextFrame()
 				{
 					AVPicture pict;
 
-#ifdef VCMI_SDL1
-					if (overlay) {
-						SDL_LockYUVOverlay(overlay);
-
-						pict.data[0] = overlay->pixels[0];
-						pict.data[1] = overlay->pixels[2];
-						pict.data[2] = overlay->pixels[1];
-
-						pict.linesize[0] = overlay->pitches[0];
-						pict.linesize[1] = overlay->pitches[2];
-						pict.linesize[2] = overlay->pitches[1];
-
-						sws_scale(sws, frame->data, frame->linesize,
-								  0, codecContext->height, pict.data, pict.linesize);
-
-						SDL_UnlockYUVOverlay(overlay);
-#else
 					if (texture) {
 						avpicture_alloc(&pict, AV_PIX_FMT_YUV420P, pos.w, pos.h);
 
@@ -311,7 +278,6 @@ bool CVideoPlayer::nextFrame()
 								pict.data[1], pict.linesize[1],
 								pict.data[2], pict.linesize[2]);
 						avpicture_free(&pict);
-#endif
 					}
 					else
 					{
@@ -387,22 +353,12 @@ void CVideoPlayer::close()
 		sws = nullptr;
 	}
 
-#ifdef VCMI_SDL1
-	if (overlay)
-	{
-		SDL_FreeYUVOverlay(overlay);
-		overlay = nullptr;
-	}
-#else
 	if (texture)
 	{
 		SDL_DestroyTexture(texture);
 		texture = nullptr;
 	}
 
-#endif
-
-
 	if (dest)
 	{
 		SDL_FreeSurface(dest);
@@ -455,13 +411,8 @@ bool CVideoPlayer::playVideo(int x, int y, SDL_Surface *dst, bool stopOnKey)
 		if(stopOnKey && keyDown())
 			return false;
 
-#ifdef VCMI_SDL1
-		SDL_DisplayYUVOverlay(overlay, &pos);
-#else
 		SDL_RenderCopy(mainRenderer, texture, NULL, &pos);
 		SDL_RenderPresent(mainRenderer);
-#endif
-
 
 		// Wait 3 frames
 		GH.mainFPSmng->framerateDelay();

+ 1 - 8
client/CVideoHandler.h

@@ -47,9 +47,6 @@ public:
 
 #include <SDL.h>
 #include <SDL_video.h>
-#if SDL_VERSION_ATLEAST(1,3,0) && !SDL_VERSION_ATLEAST(2,0,0)
-#include <SDL_compat.h>
-#endif
 
 extern "C" {
 #include <libavformat/avformat.h>
@@ -80,12 +77,8 @@ class CVideoPlayer : public IMainVideoPlayer
 	AVIOContext * context;
 
 	// Destination. Either overlay or dest.
-#ifdef VCMI_SDL1
-	SDL_Overlay * overlay;
-#else
-	SDL_Texture *texture;
-#endif
 
+	SDL_Texture *texture;
 	SDL_Surface *dest;
 	SDL_Rect destRect;			// valid when dest is used
 	SDL_Rect pos;				// destination on screen

+ 0 - 2
client/Graphics.cpp

@@ -266,9 +266,7 @@ void Graphics::loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphi
 		for(auto & curImg : curImgs)
 		{
 			CSDL_Ext::setDefaultColorKey(curImg.bitmap);
-			#ifndef VCMI_SDL1
 			SDL_SetSurfaceBlendMode(curImg.bitmap,SDL_BLENDMODE_NONE);
-			#endif
 		}
 	}
 }

+ 0 - 41
client/VCMI_client.cbp

@@ -47,47 +47,6 @@
 					<Add directory="$(#sdl2.lib)" />
 				</Linker>
 			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../VCMI_client" prefix_auto="1" extension_auto="1" />
-				<Option working_dir="../" />
-				<Option object_output="../obj/Debug/" />
-				<Option type="1" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-Og" />
-					<Add option="-g" />
-					<Add directory="$(#sdl.include)" />
-				</Compiler>
-				<Linker>
-					<Add option="-lSDL" />
-					<Add option="-lSDL_image" />
-					<Add option="-lSDL_mixer" />
-					<Add option="-lSDL_ttf" />
-					<Add directory="$(#sdl.lib)" />
-				</Linker>
-			</Target>
-			<Target title="Release-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../VCMI_client" prefix_auto="1" extension_auto="1" />
-				<Option working_dir="../" />
-				<Option object_output="../obj/Release/" />
-				<Option type="1" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-fomit-frame-pointer" />
-					<Add option="-O2" />
-					<Add directory="$(#sdl.include)" />
-				</Compiler>
-				<Linker>
-					<Add option="-s" />
-					<Add option="-lSDL" />
-					<Add option="-lSDL_image" />
-					<Add option="-lSDL_mixer" />
-					<Add option="-lSDL_ttf" />
-					<Add directory="$(#sdl.lib)" />
-				</Linker>
-			</Target>
 		</Build>
 		<Compiler>
 			<Add option="-Wextra" />

+ 5 - 3
client/battle/CBattleAnimations.cpp

@@ -233,7 +233,7 @@ std::string CDefenceAnimation::getMySound()
 	if(killed)
 		return battle_sound(stack->getCreature(), killed);
 
-	if (stack->valOfBonuses(Selector::durationType(Bonus::STACK_GETS_TURN)))
+	if (stack->valOfBonuses(Bonus::UntilGetsTurn))
 		return battle_sound(stack->getCreature(), defend);
 	return battle_sound(stack->getCreature(), wince);
 }
@@ -242,8 +242,10 @@ CCreatureAnim::EAnimType CDefenceAnimation::getMyAnimType()
 {
 	if(killed)
 		return CCreatureAnim::DEATH;
-
-	if (stack->valOfBonuses(Selector::durationType(Bonus::STACK_GETS_TURN).And(Selector::typeSubtype(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE))))
+	
+	auto selector = CSelector(Bonus::UntilGetsTurn).And(Selector::typeSubtype(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE));
+	
+	if(stack->valOfBonuses(selector))
 		return CCreatureAnim::DEFENCE;
 	return CCreatureAnim::HITTED;
 }

+ 1 - 1
client/battle/CBattleInterface.cpp

@@ -1487,7 +1487,7 @@ void CBattleInterface::battleStacksEffectsSet(const SetStackEffect & sse)
 				txtid++; //move to plural text
 
 			BonusList defenseBonuses = *(stack->getBonuses(Selector::typeSubtype(Bonus::PRIMARY_SKILL, PrimarySkill::DEFENSE)));
-			defenseBonuses.remove_if(Selector::durationType(Bonus::STACK_GETS_TURN)); //remove bonuses gained from defensive stance
+			defenseBonuses.remove_if(Bonus::UntilGetsTurn); //remove bonuses gained from defensive stance
 			int val = stack->Defense() - defenseBonuses.totalValue();
 			auto txt = boost::format (CGI->generaltexth->allTexts[txtid]) % ((stack->count != 1) ? stack->getCreature()->namePl : stack->getCreature()->nameSing) % val;
 			console->addText(boost::to_string(txt));

+ 0 - 18
client/battle/CCreatureAnimation.cpp

@@ -267,11 +267,7 @@ static SDL_Color genShadow(ui8 alpha)
 
 static SDL_Color genBorderColor(ui8 alpha, const SDL_Color & base)
 {
-	#ifdef VCMI_SDL1
-	return CSDL_Ext::makeColor(base.r, base.g, base.b, ui8(base.unused * alpha / 256));
-	#else
 	return CSDL_Ext::makeColor(base.r, base.g, base.b, ui8(base.a * alpha / 256));
-	#endif
 }
 
 static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2)
@@ -281,22 +277,12 @@ static ui8 mixChannels(ui8 c1, ui8 c2, ui8 a1, ui8 a2)
 
 static SDL_Color addColors(const SDL_Color & base, const SDL_Color & over)
 {
-	#ifdef VCMI_SDL1
-	return CSDL_Ext::makeColor(
-			mixChannels(over.r, base.r, over.unused, base.unused),
-			mixChannels(over.g, base.g, over.unused, base.unused),
-			mixChannels(over.b, base.b, over.unused, base.unused),
-			ui8(over.unused + base.unused * (255 - over.unused) / 256)
-			);
-	#else
 	return CSDL_Ext::makeColor(
 			mixChannels(over.r, base.r, over.a, base.a),
 			mixChannels(over.g, base.g, over.a, base.a),
 			mixChannels(over.b, base.b, over.a, base.a),
 			ui8(over.a + base.a * (255 - over.a) / 256)
 			);
-
-	#endif // VCMI_SDL1
 }
 
 std::array<SDL_Color, 8> CCreatureAnimation::genSpecialPalette()
@@ -427,11 +413,7 @@ inline void CCreatureAnimation::putPixel(ui8 * dest, const SDL_Color & color, si
 	if (index < 8)
 	{
 		const SDL_Color & pal = special[index];
-		#ifdef VCMI_SDL1
-		ColorPutter<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.unused);
-		#else
 		ColorPutter<bpp, 0>::PutColor(dest, pal.r, pal.g, pal.b, pal.a);
-		#endif // 0		
 	}
 	else
 	{

+ 3 - 40
client/gui/CAnimation.cpp

@@ -387,7 +387,7 @@ inline void SDLImageLoader::EndLine()
 SDLImageLoader::~SDLImageLoader()
 {
 	SDL_UnlockSurface(image->surf);
-	SDL_SetColorKey(image->surf, SDL_SRCCOLORKEY, 0);
+	SDL_SetColorKey(image->surf, SDL_TRUE, 0);
 	//TODO: RLE if compressed and bpp>1
 }
 
@@ -444,13 +444,9 @@ inline ui8 CompImageLoader::typeOf(ui8 color)
 {
 	if (color == 0)
 		return 0;
-	#ifdef VCMI_SDL1
-	if (image->palette[color].unused != 255)
-		return 1;
-	#else
+
 	if (image->palette[color].a != 255)
 		return 1;
-	#endif // 0
 		
 	return 2;
 }
@@ -628,22 +624,11 @@ SDLImage::SDLImage(std::string filename, bool compressed):
 	{
 		SDL_Surface *temp = surf;
 		// add RLE flag
-		#ifdef VCMI_SDL1
-		if (surf->format->palette)
-		{
-			const SDL_Color &c = temp->format->palette->colors[0];
-			SDL_SetColorKey(temp, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
-				SDL_MapRGB(temp -> format, c.r, c.g, c.b));
-		}
-		else
-			SDL_SetColorKey(temp, SDL_RLEACCEL, 0);
-		#else
 		if (surf->format->palette)
 		{
 			CSDL_Ext::setColorKey(temp,temp->format->palette->colors[0]);
 		}
 		SDL_SetSurfaceRLE(temp, SDL_RLEACCEL);		
-		#endif		
 
 		// convert surface to enable RLE
 		surf = SDL_ConvertSurface(temp, temp->format, temp->flags);
@@ -811,21 +796,13 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha)
 			for (size_t i=0; i<size; i++)
 			{
 				SDL_Color col = palette[*(data++)];
-				#ifdef VCMI_SDL1
-				col.unused = (ui32)col.unused*alpha/255;
-				#else
 				col.a = (ui32)col.a*alpha/255;
-				#endif // 0				
 				ColorPutter<bpp, 1>::PutColorAlpha(dest, col);
 			}
 			return;
 		}
-		
-		#ifdef VCMI_SDL1
-		if (palette[color].unused == 255)
-		#else
+
 		if (palette[color].a == 255)
-		#endif // 0		
 		{
 			//Put row of RGB data
 			for (size_t i=0; i<size; i++)
@@ -842,19 +819,6 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha)
 	//RLE-d sequence
 	else
 	{
-		#ifdef VCMI_SDL1
-		if (alpha != 255 && palette[type].unused !=0)//Per-surface alpha is set
-		{
-			SDL_Color col = palette[type];
-			col.unused = (int)col.unused*(255-alpha)/255;
-			for (size_t i=0; i<size; i++)
-				ColorPutter<bpp, 1>::PutColorAlpha(dest, col);
-			return;
-		}	
-
-		switch (palette[type].unused)
-				
-		#else
 		if (alpha != 255 && palette[type].a !=0)//Per-surface alpha is set
 		{
 			SDL_Color col = palette[type];
@@ -865,7 +829,6 @@ void CompImage::BlitBlock(ui8 type, ui8 size, ui8 *&data, ui8 *&dest, ui8 alpha)
 		}
 		
 		switch (palette[type].a)
-		#endif // 0
 		{
 			case 0:
 			{

+ 0 - 2
client/gui/CCursorHandler.cpp

@@ -27,10 +27,8 @@ void CCursorHandler::initCursor()
 	currentCursor = nullptr;
 
 	help = CSDL_Ext::newSurface(40,40);
-	#ifndef VCMI_SDL1
 	//No blending. Ensure, that we are copying pixels during "screen restore draw"
 	SDL_SetSurfaceBlendMode(help,SDL_BLENDMODE_NONE);	
-	#endif // VCMI_SDL1
 	SDL_ShowCursor(SDL_DISABLE);
 
 	changeGraphic(ECursor::ADVENTURE, 0);

+ 53 - 74
client/gui/CGuiHandler.cpp

@@ -1,5 +1,6 @@
 #include "StdInc.h"
 #include "CGuiHandler.h"
+#include "../lib/CondSh.h"
 
 #include <SDL.h>
 
@@ -15,6 +16,7 @@
 extern std::queue<SDL_Event> events;
 extern boost::mutex eventsM;
 
+CondSh<bool> CGuiHandler::terminate_cond;
 boost::thread_specific_ptr<bool> inGuiThread;
 
 SObjectConstruction::SObjectConstruction( CIntObject *obj )
@@ -63,10 +65,7 @@ void CGuiHandler::processLists(const ui16 activityFlag, std::function<void (std:
 	processList(CIntObject::TIME,activityFlag,&timeinterested,cb);
 	processList(CIntObject::WHEEL,activityFlag,&wheelInterested,cb);
 	processList(CIntObject::DOUBLECLICK,activityFlag,&doubleClickInterested,cb);
-	
-	#ifndef VCMI_SDL1
 	processList(CIntObject::TEXTINPUT,activityFlag,&textInterested,cb);
-	#endif // VCMI_SDL1
 }
 
 void CGuiHandler::handleElementActivate(CIntObject * elem, ui16 activityFlag)
@@ -196,10 +195,8 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
 		//translate numpad keys
 		if(key.keysym.sym == SDLK_KP_ENTER)
 		{
-			key.keysym.sym = (SDLKey)SDLK_RETURN;
-			#ifndef VCMI_SDL1
+			key.keysym.sym = SDLK_RETURN;
 			key.keysym.scancode = SDL_SCANCODE_RETURN;
-			#endif // VCMI_SDL1
 		}
 
 		bool keysCaptured = false;
@@ -270,19 +267,7 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
 				}
 			}
 		}
-		#ifdef VCMI_SDL1 //SDL1x only events
-		else if(sEvent->button.button == SDL_BUTTON_WHEELDOWN || sEvent->button.button == SDL_BUTTON_WHEELUP)
-		{
-			std::list<CIntObject*> hlp = wheelInterested;
-			for(auto i=hlp.begin(); i != hlp.end() && current; i++)
-			{
-				if(!vstd::contains(wheelInterested,*i)) continue;
-				(*i)->wheelScrolled(sEvent->button.button == SDL_BUTTON_WHEELDOWN, isItIn(&(*i)->pos,sEvent->motion.x,sEvent->motion.y));
-			}
-		}
-		#endif
 	}
-	#ifndef VCMI_SDL1 //SDL2x only events	
 	else if (sEvent->type == SDL_MOUSEWHEEL)
 	{
 		std::list<CIntObject*> hlp = wheelInterested;
@@ -307,7 +292,6 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
 		}
 	}	
 	//todo: muiltitouch
-	#endif // VCMI_SDL1
 	else if ((sEvent->type==SDL_MOUSEBUTTONUP) && (sEvent->button.button == SDL_BUTTON_LEFT))
 	{
 		std::list<CIntObject*> hlp = lclickable;
@@ -341,7 +325,6 @@ void CGuiHandler::handleEvent(SDL_Event *sEvent)
 		}
 	}
 	current = nullptr;
-
 } //event end
 
 void CGuiHandler::handleMouseMotion(SDL_Event *sEvent)
@@ -394,12 +377,9 @@ void CGuiHandler::handleMoveInterested( const SDL_MouseMotionEvent & motion )
 void CGuiHandler::fakeMouseMove()
 {
 	SDL_Event evnt;
-#ifdef VCMI_SDL1
-	SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0};
-#else
 	SDL_MouseMotionEvent sme = {SDL_MOUSEMOTION, 0, 0, 0, 0, 0, 0, 0, 0};
-#endif	
 	int x, y;
+
 	sme.state = SDL_GetMouseState(&x, &y);
 	sme.x = x;
 	sme.y = y;
@@ -411,28 +391,42 @@ void CGuiHandler::fakeMouseMove()
 
 void CGuiHandler::renderFrame()
 {
-	auto doUpdate = [this]()
 	{
-		if(nullptr != curInt)
+	// Updating GUI requires locking pim mutex (that protects screen and GUI state).
+	// During game:
+	// When ending the game, the pim mutex might be hold by other thread,
+	// that will notify us about the ending game by setting terminate_cond flag.		
+	//in PreGame terminate_cond stay false 
+		
+		bool acquiredTheLockOnPim = false; //for tracking whether pim mutex locking succeeded
+		while(!terminate_cond.get() && !(acquiredTheLockOnPim = CPlayerInterface::pim->try_lock())) //try acquiring long until it succeeds or we are told to terminate
+			boost::this_thread::sleep(boost::posix_time::milliseconds(15));
+
+		if(!acquiredTheLockOnPim)
 		{
-			curInt -> update();
-		}			
+			// We broke the while loop above and not because of mutex, so we must be terminating.
+			assert(terminate_cond.get());
+			return;
+		}
+
+		// If we are here, pim mutex has been successfully locked - let's store it in a safe RAII lock.
+		boost::unique_lock<boost::recursive_mutex> un(*CPlayerInterface::pim, boost::adopt_lock);
+
+		if(nullptr != curInt)
+			curInt->update();
+		
+		if (settings["general"]["showfps"].Bool())
+			drawFPSCounter();		
+			
 		// draw the mouse cursor and update the screen
 		CCS->curh->render();
 
-		#ifndef	VCMI_SDL1
 		if(0 != SDL_RenderCopy(mainRenderer, screenTexture, nullptr, nullptr))
 			logGlobal->errorStream() << __FUNCTION__ << " SDL_RenderCopy " << SDL_GetError();
 
-		SDL_RenderPresent(mainRenderer);				
-		#endif		
-		
-	};
-	
-	if(curInt)
-		curInt->runLocked(doUpdate);
-	else
-		doUpdate();
+		SDL_RenderPresent(mainRenderer);					
+	}
+
 	
 	mainFPSmng->framerateDelay(); // holds a constant FPS	
 }
@@ -448,6 +442,8 @@ CGuiHandler::CGuiHandler()
 	// Creates the FPS manager and sets the framerate to 48 which is doubled the value of the original Heroes 3 FPS rate
 	mainFPSmng = new CFramerateManager(48);
 	//do not init CFramerateManager here --AVS
+	
+	terminate_cond.set(false);
 }
 
 CGuiHandler::~CGuiHandler()
@@ -470,23 +466,8 @@ void CGuiHandler::drawFPSCounter()
 	graphics->fonts[FONT_BIG]->renderTextLeft(screen, fps, yellow, Point(10, 10));
 }
 
-SDLKey CGuiHandler::arrowToNum( SDLKey key )
+SDL_Keycode CGuiHandler::arrowToNum(SDL_Keycode key )
 {
-	#ifdef VCMI_SDL1
-	switch(key)
-	{
-	case SDLK_DOWN:
-		return SDLK_KP2;
-	case SDLK_UP:
-		return SDLK_KP8;
-	case SDLK_LEFT:
-		return SDLK_KP4;
-	case SDLK_RIGHT:
-		return SDLK_KP6;
-	default:
-		throw std::runtime_error("Wrong key!");assert(0);
-	}	
-	#else
 	switch(key)
 	{
 	case SDLK_DOWN:
@@ -500,20 +481,14 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key )
 	default:
 		throw std::runtime_error("Wrong key!");
 	}	
-	#endif // 0
 }
 
-SDLKey CGuiHandler::numToDigit( SDLKey key )
+SDL_Keycode CGuiHandler::numToDigit(SDL_Keycode key)
 {
-#ifdef VCMI_SDL1
-	if(key >= SDLK_KP0 && key <= SDLK_KP9)
-		return SDLKey(key - SDLK_KP0 + SDLK_0);
-#endif // 0
 
 #define REMOVE_KP(keyName) case SDLK_KP_ ## keyName : return SDLK_ ## keyName;
 	switch(key)
 	{
-#ifndef VCMI_SDL1
 		REMOVE_KP(0)
 		REMOVE_KP(1)
 		REMOVE_KP(2)
@@ -524,7 +499,6 @@ SDLKey CGuiHandler::numToDigit( SDLKey key )
 		REMOVE_KP(7)
 		REMOVE_KP(8)
 		REMOVE_KP(9)		
-#endif // VCMI_SDL1		
 		REMOVE_KP(PERIOD)
 		REMOVE_KP(MINUS)
 		REMOVE_KP(PLUS)
@@ -542,22 +516,15 @@ SDLKey CGuiHandler::numToDigit( SDLKey key )
 #undef REMOVE_KP
 }
 
-bool CGuiHandler::isNumKey( SDLKey key, bool number )
+bool CGuiHandler::isNumKey(SDL_Keycode key, bool number)
 {
-	#ifdef VCMI_SDL1
-	if(number)
-		return key >= SDLK_KP0 && key <= SDLK_KP9;
-	else
-		return key >= SDLK_KP0 && key <= SDLK_KP_EQUALS;
-	#else
 	if(number)
 		return key >= SDLK_KP_1 && key <= SDLK_KP_0;
 	else
 		return (key >= SDLK_KP_1 && key <= SDLK_KP_0) || key == SDLK_KP_MINUS || key == SDLK_KP_PLUS || key == SDLK_KP_EQUALS;
-	#endif // 0
 }
 
-bool CGuiHandler::isArrowKey( SDLKey key )
+bool CGuiHandler::isArrowKey(SDL_Keycode key)
 {
 	return key == SDLK_UP || key == SDLK_DOWN || key == SDLK_LEFT || key == SDLK_RIGHT;
 }
@@ -580,6 +547,8 @@ CFramerateManager::CFramerateManager(int rate)
 	this->rate = rate;
 	this->rateticks = (1000.0 / rate);
 	this->fps = 0;
+	this->accumulatedFrames = 0;
+	this->accumulatedTime = 0;
 }
 
 void CFramerateManager::init()
@@ -591,18 +560,28 @@ void CFramerateManager::framerateDelay()
 {
 	ui32 currentTicks = SDL_GetTicks();
 	timeElapsed = currentTicks - lastticks;
-
+	
 	// FPS is higher than it should be, then wait some time
 	if (timeElapsed < rateticks)
 	{
 		SDL_Delay(ceil(this->rateticks) - timeElapsed);
 	}
-	currentTicks = SDL_GetTicks();
+	
+	accumulatedTime += timeElapsed;
+	accumulatedFrames++;
 
-	fps = ceil(1000.0 / timeElapsed);
+	if(accumulatedFrames >= 100)
+	{
+		//about 2 second should be passed
+		fps = ceil(1000.0 / (accumulatedTime/accumulatedFrames));		
+		accumulatedTime = 0;
+		accumulatedFrames = 0;	
+	};	
 
+	currentTicks = SDL_GetTicks();
 	// recalculate timeElapsed for external calls via getElapsed()
 	// limit it to 1000 ms to avoid breaking animation in case of huge lag (e.g. triggered breakpoint)
 	timeElapsed = std::min<ui32>(currentTicks - lastticks, 1000);
+
 	lastticks = SDL_GetTicks();
 }

+ 12 - 11
client/gui/CGuiHandler.h

@@ -8,9 +8,9 @@ class CFramerateManager;
 class CGStatusBar;
 class CIntObject;
 class IUpdateable;
-class ILockedUpdatable;
 class IShowActivatable;
 class IShowable;
+template <typename T> struct CondSh;
 
 /*
  * CGuiHandler.h, part of VCMI engine
@@ -29,7 +29,7 @@ private:
 	double rateticks;
 	ui32 lastticks, timeElapsed;
 	int rate;
-
+	ui32 accumulatedTime,accumulatedFrames;
 public:
 	int fps; // the actual fps value
 
@@ -58,10 +58,9 @@ private:
 				   motioninterested,
 	               timeinterested,
 	               wheelInterested,
-	               doubleClickInterested;
-	#ifndef VCMI_SDL1
-	CIntObjectList textInterested;
-	#endif // VCMI_SDL1
+	               doubleClickInterested,
+	               textInterested;
+
 	               
 	void processLists(const ui16 activityFlag, std::function<void (std::list<CIntObject*> *)> cb);               
 public:
@@ -73,7 +72,7 @@ public:
 	std::vector<IShowable*> objsToBlit;
 
 	SDL_Event * current; //current event - can be set to nullptr to stop handling event
-	ILockedUpdatable *curInt;
+	IUpdateable *curInt;
 
 	Point lastClick;
 	unsigned lastClickTime;
@@ -104,12 +103,14 @@ public:
 	ui8 captureChildren; //all newly created objects will get their parents from stack and will be added to parents children list
 	std::list<CIntObject *> createdObj; //stack of objs being created
 
-	static SDLKey arrowToNum(SDLKey key); //converts arrow key to according numpad key
-	static SDLKey numToDigit(SDLKey key);//converts numpad digit key to normal digit key
-	static bool isNumKey(SDLKey key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits)
-	static bool isArrowKey(SDLKey key);
+	static SDL_Keycode arrowToNum(SDL_Keycode key); //converts arrow key to according numpad key
+	static SDL_Keycode numToDigit(SDL_Keycode key);//converts numpad digit key to normal digit key
+	static bool isNumKey(SDL_Keycode key, bool number = true); //checks if key is on numpad (numbers - check only for numpad digits)
+	static bool isArrowKey(SDL_Keycode key);
 	static bool amIGuiThread();
 	static void pushSDLEvent(int type, int usercode = 0);
+	
+	static CondSh<bool> terminate_cond; // confirm termination
 };
 
 extern CGuiHandler GH; //global gui handler

+ 0 - 9
client/gui/CIntObject.h

@@ -38,13 +38,6 @@ public:
 	virtual ~IUpdateable(){}; //d-tor
 };
 
-class ILockedUpdatable: public IUpdateable
-{
-public:
-	virtual void runLocked(std::function<void()> cb) = 0;
-	virtual ~ILockedUpdatable(){}; //d-tor
-};
-
 // Defines a show method
 class IShowable
 {
@@ -133,10 +126,8 @@ public:
 	virtual void keyPressed(const SDL_KeyboardEvent & key){}
 	virtual bool captureThisEvent(const SDL_KeyboardEvent & key); //allows refining captureAllKeys against specific events (eg. don't capture ENTER)
 
-#ifndef VCMI_SDL1
 	virtual void textInputed(const SDL_TextInputEvent & event){};
 	virtual void textEdited(const SDL_TextEditingEvent & event){};
-#endif // VCMI_SDL1
 
 	//mouse movement handling
 	bool strongInterest; //if true - report all mouse movements, if not - only when hovered

+ 0 - 11
client/gui/SDL_Compat.h

@@ -13,23 +13,12 @@
 #include <SDL_version.h>
 
 #if (SDL_MAJOR_VERSION == 2)
-#define VCMI_SDL2
 
 #include <SDL_keycode.h>
 typedef int SDLX_Coord;
 typedef int SDLX_Size;
 
-typedef SDL_Keycode SDLKey;
 
-#define SDL_SRCCOLORKEY SDL_TRUE
-
-#define SDL_FULLSCREEN SDL_WINDOW_FULLSCREEN
-
-#elif (SDL_MAJOR_VERSION == 1) 
-#define VCMI_SDL1
-//SDL 1.x
-typedef Sint16 SDLX_Coord;
-typedef Uint16 SDLX_Size;
 #else
 #error "unknown or unsupported SDL version"
 #endif

+ 3 - 34
client/gui/SDL_Extensions.cpp

@@ -14,7 +14,6 @@ const SDL_Color Colors::METALLIC_GOLD = { 173, 142, 66, 0 };
 const SDL_Color Colors::GREEN = { 0, 255, 0, 0 };
 const SDL_Color Colors::DEFAULT_KEY_COLOR = {0, 255, 255, 0};
 
-#if (SDL_MAJOR_VERSION == 2)
 void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h)
 {
 	Rect rect(x,y,w,h);
@@ -27,7 +26,6 @@ void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h)
 	SDL_RenderPresent(mainRenderer);	
 	
 }
-#endif // VCMI_SDL1
 
 SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given
 {
@@ -171,7 +169,7 @@ void CSDL_Ext::alphaTransform(SDL_Surface *src)
 		SDL_Color & palColor = src->format->palette->colors[i];
 		palColor = colors[i];
 	}
-	SDL_SetColorKey(src, SDL_SRCCOLORKEY, 0);
+	SDL_SetColorKey(src, SDL_TRUE, 0);
 }
 
 static void prepareOutRect(SDL_Rect *src, SDL_Rect *dst, const SDL_Rect & clip_rect)
@@ -460,11 +458,7 @@ int CSDL_Ext::blit8bppAlphaTo24bppT(const SDL_Surface * src, const SDL_Rect * sr
 				for(int x = w; x; x--)
 				{
 					const SDL_Color &tbc = colors[*color++]; //color to blit
-					#ifdef VCMI_SDL1
-					ColorPutter<bpp, +1>::PutColorAlphaSwitch(p, tbc.r, tbc.g, tbc.b, tbc.unused);
-					#else
 					ColorPutter<bpp, +1>::PutColorAlphaSwitch(p, tbc.r, tbc.g, tbc.b, tbc.a);
-					#endif // 0					
 				}
 			}
 			SDL_UnlockSurface(dst);
@@ -489,11 +483,7 @@ int CSDL_Ext::blit8bppAlphaTo24bpp(const SDL_Surface * src, const SDL_Rect * src
 Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
 {
 	Uint32 ret = 0;
-	#ifdef VCMI_SDL1
-	ret+=color->unused;
-	#else
 	ret+=color->a;
-	#endif // 0	
 	ret<<=8; //*=256
 	ret+=color->b;
 	ret<<=8; //*=256
@@ -505,15 +495,10 @@ Uint32 CSDL_Ext::colorToUint32(const SDL_Color * color)
 
 void CSDL_Ext::update(SDL_Surface * what)
 {
-	#ifdef VCMI_SDL1
-	if(what)
-		SDL_UpdateRect(what, 0, 0, what->w, what->h);	
-	#else
 	if(!what)
 		return;
 	if(0 !=SDL_UpdateTexture(screenTexture, nullptr, what->pixels, what->pitch))
 		logGlobal->errorStream() << __FUNCTION__ << "SDL_UpdateTexture " << SDL_GetError();		
-	#endif // VCMI_SDL1
 }
 void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, const int3 &color)
 {
@@ -633,21 +618,13 @@ bool CSDL_Ext::isTransparent( SDL_Surface * srf, int x, int y )
 
 	SDL_Color color;
 	
-	#ifdef VCMI_SDL1
-	SDL_GetRGBA(SDL_GetPixel(srf, x, y), srf->format, &color.r, &color.g, &color.b, &color.unused);
-	#else
 	SDL_GetRGBA(SDL_GetPixel(srf, x, y), srf->format, &color.r, &color.g, &color.b, &color.a);
-	#endif // 0	
 
 	// color is considered transparent here if
 	// a) image has aplha: less than 50% transparency
 	// b) no alpha: color is cyan
 	if (srf->format->Amask)
-	#ifdef VCMI_SDL1
-		return color.unused < 128; // almost transparent
-	#else
 		return color.a < 128; // almost transparent
-	#endif // 0				
 	else
 		return (color.r == 0 && color.g == 255 && color.b == 255);
 }
@@ -988,38 +965,30 @@ SDL_Color CSDL_Ext::makeColor(ui8 r, ui8 g, ui8 b, ui8 a)
 
 void CSDL_Ext::startTextInput(SDL_Rect * where)
 {
-	#ifndef VCMI_SDL1
 	if (SDL_IsTextInputActive() == SDL_FALSE)		
 	{		
 		SDL_StartTextInput();		
 	}		
 	SDL_SetTextInputRect(where);
-	#endif
 }
 
 void CSDL_Ext::stopTextInput()
 {
-	#ifndef VCMI_SDL1
 	if (SDL_IsTextInputActive() == SDL_TRUE)
 	{		
 		SDL_StopTextInput();			
 	}		
-	#endif	
 }
 
 STRONG_INLINE static uint32_t mapColor(SDL_Surface * surface, SDL_Color color)
 {
-	#ifdef VCMI_SDL1
-	return SDL_MapRGB(surface->format, color.r, color.g, color.b); 
-	#else
 	return SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a); 
-	#endif		
 }
 
 void CSDL_Ext::setColorKey(SDL_Surface * surface, SDL_Color color)
 {
 	uint32_t key = mapColor(surface,color);
-	SDL_SetColorKey(surface, SDL_SRCCOLORKEY, key);	
+	SDL_SetColorKey(surface, SDL_TRUE, key);	
 }
 
 void CSDL_Ext::setDefaultColorKey(SDL_Surface * surface)
@@ -1034,7 +1003,7 @@ void CSDL_Ext::setDefaultColorKeyPresize(SDL_Surface * surface)
 
 	// set color key only if exactly such color was found
 	if (color.r == Colors::DEFAULT_KEY_COLOR.r && color.g == Colors::DEFAULT_KEY_COLOR.g && color.b == Colors::DEFAULT_KEY_COLOR.b)
-		SDL_SetColorKey(surface, SDL_SRCCOLORKEY, key);	
+		SDL_SetColorKey(surface, SDL_TRUE, key);	
 }
 
 

+ 1 - 37
client/gui/SDL_Extensions.h

@@ -10,15 +10,10 @@
  
 #pragma once
 #include <SDL_version.h>
-
-#ifndef VCMI_SDL1
 #include <SDL_render.h>
-#endif
-
 #include <SDL_video.h>
 #include <SDL_events.h>
 #include "../../lib/int3.h"
-//#include "../Graphics.h"
 #include "Geometries.h"
 #include "../../lib/GameConstants.h"
 
@@ -32,13 +27,6 @@
 	#define STRONG_INLINE inline
 #endif
 
-#if SDL_VERSION_ATLEAST(1,3,0)
-#define SDL_GetKeyState SDL_GetKeyboardState
-#endif
-
-//SDL2 support
-#if (SDL_MAJOR_VERSION == 2)
-
 extern SDL_Window * mainWindow;
 extern SDL_Renderer * mainRenderer;
 extern SDL_Texture * screenTexture;
@@ -54,43 +42,27 @@ inline void SDL_WarpMouse(int x, int y)
 }
 
 void SDL_UpdateRect(SDL_Surface *surface, int x, int y, int w, int h);
-#endif
 
 inline bool isCtrlKeyDown()
 {
-	#ifdef VCMI_SDL1
-	return SDL_GetKeyState(nullptr)[SDLK_LCTRL] || SDL_GetKeyState(nullptr)[SDLK_RCTRL];
-	#else
 	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
-	#endif
 }
 
 inline bool isAltKeyDown()
 {
-	#ifdef VCMI_SDL1
-	return SDL_GetKeyState(nullptr)[SDLK_LALT] || SDL_GetKeyState(nullptr)[SDLK_RALT];
-	#else
 	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT];
-	#endif
 }
 
 inline bool isShiftKeyDown()
 {
-	#ifdef VCMI_SDL1
-	return SDL_GetKeyState(nullptr)[SDLK_LSHIFT] || SDL_GetKeyState(nullptr)[SDLK_RSHIFT];
-	#else
 	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LSHIFT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RSHIFT];
-	#endif
 }
 namespace CSDL_Ext
 {
+	//todo: remove
 	STRONG_INLINE void colorSetAlpha(SDL_Color & color, Uint8 alpha)
 	{
-#ifdef VCMI_SDL1
-		color.unused = alpha;
-#else
 		color.a = alpha;
-#endif	
 	}
 	//todo: should this better be assignment operator?
 	STRONG_INLINE void colorAssign(SDL_Color & dest, const SDL_Color & source)
@@ -98,20 +70,12 @@ namespace CSDL_Ext
 		dest.r = source.r;
 		dest.g = source.g;
 		dest.b = source.b;
-#ifdef VCMI_SDL1
-		dest.unused = source.unused;
-#else
 		dest.a = source.a;
-#endif			
 	}
 
 	inline void setAlpha(SDL_Surface * bg, int value)
 	{
-#ifdef VCMI_SDL1
-		SDL_SetAlpha(bg, SDL_SRCALPHA, value);
-#else
 		SDL_SetSurfaceAlphaMod(bg, value);
-#endif
 	}
 }
 struct Rect;

+ 0 - 8
client/gui/SDL_Pixels.h

@@ -135,11 +135,7 @@ struct ColorPutter<2, incrementPtr>
 template<int bpp, int incrementPtr>
 STRONG_INLINE void ColorPutter<bpp, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color)
 {
-	#ifdef VCMI_SDL1
-	PutColor(ptr, Color.r, Color.g, Color.b, Color.unused);
-	#else
 	PutColor(ptr, Color.r, Color.g, Color.b, Color.a);
-	#endif
 }
 
 template<int bpp, int incrementPtr>
@@ -268,11 +264,7 @@ STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColor(Uint8 *&ptr, const Uin
 template <int incrementPtr>
 STRONG_INLINE void ColorPutter<2, incrementPtr>::PutColorAlpha(Uint8 *&ptr, const SDL_Color & Color)
 {
-	#ifdef VCMI_SDL1
-	PutColor(ptr, Color.r, Color.g, Color.b, Color.unused);
-	#else
 	PutColor(ptr, Color.r, Color.g, Color.b, Color.a);
-	#endif
 }
 
 template <int incrementPtr>

+ 0 - 20
client/widgets/AdventureMapClasses.cpp

@@ -1121,24 +1121,11 @@ void CInGameConsole::keyPressed (const SDL_KeyboardEvent & key)
 		}
 	default:
 		{
-			#ifdef VCMI_SDL1
-			if(enteredText.size() > 0 && enteredText.size() < conf.go()->ac.inputLineLength)
-			{
-				if( key.keysym.unicode < 0x80 && key.keysym.unicode > 0 )
-				{
-					enteredText[enteredText.size()-1] = (char)key.keysym.unicode;
-					enteredText += "_";
-					refreshEnteredText();
-				}
-			}
-			#endif // VCMI_SDL1
 			break;
 		}
 	}
 }
 
-#ifndef VCMI_SDL1
-
 void CInGameConsole::textInputed(const SDL_TextInputEvent & event)
 {
 	if(!captureAllKeys || enteredText.size() == 0)
@@ -1156,8 +1143,6 @@ void CInGameConsole::textEdited(const SDL_TextEditingEvent & event)
  //do nothing here
 }
 
-#endif // VCMI_SDL1
-
 void CInGameConsole::startEnteringText()
 {
 	CSDL_Ext::startTextInput(&pos);
@@ -1219,14 +1204,9 @@ void CInGameConsole::refreshEnteredText()
 
 CInGameConsole::CInGameConsole() : prevEntDisp(-1), defaultTimeout(10000), maxDisplayedTexts(10)
 {
-	#ifdef VCMI_SDL1
-	addUsedEvents(KEYBOARD);
-	#else
 	addUsedEvents(KEYBOARD | TEXTINPUT);
-	#endif
 }
 
-
 CAdvMapPanel::CAdvMapPanel(SDL_Surface * bg, Point position)
 	: CIntObject(),
 	  background(bg)

+ 0 - 2
client/widgets/AdventureMapClasses.h

@@ -369,10 +369,8 @@ public:
 	void print(const std::string &txt);
 	void keyPressed (const SDL_KeyboardEvent & key); //call-in
 
-#ifndef VCMI_SDL1
 	void textInputed(const SDL_TextInputEvent & event) override;
 	void textEdited(const SDL_TextEditingEvent & event) override;
-#endif // VCMI_SDL1
 
 	void startEnteringText();
 	void endEnteringText(bool printEnteredText);

+ 0 - 5
client/widgets/Buttons.cpp

@@ -295,13 +295,8 @@ void CButton::showAll(SDL_Surface * to)
 {
 	CIntObject::showAll(to);
 	
-	#ifdef VCMI_SDL1
-	if (borderColor && borderColor->unused == 0)
-		CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor->r, borderColor->g, borderColor->b));
-	#else
 	if (borderColor && borderColor->a == 0)
 		CSDL_Ext::drawBorder(to, pos.x-1, pos.y-1, pos.w+2, pos.h+2, int3(borderColor->r, borderColor->g, borderColor->b));
-	#endif // 0
 }
 
 std::pair<std::string, std::string> CButton::tooltip()

+ 2 - 27
client/widgets/TextControls.cpp

@@ -461,9 +461,7 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
 	}
 
 	bool redrawNeeded = false;
-	#ifdef VCMI_SDL1
-	std::string oldText = text;
-	#endif // 0	
+	
 	switch(key.keysym.sym)
 	{
 	case SDLK_DELETE: // have index > ' ' so it won't be filtered out by default section
@@ -481,20 +479,9 @@ void CTextInput::keyPressed( const SDL_KeyboardEvent & key )
 		}			
 		break;
 	default:
-		#ifdef VCMI_SDL1
-		if (key.keysym.unicode < ' ')
-			return;
-		else
-		{
-			text += key.keysym.unicode; //TODO 16-/>8
-			redrawNeeded = true;
-		}			
-		#endif // 0
 		break;
 	}
-	#ifdef VCMI_SDL1
-	filters(text, oldText);
-	#endif // 0
+
 	if (redrawNeeded)
 	{
 		redraw();
@@ -514,18 +501,9 @@ bool CTextInput::captureThisEvent(const SDL_KeyboardEvent & key)
 	if(key.keysym.sym == SDLK_RETURN || key.keysym.sym == SDLK_KP_ENTER)
 		return false;
 	
-	#ifdef VCMI_SDL1
-	//this should allow all non-printable keys to go through (for example arrows)
-	if (key.keysym.unicode < ' ')
-		return false;
-
-	return true;
-	#else
 	return false;
-	#endif
 }
 
-#ifndef VCMI_SDL1
 void CTextInput::textInputed(const SDL_TextInputEvent & event)
 {
 	if(!focus)
@@ -553,9 +531,6 @@ void CTextInput::textEdited(const SDL_TextEditingEvent & event)
 	cb(text+newText);	
 }
 
-#endif
-
-
 void CTextInput::filenameFilter(std::string & text, const std::string &)
 {
 	static const std::string forbiddenChars = "<>:\"/\\|?*\r\n"; //if we are entering a filename, some special characters won't be allowed

+ 0 - 4
client/widgets/TextControls.h

@@ -174,12 +174,8 @@ public:
 	void keyPressed(const SDL_KeyboardEvent & key) override;
 	bool captureThisEvent(const SDL_KeyboardEvent & key) override;
 	
-#ifndef VCMI_SDL1
 	void textInputed(const SDL_TextInputEvent & event) override;
 	void textEdited(const SDL_TextEditingEvent & event) override;
-	
-	
-#endif // VCMI_SDL1	
 
 	//Filter that will block all characters not allowed in filenames
 	static void filenameFilter(std::string &text, const std::string & oldText);

+ 5 - 8
client/windows/CAdvmapInterface.cpp

@@ -1029,7 +1029,7 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 		return;
 
 	ui8 Dir = 0;
-	int k = key.keysym.sym;
+	SDL_Keycode k = key.keysym.sym;
 	const CGHeroInstance *h = curHero(); //selected hero
 	const CGTownInstance *t = curTown(); //selected town
 
@@ -1156,17 +1156,14 @@ void CAdvMapInt::keyPressed(const SDL_KeyboardEvent & key)
 												int3(-1, -1, 0), int3(0, -1, 0), int3(+1, -1, 0) };
 
 			//numpad arrow
-			if(CGuiHandler::isArrowKey(SDLKey(k)))
-				k = CGuiHandler::arrowToNum(SDLKey(k));
+			if(CGuiHandler::isArrowKey(k))
+				k = CGuiHandler::arrowToNum(k);
 
-			#ifdef VCMI_SDL1
-			k -= SDLK_KP0 + 1;
-			#else
 			k -= SDLK_KP_1;
-			#endif // VCMI_SDL1
+
 			if(k < 0 || k > 8)
 				return;
-			
+
 			if (!CGI->mh->canStartHeroMovement())
 				return;
 

+ 1 - 1
client/windows/CCreatureWindow.cpp

@@ -748,7 +748,7 @@ void CStackWindow::initSections()
 void CStackWindow::initBonusesList()
 {
 	BonusList output, input;
-	input = *(info->stackNode->getBonuses(Selector::durationType(Bonus::PERMANENT).And(Selector::anyRange())));
+	input = *(info->stackNode->getBonuses(CSelector(Bonus::Permanent).And(Selector::anyRange())));
 
 	while (!input.empty())
 	{

+ 2 - 2
client/windows/CSpellWindow.cpp

@@ -571,7 +571,7 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
 		//alt + 1234567890-= casts spell from 1 - 12 slot
 		if(LOCPLINT->altPressed())
 		{
-			SDLKey hlpKey = key.keysym.sym;
+			SDL_Keycode hlpKey = key.keysym.sym;
 			if(CGuiHandler::isNumKey(hlpKey, false))
 			{
 				if(hlpKey == SDLK_KP_PLUS)
@@ -580,7 +580,7 @@ void CSpellWindow::keyPressed(const SDL_KeyboardEvent & key)
 					hlpKey = CGuiHandler::numToDigit(hlpKey);
 			}
 
-			static const SDLKey spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS};
+			static const SDL_Keycode spellSelectors[] = {SDLK_1, SDLK_2, SDLK_3, SDLK_4, SDLK_5, SDLK_6, SDLK_7, SDLK_8, SDLK_9, SDLK_0, SDLK_MINUS, SDLK_EQUALS};
 
 			int index = -1;
 			while(++index < ARRAY_COUNT(spellSelectors) && spellSelectors[index] != hlpKey);

+ 1 - 3
client/windows/GUIClasses.cpp

@@ -656,7 +656,7 @@ void CSystemOptionsWindow::setGameRes(int index)
 
 void CSystemOptionsWindow::bquitf()
 {
-	LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this]{ closeAndPushEvent(SDL_QUIT); }, 0);
+	LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[578], [this]{ closeAndPushEvent(SDL_USEREVENT, FORCE_QUIT); }, 0);
 }
 
 void CSystemOptionsWindow::breturnf()
@@ -1089,9 +1089,7 @@ CPuzzleWindow::CPuzzleWindow(const int3 &GrailPos, double discoveredRatio):
 			piecesToRemove.push_back(piece);
 			piece->needRefresh = true;
 			piece->recActions = piece->recActions & ~SHOWALL;
-			#ifndef VCMI_SDL1
 			SDL_SetSurfaceBlendMode(piece->bg,SDL_BLENDMODE_BLEND);
-			#endif // VCMI_SDL1
 		}
 	}
 }

+ 18 - 18
config/heroClasses.json

@@ -6,7 +6,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "might",
 		"commander" : "zealot",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH00_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH00_.def", "editorAnimation": "AH00_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH00.DEF",  "female" : "CH01.DEF" } }
 	},
 	"cleric" :
@@ -16,7 +16,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "magic",
 		"commander" : "zealot",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH01_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH01_.def", "editorAnimation": "AH01_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH00.DEF",  "female" : "CH01.DEF" } }
 	},
 	"ranger" :
@@ -26,7 +26,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "might",
 		"commander" : "grandElf",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH02_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH02_.def", "editorAnimation": "AH02_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH02.DEF",  "female" : "CH03.DEF" } }
 	},
 	"druid" :
@@ -36,7 +36,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "magic",
 		"commander" : "grandElf",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH03_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH03_.def", "editorAnimation": "AH03_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH02.DEF",  "female" : "CH03.DEF" } }
 	},
 	"alchemist" :
@@ -46,7 +46,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "might",
 		"commander" : "archMage",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH04_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH04_.def", "editorAnimation": "AH04_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH05.DEF",  "female" : "CH04.DEF" } }
 	},
 	"wizard" :
@@ -56,7 +56,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "magic",
 		"commander" : "archMage",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH05_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH05_.def", "editorAnimation": "AH05_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH05.DEF",  "female" : "CH04.DEF" } }
 	},
 	"demoniac" :
@@ -66,7 +66,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "might",
 		"commander" : "magog",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH06_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH06_.def", "editorAnimation": "AH06_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH06.DEF",  "female" : "CH07.DEF" } }
 	},
 	"heretic" :
@@ -76,7 +76,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "magic",
 		"commander" : "magog",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH07_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH07_.def", "editorAnimation": "AH07_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH06.DEF",  "female" : "CH07.DEF" } }
 	},
 	"deathknight" :
@@ -86,7 +86,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "might",
 		"commander" : "powerLich",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH08_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH08_.def", "editorAnimation": "AH08_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH08.DEF",  "female" : "CH09.DEF" } }
 	},
 	"necromancer" :
@@ -96,7 +96,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "magic",
 		"commander" : "powerLich",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH09_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH09_.def", "editorAnimation": "AH09_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH08.DEF",  "female" : "CH09.DEF" } }
 	},
 	"warlock" :
@@ -106,7 +106,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "might",
 		"commander" : "medusaQueen",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH10_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH10_.def", "editorAnimation": "AH10_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH010.DEF",  "female" : "CH11.DEF" } }
 	},
 	"overlord" :
@@ -116,7 +116,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "magic",
 		"commander" : "medusaQueen",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH11_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH11_.def", "editorAnimation": "AH11_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH010.DEF",  "female" : "CH11.DEF" } }
 	},
 	"barbarian" :
@@ -126,7 +126,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "might",
 		"commander" : "orcChieftain",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH12_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH12_.def", "editorAnimation": "AH12_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH013.DEF",  "female" : "CH012.DEF" } }
 	},
 	"battlemage" :
@@ -136,7 +136,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "magic",
 		"commander" : "orcChieftain",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH13_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH13_.def", "editorAnimation": "AH13_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH013.DEF",  "female" : "CH012.DEF" } }
 	},
 	"beastmaster" :
@@ -146,7 +146,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "might",
 		"commander" : "lizardWarrior",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH14_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH14_.def", "editorAnimation": "AH14_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH014.DEF",  "female" : "CH015.DEF" } }
 	},
 	"witch" :
@@ -156,7 +156,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "magic",
 		"commander" : "lizardWarrior",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH15_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH15_.def", "editorAnimation": "AH15_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH014.DEF",  "female" : "CH015.DEF" } }
 	},
 	"planeswalker" :
@@ -166,7 +166,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "might",
 		"commander" : "iceElemental",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH16_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH16_.def", "editorAnimation": "AH16_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH16.DEF",  "female" : "CH16.DEF" } }
 	},
 	"elementalist" :
@@ -176,7 +176,7 @@
 		"defaultTavern" : 5,
 		"affinity" : "magic",
 		"commander" : "iceElemental",
-		"mapObject" : { "templates" : { "default" : { "animation" : "AH17_.def" } } },
+		"mapObject" : { "templates" : { "default" : { "animation" : "AH17_.def", "editorAnimation": "AH17_E.def" } } },
 		"animation":  { "battle" : { "male" : "CH17.DEF",  "female" : "CH17.DEF" } }
 	}
 }

+ 7 - 1
config/objects/generic.json

@@ -235,7 +235,10 @@
 					"value"		: 3000,
 					"rarity"	: 100
 				}
-			}
+			},
+			"object1":{ //WoG?
+				"index" :1
+			}			
 		}
 	},
 	"eyeOfTheMagi" : {
@@ -388,6 +391,9 @@
 					"value"		: 1500,
 					"rarity"	: 80
 				}
+			},
+			"object1" : { //WoG?
+				"index" : 1
 			}
 		}
 	},

+ 17 - 3
config/objects/moddables.json

@@ -190,6 +190,7 @@
 			"crystalCavern" : { "index" : 4, "rmg" : { "value" : 3500 } },
 			"gemPond" :       { "index" : 5, "rmg" : { "value" : 3500 } },
 			"goldMine" :      { "index" : 6, "rmg" : { "value" : 7000 } },
+			"abandoned" :	  { "index" : 7}
 		}
 	},
 	"abandonedMine" : {
@@ -200,9 +201,22 @@
 		}
 	},
 
-	// subtype: 0 = normal, 1 = anti-magic
-	"garrisonHorizontal"			: { "index" :33, "handler": "garrison" },
-	"garrisonVertical"				: { "index" :219, "handler": "garrison" },
+	"garrisonHorizontal": { 
+		"index" :33, 
+		"handler": "garrison",
+		"types":{
+			"normal":{"index": 0},
+			"antiMagic":{"index": 1}			
+		}	
+	},
+	"garrisonVertical": { 
+		"index" :219, 
+		"handler": "garrison",
+		"types":{
+			"normal":{"index": 0},
+			"antiMagic":{"index": 1}			
+		}	
+	},
 
 	// Subtype: paired monoliths
 	"monolithOneWayEntrance" : {

+ 3 - 0
config/objects/rewardable.json

@@ -389,6 +389,9 @@
 					"value"		: 100,
 					"rarity"	: 100
 				}
+			},
+			"object1" : {//WoG?
+				"index" : 1
 			}
 		}
 	},

+ 5 - 0
config/schemas/objectTemplate.json

@@ -12,6 +12,11 @@
 			"description": "Path to def file with animation of this object",
 			"format" : "defFile"
 		},
+		"editorAnimation":{
+			"type" : "string",
+			"description": "Optional path to def file with animation of this object to use in map editor",
+			"format" : "defFile"			
+		},
 		"visitableFrom": {
 			"type":"array",
 			"description": "Directions from which this object is visible",

+ 5 - 5
lib/CGameState.cpp

@@ -1353,11 +1353,11 @@ void CGameState::prepareCrossoverHeroes(std::vector<CGameState::CampaignHeroRepl
 	// Removing short-term bonuses
 	for(CGHeroInstance * cgh : crossoverHeroes)
 	{
-		cgh->popBonuses(Selector::durationType(Bonus::ONE_DAY));
-		cgh->popBonuses(Selector::durationType(Bonus::ONE_WEEK));
-		cgh->popBonuses(Selector::durationType(Bonus::N_TURNS));
-		cgh->popBonuses(Selector::durationType(Bonus::N_DAYS));
-		cgh->popBonuses(Selector::durationType(Bonus::ONE_BATTLE));
+		cgh->popBonuses(CSelector(Bonus::OneDay)
+			.Or(CSelector(Bonus::OneWeek))
+			.Or(CSelector(Bonus::NTurns))
+			.Or(CSelector(Bonus::NDays))
+			.Or(CSelector(Bonus::OneBattle)));
 	}
 
 }

+ 0 - 11
lib/HeroBonus.cpp

@@ -782,11 +782,6 @@ void CBonusSystemNode::popBonuses(const CSelector &s)
 		child->popBonuses(s);
 }
 
-// void CBonusSystemNode::addNewBonus(const Bonus &b)
-// {
-// 	addNewBonus(new Bonus(b));
-// }
-
 void CBonusSystemNode::addNewBonus(Bonus *b)
 {
 	assert(!vstd::contains(exportedBonuses,b));
@@ -1204,7 +1199,6 @@ namespace Selector
 	DLL_LINKAGE CSelectFieldEqual<Bonus::BonusType> type(&Bonus::type);
 	DLL_LINKAGE CSelectFieldEqual<TBonusSubtype> subtype(&Bonus::subtype);
 	DLL_LINKAGE CSelectFieldEqual<si32> info(&Bonus::additionalInfo);
-	DLL_LINKAGE CSelectFieldEqual<ui16> duration(&Bonus::duration);
 	DLL_LINKAGE CSelectFieldEqual<Bonus::BonusSource> sourceType(&Bonus::source);
 	DLL_LINKAGE CSelectFieldEqual<Bonus::LimitEffect> effectRange(&Bonus::effectRange);
 	DLL_LINKAGE CWillLastTurns turns;
@@ -1228,11 +1222,6 @@ namespace Selector
 			.And(CSelectFieldEqual<ui32>(&Bonus::sid)(sourceID));
 	}
 
-	CSelector DLL_EXPORT durationType(ui16 duration)
-	{
-		return CSelectFieldEqual<ui16>(&Bonus::duration)(duration);
-	}
-
 	CSelector DLL_LINKAGE sourceTypeSel(Bonus::BonusSource source)
 	{
 		return CSelectFieldEqual<Bonus::BonusSource>(&Bonus::source)(source);

+ 12 - 2
lib/HeroBonus.h

@@ -337,6 +337,14 @@ struct DLL_LINKAGE Bonus
 	{
 		return a->additionalInfo < b->additionalInfo;
 	}
+	static bool NDays(const Bonus *hb)
+	{
+		return hb->duration & Bonus::N_DAYS;
+	}
+	static bool NTurns(const Bonus *hb)
+	{
+		return hb->duration & Bonus::N_TURNS;
+	}	
 	static bool OneDay(const Bonus *hb)
 	{
 		return hb->duration & Bonus::ONE_DAY;
@@ -349,6 +357,10 @@ struct DLL_LINKAGE Bonus
 	{
 		return hb->duration & Bonus::ONE_BATTLE;
 	}
+	static bool Permanent(const Bonus *hb)
+	{
+		return hb->duration & Bonus::PERMANENT;
+	}
 	static bool UntilGetsTurn(const Bonus *hb)
 	{
 		return hb->duration & Bonus::STACK_GETS_TURN;
@@ -947,7 +959,6 @@ namespace Selector
 	extern DLL_LINKAGE CSelectFieldEqual<Bonus::BonusType> type;
 	extern DLL_LINKAGE CSelectFieldEqual<TBonusSubtype> subtype;
 	extern DLL_LINKAGE CSelectFieldEqual<si32> info;
-	extern DLL_LINKAGE CSelectFieldEqual<ui16> duration;
 	extern DLL_LINKAGE CSelectFieldEqual<Bonus::BonusSource> sourceType;
 	extern DLL_LINKAGE CSelectFieldEqual<Bonus::LimitEffect> effectRange;
 	extern DLL_LINKAGE CWillLastTurns turns;
@@ -956,7 +967,6 @@ namespace Selector
 	CSelector DLL_LINKAGE typeSubtype(Bonus::BonusType Type, TBonusSubtype Subtype);
 	CSelector DLL_LINKAGE typeSubtypeInfo(Bonus::BonusType type, TBonusSubtype subtype, si32 info);
 	CSelector DLL_LINKAGE source(Bonus::BonusSource source, ui32 sourceID);
-	CSelector DLL_LINKAGE durationType(ui16 duration);
 	CSelector DLL_LINKAGE sourceTypeSel(Bonus::BonusSource source);
 
 	bool DLL_LINKAGE matchesType(const CSelector &sel, Bonus::BonusType type);

+ 16 - 29
lib/NetPacksLib.cpp

@@ -328,7 +328,7 @@ DLL_LINKAGE void RemoveBonus::applyGs( CGameState *gs )
 	else
 		node = gs->getPlayer(PlayerColor(whoID));
 
-	BonusList &bonuses = node->getBonusList();
+	BonusList &bonuses = node->getExportedBonusList();
 
 	for (int i = 0; i < bonuses.size(); i++)
 	{
@@ -336,7 +336,7 @@ DLL_LINKAGE void RemoveBonus::applyGs( CGameState *gs )
 		if(b->source == source && b->sid == id)
 		{
 			bonus = *b; //backup bonus (to show to interfaces later)
-			bonuses.erase(i);
+			node->removeBonus(b);			
 			break;
 		}
 	}
@@ -1110,7 +1110,7 @@ DLL_LINKAGE void BattleSetActiveStack::applyGs( CGameState *gs )
 	CStack *st = gs->curB->getStack(stack);
 
 	//remove bonuses that last until when stack gets new turn
-	st->getBonusList().remove_if(Bonus::UntilGetsTurn);
+	st->popBonuses(Bonus::UntilGetsTurn);
 
 	if(vstd::contains(st->state,EBattleStackState::MOVED)) //if stack is moving second time this turn it must had a high morale bonus
 		st->state.insert(EBattleStackState::HAD_MORALE);
@@ -1278,13 +1278,13 @@ DLL_LINKAGE void BattleAttack::applyGs( CGameState *gs )
 	for(BattleStackAttacked stackAttacked : bsa)
 		stackAttacked.applyGs(gs);
 
-	attacker->getBonusList().remove_if(Bonus::UntilAttack);
+	attacker->popBonuses(Bonus::UntilAttack);
 
 	for(auto & elem : bsa)
 	{
 		CStack * stack = gs->curB->getStack(elem.stackAttacked, false);
 		if (stack) //cloned stack is already gone
-			stack->getBonusList().remove_if(Bonus::UntilBeingAttacked);
+			stack->popBonuses(Bonus::UntilBeingAttacked);
 	}
 }
 
@@ -1342,21 +1342,6 @@ DLL_LINKAGE void BattleSpellCast::applyGs( CGameState *gs )
 	spell->applyBattle(gs->curB, this);
 }
 
-void actualizeEffect(CStack * s, const std::vector<Bonus> & ef)
-{
-	//actualizing features vector
-
-	for(const Bonus &fromEffect : ef)
-	{
-		for(Bonus *stackBonus : s->getBonusList()) //TODO: optimize
-		{
-			if(stackBonus->source == Bonus::SPELL_EFFECT && stackBonus->type == fromEffect.type && stackBonus->subtype == fromEffect.subtype)
-			{
-				stackBonus->turnsRemain = std::max(stackBonus->turnsRemain, fromEffect.turnsRemain);
-			}
-		}
-	}
-}
 void actualizeEffect(CStack * s, const Bonus & ef)
 {
 	for(Bonus *stackBonus : s->getBonusList()) //TODO: optimize
@@ -1366,6 +1351,17 @@ void actualizeEffect(CStack * s, const Bonus & ef)
 			stackBonus->turnsRemain = std::max(stackBonus->turnsRemain, ef.turnsRemain);
 		}
 	}
+	CBonusSystemNode::treeHasChanged();	
+}
+
+void actualizeEffect(CStack * s, const std::vector<Bonus> & ef)
+{
+	//actualizing features vector
+
+	for(const Bonus &fromEffect : ef)
+	{
+		actualizeEffect(s, fromEffect);
+	}
 }
 
 DLL_LINKAGE void SetStackEffect::applyGs( CGameState *gs )
@@ -1460,15 +1456,6 @@ DLL_LINKAGE void StacksHealedOrResurrected::applyGs( CGameState *gs )
 		//removal of negative effects
 		if(resurrected)
 		{
-
-// 			for (BonusList::iterator it = changedStack->bonuses.begin(); it != changedStack->bonuses.end(); it++)
-// 			{
-// 				if(VLC->spellh->spells[(*it)->sid]->positiveness < 0)
-// 				{
-// 					changedStack->bonuses.erase(it);
-// 				}
-// 			}
-
 			//removing all features from negative spells
 			const BonusList tmpFeatures = changedStack->getBonusList();
 			//changedStack->bonuses.clear();

+ 0 - 35
lib/VCMI_lib.cbp

@@ -42,41 +42,6 @@
 					<Add directory="$(#sdl2.lib)" />
 				</Linker>
 			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../VCMI_lib" prefix_auto="0" extension_auto="1" />
-				<Option object_output="../obj/Debug/Lib" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Option host_application="D:/projects/vcmi/engine/VCMI_client.exe" />
-				<Option run_host_application_in_terminal="1" />
-				<Option createStaticLib="1" />
-				<Compiler>
-					<Add option="-Og" />
-					<Add option="-g" />
-					<Add directory="$(#sdl.include)" />
-				</Compiler>
-				<Linker>
-					<Add directory="$(#sdl.lib)" />
-				</Linker>
-			</Target>
-			<Target title="Release-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../VCMI_lib" prefix_auto="0" extension_auto="1" />
-				<Option object_output="../obj/Release/Lib" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Option createStaticLib="1" />
-				<Compiler>
-					<Add option="-fomit-frame-pointer" />
-					<Add option="-O2" />
-					<Add directory="$(#sdl.include)" />
-				</Compiler>
-				<Linker>
-					<Add option="-s" />
-					<Add directory="$(#sdl.lib)" />
-				</Linker>
-			</Target>
 		</Build>
 		<Compiler>
 			<Add option="-Wextra" />

+ 0 - 29
lib/minizip/minizip.cbp

@@ -35,35 +35,6 @@
 					<Add option="-s" />
 				</Linker>
 			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../../minizip" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Debug/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Option createStaticLib="1" />
-				<Compiler>
-					<Add option="-Wall" />
-					<Add option="-g" />
-					<Add option="-DBUILD_DLL" />
-				</Compiler>
-			</Target>
-			<Target title="Release-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../../minizip" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Release/" />
-				<Option type="3" />
-				<Option compiler="gcc" />
-				<Option createStaticLib="1" />
-				<Compiler>
-					<Add option="-O2" />
-					<Add option="-Wall" />
-					<Add option="-DBUILD_DLL" />
-				</Compiler>
-				<Linker>
-					<Add option="-s" />
-				</Linker>
-			</Target>
 		</Build>
 		<Compiler>
 			<Add directory="$(#zlib.include)" />

+ 102 - 56
server/CGameHandler.cpp

@@ -1020,50 +1020,76 @@ int CGameHandler::moveStack(int stack, BattleHex dest)
 	}
 	else //for non-flying creatures
 	{
-		// send one package with the creature path information
-
-		shared_ptr<const CObstacleInstance> obstacle; //obstacle that interrupted movement
+		shared_ptr<const CObstacleInstance> obstacle, obstacle2; //obstacle that interrupted movement
 		std::vector<BattleHex> tiles;
-		int tilesToMove = std::max((int)(path.first.size() - creSpeed), 0);
+		const int tilesToMove = std::max((int)(path.first.size() - creSpeed), 0);
 		int v = path.first.size()-1;
 
-startWalking:
-		for(; v >= tilesToMove; --v)
+		bool stackIsMoving = true;
+		
+		while(stackIsMoving)
 		{
-			BattleHex hex = path.first[v];
-			tiles.push_back(hex);
-
-			if((obstacle = battleGetObstacleOnPos(hex, false)))
+			if(v<tilesToMove)
 			{
-				//we walked onto something, so we finalize this portion of stack movement check into obstacle
+				logGlobal->error("Movement terminated abnormally");
 				break;
 			}
-		}
 
-		if (tiles.size() > 0)
-		{
-			//commit movement
-			BattleStackMoved sm;
-			sm.stack = curStack->ID;
-			sm.distance = path.second;
-			sm.teleporting = false;
-			sm.tilesToMove = tiles;
-			sendAndApply(&sm);
-		}
+			for(bool obstacleHit = false; (!obstacleHit) && (v >= tilesToMove); --v)
+			{
+				BattleHex hex = path.first[v];
+				tiles.push_back(hex);
 
-		//we don't handle obstacle at the destination tile -> it's handled separately in the if at the end
-		if(obstacle && curStack->position != dest)
-		{
-			handleDamageFromObstacle(*obstacle, curStack);
+				//if we walked onto something, finalize this portion of stack movement check into obstacle
+				if((obstacle = battleGetObstacleOnPos(hex, false)))
+					obstacleHit = true;
+
+				if(curStack->doubleWide())
+				{
+					BattleHex otherHex = curStack->occupiedHex(hex);
+
+					//two hex creature hit obstacle by backside
+					if(otherHex.isValid() && ((obstacle2 = battleGetObstacleOnPos(otherHex, false))))
+						obstacleHit = true;
+				}
+			}
 
-			//if stack didn't die in explosion, continue movement
-			if(!obstacle->stopsMovement() && curStack->alive())
+			if(tiles.size() > 0)
 			{
-				obstacle.reset();
+				//commit movement
+				BattleStackMoved sm;
+				sm.stack = curStack->ID;
+				sm.distance = path.second;
+				sm.teleporting = false;
+				sm.tilesToMove = tiles;
+				sendAndApply(&sm);
 				tiles.clear();
-				v--;
-				goto startWalking; //TODO it's so evil
 			}
+
+			//we don't handle obstacle at the destination tile -> it's handled separately in the if at the end
+			if(curStack->position != dest)
+			{
+				auto processObstacle = [&](shared_ptr<const CObstacleInstance> & obs)
+				{
+					if(obs)
+					{
+						handleDamageFromObstacle(*obs, curStack);
+
+						//if stack die in explosion or interrupted by obstacle, abort movement
+						if(obs->stopsMovement() || !curStack->alive())
+							stackIsMoving = false;
+
+						obs.reset();						
+					}
+				};
+				
+				processObstacle(obstacle);
+				if(curStack->alive())
+					processObstacle(obstacle2);
+			}
+			else
+				//movement finished normally: we reached destination
+				stackIsMoving = false;
 		}
 	}
 
@@ -1075,6 +1101,18 @@ startWalking:
 			handleDamageFromObstacle(*theLastObstacle, curStack);
 		}
 	}
+
+	if(curStack->alive() && curStack->doubleWide())
+	{
+		BattleHex otherHex = curStack->occupiedHex(curStack->position);
+		
+		if(otherHex.isValid())
+			if(auto theLastObstacle = battleGetObstacleOnPos(otherHex, false))
+			{
+				//two hex creature hit obstacle by backside
+				handleDamageFromObstacle(*theLastObstacle, curStack);
+			}
+	}	
 	return ret;
 }
 
@@ -4175,34 +4213,42 @@ void CGameHandler::stackTurnTrigger(const CStack * st)
 		}
 		BonusList bl = *(st->getBonuses(Selector::type(Bonus::ENCHANTER)));
 		int side = gs->curB->whatSide(st->owner);
-		if (bl.size() && st->casts && !gs->curB->sides.at(side).enchanterCounter)
+		if (st->casts && !gs->curB->sides.at(side).enchanterCounter)
 		{
-			auto bonus = *RandomGeneratorUtil::nextItem(bl, gs->getRandomGenerator());
-			auto spellID = SpellID(bonus->subtype);
-			const CSpell * spell = SpellID(spellID).toSpell();
-			if (gs->curB->battleCanCastThisSpell(st->owner, spell, ECastingMode::ENCHANTER_CASTING) == ESpellCastProblem::OK) //TODO: select another available?
+			bool casted = false;
+			while (!bl.empty() and !casted)
 			{
-				BattleSpellCastParameters parameters(gs->curB);
-				parameters.spellLvl = bonus->val;
-				parameters.destination = BattleHex::INVALID;
-				parameters.casterSide = side;
-				parameters.casterColor = st->owner;	
-				parameters.caster = nullptr;
-				parameters.secHero = gs->curB->getHero(gs->curB->theOtherPlayer(st->owner));
-				parameters.usedSpellPower = 0;	
-				parameters.mode = ECastingMode::ENCHANTER_CASTING;
-				parameters.casterStack = st;	
-				parameters.selectedStack = nullptr;
+				auto bonus = *RandomGeneratorUtil::nextItem(bl, gs->getRandomGenerator());
+				auto spellID = SpellID(bonus->subtype);
+				const CSpell * spell = SpellID(spellID).toSpell();
+				bl.remove_if([&bonus](Bonus * b){return b==bonus;});					
 				
-				spell->battleCast(spellEnv, parameters);				
-
-				BattleSetStackProperty ssp;
-				ssp.which = BattleSetStackProperty::ENCHANTER_COUNTER;
-				ssp.absolute = false;
-				ssp.val = bonus->additionalInfo; //increase cooldown counter
-				ssp.stackID = st->ID;
-				sendAndApply(&ssp);
-			}
+				if (gs->curB->battleCanCastThisSpell(st->owner, spell, ECastingMode::ENCHANTER_CASTING) == ESpellCastProblem::OK)
+				{
+					BattleSpellCastParameters parameters(gs->curB);
+					parameters.spellLvl = bonus->val;
+					parameters.destination = BattleHex::INVALID;
+					parameters.casterSide = side;
+					parameters.casterColor = st->owner;	
+					parameters.caster = nullptr;
+					parameters.secHero = gs->curB->getHero(gs->curB->theOtherPlayer(st->owner));
+					parameters.usedSpellPower = 0;	
+					parameters.mode = ECastingMode::ENCHANTER_CASTING;
+					parameters.casterStack = st;	
+					parameters.selectedStack = nullptr;
+					
+					spell->battleCast(spellEnv, parameters);				
+
+					BattleSetStackProperty ssp;
+					ssp.which = BattleSetStackProperty::ENCHANTER_COUNTER;
+					ssp.absolute = false;
+					ssp.val = bonus->additionalInfo; //increase cooldown counter
+					ssp.stackID = st->ID;
+					sendAndApply(&ssp);
+					
+					casted = true;
+				}				
+			};
 		}
 		bl = *(st->getBonuses(Selector::type(Bonus::ENCHANTED)));
 		for (auto b : bl)

+ 0 - 29
server/VCMI_server.cbp

@@ -35,35 +35,6 @@
 					<Add option="-s" />
 				</Linker>
 			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../VCMI_server" prefix_auto="1" extension_auto="1" />
-				<Option object_output="../obj/Debug/Server" />
-				<Option type="1" />
-				<Option compiler="gcc" />
-				<Option use_console_runner="0" />
-				<Compiler>
-					<Add option="-Og" />
-					<Add option="-ggdb" />
-					<Add directory="$(#sdl.include)" />
-				</Compiler>
-			</Target>
-			<Target title="Release-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../VCMI_server" prefix_auto="1" extension_auto="1" />
-				<Option object_output="../obj/Release/Server" />
-				<Option type="1" />
-				<Option compiler="gcc" />
-				<Option use_console_runner="0" />
-				<Compiler>
-					<Add option="-fomit-frame-pointer" />
-					<Add option="-O2" />
-					<Add directory="$(#sdl.include)" />
-				</Compiler>
-				<Linker>
-					<Add option="-s" />
-				</Linker>
-			</Target>
 		</Build>
 		<Compiler>
 			<Add option="-Wextra" />

+ 0 - 12
test/Test.cbp

@@ -18,18 +18,6 @@
 					<Add option="-g" />
 				</Compiler>
 			</Target>
-			<Target title="Debug-win32-SDL1">
-				<Option platforms="Windows;" />
-				<Option output="../Test" prefix_auto="1" extension_auto="1" />
-				<Option object_output="obj/Debug/" />
-				<Option type="1" />
-				<Option compiler="gcc" />
-				<Compiler>
-					<Add option="-march=athlon-xp" />
-					<Add option="-Wextra" />
-					<Add option="-g" />
-				</Compiler>
-			</Target>
 		</Build>
 		<Compiler>
 			<Add option="-Wall" />