1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-05 13:04:54 +02:00

[programming challenge] Don't dramatically crash upon illegal tatics movement.

This commit is contained in:
Michał W. Urbańczyk 2011-12-28 01:37:29 +00:00
parent 7b081de638
commit 2691fd62f4
2 changed files with 11 additions and 1 deletions

View File

@ -16,6 +16,16 @@ CBattleCallback::CBattleCallback(CGameState *GS, int Player, IConnectionHandler
bool CBattleCallback::battleMakeTacticAction( BattleAction * action )
{
assert(gs->curB->tacticDistance);
if(action->actionType == BattleAction::WALK)
{
if(!gs->curB->isInTacticRange(action->destinationTile))
{
tlog0 << "Requesting movement to tile that is not in tactics range? Illegal!\n";
if(!action->destinationTile.isValid())
tlog0 << "Moreover the hex is invalid!!!\n";
return false;
}
}
MakeAction ma;
ma.ba = *action;
sendRequest(&ma);

View File

@ -643,7 +643,7 @@ void CVCMIServer::startDuel(const std::string &battle, const std::string &leftAI
testMem.set(true);
boost::thread* memMon = new boost::thread(boost::bind(memoryMonitor, PIDs[0], PIDs[1], PIDs[2]));
std::string logFName = LOGS_DIR + "/duel_log.vdat";
std::string logFName = LOGS_DIR + "/" + leftAI + "_vs_"+rightAI+"_on_" + battle + ".vdat";
tlog0 << "Logging battle activities (for replay possibility) in " << logFName << std::endl;
gh->gameLog = new CSaveFile(logFName);
gh->gameLog->smartPointerSerialization = false;