2008-07-01 11:01:02 +03:00
|
|
|
#pragma once
|
2008-07-25 20:28:28 +03:00
|
|
|
#include "../global.h"
|
|
|
|
#include <set>
|
2008-08-04 12:05:52 +03:00
|
|
|
#include "../CGameState.h"
|
|
|
|
#include "../lib/Connection.h"
|
2008-08-05 02:04:15 +03:00
|
|
|
#ifndef _MSC_VER
|
2008-08-04 23:27:47 +03:00
|
|
|
#include <boost/thread.hpp>
|
2008-08-05 02:04:15 +03:00
|
|
|
#endif
|
2008-07-25 20:28:28 +03:00
|
|
|
class CVCMIServer;
|
|
|
|
class CGameState;
|
2008-08-04 12:05:52 +03:00
|
|
|
//class CConnection;
|
2008-07-25 20:28:28 +03:00
|
|
|
struct StartInfo;
|
2008-07-30 20:51:19 +03:00
|
|
|
class CCPPObjectScript;
|
|
|
|
class CScriptCallback;
|
2008-07-26 16:57:32 +03:00
|
|
|
template <typename T> struct CPack;
|
2008-08-04 18:56:36 +03:00
|
|
|
class CGHeroInstance;
|
2008-07-01 11:01:02 +03:00
|
|
|
class CGameHandler
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
|
2008-07-25 20:28:28 +03:00
|
|
|
CGameState *gs;
|
2008-07-30 20:51:19 +03:00
|
|
|
std::set<CCPPObjectScript *> cppscripts; //C++ scripts
|
|
|
|
//std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
|
|
|
|
|
2008-07-25 20:28:28 +03:00
|
|
|
CVCMIServer *s;
|
2008-08-04 18:56:36 +03:00
|
|
|
std::map<int,CConnection*> connections; //player color -> connection to clinet with interface of that player
|
|
|
|
std::map<int,int> states; //player color -> player state
|
2008-07-25 20:28:28 +03:00
|
|
|
std::set<CConnection*> conns;
|
2008-07-30 20:51:19 +03:00
|
|
|
|
|
|
|
void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
|
2008-08-04 18:56:36 +03:00
|
|
|
void changePrimSkill(int ID, int which, int val, bool abs=false);
|
|
|
|
void startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2); //use hero=NULL for no hero
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
|
2008-07-01 11:01:02 +03:00
|
|
|
public:
|
|
|
|
CGameHandler(void);
|
|
|
|
~CGameHandler(void);
|
2008-07-25 20:28:28 +03:00
|
|
|
void init(StartInfo *si, int Seed);
|
|
|
|
void handleConnection(std::set<int> players, CConnection &c);
|
2008-07-30 20:51:19 +03:00
|
|
|
template <typename T>void sendToAllClients(CPack<T> * info)
|
|
|
|
{
|
|
|
|
for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
|
|
|
|
{
|
2008-08-04 18:56:36 +03:00
|
|
|
(*i)->wmx->lock();
|
2008-07-30 20:51:19 +03:00
|
|
|
**i << info->getType() << *info->This();
|
2008-08-04 18:56:36 +03:00
|
|
|
(*i)->wmx->unlock();
|
2008-07-30 20:51:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
template <typename T>void sendAndApply(CPack<T> * info)
|
|
|
|
{
|
|
|
|
gs->apply(info);
|
|
|
|
sendToAllClients(info);
|
|
|
|
}
|
2008-07-25 20:28:28 +03:00
|
|
|
void run();
|
|
|
|
void newTurn();
|
|
|
|
|
|
|
|
friend class CVCMIServer;
|
2008-07-30 20:51:19 +03:00
|
|
|
friend class CScriptCallback;
|
2008-07-01 11:01:02 +03:00
|
|
|
};
|