|
@@ -9,8 +9,8 @@
|
|
|
#include "../hch/CTownHandler.h"
|
|
#include "../hch/CTownHandler.h"
|
|
|
#include "../CGameState.h"
|
|
#include "../CGameState.h"
|
|
|
#include "../lib/CondSh.h"
|
|
#include "../lib/CondSh.h"
|
|
|
-#include "../lib/Connection.h"
|
|
|
|
|
#include "../lib/NetPacks.h"
|
|
#include "../lib/NetPacks.h"
|
|
|
|
|
+#include "../lib/Connection.h"
|
|
|
#include "../lib/VCMI_Lib.h"
|
|
#include "../lib/VCMI_Lib.h"
|
|
|
#include "../map.h"
|
|
#include "../map.h"
|
|
|
#include "CGameHandler.h"
|
|
#include "CGameHandler.h"
|
|
@@ -24,7 +24,6 @@
|
|
|
#include <boost/thread/xtime.hpp>
|
|
#include <boost/thread/xtime.hpp>
|
|
|
#endif
|
|
#endif
|
|
|
extern bool end2;
|
|
extern bool end2;
|
|
|
-#include "../lib/BattleAction.h"
|
|
|
|
|
#ifdef min
|
|
#ifdef min
|
|
|
#undef min
|
|
#undef min
|
|
|
#endif
|
|
#endif
|
|
@@ -343,7 +342,7 @@ void CGameHandler::startBattle(CCreatureSet army1, CCreatureSet army2, int3 tile
|
|
|
ba.side = !next->attackerOwned;
|
|
ba.side = !next->attackerOwned;
|
|
|
ba.stackNumber = next->ID;
|
|
ba.stackNumber = next->ID;
|
|
|
sendAndApply(&StartAction(ba));
|
|
sendAndApply(&StartAction(ba));
|
|
|
- sendDataToClients(ui16(3008));
|
|
|
|
|
|
|
+ sendAndApply(&EndAction());
|
|
|
checkForBattleEnd(stacks); //check if this "action" ended the battle (not likely but who knows...)
|
|
checkForBattleEnd(stacks); //check if this "action" ended the battle (not likely but who knows...)
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -988,9 +987,7 @@ upgend:
|
|
|
std::string message;
|
|
std::string message;
|
|
|
c >> message;
|
|
c >> message;
|
|
|
bool cheated=true;
|
|
bool cheated=true;
|
|
|
- sendDataToClients(ui16(513));
|
|
|
|
|
- sendDataToClients(ui8(*players.begin()));
|
|
|
|
|
- sendDataToClients(message);
|
|
|
|
|
|
|
+ sendAndApply(&PlayerMessage(*players.begin(),message));
|
|
|
if(message == "vcmiistari") //give all spells and 999 mana
|
|
if(message == "vcmiistari") //give all spells and 999 mana
|
|
|
{
|
|
{
|
|
|
SetMana sm;
|
|
SetMana sm;
|
|
@@ -1084,9 +1081,7 @@ upgend:
|
|
|
if(cheated)
|
|
if(cheated)
|
|
|
{
|
|
{
|
|
|
message = "CHEATER!!!";
|
|
message = "CHEATER!!!";
|
|
|
- sendDataToClients(ui16(513));
|
|
|
|
|
- sendDataToClients(ui8(*players.begin()));
|
|
|
|
|
- sendDataToClients(message);
|
|
|
|
|
|
|
+ sendAndApply(&PlayerMessage(*players.begin(),message));
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -1154,14 +1149,14 @@ upgend:
|
|
|
{
|
|
{
|
|
|
sendAndApply(&StartAction(ba)); //start movement
|
|
sendAndApply(&StartAction(ba)); //start movement
|
|
|
moveStack(ba.stackNumber,ba.destinationTile); //move
|
|
moveStack(ba.stackNumber,ba.destinationTile); //move
|
|
|
- sendDataToClients(ui16(3008)); //end movement
|
|
|
|
|
|
|
+ sendAndApply(&EndAction());
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
case 3: //defend
|
|
case 3: //defend
|
|
|
case 8: //wait
|
|
case 8: //wait
|
|
|
{
|
|
{
|
|
|
sendAndApply(&StartAction(ba));
|
|
sendAndApply(&StartAction(ba));
|
|
|
- sendDataToClients(ui16(3008));
|
|
|
|
|
|
|
+ sendAndApply(&EndAction());
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
case 4: //retreat/flee
|
|
case 4: //retreat/flee
|
|
@@ -1211,7 +1206,7 @@ upgend:
|
|
|
)
|
|
)
|
|
|
{
|
|
{
|
|
|
tlog3 << "Attack cannot be performed!";
|
|
tlog3 << "Attack cannot be performed!";
|
|
|
- sendDataToClients(ui16(3008)); //end movement and attack
|
|
|
|
|
|
|
+ sendAndApply(&EndAction());
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1240,7 +1235,7 @@ upgend:
|
|
|
prepareAttack(bat,curStack,stackAtEnd);
|
|
prepareAttack(bat,curStack,stackAtEnd);
|
|
|
sendAndApply(&bat);
|
|
sendAndApply(&bat);
|
|
|
}
|
|
}
|
|
|
- sendDataToClients(ui16(3008)); //end movement and attack
|
|
|
|
|
|
|
+ sendAndApply(&EndAction());
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
case 7: //shoot
|
|
case 7: //shoot
|
|
@@ -1277,7 +1272,7 @@ upgend:
|
|
|
sendAndApply(&bat);
|
|
sendAndApply(&bat);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- sendDataToClients(ui16(3008)); //end shooting
|
|
|
|
|
|
|
+ sendAndApply(&EndAction());
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1519,7 +1514,7 @@ upgend:
|
|
|
- Weakness
|
|
- Weakness
|
|
|
- Death Ripple */
|
|
- Death Ripple */
|
|
|
|
|
|
|
|
- sendDataToClients(ui16(3008)); //end casting
|
|
|
|
|
|
|
+ sendAndApply(&EndAction());
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1808,7 +1803,11 @@ void CGameHandler::run(bool resume)
|
|
|
if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0 || i->first>=PLAYER_LIMIT ) continue; //players has not towns/castle - loser
|
|
if((i->second.towns.size()==0 && i->second.heroes.size()==0) || i->second.color<0 || i->first>=PLAYER_LIMIT ) continue; //players has not towns/castle - loser
|
|
|
states.setFlag(i->first,&PlayerStatus::makingTurn,true);
|
|
states.setFlag(i->first,&PlayerStatus::makingTurn,true);
|
|
|
gs->currentPlayer = i->first;
|
|
gs->currentPlayer = i->first;
|
|
|
- *connections[i->first] << ui16(100) << i->first;
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ YourTurn yt;
|
|
|
|
|
+ yt.player = i->first;
|
|
|
|
|
+ *connections[i->first] << &yt;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
//wait till turn is done
|
|
//wait till turn is done
|
|
|
boost::unique_lock<boost::mutex> lock(states.mx);
|
|
boost::unique_lock<boost::mutex> lock(states.mx);
|
|
@@ -2289,9 +2288,11 @@ void CGameHandler::setObjProperty( int objid, int prop, int val )
|
|
|
sendAndApply(&sob);
|
|
sendAndApply(&sob);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void CGameHandler::sendMessageTo( CConnection &c, std::string message )
|
|
|
|
|
|
|
+void CGameHandler::sendMessageTo( CConnection &c, const std::string &message )
|
|
|
{
|
|
{
|
|
|
- c << ui16(95) << message;
|
|
|
|
|
|
|
+ SystemMessage sm;
|
|
|
|
|
+ sm.text = message;
|
|
|
|
|
+ c << &sm;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void CGameHandler::giveHeroBonus( GiveBonus * bonus )
|
|
void CGameHandler::giveHeroBonus( GiveBonus * bonus )
|
|
@@ -2349,4 +2350,20 @@ void CGameHandler::ask( Query * sel, ui8 player, const CFunctionList<void(ui32)>
|
|
|
sendToAllClients(sel);
|
|
sendToAllClients(sel);
|
|
|
QID++;
|
|
QID++;
|
|
|
gsm.unlock();
|
|
gsm.unlock();
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void CGameHandler::sendToAllClients( CPack * info )
|
|
|
|
|
+{
|
|
|
|
|
+ for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ (*i)->wmx->lock();
|
|
|
|
|
+ **i << info;
|
|
|
|
|
+ (*i)->wmx->unlock();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void CGameHandler::sendAndApply( CPack * info )
|
|
|
|
|
+{
|
|
|
|
|
+ gs->apply(info);
|
|
|
|
|
+ sendToAllClients(info);
|
|
|
}
|
|
}
|