Sfoglia il codice sorgente

Zmiany do Programming challenge.

Michał W. Urbańczyk 14 anni fa
parent
commit
bdd66b6537

+ 1 - 0
AI/StupidAI/StupidAI.vcxproj

@@ -92,6 +92,7 @@
       <AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PrecompiledHeader>Use</PrecompiledHeader>
       <PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
+      <MinimalRebuild>false</MinimalRebuild>
     </ClCompile>
     <Link>
       <GenerateDebugInformation>true</GenerateDebugInformation>

+ 6 - 0
Odpalarka/Makefile.am

@@ -0,0 +1,6 @@
+bin_PROGRAMS = odpalarka
+
+odpalarka_LDADD = $(top_builddir)/lib/libvcmi.la
+odpalarka_CXXFLAGS = @SDL_CXXFLAGS@
+odpalarka_LDFLAGS = -L$(top_builddir)/lib
+odpalarka_SOURCES = main.cpp

+ 134 - 0
Odpalarka/Odpalarka.vcxproj

@@ -0,0 +1,134 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{27B69211-D138-4142-BBC9-40F5DEA39067}</ProjectGuid>
+    <RootNamespace>Odpalarka</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\VCMI_global.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\VCMI_global.props" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\VCMI_global.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\VCMI_global.props" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)$(Configuration)\bin\</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)$(Configuration)\bin\</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="main.cpp" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 14 - 0
Odpalarka/main.cpp

@@ -0,0 +1,14 @@
+#include "../global.h"
+#include <boost/thread.hpp>
+#include <boost/bind.hpp>
+
+int main()
+{
+	boost::thread t(boost::bind(std::system, "VCMI_server.exe b1.json StupidAI StupidAI"));
+	boost::thread tt(boost::bind(std::system, "VCMI_BattleAiHost.exe"));
+	boost::thread ttt(boost::bind(std::system, "VCMI_BattleAiHost.exe"));
+	boost::thread tttt(boost::bind(std::system, "VCMI_BattleAiHost.exe"));
+	boost::this_thread::sleep(boost::posix_time::seconds(5));
+
+	return EXIT_SUCCESS;
+}

+ 6 - 0
VCMI_BattleAiHost/Makefile.am

@@ -0,0 +1,6 @@
+bin_PROGRAMS = vcmirunner
+
+vcmirunner_LDADD = $(top_builddir)/lib/libvcmi.la
+vcmirunner_CXXFLAGS = @SDL_CXXFLAGS@
+vcmirunner_LDFLAGS = -L$(top_builddir)/lib
+vcmirunner_SOURCES = main.cpp

+ 140 - 0
VCMI_BattleAiHost/VCMI_BattleAiHost.vcxproj

