Skip to content

Commit

Permalink
Merge pull request #341 from eesast/dev
Browse files Browse the repository at this point in the history
v1.0.5
  • Loading branch information
DragonAura authored May 10, 2024
2 parents 61f2022 + d6b5152 commit 1c8c317
Show file tree
Hide file tree
Showing 16 changed files with 188 additions and 146 deletions.
12 changes: 6 additions & 6 deletions CAPI/cpp/API/include/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class ILogic
[[nodiscard]] virtual std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const = 0;
[[nodiscard]] virtual std::vector<int64_t> GetPlayerGUIDs() const = 0;
[[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetResourceState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetHomeHp() const = 0;
Expand Down Expand Up @@ -97,7 +97,7 @@ class IAPI
[[nodiscard]] virtual std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const = 0;
[[nodiscard]] virtual std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const = 0;
[[nodiscard]] virtual THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetResourceState(int32_t cellX, int32_t cellY) const = 0;
[[nodiscard]] virtual int32_t GetHomeHp() const = 0;
Expand Down Expand Up @@ -203,7 +203,7 @@ class ShipAPI : public IShipAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const override;
Expand Down Expand Up @@ -259,7 +259,7 @@ class TeamAPI : public ITeamAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
Expand Down Expand Up @@ -320,7 +320,7 @@ class ShipDebugAPI : public IShipAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
Expand Down Expand Up @@ -366,7 +366,7 @@ class TeamDebugAPI : public ITeamAPI, public IGameTimer
[[nodiscard]] std::vector<std::shared_ptr<const THUAI7::Bullet>> GetBullets() const override;
[[nodiscard]] std::vector<std::vector<THUAI7::PlaceType>> GetFullMap() const override;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetWormholeHp(int32_t x, int32_t y) const override;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const override;
[[nodiscard]] int32_t GetHomeHp() const override;
Expand Down
2 changes: 1 addition & 1 deletion CAPI/cpp/API/include/logic.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Logic : public ILogic
[[nodiscard]] std::shared_ptr<const THUAI7::GameInfo> GetGameInfo() const;
[[nodiscard]] THUAI7::PlaceType GetPlaceType(int32_t cellX, int32_t cellY) const;
[[nodiscard]] std::vector<int64_t> GetPlayerGUIDs() const;
[[nodiscard]] int32_t GetConstructionHp(int32_t cellX, int32_t cellY) const;
[[nodiscard]] std::pair<int32_t, int32_t> GetConstructionState(int32_t cellX, int32_t cellY) const;
[[nodiscard]] int32_t GetWormholeHp(int32_t cellX, int32_t cellY) const;
[[nodiscard]] int32_t GetResourceState(int32_t cellX, int32_t cellY) const;
[[nodiscard]] int32_t GetHomeHp() const;
Expand Down
2 changes: 2 additions & 0 deletions CAPI/cpp/API/include/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace AssistFunction
THUAI7::PlaceType newPlace = map[GridToCell(newX)][GridToCell(newY)];
if (newPlace == THUAI7::PlaceType::Shadow && myPlace != THUAI7::PlaceType::Shadow)
return false;
if (distance > viewRange * viewRange)
return false;
int32_t divide = std::max(std::abs(deltaX), std::abs(deltaY)) / 100;
if (divide == 0)
return true;
Expand Down
8 changes: 4 additions & 4 deletions CAPI/cpp/API/src/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ THUAI7::PlaceType TeamAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
return logic.GetPlaceType(cellX, cellY);
}

int32_t ShipAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> ShipAPI::GetConstructionState(int32_t cellX, int32_t cellY) const
{
return logic.GetConstructionHp(cellX, cellY);
return logic.GetConstructionState(cellX, cellY);
}

int32_t TeamAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> TeamAPI::GetConstructionState(int32_t cellX, int32_t cellY) const
{
return logic.GetConstructionHp(cellX, cellY);
return logic.GetConstructionState(cellX, cellY);
}

int32_t ShipAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const
Expand Down
8 changes: 4 additions & 4 deletions CAPI/cpp/API/src/DebugAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ THUAI7::PlaceType ShipDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
return logic.GetPlaceType(cellX, cellY);
}

