/** @file /ai/PathFind/pathfind.cpp @brief Zdrojovy kod CPathFind pro specificke vyhledavani cesty. Zdrojovy kod obsahujici metody tridy CPathFind pro realizaci specifickeho vyhledavani cesty modulu vyhledavani cesty. @author PZ @version 0.1 */ #include "ai/PathFind/pathfind.h" namespace ai_ns { namespace pathfind_ns { CPathFindEngine::CPathFindEngine() { hex_order=true; mm=0; mmff=0; } CPathFindEngine::~CPathFindEngine() { if (mm) { KMemFree(mm); mm=0; } if (mmff) { KMemFree(mmff); mmff=0; } } void CPathFindEngine::initMapInfo() throw (E_8K_AI_Pathfind_WrongMessageResponse) { TPacket_RET_MAP* msg_result=(TPacket_RET_MAP*) KSendGlobalMessage(MSG_GET_MAP,MOD_PATHFIND,MOD_WORLD_SERVER,0); if (msg_result == NULL) { THROW(E_8K_AI_Pathfind_WrongMessageResponse, "NULL pointer"); } else if (msg_result->status != 0) { THROW(E_8K_AI_Pathfind_WrongMessageResponse, "Wrong response"); } setMapWidth(msg_result->map->width); setMapHeight(msg_result->map->height); delete msg_result; // alokace markmapy mm=(bool*) KMemAlloc((getMapWidth()*getMapHeight())*sizeof(bool)); GLOBALLOGID(PRIORITY_AI_ALLOC, "mm ln 58 pathfind"); // alokace markmapy pro flooding mmff=(bool*) KMemAlloc((getMapWidth()*getMapHeight())*sizeof(bool)); GLOBALLOGID(PRIORITY_AI_ALLOC, "mmff ln 58 pathfind"); } bool CPathFindEngine::validSou(COORDS & s) { if (((s.x>=0) && (s.x=0) && (s.ystart.x) { if (sxlcol) { xdif++; } else { xdif--; } } else { if (sxlcol) { xdif--; } else { xdif++; } } } } uyt+=xdif; dyt-=xdif; if (target.yuyt) { return (xdif+((target.y-uyt)/2)); } else { return xdif; } } int CPathFindEngine::heuristicFunction(COORDS & start,COORDS & target) { return hexDistance(start,target); } int CPathFindEngine::getCost(int unit_id,int done_cost,COORDS & startsou,COORDS & targetsou) throw(E_8K_AI_Pathfind_WrongMessageResponse) { PACKET_GET_DISTANCE paket; paket.unit_id=unit_id; switch (pft) { case PFT_UnitsNotTransparent:paket.getcost_transparency=GCT_UnitsNotTransparent; break; case PFT_IgnoreMyUnits:paket.getcost_transparency=GCT_IgnoreMyUnits; break; case PFT_IgnoreTargetUnit:if (COORDSSAME(target_hex_coords,targetsou)) { paket.getcost_transparency=GCT_IgnoreAllUnits; } else { paket.getcost_transparency=GCT_UnitsNotTransparent; } break; case PFT_IgnoreMyUnitsAndTargetUnit:if (COORDSSAME(target_hex_coords,targetsou)) { paket.getcost_transparency=GCT_IgnoreAllUnits; } else { paket.getcost_transparency=GCT_IgnoreMyUnits; } break; case PFT_IgnoreAllUnits:paket.getcost_transparency=GCT_IgnoreAllUnits; break; case PFT_BridgeAnalysis:paket.getcost_transparency=GCT_SampleUnit; break; default:; } paket.from=(startsou.y*getMapWidth())+startsou.x; paket.to=(targetsou.y*getMapWidth())+targetsou.x; paket.points_of_movement=done_cost; TPacket_RET_DISTANCE* msg_result=(TPacket_RET_DISTANCE*) KSendGlobalMessage(MSG_GET_DISTANCE,MOD_PATHFIND,MOD_WORLD_SERVER,&paket); if (msg_result == NULL) { THROW(E_8K_AI_Pathfind_WrongMessageResponse, "getCost: NULL pointer returned.") } if (msg_result->status!=0) { THROW(E_8K_AI_Pathfind_WrongMessageResponse, "getCost: Invalid response.") } int rv=msg_result->cost; delete msg_result; return rv; } int CPathFindEngine::getMapWidth() { return _mapWidth; } int CPathFindEngine::getMapHeight() { return _mapHeight; } void CPathFindEngine::setMapWidth(int value) { _mapWidth=value; } void CPathFindEngine::setMapHeight(int value) { _mapHeight=value; } } }