@@ -0,0 +1,140 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <ItemGroup Label="ProjectConfigurations">
+    <ProjectConfiguration Include="Debug|Win32">
+      <Configuration>Debug</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Debug|x64">
+      <Configuration>Debug</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|Win32">
+      <Configuration>Release</Configuration>
+      <Platform>Win32</Platform>
+    </ProjectConfiguration>
+    <ProjectConfiguration Include="Release|x64">
+      <Configuration>Release</Configuration>
+      <Platform>x64</Platform>
+    </ProjectConfiguration>
+  </ItemGroup>
+  <PropertyGroup Label="Globals">
+    <ProjectGuid>{6A72AA10-D8CC-4685-A076-368CA64CA7C6}</ProjectGuid>
+    <RootNamespace>VCMI_BattleAiHost</RootNamespace>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+    <CLRSupport>false</CLRSupport>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>true</UseDebugLibraries>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+    <ConfigurationType>Application</ConfigurationType>
+    <UseDebugLibraries>false</UseDebugLibraries>
+    <WholeProgramOptimization>true</WholeProgramOptimization>
+    <CharacterSet>MultiByte</CharacterSet>
+  </PropertyGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+  <ImportGroup Label="ExtensionSettings">
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\VCMI_global.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\VCMI_global.props" />
+  </ImportGroup>
+  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\VCMI_global.props" />
+  </ImportGroup>
+  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
+    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+    <Import Project="..\VCMI_global.props" />
+  </ImportGroup>
+  <PropertyGroup Label="UserMacros" />
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <OutDir>$(SolutionDir)</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <OutDir>$(SolutionDir)</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <OutDir>$(SolutionDir)</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <OutDir>$(SolutionDir)</OutDir>
+    <IntDir>$(Configuration)\</IntDir>
+  </PropertyGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalLibraryDirectories>$(OutDir);</AdditionalLibraryDirectories>
+      <AdditionalDependencies>VCMI_lib.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>Disabled</Optimization>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <AdditionalDependencies>VCMI_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>VCMI_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+    <ClCompile>
+      <WarningLevel>Level3</WarningLevel>
+      <Optimization>MaxSpeed</Optimization>
+      <FunctionLevelLinking>true</FunctionLevelLinking>
+      <IntrinsicFunctions>true</IntrinsicFunctions>
+    </ClCompile>
+    <Link>
+      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <EnableCOMDATFolding>true</EnableCOMDATFolding>
+      <OptimizeReferences>true</OptimizeReferences>
+      <AdditionalDependencies>VCMI_lib.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
+    </Link>
+  </ItemDefinitionGroup>
+  <ItemGroup>
+    <ClCompile Include="main.cpp" />
+  </ItemGroup>
+  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+  <ImportGroup Label="ExtensionTargets">
+  </ImportGroup>
+</Project>

+ 82 - 0
VCMI_BattleAiHost/main.cpp

@@ -0,0 +1,82 @@
+ #include "../global.h"
+ #include "../lib/Connection.h"
+ #include <boost/lexical_cast.hpp>
+ #include <boost/thread.hpp>
+#include <fstream>
+#include "../StartInfo.h"
+
+#ifdef _WIN32
+#include <Windows.h>
+#else
+#include <unistd.h>
+#endif
+#include "../lib/CGameState.h"
+#include "../CCallback.h"
+#include "../lib/CGameInterface.h"
+#include <boost/format.hpp>
+
+using namespace std;
+using namespace boost;
+
+std::string NAME = NAME_VER + std::string(" DLL runner");
+
+int main(int argc, char** argv)
+{
+	int pid = -1;
+
+#ifdef _WIN32
+	pid = GetCurrentProcessId();
+#else
+	pid = getpid();
+#endif
+
+	logfile = new std::ofstream(("VCMI_Server_log_" + boost::lexical_cast<std::string>(pid) + ".txt").c_str());
+
+	try
+	{
+
+		string host = "127.0.0.1";
+		string port = "3030";
+
+		CConnection *serv = NULL;
+		while(!serv)
+		{
+			try
+			{
+				tlog0 << "Establishing connection...\n";
+				serv = new CConnection(host, port, "DLL host");
+			}
+			catch(...)
+			{
+				tlog1 << "\nCannot establish connection! Retrying within 2 seconds" << std::endl;
+				boost::this_thread::sleep(boost::posix_time::seconds(2));
+			}
+		}
+
+		ui8 color;
+		StartInfo si;
+		string battleAIName;
+		*serv >> si >> battleAIName >> color;
+		assert(si.mode == StartInfo::DUEL);
+		tlog0 << format("Server wants us to run %s in battle %s as side %d") % battleAIName % si.mapname % color;
+		
+
+		CGameState *gs = new CGameState();
+		gs->init(&si, 0, 0);
+
+
+		CBattleCallback * cbc = new CBattleCallback(gs, color, this);
+		CBattleGameInterface *ai = CDynLibHandler::getNewBattleAI(battleAIName);
+		ai->init(cbc);
+
+	}
+	catch(std::exception &e)
+	{
+		tlog1 << "Encountered exception: " << e.what() << std::endl;
+	}
+	catch(...)
+	{
+		tlog1 << "Encountered unknown exception!" << std::endl;
+	}
+	return EXIT_SUCCESS;
+}

+ 42 - 10
VCMI_VS10.sln

