1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

* added files for future server

* make code compiling
* broken objects scripts
This commit is contained in:
Michał W. Urbańczyk
2008-07-01 08:01:02 +00:00
parent ea8562a6b1
commit b0002ff50b
22 changed files with 403 additions and 114 deletions

View File

@ -1,9 +1,9 @@
#include "CAdvmapInterface.h"
#include "SDL_Extensions.h"
#include "hch\CDefHandler.h"
#include "hch/CDefHandler.h"
#include "CGameInfo.h"
#include "hch\CLodHandler.h"
#include "hch\CPreGameTextHandler.h"
#include "hch/CLodHandler.h"
#include "hch/CPreGameTextHandler.h"
#include "hch/CTownHandler.h"
#include "CLua.h"
#include "CCallback.h"

View File

@ -2,9 +2,9 @@
#include "CAdvmapInterface.h"
#include "client/CBitmapHandler.h"
#include "CPlayerInterface.h"
#include "hch\CPreGameTextHandler.h"
#include "hch\CGeneralTextHandler.h"
#include "hch\CTownHandler.h"
#include "hch/CPreGameTextHandler.h"
#include "hch/CGeneralTextHandler.h"
#include "hch/CTownHandler.h"
#include "CPathfinder.h"
#include "CGameInfo.h"
#include "SDL_Extensions.h"

View File

@ -1,14 +1,14 @@
#include "CBattleInterface.h"
#include "CGameInfo.h"
#include "hch\CLodHandler.h"
#include "hch/CLodHandler.h"
#include "SDL_Extensions.h"
#include "CAdvmapInterface.h"
#include "AdventureMapButton.h"
#include "hch\CHeroHandler.h"
#include "hch\CDefHandler.h"
#include "hch/CHeroHandler.h"
#include "hch/CDefHandler.h"
#include "CCallback.h"
#include "CGameState.h"
#include "hch\CGeneralTextHandler.h"
#include "hch/CGeneralTextHandler.h"
#include "client/CCreatureAnimation.h"
#include "client/Graphics.h"
#include <queue>

View File

@ -1,10 +1,10 @@
#include "stdafx.h"
#include "CCallback.h"
#include "CPathfinder.h"
#include "hch\CHeroHandler.h"
#include "hch\CTownHandler.h"
#include "hch/CHeroHandler.h"
#include "hch/CTownHandler.h"
#include "CGameInfo.h"
#include "hch\CAmbarCendamo.h"
#include "hch/CAmbarCendamo.h"
#include "mapHandler.h"
#include "CGameState.h"
#include "CPlayerInterface.h"

View File

@ -4,7 +4,7 @@
#include "SDL_thread.h"
#include "CGameInfo.h"
#include "SDL_framerate.h"
#include "hch\CLodHandler.h"
#include "hch/CLodHandler.h"
extern SDL_Surface * screen;

View File

