diff --git a/AI/StupidAI/StupidAI.vcxproj b/AI/StupidAI/StupidAI.vcxproj
index 022a23eab..621d574de 100644
--- a/AI/StupidAI/StupidAI.vcxproj
+++ b/AI/StupidAI/StupidAI.vcxproj
@@ -92,6 +92,7 @@
%(AdditionalIncludeDirectories)
Use
stdafx.h
+ false
true
diff --git a/Odpalarka/Makefile.am b/Odpalarka/Makefile.am
new file mode 100644
index 000000000..7648f9531
--- /dev/null
+++ b/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
diff --git a/Odpalarka/Odpalarka.vcxproj b/Odpalarka/Odpalarka.vcxproj
new file mode 100644
index 000000000..d1b3e2ef9
--- /dev/null
+++ b/Odpalarka/Odpalarka.vcxproj
@@ -0,0 +1,134 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ {27B69211-D138-4142-BBC9-40F5DEA39067}
+ Odpalarka
+
+
+
+ Application
+ true
+ MultiByte
+
+
+ Application
+ true
+ MultiByte
+
+
+ Application
+ false
+ true
+ MultiByte
+
+
+ Application
+ false
+ true
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(SolutionDir)
+ $(Configuration)\
+
+
+ $(SolutionDir)
+ $(Configuration)\
+
+
+ $(SolutionDir)$(Configuration)\bin\
+ $(Configuration)\
+
+
+ $(SolutionDir)$(Configuration)\bin\
+ $(Configuration)\
+
+
+
+ Level3
+ Disabled
+
+
+ true
+
+
+
+
+ Level3
+ Disabled
+
+
+ true
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+
+
+ true
+ true
+ true
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+
+
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Odpalarka/main.cpp b/Odpalarka/main.cpp
new file mode 100644
index 000000000..7d7d4bcfe
--- /dev/null
+++ b/Odpalarka/main.cpp
@@ -0,0 +1,14 @@
+#include "../global.h"
+#include
+#include
+
+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;
+}
\ No newline at end of file
diff --git a/VCMI_BattleAiHost/Makefile.am b/VCMI_BattleAiHost/Makefile.am
new file mode 100644
index 000000000..a1a37f64b
--- /dev/null
+++ b/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
diff --git a/VCMI_BattleAiHost/VCMI_BattleAiHost.vcxproj b/VCMI_BattleAiHost/VCMI_BattleAiHost.vcxproj
new file mode 100644
index 000000000..ea97ecb2d
--- /dev/null
+++ b/VCMI_BattleAiHost/VCMI_BattleAiHost.vcxproj
@@ -0,0 +1,140 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ Win32
+
+
+ Release
+ x64
+
+
+
+ {6A72AA10-D8CC-4685-A076-368CA64CA7C6}
+ VCMI_BattleAiHost
+
+
+
+ Application
+ true
+ MultiByte
+ false
+
+
+ Application
+ true
+ MultiByte
+
+
+ Application
+ false
+ true
+ MultiByte
+
+
+ Application
+ false
+ true
+ MultiByte
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(SolutionDir)
+ $(Configuration)\
+
+
+ $(SolutionDir)
+ $(Configuration)\
+
+
+ $(SolutionDir)
+ $(Configuration)\
+
+
+ $(SolutionDir)
+ $(Configuration)\
+
+
+
+ Level3
+ Disabled
+
+
+ true
+ $(OutDir);
+ VCMI_lib.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+ Disabled
+
+
+ true
+ 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)
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+
+
+ true
+ true
+ true
+ 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)
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+
+
+ true
+ true
+ true
+ 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)
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/VCMI_BattleAiHost/main.cpp b/VCMI_BattleAiHost/main.cpp
new file mode 100644
index 000000000..a18dbb7f9
--- /dev/null
+++ b/VCMI_BattleAiHost/main.cpp
@@ -0,0 +1,82 @@
+ #include "../global.h"
+ #include "../lib/Connection.h"
+ #include
+ #include
+#include
+#include "../StartInfo.h"
+
+#ifdef _WIN32
+#include
+#else
+#include
+#endif
+#include "../lib/CGameState.h"
+#include "../CCallback.h"
+#include "../lib/CGameInterface.h"
+#include
+
+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(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;
+}
\ No newline at end of file
diff --git a/VCMI_VS10.sln b/VCMI_VS10.sln
index 144c4e012..799575c6f 100644
--- a/VCMI_VS10.sln
+++ b/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
diff --git a/b1.json b/b1.json
new file mode 100644
index 000000000..8646c090c
--- /dev/null
+++ b/b1.json
@@ -0,0 +1,16 @@
+[
+ "terType" : 0,
+ "bfieldType" : 0,
+
+ "sides" :
+ [
+ {
+ "side" : 0,
+ "army" : [[10, 40]]
+ }
+ {
+ "side" : 1,
+ "army" : [[11, 41]]
+ }
+ ]
+]
\ No newline at end of file
diff --git a/lib/CDefObjInfoHandler.cpp b/lib/CDefObjInfoHandler.cpp
index 7a447a6bf..04caee53f 100644
--- a/lib/CDefObjInfoHandler.cpp
+++ b/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))
{
-
- static const char *holeDefs[] = {"AVLHOLD0.DEF", "AVLHLDS0.DEF", "AVLHOLG0.DEF", "AVLHLSN0.DEF",
- "AVLHOLS0.DEF", "AVLHOLR0.DEF", "AVLHOLX0.DEF", "AVLHOLL0.DEF"};
-
- if(i)
+ for (int i = 0; i < 8 ; i++)
{
- gobjs[124][i] = new CGDefInfo(*gobjs[124][0]);
- gobjs[124][i]->name = holeDefs[i];
+
+ 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];
+ }
}
}
+ else
+ {
+ tlog1 << "No def info for holes!\n";
+ }
}
CDefObjInfoHandler::~CDefObjInfoHandler()
diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp
index be2d32320..390313879 100644
--- a/lib/CGameState.cpp
+++ b/lib/CGameState.cpp
@@ -31,6 +31,7 @@
#include "CMapInfo.h"
#include "BattleState.h"
#include "../lib/JsonNode.h"
+#include
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);
diff --git a/lib/CGameState.h b/lib/CGameState.h
index 457e8b895..c700d5276 100644
--- a/lib/CGameState.h
+++ b/lib/CGameState.h
@@ -305,6 +305,8 @@ struct DLL_EXPORT DuelParameters
}
} sides[2];
+ static DuelParameters fromJSON(const std::string &fname);
+
DuelParameters();
template void serialize(Handler &h, const int version)
{
diff --git a/lib/CLodHandler.cpp b/lib/CLodHandler.cpp
index 64a363d25..5e5c1519e 100644
--- a/lib/CLodHandler.cpp
+++ b/lib/CLodHandler.cpp
@@ -271,38 +271,40 @@ void CLodHandler::init(const std::string lodFile, const std::string dirName)
if (!LOD.is_open())
{
tlog1 << "Cannot open " << lodFile << std::endl;
- return;
}
-
- Uint32 temp;
- LOD.seekg(8);
- LOD.read((char *)&temp, 4);
- totalFiles = SDL_SwapLE32(temp);
-
- LOD.seekg(0x5c, std::ios::beg);
- if(!LOD)
+ else
{
- tlog2 << lodFile << " doesn't store anything!\n";
- return;
+
+ 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;
+ }
+
+ struct LodEntry *lodEntries = new struct LodEntry[totalFiles];
+ LOD.read((char *)lodEntries, sizeof(struct LodEntry) * totalFiles);
+
+ for (unsigned int i=0; imap->objects, &CGObjectInstance::id);
registerVectoredType(&lib->heroh->heroes, &CHero::ID);
registerVectoredType(&lib->creh->creatures, &CCreature::idNumber);
diff --git a/lib/JsonNode.cpp b/lib/JsonNode.cpp
index 5815fa6e6..a6c2114e6 100644
--- a/lib/JsonNode.cpp
+++ b/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!");
diff --git a/lib/JsonNode.h b/lib/JsonNode.h
index c54e54c35..f14c2f26e 100644
--- a/lib/JsonNode.h
+++ b/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;
diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp
index e2fbbb010..1d548d572 100644
--- a/server/CGameHandler.cpp
+++ b/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)
diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp
index da96fb31f..00f50ce5f 100644
--- a/server/CVCMIServer.cpp
+++ b/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();
diff --git a/server/CVCMIServer.h b/server/CVCMIServer.h
index 642b00a91..59e1f2a45 100644
--- a/server/CVCMIServer.h
+++ b/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();
diff --git a/server/Makefile.am b/server/Makefile.am
index f593da912..7648f9531 100644
--- a/server/Makefile.am
+++ b/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
diff --git a/server/VCMI_server.vcxproj b/server/VCMI_server.vcxproj
index 1a75b0046..a4dcb99e1 100644
--- a/server/VCMI_server.vcxproj
+++ b/server/VCMI_server.vcxproj
@@ -35,7 +35,7 @@
Application
- Unicode
+ MultiByte
Application