@@ -1,6 +1,6 @@
 
 Microsoft Visual Studio Solution File, Format Version 11.00
-# Visual C++ Express 2010
+# Visual Studio 2010
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VCMI_client", "client\VCMI_client.vcxproj", "{8355EBA8-65C2-44A4-BC2D-78053E1BF2D6}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VCMI_lib", "lib\VCMI_lib.vcxproj", "{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}"
@@ -14,7 +14,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "StupidAI", "AI\StupidAI\Stu
 		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F} = {B952FFC5-3039-4DE1-9F08-90ACDA483D8F}
 	EndProjectSection
 EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ERM", "Scripting\ERM\ERM.vcxproj", "{8F202F43-106D-4F63-AD9D-B1D43E803E8C}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "VCMI_BattleAiHost", "VCMI_BattleAiHost\VCMI_BattleAiHost.vcxproj", "{6A72AA10-D8CC-4685-A076-368CA64CA7C6}"
+	ProjectSection(ProjectDependencies) = postProject
+		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F} = {B952FFC5-3039-4DE1-9F08-90ACDA483D8F}
+	EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Odpalarka", "Odpalarka\Odpalarka.vcxproj", "{27B69211-D138-4142-BBC9-40F5DEA39067}"
 	ProjectSection(ProjectDependencies) = postProject
 		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F} = {B952FFC5-3039-4DE1-9F08-90ACDA483D8F}
 	EndProjectSection
@@ -25,6 +30,8 @@ Global
 		Debug|x64 = Debug|x64
 		RD|Win32 = RD|Win32
 		RD|x64 = RD|x64
+		Release|Win32 = Release|Win32
+		Release|x64 = Release|x64
 	EndGlobalSection
 	GlobalSection(ProjectConfigurationPlatforms) = postSolution
 		{8355EBA8-65C2-44A4-BC2D-78053E1BF2D6}.Debug|Win32.ActiveCfg = Debug|Win32
@@ -35,6 +42,9 @@ Global
 		{8355EBA8-65C2-44A4-BC2D-78053E1BF2D6}.RD|Win32.Build.0 = RD|Win32
 		{8355EBA8-65C2-44A4-BC2D-78053E1BF2D6}.RD|x64.ActiveCfg = RD|x64
 		{8355EBA8-65C2-44A4-BC2D-78053E1BF2D6}.RD|x64.Build.0 = RD|x64
+		{8355EBA8-65C2-44A4-BC2D-78053E1BF2D6}.Release|Win32.ActiveCfg = RD|x64
+		{8355EBA8-65C2-44A4-BC2D-78053E1BF2D6}.Release|x64.ActiveCfg = RD|x64
+		{8355EBA8-65C2-44A4-BC2D-78053E1BF2D6}.Release|x64.Build.0 = RD|x64
 		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}.Debug|Win32.ActiveCfg = Debug|Win32
 		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}.Debug|Win32.Build.0 = Debug|Win32
 		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}.Debug|x64.ActiveCfg = Debug|x64
@@ -43,6 +53,9 @@ Global
 		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}.RD|Win32.Build.0 = RD|Win32
 		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}.RD|x64.ActiveCfg = RD|x64
 		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}.RD|x64.Build.0 = RD|x64
+		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}.Release|Win32.ActiveCfg = RD|x64
+		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}.Release|x64.ActiveCfg = RD|x64
+		{B952FFC5-3039-4DE1-9F08-90ACDA483D8F}.Release|x64.Build.0 = RD|x64
 		{8AF697C3-465E-4910-B31B-576A9ECDB309}.Debug|Win32.ActiveCfg = Debug|Win32
 		{8AF697C3-465E-4910-B31B-576A9ECDB309}.Debug|Win32.Build.0 = Debug|Win32
 		{8AF697C3-465E-4910-B31B-576A9ECDB309}.Debug|x64.ActiveCfg = Debug|x64