int32_t ShipDebugAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> ShipDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const
{
return logic.GetConstructionHp(cellX, cellY);
return logic.GetConstructionState(cellX, cellY);
}

int32_t ShipDebugAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const
Expand Down Expand Up @@ -395,9 +395,9 @@ THUAI7::PlaceType TeamDebugAPI::GetPlaceType(int32_t cellX, int32_t cellY) const
return logic.GetPlaceType(cellX, cellY);
}

int32_t TeamDebugAPI::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> TeamDebugAPI::GetConstructionState(int32_t cellX, int32_t cellY) const
{
return logic.GetConstructionHp(cellX, cellY);
return logic.GetConstructionState(cellX, cellY);
}

int32_t TeamDebugAPI::GetWormholeHp(int32_t cellX, int32_t cellY) const
Expand Down
24 changes: 18 additions & 6 deletions CAPI/cpp/API/src/logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,26 @@ THUAI7::PlaceType Logic::GetPlaceType(int32_t cellX, int32_t cellY) const
return currentState->gameMap[cellX][cellY];
}

int32_t Logic::GetConstructionHp(int32_t cellX, int32_t cellY) const
std::pair<int32_t, int32_t> Logic::GetConstructionState(int32_t cellX, int32_t cellY) const
{
std::unique_lock<std::mutex> lock(mtxState);
logger->debug("Called GetConstructionHp");
logger->debug("Called GetConstructionState");
auto pos = std::make_pair(cellX, cellY);
auto it = currentState->mapInfo->factoryState.find(pos);
auto it2 = currentState->mapInfo->communityState.find(pos);
auto it3 = currentState->mapInfo->fortState.find(pos);
if (it != currentState->mapInfo->factoryState.end())
{
return currentState->mapInfo->factoryState[pos].first;
return currentState->mapInfo->factoryState[pos];
}
else if (it2 != currentState->mapInfo->communityState.end())
return currentState->mapInfo->communityState[pos].first;
return currentState->mapInfo->communityState[pos];
else if (it3 != currentState->mapInfo->fortState.end())
return currentState->mapInfo->fortState[pos].first;
return currentState->mapInfo->fortState[pos];
else
{
logger->warn("Construction not found");
return -1;
return std::make_pair(-1, -1);
}
}

Expand Down Expand Up @@ -477,6 +477,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->factoryState[pos].first = item.factory_message().team_id();
bufferState->mapInfo->factoryState[pos].second = item.factory_message().hp();
logger->debug("Update Factory!");
}
Expand All @@ -491,6 +492,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->factoryState[pos].first = item.factory_message().team_id();
bufferState->mapInfo->factoryState[pos].second = item.factory_message().hp();
logger->debug("Update Factory!");
}
Expand All @@ -507,6 +509,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->communityState[pos].first = item.community_message().team_id();
bufferState->mapInfo->communityState[pos].second = item.community_message().hp();
logger->debug("Update Community!");
}
Expand All @@ -521,6 +524,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->communityState[pos].first = item.community_message().team_id();
bufferState->mapInfo->communityState[pos].second = item.community_message().hp();
logger->debug("Update Community!");
}
Expand All @@ -537,6 +541,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->fortState[pos].first = item.fort_message().team_id();
bufferState->mapInfo->fortState[pos].second = item.fort_message().hp();
logger->debug("Update Fort!");
}
Expand All @@ -551,6 +556,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->fortState[pos].first = item.fort_message().team_id();
bufferState->mapInfo->fortState[pos].second = item.fort_message().hp();
logger->debug("Update Fort!");
}
Expand Down Expand Up @@ -675,6 +681,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->factoryState[pos].first = item.factory_message().team_id();
bufferState->mapInfo->factoryState[pos].second = item.factory_message().hp();
logger->debug("Update Factory!");
}
Expand All @@ -689,6 +696,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->factoryState[pos].first = item.factory_message().team_id();
bufferState->mapInfo->factoryState[pos].second = item.factory_message().hp();
logger->debug("Update Factory!");
}
Expand All @@ -705,6 +713,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->communityState[pos].first = item.community_message().team_id();
bufferState->mapInfo->communityState[pos].second = item.community_message().hp();
logger->debug("Update Community!");
}
Expand All @@ -719,6 +728,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->communityState[pos].first = item.community_message().team_id();
bufferState->mapInfo->communityState[pos].second = item.community_message().hp();
logger->debug("Update Community!");
}
Expand All @@ -735,6 +745,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->fortState[pos].first = item.fort_message().team_id();
bufferState->mapInfo->fortState[pos].second = item.fort_message().hp();
logger->debug("Update Fort!");
}
Expand All @@ -749,6 +760,7 @@ void Logic::LoadBufferCase(const protobuf::MessageOfObj& item)
}
else
{
bufferState->mapInfo->fortState[pos].first = item.fort_message().team_id();
bufferState->mapInfo->fortState[pos].second = item.fort_message().hp();
logger->debug("Update Fort!");
}
Expand Down
12 changes: 8 additions & 4 deletions CAPI/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ set(CMAKE_CXX_STANDARD 17)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2 -pthread")