@ -472,66 +472,66 @@ void CGameState::init(StartInfo * si, Mapa * map, int seed)
}
}
/****************************SCRIPTS************************************************/
std::map<int, std::map<std::string, CObjectScript*> > * skrypty = &objscr; //alias for easier access
/****************************C++ OBJECT SCRIPTS************************************************/
std::map<int,CCPPObjectScript*> scripts;
CScriptCallback * csc = new CScriptCallback();
csc->gs = this;
handleCPPObjS(&scripts,new CVisitableOPH(csc));
handleCPPObjS(&scripts,new CVisitableOPW(csc));
handleCPPObjS(&scripts,new CPickable(csc));
handleCPPObjS(&scripts,new CMines(csc));
handleCPPObjS(&scripts,new CTownScript(csc));
handleCPPObjS(&scripts,new CHeroScript(csc));
handleCPPObjS(&scripts,new CMonsterS(csc));
handleCPPObjS(&scripts,new CCreatureGen(csc));
//created map
///****************************SCRIPTS************************************************/
//std::map<int, std::map<std::string, CObjectScript*> > * skrypty = &objscr; //alias for easier access
///****************************C++ OBJECT SCRIPTS************************************************/
//std::map<int,CCPPObjectScript*> scripts;
//CScriptCallback * csc = new CScriptCallback();
//csc->gs = this;
//handleCPPObjS(&scripts,new CVisitableOPH(csc));
//handleCPPObjS(&scripts,new CVisitableOPW(csc));
//handleCPPObjS(&scripts,new CPickable(csc));
//handleCPPObjS(&scripts,new CMines(csc));
//handleCPPObjS(&scripts,new CTownScript(csc));
//handleCPPObjS(&scripts,new CHeroScript(csc));
//handleCPPObjS(&scripts,new CMonsterS(csc));
//handleCPPObjS(&scripts,new CCreatureGen(csc));
////created map
/****************************LUA OBJECT SCRIPTS************************************************/
std::vector<std::string> * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files
for (int i=0; i<lf->size(); i++)
{
try
{
std::vector<std::string> * temp = CLuaHandler::functionList((*lf)[i]);
CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]);
CLuaCallback::registerFuncs(objs->is);
//objs
for (int j=0; j<temp->size(); j++)
{
int obid ; //obj ID
int dspos = (*temp)[j].find_first_of('_');
obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str());
std::string fname = (*temp)[j].substr(0,dspos);
if (skrypty->find(obid)==skrypty->end())
skrypty->insert(std::pair<int, std::map<std::string, CObjectScript*> >(obid,std::map<std::string,CObjectScript*>()));
(*skrypty)[obid].insert(std::pair<std::string, CObjectScript*>(fname,objs));
}
delete temp;
}HANDLE_EXCEPTION
}
/****************************INITIALIZING OBJECT SCRIPTS************************************************/
std::string temps("newObject");
for (int i=0; i<map->objects.size(); i++)
{
//c++ scripts
if (scripts.find(map->objects[i]->ID) != scripts.end())
{
map->objects[i]->state = scripts[map->objects[i]->ID];
map->objects[i]->state->newObject(map->objects[i]);
}
else
{
map->objects[i]->state = NULL;
}
///****************************LUA OBJECT SCRIPTS************************************************/
//std::vector<std::string> * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files
//for (int i=0; i<lf->size(); i++)
//{
// try
// {
// std::vector<std::string> * temp = CLuaHandler::functionList((*lf)[i]);
// CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]);
// CLuaCallback::registerFuncs(objs->is);
// //objs
// for (int j=0; j<temp->size(); j++)
// {
// int obid ; //obj ID
// int dspos = (*temp)[j].find_first_of('_');
// obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str());
// std::string fname = (*temp)[j].substr(0,dspos);
// if (skrypty->find(obid)==skrypty->end())
// skrypty->insert(std::pair<int, std::map<std::string, CObjectScript*> >(obid,std::map<std::string,CObjectScript*>()));
// (*skrypty)[obid].insert(std::pair<std::string, CObjectScript*>(fname,objs));
// }
// delete temp;
// }HANDLE_EXCEPTION
//}
///****************************INITIALIZING OBJECT SCRIPTS************************************************/
//std::string temps("newObject");
//for (int i=0; i<map->objects.size(); i++)
//{
// //c++ scripts
// if (scripts.find(map->objects[i]->ID) != scripts.end())
// {
// map->objects[i]->state = scripts[map->objects[i]->ID];
// map->objects[i]->state->newObject(map->objects[i]);
// }
// else
// {
// map->objects[i]->state = NULL;
// }
// lua scripts
if(checkFunc(map->objects[i]->ID,temps))
(*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
}
// // lua scripts
// if(checkFunc(map->objects[i]->ID,temps))
// (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
//}
delete lf;
//delete lf;
}
void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2)
{/*

View File

@ -2,18 +2,18 @@
#include "global.h"
#include "CHeroWindow.h"
#include "CGameInfo.h"
#include "hch\CHeroHandler.h"
#include "hch\CGeneralTextHandler.h"
#include "hch/CHeroHandler.h"
#include "hch/CGeneralTextHandler.h"
#include "SDL.h"
#include "SDL_Extensions.h"
#include "CAdvmapInterface.h"
#include "hch\CLodHandler.h"
#include "hch/CLodHandler.h"
#include "AdventureMapButton.h"
#include "hch\CObjectHandler.h"
#include "hch/CObjectHandler.h"
#include "CMessage.h"
#include "CCallback.h"
#include "hch/CArtHandler.h"
#include "hch\CAbilityHandler.h"
#include "hch/CAbilityHandler.h"
#include <sstream>
#include "client/Graphics.h"
extern SDL_Surface * screen;

39
CMT.cpp
View File

@ -3,9 +3,9 @@
#include "stdafx.h"
#include "SDL.h"
#include "SDL_TTF.h"
#include "hch\CVideoHandler.h"
#include "hch/CVideoHandler.h"
#include "SDL_mixer.h"
#include "hch\CBuildingHandler.h"
#include "hch/CBuildingHandler.h"
#include "SDL_Extensions.h"
#include "SDL_framerate.h"
#include <cmath>
@ -13,24 +13,24 @@
#include <vector>
#include "zlib.h"
#include <cmath>
#include "hch\CArtHandler.h"
#include "hch\CHeroHandler.h"
#include "hch\CCreatureHandler.h"
#include "hch\CAbilityHandler.h"
#include "hch\CSpellHandler.h"
#include "hch\CBuildingHandler.h"
#include "hch\CObjectHandler.h"
#include "hch/CArtHandler.h"
#include "hch/CHeroHandler.h"
#include "hch/CCreatureHandler.h"
#include "hch/CAbilityHandler.h"
#include "hch/CSpellHandler.h"
#include "hch/CBuildingHandler.h"
#include "hch/CObjectHandler.h"
#include "CGameInfo.h"
#include "hch\CMusicHandler.h"
#include "hch\CLodHandler.h"
#include "hch\CDefHandler.h"
#include "hch\CTownHandler.h"
#include "hch\CDefObjInfoHandler.h"
#include "hch\CAmbarCendamo.h"
#include "hch/CMusicHandler.h"
#include "hch/CLodHandler.h"
#include "hch/CDefHandler.h"
#include "hch/CTownHandler.h"
#include "hch/CDefObjInfoHandler.h"
#include "hch/CAmbarCendamo.h"
#include "mapHandler.h"
#include "global.h"
#include "CPreGame.h"
#include "hch\CGeneralTextHandler.h"
#include "hch/CGeneralTextHandler.h"
#include "CConsoleHandler.h"
#include "CCursorHandler.h"
#include "CScreenHandler.h"
@ -41,8 +41,9 @@
#include "CLuaHandler.h"
#include "CLua.h"
#include "CAdvmapInterface.h"
#include "client\Graphics.h"
#include "client/Graphics.h"
#include <boost/asio.hpp>
#include <boost/thread.hpp>
std::string NAME = NAME_VER + std::string(" (client)");
DLL_EXPORT void initDLL(CLodHandler *b);
using boost::asio::ip::tcp;
@ -59,7 +60,9 @@ void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * sc
CGI->state->cppscripts.insert(script);
}
int _tmain(int argc, _TCHAR* argv[])
{ /*
{
boost::thread servthr(boost::bind(system,"Debug\\VCMI_server.exe"));
/*
boost::asio::io_service io_service;
boost::system::error_code error = boost::asio::error::host_not_found;
tcp::socket socket(io_service);

View File

@ -1,14 +1,14 @@
#include "stdafx.h"
#include "CMessage.h"
#include "SDL_TTF.h"
#include "hch\CDefHandler.h"
#include "hch/CDefHandler.h"
#include "CGameInfo.h"
#include "SDL_Extensions.h"
#include "hch\CLodHandler.h"
#include "hch/CLodHandler.h"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
#include "CPlayerInterface.h"
#include "hch\CDefHandler.h"
#include "hch/CDefHandler.h"
#include "CGameInfo.h"
#include "SDL_Extensions.h"
#include <sstream>

View File

@ -2,7 +2,7 @@
#include "global.h"
#include "CPathfinder.h"
#include "CGameInfo.h"
#include "hch\CAmbarCendamo.h"
#include "hch/CAmbarCendamo.h"
#include "mapHandler.h"
#include "CGameState.h"

View File

@ -22,7 +22,7 @@
#include "timeHandler.h"
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/replace.hpp>
#include "hch\CPreGameTextHandler.h"
#include "hch/CPreGameTextHandler.h"
#include "CBattleInterface.h"
#include "CLua.h"
#include <cmath>

Binary file not shown.

View File

@ -4,10 +4,10 @@
#include <set>
#include "SDL.h"
#include "StartInfo.h"
#include "hch\CPreGameTextHandler.h"
#include "hch/CPreGameTextHandler.h"
#include "CMessage.h"
#include "map.h"
#include "hch\CMusicHandler.h"
#include "hch/CMusicHandler.h"
class CPreGame;
extern CPreGame * CPG;

View File

@ -6,7 +6,7 @@
#include "SDL_Extensions.h"
#include "CCursorHandler.h"
#include "CGameInfo.h"
#include "hch\CDefHandler.h"
#include "hch/CDefHandler.h"
extern SDL_Surface * screen, * screen2;

View File

@ -7,7 +7,7 @@
#include <algorithm>
#include "CMessage.h"
#include <boost/algorithm/string.hpp>
#include "hch\CDefHandler.h"
#include "hch/CDefHandler.h"
#include <map>
#include "client\Graphics.h"

View File

@ -603,10 +603,6 @@
RelativePath="..\CHeroWindow.h"
>
</File>
<File
RelativePath="..\CLua.h"
>
</File>
<File
RelativePath="..\CLuaHandler.h"
>

View File

@ -3,13 +3,13 @@
#include "SDL_Extensions.h"
#include "CGameInfo.h"
#include <cstdlib>
#include "hch\CLodHandler.h"
#include "hch\CDefObjInfoHandler.h"
#include "hch/CLodHandler.h"
#include "hch/CDefObjInfoHandler.h"
#include <algorithm>
#include "CGameState.h"
#include "CLua.h"
#include "hch\CHeroHandler.h"
#include "hch\CTownHandler.h"
#include "hch/CHeroHandler.h"
#include "hch/CTownHandler.h"
#include "client\Graphics.h"
#include <iomanip>
#include <sstream>

View File

@ -1,11 +1,11 @@
#ifndef MAPHANDLER_H
#define MAPHANDLER_H
#include "hch\CAmbarCendamo.h"
#include "hch/CAmbarCendamo.h"
#include "CGameInfo.h"
#include "hch\CDefHandler.h"
#include "hch/CDefHandler.h"
#include <boost/logic/tribool.hpp>
#include "hch\CObjectHandler.h"
#include "hch/CObjectHandler.h"
#include <list>
const int Woff = 12; //width of map's frame
const int Hoff = 8;

9
server/CGameHandler.cpp Normal file
View File

@ -0,0 +1,9 @@
#include "CGameHandler.h"
CGameHandler::CGameHandler(void)
{
}
CGameHandler::~CGameHandler(void)
{
}

8
server/CGameHandler.h Normal file
View File

@ -0,0 +1,8 @@
#pragma once
class CGameHandler
{
public:
CGameHandler(void);
~CGameHandler(void);
};

192
server/VCMI_server.vcproj Normal file
View File

@ -0,0 +1,192 @@
<?xml version="1.0" encoding="windows-1250"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="VCMI_server"
ProjectGUID="{8AF697C3-465E-4910-B31B-576A9ECDB309}"
RootNamespace="VCMI_server"
TargetFrameworkVersion="196613"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
WarningLevel="3"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="2"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
WarningLevel="3"
DebugInformationFormat="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
GenerateDebugInformation="true"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<Filter
Name="Source Files"
Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
RelativePath=".\CGameHandler.cpp"
>
</File>
<File
RelativePath=".\server_main.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\CGameHandler.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
</Filter>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

81
server/server_main.cpp Normal file
View File

@ -0,0 +1,81 @@
#include <iostream>
#include <string>
#include <boost/bind.hpp>
#include <boost/asio.hpp>
#include "../global.h"
std::string NAME = NAME_VER + std::string(" (server)");
//using boost::asio::ip::tcp;
//using namespace boost;
//using namespace boost::asio;
//
//class CConnection
//{
//public:
// int ID;
// tcp::socket socket;
// void witaj()
// {
// char message[50]; strcpy_s(message,50,NAME.c_str());message[NAME.size()]='\n';
// write(socket,buffer("Aiya!\n"));
// write(socket,buffer(message,NAME.size()+1));
// }
// CConnection(io_service& io_service, int id=-1)
// : socket(io_service), ID(id)
// {
// }
//};
//
//class CVCMIServer
//{
// tcp::acceptor acceptor;
// std::vector<CConnection*> connections;
//public:
// CVCMIServer(io_service& io_service)
// : acceptor(io_service, tcp::endpoint(tcp::v4(), 3030))
// {
// start_accept();
// }
//
//private:
// void start_accept()
// {
// std::cout<<"Listening for connections at port " << acceptor.local_endpoint().port() << std::endl;
// CConnection * new_connection = new CConnection(acceptor.io_service());
// acceptor.accept(new_connection->socket);
// new_connection->witaj();
// acceptor.async_accept(new_connection->socket,
// boost::bind(&CVCMIServer::gotConnection, this, new_connection,
// placeholders::error));
// }
//
// void gotConnection(CConnection * connection,const system::error_code& error)
// {
// if (!error)
// {
// std::cout<<"Got connection!" << std::endl;
// connection->witaj();
// start_accept();
// }
// else
// {
// std::cout<<"Got connection but there is an error " << std::endl;
// }
// }
//
//};
//
int main()
{
// try
// {
// io_service io_service;
// CVCMIServer server(io_service);
// io_service.run();
// }
// catch (std::exception& e)
// {
// std::cerr << e.what() << std::endl;
// }
//
return 0;
}