@@ -51,6 +64,9 @@ Global
 		{8AF697C3-465E-4910-B31B-576A9ECDB309}.RD|Win32.Build.0 = RD|Win32
 		{8AF697C3-465E-4910-B31B-576A9ECDB309}.RD|x64.ActiveCfg = RD|x64
 		{8AF697C3-465E-4910-B31B-576A9ECDB309}.RD|x64.Build.0 = RD|x64
+		{8AF697C3-465E-4910-B31B-576A9ECDB309}.Release|Win32.ActiveCfg = RD|x64
+		{8AF697C3-465E-4910-B31B-576A9ECDB309}.Release|x64.ActiveCfg = RD|x64
+		{8AF697C3-465E-4910-B31B-576A9ECDB309}.Release|x64.Build.0 = RD|x64
 		{B6A14ED9-E7C1-411B-A596-2FE90B3145B4}.Debug|Win32.ActiveCfg = Debug|Win32
 		{B6A14ED9-E7C1-411B-A596-2FE90B3145B4}.Debug|Win32.Build.0 = Debug|Win32
 		{B6A14ED9-E7C1-411B-A596-2FE90B3145B4}.Debug|x64.ActiveCfg = Debug|x64
@@ -59,6 +75,9 @@ Global
 		{B6A14ED9-E7C1-411B-A596-2FE90B3145B4}.RD|Win32.Build.0 = RD|Win32
 		{B6A14ED9-E7C1-411B-A596-2FE90B3145B4}.RD|x64.ActiveCfg = RD|x64
 		{B6A14ED9-E7C1-411B-A596-2FE90B3145B4}.RD|x64.Build.0 = RD|x64
+		{B6A14ED9-E7C1-411B-A596-2FE90B3145B4}.Release|Win32.ActiveCfg = RD|x64
+		{B6A14ED9-E7C1-411B-A596-2FE90B3145B4}.Release|x64.ActiveCfg = RD|x64
+		{B6A14ED9-E7C1-411B-A596-2FE90B3145B4}.Release|x64.Build.0 = RD|x64
 		{15DABC90-234A-4B6B-9EEB-777C4768B82B}.Debug|Win32.ActiveCfg = Debug|Win32
 		{15DABC90-234A-4B6B-9EEB-777C4768B82B}.Debug|Win32.Build.0 = Debug|Win32
 		{15DABC90-234A-4B6B-9EEB-777C4768B82B}.Debug|x64.ActiveCfg = Debug|x64
@@ -67,14 +86,27 @@ Global
 		{15DABC90-234A-4B6B-9EEB-777C4768B82B}.RD|Win32.Build.0 = RD|Win32
 		{15DABC90-234A-4B6B-9EEB-777C4768B82B}.RD|x64.ActiveCfg = RD|x64
 		{15DABC90-234A-4B6B-9EEB-777C4768B82B}.RD|x64.Build.0 = RD|x64