if(NOT MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
endif()

aux_source_directory(./API/src CPP_LIST)
aux_source_directory(./proto PROTO_CPP_LIST)

Expand All @@ -21,8 +25,8 @@ add_executable(capi ${CPP_LIST} ${PROTO_CPP_LIST})
target_include_directories(capi PUBLIC ${PROJECT_SOURCE_DIR}/proto ${PROJECT_SOURCE_DIR}/API/include ${PROJECT_SOURCE_DIR}/tclap/include ${PROJECT_SOURCE_DIR}/spdlog/include)

target_link_libraries(capi
protobuf::libprotobuf
gRPC::grpc
gRPC::grpc++_reflection
gRPC::grpc++
protobuf::libprotobuf
gRPC::grpc
gRPC::grpc++_reflection
gRPC::grpc++
)
8 changes: 4 additions & 4 deletions CAPI/python/PyAPI/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]:
def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType:
return self.__logic.GetPlaceType(cellX, cellY)

def GetConstructionHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetConstructionHp(cellX, cellY)
def GetConstructionState(self, cellX: int, cellY: int) -> tuple:
return self.__logic.GetConstructionState(cellX, cellY)

def GetWormholeHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetWormholeHp(cellX, cellY)
Expand Down Expand Up @@ -184,8 +184,8 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]:
def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType:
return self.__logic.GetPlaceType(cellX, cellY)

def GetConstructionHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetConstructionHp(cellX, cellY)
def GetConstructionState(self, cellX: int, cellY: int) -> tuple:
return self.__logic.GetConstructionState(cellX, cellY)

def GetWormholeHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetWormholeHp(cellX, cellY)
Expand Down
8 changes: 4 additions & 4 deletions CAPI/python/PyAPI/DebugAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]:
def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType:
return self.__logic.GetPlaceType(cellX, cellY)

def GetConstructionHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetConstructionHp(cellX, cellY)
def GetConstructionState(self, cellX: int, cellY: int) -> tuple:
return self.__logic.GetConstructionState(cellX, cellY)

def GetWormholeHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetWormholeHp(cellX, cellY)
Expand Down Expand Up @@ -440,8 +440,8 @@ def GetFullMap(self) -> List[List[THUAI7.PlaceType]]:
def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType:
return self.__logic.GetPlaceType(cellX, cellY)

def GetConstructionHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetConstructionHp(cellX, cellY)
def GetConstructionState(self, cellX: int, cellY: int) -> tuple:
return self.__logic.GetConstructionState(cellX, cellY)

def GetWormholeHp(self, cellX: int, cellY: int) -> int:
return self.__logic.GetWormholeHp(cellX, cellY)
Expand Down
4 changes: 2 additions & 2 deletions CAPI/python/PyAPI/Interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType:
pass

@abstractmethod
def GetConstructionHp(self, cellX: int, cellY: int) -> int:
def GetConstructionState(self, cellX: int, cellY: int) -> tuple:
pass

@abstractmethod
Expand Down Expand Up @@ -194,7 +194,7 @@ def GetPlaceType(self, cellX: int, cellY: int) -> THUAI7.PlaceType:
pass

@abstractmethod
def GetConstructionHp(self, cellX: int, cellY: int) -> int:
def GetConstructionState(self, cellX: int, cellY: int) -> tuple:
pass

@abstractmethod
Expand Down
Loading

0 comments on commit 1c8c317

Please sign in to comment.