diff --git a/CAPI/cpp/API/include/Communication.h b/CAPI/cpp/API/include/Communication.h index 8ab441f8..9b7a46f3 100755 --- a/CAPI/cpp/API/include/Communication.h +++ b/CAPI/cpp/API/include/Communication.h @@ -24,9 +24,7 @@ class Communication { public: Communication(std::string sIP, std::string sPort); - ~Communication() - { - } + ~Communication() = default; bool TryConnection(int32_t playerID, int32_t teamID); protobuf::MessageToClient GetMessage2Client(); void AddPlayer(int32_t playerID, int32_t teamID, THUAI7::ShipType ShipType); @@ -52,8 +50,8 @@ class Communication protobuf::MessageToClient message2Client; std::mutex mtxMessage; std::mutex mtxLimit; - int32_t counter; - int32_t counterMove; + int32_t counter{}; + int32_t counterMove{}; static constexpr const int32_t limit = 50; static constexpr const int32_t moveLimit = 10; std::condition_variable cvMessage; diff --git a/CAPI/cpp/API/include/logic.h b/CAPI/cpp/API/include/logic.h index e03bad4e..3b41a065 100755 --- a/CAPI/cpp/API/include/logic.h +++ b/CAPI/cpp/API/include/logic.h @@ -63,7 +63,7 @@ class Logic : public ILogic std::condition_variable cvAI; // 信息队列 - ConcurrentQueue> messageQueue; + ConcurrentQueue> messageQueue; // 存储状态,分别是现在的状态和缓冲区的状态。 State state[2]; diff --git a/CAPI/cpp/API/include/structures.h b/CAPI/cpp/API/include/structures.h index 375c57e1..719fb31a 100755 --- a/CAPI/cpp/API/include/structures.h +++ b/CAPI/cpp/API/include/structures.h @@ -14,7 +14,6 @@ namespace THUAI7 { - // 游戏状态 enum class GameState : unsigned char { @@ -197,8 +196,8 @@ namespace THUAI7 int32_t hp; // 血量 int32_t armor; // 装甲 int32_t shield; // 护盾 - int32_t playerID; // 船的id - int32_t teamID; + int64_t playerID; // 船的id + int64_t teamID; int64_t guid; // 全局唯一ID ShipState shipState; // 船所处状态 ShipType shipType; @@ -213,10 +212,10 @@ namespace THUAI7 struct Team { - int32_t playerID; - int32_t teamID; - int32_t score; - int32_t energy; + int64_t playerID; + int64_t teamID; + int64_t score; + int64_t energy; }; struct Home @@ -224,7 +223,7 @@ namespace THUAI7 int32_t x; int32_t y; int32_t hp; - int32_t teamID; + int64_t teamID; int64_t guid; }; @@ -234,21 +233,20 @@ namespace THUAI7 int32_t y; // y坐标 double facingDirection; // 朝向 int64_t guid; // - int32_t teamID; // 子弹所属队伍 + int64_t teamID; // 子弹所属队伍 BulletType bulletType; // 子弹类型 int32_t damage; // 伤害值 int32_t attackRange; - int32_t bombRange; - double explodeRange; // 炸弹爆炸范围 - int32_t speed; // 子弹速度 + double bombRange; // 炸弹爆炸范围 + int32_t speed; // 子弹速度 }; struct ConstructionState { - int32_t teamID; + int64_t teamID; int32_t hp; ConstructionType constructionType; - ConstructionState(std::pair teamHP, ConstructionType type) : + ConstructionState(std::pair teamHP, ConstructionType type) : teamID(teamHP.first), hp(teamHP.second), constructionType(type) @@ -266,15 +264,17 @@ namespace THUAI7 // double bombRange, // }; + using cellxy_t = std::pair; + struct GameMap { // x,y,id,hp - std::map, std::pair> factoryState; - std::map, std::pair> communityState; - std::map, std::pair> fortState; - std::map, std::pair> homeState; - std::map, int32_t> wormholeState; - std::map, int32_t> resourceState; + std::map> factoryState; + std::map> communityState; + std::map> fortState; + std::map> homeState; + std::map wormholeState; + std::map resourceState; }; struct GameInfo @@ -368,7 +368,8 @@ namespace THUAI7 {ModuleType::ModulePlasmaGun, "ModulePlasmaGun"}, {ModuleType::ModuleShellGun, "ModuleShellGun"}, {ModuleType::ModuleMissileGun, "ModuleMissileGun"}, - {ModuleType::ModuleArcGun, "ModuleArcGun"}}; + {ModuleType::ModuleArcGun, "ModuleArcGun"}, + }; inline std::map messageOfObjDict{ {MessageOfObj::NullMessageOfObj, "NullMessageOfObj"}, diff --git a/CAPI/cpp/API/include/utils.hpp b/CAPI/cpp/API/include/utils.hpp index 52ac4973..5a38ea56 100755 --- a/CAPI/cpp/API/include/utils.hpp +++ b/CAPI/cpp/API/include/utils.hpp @@ -17,9 +17,9 @@ #undef SendMessage #undef PeekMessage +// 用于将THUAI7的类转换为Protobuf的类 namespace AssistFunction { - constexpr int32_t numOfGridPerCell = 1000; [[nodiscard]] constexpr inline int32_t GridToCell(int32_t grid) noexcept @@ -29,21 +29,21 @@ namespace AssistFunction [[nodiscard]] constexpr inline int32_t GridToCell(double grid) noexcept { - return int(grid) / numOfGridPerCell; + return int32_t(grid) / numOfGridPerCell; } inline bool HaveView(int32_t x, int32_t y, int32_t newX, int32_t newY, int32_t viewRange, std::vector>& map) { - int32_t deltaX = newX - x; - int32_t deltaY = newY - y; - double distance = double(deltaX * deltaX) + double(deltaY * deltaY); + double deltaX = newX - x; + double deltaY = newY - y; + double distance = std::pow(deltaX, 2) + std::pow(deltaY, 2); THUAI7::PlaceType myPlace = map[GridToCell(x)][GridToCell(y)]; THUAI7::PlaceType newPlace = map[GridToCell(newX)][GridToCell(newY)]; if (newPlace == THUAI7::PlaceType::Shadow && myPlace != THUAI7::PlaceType::Shadow) return false; - if (distance > viewRange * viewRange) + if (distance > std::pow(viewRange, 2)) return false; - int32_t divide = std::max(std::abs(deltaX), std::abs(deltaY)) / 100; + int32_t divide = int32_t(std::max(std::abs(deltaX), std::abs(deltaY)) / 100); if (divide == 0) return true; double dx = deltaX / divide; @@ -539,15 +539,14 @@ namespace THUAI72Proto playerMsg.set_ship_type(THUAI72Proto::shipTypeDict[ShipType]); return playerMsg; } - - // 用于将THUAI7的类转换为Protobuf的类 } // namespace THUAI72Proto + namespace Time { inline double TimeSinceStart(const std::chrono::system_clock::time_point& sp) { - std::chrono::system_clock::time_point tp = std::chrono::system_clock::now(); - std::chrono::duration time_span = std::chrono::duration_cast>(tp - sp); + auto tp = std::chrono::system_clock::now(); + auto time_span = std::chrono::duration_cast>(tp - sp); return time_span.count(); } } // namespace Time diff --git a/CAPI/cpp/API/src/logic.cpp b/CAPI/cpp/API/src/logic.cpp index 9710b355..56a18360 100755 --- a/CAPI/cpp/API/src/logic.cpp +++ b/CAPI/cpp/API/src/logic.cpp @@ -95,7 +95,7 @@ std::optional Logic::GetConstructionState(int32_t cel { std::unique_lock lock(mtxState); logger->debug("Called GetConstructionState"); - auto pos = std::make_pair(cellX, cellY); + auto pos = THUAI7::cellxy_t(cellX, cellY); auto it = currentState->mapInfo->factoryState.find(pos); auto it2 = currentState->mapInfo->communityState.find(pos); auto it3 = currentState->mapInfo->fortState.find(pos); @@ -118,7 +118,7 @@ int32_t Logic::GetWormholeHp(int32_t cellX, int32_t cellY) const { std::unique_lock lock(mtxState); logger->debug("Called GetWormholeHp"); - auto pos = std::make_pair(cellX, cellY); + auto pos = THUAI7::cellxy_t(cellX, cellY); auto it = currentState->mapInfo->wormholeState.find(pos); if (it != currentState->mapInfo->wormholeState.end()) { @@ -144,7 +144,7 @@ int32_t Logic::GetResourceState(int32_t cellX, int32_t cellY) const { std::unique_lock lock(mtxState); logger->debug("Called GetResourceState"); - auto pos = std::make_pair(cellX, cellY); + auto pos = THUAI7::cellxy_t(cellX, cellY); auto it = currentState->mapInfo->resourceState.find(pos); if (it != currentState->mapInfo->resourceState.end()) { @@ -220,7 +220,7 @@ std::pair Logic::GetMessage() else { logger->warn("No message"); - return std::make_pair(-1, ""); + return std::pair(-1, std::string("")); } } @@ -322,7 +322,7 @@ void Logic::ProcessMessage() if (Proto2THUAI7::messageOfObjDict[item.message_of_obj_case()] == THUAI7::MessageOfObj::MapMessage) { auto map = std::vector>(); - auto mapResult = item.map_message(); + auto& mapResult = item.map_message(); for (int32_t i = 0; i < item.map_message().rows_size(); i++) { std::vector row; @@ -451,10 +451,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::HomeMessage: if (item.home_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.home_message().x()), AssistFunction::GridToCell(item.home_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.home_message().x()), + AssistFunction::GridToCell(item.home_message().y()) + ); if (bufferState->mapInfo->homeState.count(pos) == 0) { - bufferState->mapInfo->homeState.emplace(pos, std::make_pair(item.home_message().team_id(), item.home_message().hp())); + bufferState->mapInfo->homeState.emplace(pos, std::pair(item.home_message().team_id(), item.home_message().hp())); logger->debug("Load Home!"); } else @@ -465,10 +468,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (AssistFunction::HaveView(x, y, item.home_message().x(), item.home_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.home_message().x()), AssistFunction::GridToCell(item.home_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.home_message().x()), + AssistFunction::GridToCell(item.home_message().y()) + ); if (bufferState->mapInfo->homeState.count(pos) == 0) { - bufferState->mapInfo->homeState.emplace(pos, std::make_pair(item.home_message().team_id(), item.home_message().hp())); + bufferState->mapInfo->homeState.emplace(pos, std::pair(item.home_message().team_id(), item.home_message().hp())); logger->debug("Load Home!"); } else @@ -481,10 +487,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::FactoryMessage: if (item.factory_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.factory_message().x()), + AssistFunction::GridToCell(item.factory_message().y()) + ); if (bufferState->mapInfo->factoryState.count(pos) == 0) { - bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id(), item.factory_message().hp())); + bufferState->mapInfo->factoryState.emplace(pos, std::pair(item.factory_message().team_id(), item.factory_message().hp())); logger->debug("Load Factory!"); } else @@ -496,10 +505,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (AssistFunction::HaveView(x, y, item.factory_message().x(), item.factory_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.factory_message().x()), + AssistFunction::GridToCell(item.factory_message().y()) + ); if (bufferState->mapInfo->factoryState.count(pos) == 0) { - bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id(), item.factory_message().hp())); + bufferState->mapInfo->factoryState.emplace(pos, std::pair(item.factory_message().team_id(), item.factory_message().hp())); logger->debug("Load Factory!"); } else @@ -513,10 +525,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::CommunityMessage: if (item.community_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.community_message().x()), + AssistFunction::GridToCell(item.community_message().y()) + ); if (bufferState->mapInfo->communityState.count(pos) == 0) { - bufferState->mapInfo->communityState.emplace(pos, std::make_pair(item.community_message().team_id(), item.community_message().hp())); + bufferState->mapInfo->communityState.emplace(pos, std::pair(item.community_message().team_id(), item.community_message().hp())); logger->debug("Load Community!"); } else @@ -528,10 +543,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (AssistFunction::HaveView(x, y, item.community_message().x(), item.community_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.community_message().x()), + AssistFunction::GridToCell(item.community_message().y()) + ); if (bufferState->mapInfo->communityState.count(pos) == 0) { - bufferState->mapInfo->communityState.emplace(pos, std::make_pair(item.community_message().team_id(), item.community_message().hp())); + bufferState->mapInfo->communityState.emplace(pos, std::pair(item.community_message().team_id(), item.community_message().hp())); logger->debug("Load Community!"); } else @@ -545,10 +563,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::FortMessage: if (item.fort_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.fort_message().x()), + AssistFunction::GridToCell(item.fort_message().y()) + ); if (bufferState->mapInfo->fortState.count(pos) == 0) { - bufferState->mapInfo->fortState.emplace(pos, std::make_pair(item.fort_message().team_id(), item.fort_message().hp())); + bufferState->mapInfo->fortState.emplace(pos, std::pair(item.fort_message().team_id(), item.fort_message().hp())); logger->debug("Load Fort!"); } else @@ -560,10 +581,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (AssistFunction::HaveView(x, y, item.fort_message().x(), item.fort_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.fort_message().x()), + AssistFunction::GridToCell(item.fort_message().y()) + ); if (bufferState->mapInfo->fortState.count(pos) == 0) { - bufferState->mapInfo->fortState.emplace(pos, std::make_pair(item.fort_message().team_id(), item.fort_message().hp())); + bufferState->mapInfo->fortState.emplace(pos, std::pair(item.fort_message().team_id(), item.fort_message().hp())); logger->debug("Load Fort!"); } else @@ -577,7 +601,10 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::WormholeMessage: if (AssistFunction::HaveView(x, y, item.wormhole_message().x(), item.wormhole_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.wormhole_message().x()), AssistFunction::GridToCell(item.wormhole_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.wormhole_message().x()), + AssistFunction::GridToCell(item.wormhole_message().y()) + ); if (bufferState->mapInfo->wormholeState.count(pos) == 0) { bufferState->mapInfo->wormholeState.emplace(pos, item.wormhole_message().hp()); @@ -593,7 +620,10 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::ResourceMessage: if (AssistFunction::HaveView(x, y, item.resource_message().x(), item.resource_message().y(), viewRange, bufferState->gameMap)) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.resource_message().x()), AssistFunction::GridToCell(item.resource_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.resource_message().x()), + AssistFunction::GridToCell(item.resource_message().y()) + ); if (bufferState->mapInfo->resourceState.count(pos) == 0) { bufferState->mapInfo->resourceState.emplace(pos, item.resource_message().progress()); @@ -608,17 +638,17 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) break; case THUAI7::MessageOfObj::NewsMessage: { - auto news = item.news_message(); + auto& news = item.news_message(); if (news.to_id() == playerID && news.team_id() == teamID) { if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::TextMessage) { - messageQueue.emplace(std::make_pair(news.from_id(), news.text_message())); + messageQueue.emplace(std::pair(news.from_id(), news.text_message())); logger->debug("Load Text News!"); } else if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::BinaryMessage) { - messageQueue.emplace(std::make_pair(news.from_id(), news.binary_message())); + messageQueue.emplace(std::pair(news.from_id(), news.binary_message())); logger->debug("Load Binary News!"); } else @@ -655,10 +685,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::HomeMessage: if (item.home_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.home_message().x()), AssistFunction::GridToCell(item.home_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.home_message().x()), + AssistFunction::GridToCell(item.home_message().y()) + ); if (bufferState->mapInfo->homeState.count(pos) == 0) { - bufferState->mapInfo->homeState.emplace(pos, std::make_pair(item.home_message().team_id(), item.home_message().hp())); + bufferState->mapInfo->homeState.emplace(pos, std::pair(item.home_message().team_id(), item.home_message().hp())); logger->debug("Load Home!"); } else @@ -669,10 +702,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (HaveOverView(item.home_message().x(), item.home_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.home_message().x()), AssistFunction::GridToCell(item.home_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.home_message().x()), + AssistFunction::GridToCell(item.home_message().y()) + ); if (bufferState->mapInfo->homeState.count(pos) == 0) { - bufferState->mapInfo->homeState.emplace(pos, std::make_pair(item.home_message().team_id(), item.home_message().hp())); + bufferState->mapInfo->homeState.emplace(pos, std::pair(item.home_message().team_id(), item.home_message().hp())); logger->debug("Load Home!"); } else @@ -685,10 +721,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::FactoryMessage: if (item.factory_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.factory_message().x()), + AssistFunction::GridToCell(item.factory_message().y()) + ); if (bufferState->mapInfo->factoryState.count(pos) == 0) { - bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id(), item.factory_message().hp())); + bufferState->mapInfo->factoryState.emplace(pos, std::pair(item.factory_message().team_id(), item.factory_message().hp())); logger->debug("Load Factory!"); } else @@ -700,10 +739,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (HaveOverView(item.factory_message().x(), item.factory_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.factory_message().x()), AssistFunction::GridToCell(item.factory_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.factory_message().x()), + AssistFunction::GridToCell(item.factory_message().y()) + ); if (bufferState->mapInfo->factoryState.count(pos) == 0) { - bufferState->mapInfo->factoryState.emplace(pos, std::make_pair(item.factory_message().team_id(), item.factory_message().hp())); + bufferState->mapInfo->factoryState.emplace(pos, std::pair(item.factory_message().team_id(), item.factory_message().hp())); logger->debug("Load Factory!"); } else @@ -717,10 +759,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::CommunityMessage: if (item.community_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.community_message().x()), + AssistFunction::GridToCell(item.community_message().y()) + ); if (bufferState->mapInfo->communityState.count(pos) == 0) { - bufferState->mapInfo->communityState.emplace(pos, std::make_pair(item.community_message().team_id(), item.community_message().hp())); + bufferState->mapInfo->communityState.emplace(pos, std::pair(item.community_message().team_id(), item.community_message().hp())); logger->debug("Load Community!"); } else @@ -732,10 +777,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (HaveOverView(item.community_message().x(), item.community_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.community_message().x()), AssistFunction::GridToCell(item.community_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.community_message().x()), + AssistFunction::GridToCell(item.community_message().y()) + ); if (bufferState->mapInfo->communityState.count(pos) == 0) { - bufferState->mapInfo->communityState.emplace(pos, std::make_pair(item.community_message().team_id(), item.community_message().hp())); + bufferState->mapInfo->communityState.emplace(pos, std::pair(item.community_message().team_id(), item.community_message().hp())); logger->debug("Load Community!"); } else @@ -749,10 +797,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::FortMessage: if (item.fort_message().team_id() == teamID) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.fort_message().x()), + AssistFunction::GridToCell(item.fort_message().y()) + ); if (bufferState->mapInfo->fortState.count(pos) == 0) { - bufferState->mapInfo->fortState.emplace(pos, std::make_pair(item.fort_message().team_id(), item.fort_message().hp())); + bufferState->mapInfo->fortState.emplace(pos, std::pair(item.fort_message().team_id(), item.fort_message().hp())); logger->debug("Load Fort!"); } else @@ -764,10 +815,13 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) } else if (HaveOverView(item.fort_message().x(), item.fort_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.fort_message().x()), AssistFunction::GridToCell(item.fort_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.fort_message().x()), + AssistFunction::GridToCell(item.fort_message().y()) + ); if (bufferState->mapInfo->fortState.count(pos) == 0) { - bufferState->mapInfo->fortState.emplace(pos, std::make_pair(item.fort_message().team_id(), item.fort_message().hp())); + bufferState->mapInfo->fortState.emplace(pos, std::pair(item.fort_message().team_id(), item.fort_message().hp())); logger->debug("Load Fort!"); } else @@ -781,7 +835,10 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::WormholeMessage: if (HaveOverView(item.wormhole_message().x(), item.wormhole_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.wormhole_message().x()), AssistFunction::GridToCell(item.wormhole_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.wormhole_message().x()), + AssistFunction::GridToCell(item.wormhole_message().y()) + ); if (bufferState->mapInfo->wormholeState.count(pos) == 0) { bufferState->mapInfo->wormholeState.emplace(pos, item.wormhole_message().hp()); @@ -797,7 +854,10 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::ResourceMessage: if (HaveOverView(item.resource_message().x(), item.resource_message().y())) { - auto pos = std::make_pair(AssistFunction::GridToCell(item.resource_message().x()), AssistFunction::GridToCell(item.resource_message().y())); + auto pos = THUAI7::cellxy_t( + AssistFunction::GridToCell(item.resource_message().x()), + AssistFunction::GridToCell(item.resource_message().y()) + ); if (bufferState->mapInfo->resourceState.count(pos) == 0) { bufferState->mapInfo->resourceState.emplace(pos, item.resource_message().progress()); @@ -813,15 +873,15 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item) case THUAI7::MessageOfObj::NewsMessage: if (item.news_message().team_id() == teamID && item.news_message().to_id() == playerID) { - auto news = item.news_message(); + auto& news = item.news_message(); if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::TextMessage) { - messageQueue.emplace(std::make_pair(news.from_id(), news.text_message())); + messageQueue.emplace(std::pair(news.from_id(), news.text_message())); logger->debug("Load Text News!"); } else if (Proto2THUAI7::newsTypeDict[news.news_case()] == THUAI7::NewsType::BinaryMessage) { - messageQueue.emplace(std::make_pair(news.from_id(), news.binary_message())); + messageQueue.emplace(std::pair(news.from_id(), news.binary_message())); logger->debug("Load Binary News!"); } else