-		{8F202F43-106D-4F63-AD9D-B1D43E803E8C}.Debug|Win32.ActiveCfg = Debug|Win32
-		{8F202F43-106D-4F63-AD9D-B1D43E803E8C}.Debug|Win32.Build.0 = Debug|Win32
-		{8F202F43-106D-4F63-AD9D-B1D43E803E8C}.Debug|x64.ActiveCfg = Debug|x64
-		{8F202F43-106D-4F63-AD9D-B1D43E803E8C}.Debug|x64.Build.0 = Debug|x64
-		{8F202F43-106D-4F63-AD9D-B1D43E803E8C}.RD|Win32.ActiveCfg = RD|Win32
-		{8F202F43-106D-4F63-AD9D-B1D43E803E8C}.RD|Win32.Build.0 = RD|Win32
-		{8F202F43-106D-4F63-AD9D-B1D43E803E8C}.RD|x64.ActiveCfg = RD|x64
-		{8F202F43-106D-4F63-AD9D-B1D43E803E8C}.RD|x64.Build.0 = RD|x64
+		{15DABC90-234A-4B6B-9EEB-777C4768B82B}.Release|Win32.ActiveCfg = RD|x64
+		{15DABC90-234A-4B6B-9EEB-777C4768B82B}.Release|x64.ActiveCfg = RD|x64
+		{15DABC90-234A-4B6B-9EEB-777C4768B82B}.Release|x64.Build.0 = RD|x64
+		{6A72AA10-D8CC-4685-A076-368CA64CA7C6}.Debug|Win32.ActiveCfg = Debug|Win32
+		{6A72AA10-D8CC-4685-A076-368CA64CA7C6}.Debug|Win32.Build.0 = Debug|Win32
+		{6A72AA10-D8CC-4685-A076-368CA64CA7C6}.Debug|x64.ActiveCfg = Debug|x64
+		{6A72AA10-D8CC-4685-A076-368CA64CA7C6}.RD|Win32.ActiveCfg = Release|Win32
+		{6A72AA10-D8CC-4685-A076-368CA64CA7C6}.RD|Win32.Build.0 = Release|Win32
+		{6A72AA10-D8CC-4685-A076-368CA64CA7C6}.RD|x64.ActiveCfg = Release|Win32
+		{6A72AA10-D8CC-4685-A076-368CA64CA7C6}.Release|Win32.ActiveCfg = Release|Win32
+		{6A72AA10-D8CC-4685-A076-368CA64CA7C6}.Release|Win32.Build.0 = Release|Win32
+		{6A72AA10-D8CC-4685-A076-368CA64CA7C6}.Release|x64.ActiveCfg = Release|Win32
+		{27B69211-D138-4142-BBC9-40F5DEA39067}.Debug|Win32.ActiveCfg = Debug|Win32
+		{27B69211-D138-4142-BBC9-40F5DEA39067}.Debug|Win32.Build.0 = Debug|Win32
+		{27B69211-D138-4142-BBC9-40F5DEA39067}.Debug|x64.ActiveCfg = Debug|x64
+		{27B69211-D138-4142-BBC9-40F5DEA39067}.RD|Win32.ActiveCfg = Release|Win32
+		{27B69211-D138-4142-BBC9-40F5DEA39067}.RD|Win32.Build.0 = Release|Win32
+		{27B69211-D138-4142-BBC9-40F5DEA39067}.RD|x64.ActiveCfg = Release|Win32
+		{27B69211-D138-4142-BBC9-40F5DEA39067}.Release|Win32.ActiveCfg = Release|Win32
+		{27B69211-D138-4142-BBC9-40F5DEA39067}.Release|Win32.Build.0 = Release|Win32
+		{27B69211-D138-4142-BBC9-40F5DEA39067}.Release|x64.ActiveCfg = Release|Win32
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 16 - 0
b1.json

@@ -0,0 +1,16 @@
+[
+	"terType" : 0,
+	"bfieldType" : 0,
+	
+	"sides" : 
+	[
+		{
+			"side" : 0,
+			"army" : [[10, 40]]
+		}
+		{
+			"side" : 1,
+			"army" : [[11, 41]]
+		}
+	]
+]

+ 14 - 7
lib/CDefObjInfoHandler.cpp

@@ -124,18 +124,25 @@ void CDefObjInfoHandler::load()
 			castles[nobj->subid]=nobj;
 	}
 
-	for (int i = 0; i < 8 ; i++)
+	if(vstd::contains(gobjs, 124))
 	{
+		for (int i = 0; i < 8 ; i++)
+		{
 
-		static const char *holeDefs[] = {"AVLHOLD0.DEF", "AVLHLDS0.DEF", "AVLHOLG0.DEF", "AVLHLSN0.DEF",
-			"AVLHOLS0.DEF", "AVLHOLR0.DEF", "AVLHOLX0.DEF", "AVLHOLL0.DEF"};
+			static const char *holeDefs[] = {"AVLHOLD0.DEF", "AVLHLDS0.DEF", "AVLHOLG0.DEF", "AVLHLSN0.DEF",
+				"AVLHOLS0.DEF", "AVLHOLR0.DEF", "AVLHOLX0.DEF", "AVLHOLL0.DEF"};
 
-		if(i)
-		{
-			gobjs[124][i] = new CGDefInfo(*gobjs[124][0]);
-			gobjs[124][i]->name = holeDefs[i];
+			if(i)
+			{
+				gobjs[124][i] = new CGDefInfo(*gobjs[124][0]);
+				gobjs[124][i]->name = holeDefs[i];
+			}
 		}
 	}
+	else
+	{
+		tlog1 << "No def info for holes!\n";
+	}
 }
  
 CDefObjInfoHandler::~CDefObjInfoHandler()

