/** @file /ai/MapAnalyzer/mapanalyzertransciever.cpp @brief Zdrojovy kod s deklaraci transcieveru pro Map Analyzer Engine. Zdrojovy kod s deklaraci transcieveru pro Map Analyzer Engine. @author PZ @version 0.1 */ #include "ai/MapAnalyzer/mapanalyzertransciever.h" namespace ai_ns { namespace mapanalyzer_ns { CMapAnalyzerTransciever* MATrans; CMapAnalyzerTransciever::CMapAnalyzerTransciever() { MATrans=this; // inicializace transcieveru initTransciever(); } void CMapAnalyzerTransciever::initTransciever() { mapanalyzer_transceiver.fnc = MAPANALYZER_MSG_HANDLER; mapanalyzer_transceiver.iActived = true; mapanalyzer_transceiver.iPriority = 5; mapanalyzer_transceiver.PrimaryID = MOD_MAPANALYZER; KRegisterGlobalTransceiver(&mapanalyzer_transceiver, MOD_MAPANALYZER); } RVAL MAPANALYZER_MSG_HANDLER(MESSAGE_ID mid,SENDER s,PARAM p) { // GLOBALLOG("Map Analyzer: Message Id: %d; Sender %d; Param %p\n", mid, s, &p); switch (mid) { case MSG_MAPANALYZER_INIT: // inicializace s mapou { MATrans->initMapAnalyzer((TPacket_AI_LetsGo*) p); } break; case MSG_MAPANALYZER_GET_NEAREST_FREE_PRODUCTION_BUILDING_FOR_UNIT_TRAIN: // nejblizsi produkcni budova, ktera umi vyrobit danou jednotku { int* rv=(int*) KMemAlloc(sizeof(int)); *rv=MATrans->getNearestFreeProductionBuildingForUnitTrain(((TPacket_MapAnalyzer_NearestFreeProductionBuildingForUnitTrain*) p)->player_id,((TPacket_MapAnalyzer_NearestFreeProductionBuildingForUnitTrain*) p)->start_hex,((TPacket_MapAnalyzer_NearestFreeProductionBuildingForUnitTrain*) p)->unit_type); return rv; } case MSG_MAPANALYZER_GET_BEST_PRODUCTION_BUILDING_PLACE: // nejlepsi misto pro stavbu produkcni budovy { int* rv=(int*) KMemAlloc(sizeof(int)); *rv=MATrans->getBestProductionBuildingPlace(((TPacket_MapAnalyzer_BestProductionBuildingPlace*) p)->player_id,((TPacket_MapAnalyzer_BestProductionBuildingPlace*) p)->building_type,(&(((TPacket_MapAnalyzer_BestProductionBuildingPlace*) p)->planned_buildings_coordinates)),((TPacket_MapAnalyzer_BestProductionBuildingPlace*) p)->assigned_builder_position); return rv; } case MSG_MAPANALYZER_FIND_PLAYER_EMPIRE_CENTER: // najde pomyslny stred hracova uzemi { int* rv=(int*) KMemAlloc(sizeof(int)); *rv=MATrans->findPlayerEmpireCenter(((TPacket_MapAnalyzer_FindPlayerEmpireCenter*) p)->player_id); return rv; } case MSG_MAPANALYZER_GET_HEX_DISTANCE: // prosta vzdalenost mezi dvema hexy { int* rv=(int*) KMemAlloc(sizeof(int)); *rv=MATrans->hexDistance(((TPacket_MapAnalyzer_GetHexDistance*) p)->hexid1,((TPacket_MapAnalyzer_GetHexDistance*) p)->hexid2); return rv; } case MSG_MAPANALYZER_FIND_CITY_BY_POSITION: // vrati ukazatel na strukturu TOWN, kteremu nalezi dany hex { return (MATrans->findCityByPosition(((TPacket_MapAnalyzer_FindCityByPosition*) p)->position)); } case MSG_MAPANALYZER_GET_RANDOM_INVISIBLE_HEX: // vrati souradnice nahodneho neprozkoumaneho hexu { int* rv=(int*) KMemAlloc(sizeof(int)); *rv=MATrans->getRandomInvisibleHex(((TPacket_MapAnalyzer_GetRandomInvisibleHex*) p)->player_id); return rv; } case MSG_MAPANALYZER_GET_ACTION_RADIUS: // vrati tridu se seznamem hexu akcniho radiusu zadaneho polomeru od urciteho hexu { return (MATrans->getActionRadius(((TPacket_MapAnalyzer_GetActionRadius*) p)->position,((TPacket_MapAnalyzer_GetActionRadius*) p)->radius_size)); } case MSG_MAPANALYZER_UNIT_TRAINABLE_IN_BUILDING: // vrati priznak, zdali je v budove na danem hexu mozno vytvorit danou jednotku { bool* rv=(bool*) KMemAlloc(sizeof(bool)); *rv=MATrans->isUnitPossibleToTrainInBuildingOnHex(((TPacket_MapAnalyzer_UnitTrainableInBuilding*) p)->building_placement,((TPacket_MapAnalyzer_UnitTrainableInBuilding*) p)->unit_type); return rv; } case MSG_MAPANALYZER_BRIDGE_BUILDING_ANALYSIS: // vrati souradnice pro nejvhodneji postaveny most, nebo (-1) pokud most neni treba stavet { TPacket_MapAnalyzer_BridgeBuildingResponse* bbr=(TPacket_MapAnalyzer_BridgeBuildingResponse*) MATrans->bridgeBuildingAnalysis(((TPacket_MapAnalyzer_BridgeBuildingAnalysis*) p)->player_id); return bbr; } case MSG_MAPANALYZER_FIND_UNIT_POSITION: // vrati pozici jednotky zadaneho World ID { int* rv=(int*) KMemAlloc(sizeof(int)); *rv=MATrans->findUnitPosition(((TPacket_MapAnalyzer_FindUnitPosition*) p)->unit_world_id); return rv; } default:; } return 0; } } }