1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-05 00:49:09 +02:00

Logging battle activites. Replaying battles with client.

Added an AI for answer validation (it returns junk action packets).
Minor fixes.
This commit is contained in:
Michał W. Urbańczyk
2011-10-06 20:55:19 +00:00
parent 1fc34d8a0b
commit 94e7fa5b3c
13 changed files with 408 additions and 46 deletions

View File

@ -471,6 +471,10 @@ void CGameHandler::endBattle(int3 tile, const CGHeroInstance *hero1, const CGHer
casualtiesPoints = c->AIValue * i->second;
}
tlog0 << boost::format("Total casualties points: %d\n") % casualtiesPoints;
//battle ai1 ai2 winner_side winner_casualties
std::ofstream resultsList("results.txt", std::fstream::out | std::fstream::app);
resultsList << boost::format("\n%s\t%s\t%s\t%d\t%d") % gs->scenarioOps->mapname % ais[0] % ais[1] % (int)battleResult.data->winner % casualtiesPoints;
}
sendAndApply(&resultsApplied);
@ -640,6 +644,7 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
while(1)//server should never shut connection first //was: while(!end2)
{
pack = c.retreivePack();
receivedPack(c.connectionID, pack);
int packType = typeList.getTypeID(pack); //get the id of type
if(packType == typeList.getTypeID<CloseServer>())
{
@ -1929,6 +1934,7 @@ void CGameHandler::ask( Query * sel, ui8 player, const CFunctionList<void(ui32)>
void CGameHandler::sendToAllClients( CPackForClient * info )
{
broadcastedPack(info);
tlog5 << "Sending to all clients a package of type " << typeid(*info).name() << std::endl;
for(std::set<CConnection*>::iterator i=conns.begin(); i!=conns.end();i++)
{
@ -5247,6 +5253,25 @@ void CGameHandler::spawnWanderingMonsters(int creatureID)
}
}
static boost::mutex logMx;
void CGameHandler::receivedPack(ui8 connectionNr, CPack *pack)
{
if(gameLog)
{
boost::unique_lock<boost::mutex> lock(logMx);
*gameLog << connectionNr << pack << ui8('*');
}
}
void CGameHandler::broadcastedPack(CPack *pack)
{
if(gameLog)
{
boost::unique_lock<boost::mutex> lock(logMx);
*gameLog << ui8(255) << pack << ui8('*');
}
}
CasualtiesAfterBattle::CasualtiesAfterBattle(const CArmedInstance *army, BattleInfo *bat)
{
int color = army->tempOwner;