+ 35 - 3
lib/CGameState.cpp

@@ -31,6 +31,7 @@
 #include "CMapInfo.h"
 #include "BattleState.h"
 #include "../lib/JsonNode.h"
+#include <boost/algorithm/string/predicate.hpp>
 
 boost::rand48 ran;
 class CGObjectInstance;
@@ -939,9 +940,18 @@ void CGameState::init( StartInfo * si, ui32 checksum, int Seed )
 			DuelParameters dp;
 			try
 			{
-				CLoadFile lf(scenarioOps->mapname);
-				lf >> dp;
-				success = true;
+				if(boost::algorithm::ends_with(scenarioOps->mapname, ".json"))
+				{
+					tlog0 << "Loading duel settings from JSON file: " << scenarioOps->mapname << std::endl;
+					dp = DuelParameters::fromJSON(scenarioOps->mapname);
+					tlog0 << "JSON file has been succesfully read!\n";
+				}
+				else
+				{
+					CLoadFile lf(scenarioOps->mapname);
+					lf >> dp;
+					success = true;
+				}
 			}
 			catch(...)
 			{}
@@ -2694,6 +2704,28 @@ DuelParameters::DuelParameters()
 	bfieldType = 15;
 }
 
+DuelParameters DuelParameters::fromJSON(const std::string &fname)
+{
+	DuelParameters ret;
+
+	const JsonNode duelData(fname);
+	ret.terType = duelData["terType"].Float();
+	ret.bfieldType = duelData["bfieldType"].Float();
+	BOOST_FOREACH(const JsonNode &n, duelData["sides"].Vector())
+	{
+		SideSettings &ss = ret.sides[(int)n["side"].Float()];
+		int i = 0;
+		BOOST_FOREACH(const JsonNode &stackNode, n["army"].Vector())
+		{
+			ss.stacks[i].type = stackNode.Vector()[0].Float();
+			ss.stacks[i].count = stackNode.Vector()[1].Float();
+			i++;
+		}
+	}
+
+	return ret;
+}
+
 TeamState::TeamState()
 {
 	setNodeType(TEAM);

+ 2 - 0
lib/CGameState.h

@@ -305,6 +305,8 @@ struct DLL_EXPORT DuelParameters
 		}
 	} sides[2];
 
