| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- #define VCMI_DLL
- #include "CBattleCallback.h"
- #include "NetPacks.h"
- #include "Connection.h"
- #include "CGameState.h"
- #include <boost/thread/shared_mutex.hpp>
- #include "BattleState.h"
- CBattleCallback::CBattleCallback(CGameState *GS, int Player, IConnectionHandler *C )
- {
- gs = GS;
- player = Player;
- connHandler = C;
- }
- bool CBattleCallback::battleMakeTacticAction( BattleAction * action )
- {
- assert(gs->curB->tacticDistance);
- MakeAction ma;
- ma.ba = *action;
- sendRequest(&ma);
- return true;
- }
- int CBattleCallback::battleMakeAction(BattleAction* action)
- {
- assert(action->actionType == BattleAction::HERO_SPELL);
- MakeCustomAction mca(*action);
- sendRequest(&mca);
- return 0;
- }
- void CBattleCallback::sendRequest(const CPack* request)
- {
- //TODO should be part of CClient (client owns connection, not CB)
- //but it would have to be very tricky cause template/serialization issues
- if(waitTillRealize)
- connHandler->waitingRequest.set(typeList.getTypeID(request));
- connHandler->serv->sendPack(*request);
- if(waitTillRealize)
- {
- if(unlockGsWhenWaiting)
- gs->mx->unlock_shared();
- connHandler->waitingRequest.waitWhileTrue();
- if(unlockGsWhenWaiting)
- gs->mx->lock_shared();
- }
- }
- IConnectionHandler::IConnectionHandler()
- : waitingRequest(0)
- {
- }
- IConnectionHandler::~IConnectionHandler()
- {
- }
|