+	static DuelParameters fromJSON(const std::string &fname);
+
 	DuelParameters();
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{

+ 27 - 25
lib/CLodHandler.cpp

@@ -271,37 +271,39 @@ void CLodHandler::init(const std::string lodFile, const std::string dirName)
 	if (!LOD.is_open()) 
 	{
 		tlog1 << "Cannot open " << lodFile << std::endl;
-		return;
 	}
+	else
+	{
 
-	Uint32 temp;
-	LOD.seekg(8);
-	LOD.read((char *)&temp, 4);
-	totalFiles = SDL_SwapLE32(temp);
+		Uint32 temp;
+		LOD.seekg(8);
+		LOD.read((char *)&temp, 4);
+		totalFiles = SDL_SwapLE32(temp);
 
-	LOD.seekg(0x5c, std::ios::beg);
-	if(!LOD)
-	{
-		tlog2 << lodFile << " doesn't store anything!\n";
-		return;
-	}
+		LOD.seekg(0x5c, std::ios::beg);
+		if(!LOD)
+		{
+			tlog2 << lodFile << " doesn't store anything!\n";
+			return;
+		}
 
-	struct LodEntry *lodEntries = new struct LodEntry[totalFiles];
-	LOD.read((char *)lodEntries, sizeof(struct LodEntry) * totalFiles);
+		struct LodEntry *lodEntries = new struct LodEntry[totalFiles];
+		LOD.read((char *)lodEntries, sizeof(struct LodEntry) * totalFiles);
 
-	for (unsigned int i=0; i<totalFiles; i++)
-	{
-		Entry entry;
-		initEntry(entry, lodEntries[i].filename);
-		
-		entry.offset= SDL_SwapLE32(lodEntries[i].offset);
-		entry.realSize = SDL_SwapLE32(lodEntries[i].uncompressedSize);
-		entry.size = SDL_SwapLE32(lodEntries[i].size);
-
-		entries.insert(entry);
-	}
+		for (unsigned int i=0; i<totalFiles; i++)
+		{
+			Entry entry;
+			initEntry(entry, lodEntries[i].filename);
+
+			entry.offset= SDL_SwapLE32(lodEntries[i].offset);
+			entry.realSize = SDL_SwapLE32(lodEntries[i].uncompressedSize);
+			entry.size = SDL_SwapLE32(lodEntries[i].size);
 
-	delete [] lodEntries;
+			entries.insert(entry);
+		}
+
+		delete [] lodEntries;
+	}
 
 	boost::filesystem::recursive_directory_iterator enddir;
 	if(boost::filesystem::exists(dirName))

+ 1 - 0
lib/Connection.cpp

@@ -408,6 +408,7 @@ CSerializer::CSerializer()
 
 void CSerializer::addStdVecItems(CGameState *gs, LibClasses *lib)
 {
+	assert(gs);
 	registerVectoredType(&gs->map->objects, &CGObjectInstance::id);
 	registerVectoredType(&lib->heroh->heroes, &CHero::ID);
 	registerVectoredType(&lib->creh->creatures, &CCreature::idNumber);

+ 5 - 5
lib/JsonNode.cpp

@@ -107,7 +107,7 @@ bool & JsonNode::Bool()
 	return data.Bool;
 }
 
-float & JsonNode::Float()
+double & JsonNode::Float()
 {
 	setType(DATA_FLOAT);
 	return data.Float;
@@ -140,8 +140,8 @@ const bool & JsonNode::Bool() const
 	return data.Bool;
 }
 
-const float floatDefault = 0;
-const float & JsonNode::Float() const
+const double floatDefault = 0;
+const double & JsonNode::Float() const
 {
 	if (type == DATA_NULL)
 		return floatDefault;
@@ -562,7 +562,7 @@ bool JsonParser::extractFloat(JsonNode &node)
 {
 	assert(input[pos] == '-' || (input[pos] >= '0' && input[pos] <= '9'));
 	bool negative=false;
-	float result=0;
+	double result=0;
 
 	if (input[pos] == '-')
 	{
@@ -583,7 +583,7 @@ bool JsonParser::extractFloat(JsonNode &node)
 	{
 		//extract fractional part
 		pos++;
-		float fractMult = 0.1;
+		double fractMult = 0.1;
 		if (input[pos] < '0' || input[pos] > '9')
 			return error("Decimal part expected!");
 

+ 3 - 3
lib/JsonNode.h

@@ -28,7 +28,7 @@ private:
 	union JsonData
 	{
 		bool Bool;
-		float Float;
+		double Float;
 		std::string* String;
 		JsonVector* Vector;
 		JsonMap* Struct;
@@ -60,14 +60,14 @@ public:
 
 	//non-const accessors, node will change type on type mismatch
 	bool & Bool();
-	float & Float();
+	double & Float();
 	std::string & String();
 	JsonVector & Vector();
 	JsonMap & Struct();
 
 	//const accessors, will cause assertion failure on type mismatch
 	const bool & Bool() const;
-	const float & Float() const;
+	const double & Float() const;
 	const std::string & String() const;
 	const JsonVector & Vector() const;
 	const JsonMap & Struct() const;

+ 0 - 6
server/CGameHandler.cpp

@@ -1213,12 +1213,6 @@ void CGameHandler::run(bool resume)
 		boost::thread(boost::bind(&CGameHandler::handleConnection,this,pom,boost::ref(**i)));
 	}
 
-	if(gs->scenarioOps->mode == StartInfo::DUEL)
-	{
-		runBattle();
-		return;
-	}
-
 	while (!end2)
 	{
 		if(!resume)

+ 48 - 1
server/CVCMIServer.cpp

@@ -335,7 +335,6 @@ CGameHandler * CVCMIServer::initGhFromHostingConnection(CConnection &c)
 		c << ui8(0); //OK!
 	}
 
-	gh->init(&si,std::time(NULL));
 	c.addStdVecItems(gh->gs);
 	gh->conns.insert(&c);
 
@@ -499,6 +498,51 @@ void CVCMIServer::loadGame()
 	gh.run(true);
 }
 
+void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI, const std::string &rightAI)
+{
+	//we need three connections
+	CConnection *conns[3] = {0};
+	for (int i = 0; i < 3 ; i++)
+	{
+		boost::system::error_code error;
+		tcp::socket * s = new tcp::socket(acceptor->get_io_service());
+		acceptor->accept(*s, error);
+
+		if (error)
+		{
+			tlog2<<"Got connection but there is an error " << std::endl << error;
+			i--;
+			delNull(s);
+		}
+		else
+		{
+			tlog0<<"We've accepted someone... " << std::endl;
+			conns[i] = new CConnection(s, NAME);
+			tlog0<<"Got connection!" << std::endl;
+		}
+	}
+
+	StartInfo si;
+	si.mode = StartInfo::DUEL;
+	si.mapname = battle;
+	
+	CGameHandler *gh = new CGameHandler();
+	gh->init(&si,std::time(NULL));
+
+	BOOST_FOREACH(CConnection *c, conns)
+	{
+		c->addStdVecItems(gh->gs, VLC);
+		gh->connections[gh->conns.size()] = c;
+		gh->conns.insert(c);
+	}
+		
+	gh->runBattle();
+
+	delNull(gh);
+	boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
+	exit(0);
+}
+
 #ifndef __GNUC__
 int _tmain(int argc, _TCHAR* argv[])
 #else
@@ -523,6 +567,9 @@ int main(int argc, char** argv)
 	{
 		io_service io_service;
 		CVCMIServer server;
+		assert(argc == 4);
+		server.startDuel(argv[1], argv[2], argv[3]);
+
 		while(!end2)
 		{
 			server.start();

+ 1 - 0
server/CVCMIServer.h

@@ -54,6 +54,7 @@ public:
 	~CVCMIServer(); //d-tor
 
 	void start();
+	void startDuel(const std::string &battle, const std::string &leftAI, const std::string &rightAI);
 	CGameHandler *initGhFromHostingConnection(CConnection &c);
 
 	void newGame();

+ 6 - 17
server/Makefile.am

@@ -1,17 +1,6 @@
-bin_PROGRAMS = vcmiserver
-
-vcmiserver_LDADD = $(top_builddir)/lib/libvcmi.la
-vcmiserver_CXXFLAGS = @SDL_CXXFLAGS@
-vcmiserver_LDFLAGS = -L$(top_builddir)/lib
-vcmiserver_SOURCES = \
-	../CConsoleHandler.cpp \
-	../CConsoleHandler.h \
-	../CThreadHelper.cpp \
-	../CThreadHelper.h \
-	CGameHandler.cpp \
-	CGameHandler.h \
-	CVCMIServer.cpp \
-	CVCMIServer.h \
-	NetPacksServer.cpp \
-	stdafx.cpp \
-	stdafx.h
+bin_PROGRAMS = odpalarka
+
+odpalarka_LDADD = $(top_builddir)/lib/libvcmi.la
+odpalarka_CXXFLAGS = @SDL_CXXFLAGS@
+odpalarka_LDFLAGS = -L$(top_builddir)/lib
+odpalarka_SOURCES = main.cpp

+ 1 - 1
server/VCMI_server.vcxproj

@@ -35,7 +35,7 @@
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
-    <CharacterSet>Unicode</CharacterSet>
+    <CharacterSet>MultiByte</CharacterSet>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>