diff --git a/CAPI/API/include/state.h b/CAPI/API/include/state.h index 4de69cc..f83585c 100644 --- a/CAPI/API/include/state.h +++ b/CAPI/API/include/state.h @@ -20,6 +20,10 @@ struct State std::vector> trickers; std::vector> props; + std::vector> bullets; + + std::vector> bombedBullets; + std::vector> gamemap; std::vector guids; diff --git a/CAPI/API/include/structures.h b/CAPI/API/include/structures.h index 2579d96..d650770 100644 --- a/CAPI/API/include/structures.h +++ b/CAPI/API/include/structures.h @@ -50,6 +50,16 @@ namespace THUAI6 PropType4 = 4, }; + enum class BulletType : unsigned char + { + NullBulletType = 0, + LineBullet = 1, + CommonBullet = 2, + FastBullet = 3, + OrdinaryBullet = 4, + AtomBomb = 5, + }; + // 玩家类型 enum class PlayerType : unsigned char { @@ -106,6 +116,11 @@ namespace THUAI6 Addicted = 3, Quit = 4, Graduated = 5, + Treated = 6, + Rescued = 7, + Stunned = 8, + Treating = 9, + Rescuing = 10, }; // 玩家类 @@ -147,6 +162,28 @@ namespace THUAI6 std::vector buff; // buff }; + struct Bullet + { + BulletType bulletType; // 子弹类型 + int32_t x; // x坐标 + int32_t y; // y坐标 + double facingDirection; // 朝向 + int64_t guid; // 全局唯一ID + PlayerType team; // 子弹所属队伍 + PlaceType place; // 所处格子的类型 + double bombRange; // 炸弹爆炸范围 + }; + + struct BombedBullet + { + BulletType bulletType; + int32_t x; + int32_t y; + double facingDirection; + int64_t mappingID; + double bombRange; + }; + struct Prop { int32_t x; @@ -176,6 +213,11 @@ namespace THUAI6 {StudentState::Addicted, "Addicted"}, {StudentState::Quit, "Quit"}, {StudentState::Graduated, "Graduated"}, + {StudentState::Treated, "Treated"}, + {StudentState::Rescued, "Rescued"}, + {StudentState::Stunned, "Stunned"}, + {StudentState::Treating, "Treating"}, + {StudentState::Rescuing, "Rescuing"}, }; inline std::map playerTypeDict{ diff --git a/CAPI/API/include/utils.hpp b/CAPI/API/include/utils.hpp index cdbd5c2..49f0d6f 100644 --- a/CAPI/API/include/utils.hpp +++ b/CAPI/API/include/utils.hpp @@ -20,11 +20,13 @@ namespace AssistFunction return grid / numOfGridPerCell; } - inline bool HaveView(int viewRange, int x, int y, int newX, int newY, const std::vector>& map) + inline bool HaveView(int viewRange, int x, int y, int newX, int newY, THUAI6::PlaceType myPlace, THUAI6::PlaceType newPlace, std::vector>& map) { int deltaX = newX - x; int deltaY = newY - y; double distance = deltaX * deltaX + deltaY * deltaY; + if (newPlace == THUAI6::PlaceType::Grass && myPlace != THUAI6::PlaceType::Grass) // 草丛外必不可能看到草丛内 + return false; if (distance < viewRange * viewRange) { int divide = std::max(std::abs(deltaX), std::abs(deltaY)) / 100; @@ -32,13 +34,22 @@ namespace AssistFunction double dy = deltaY / divide; double myX = double(x); double myY = double(y); - for (int i = 0; i < divide; i++) - { - myX += dx; - myY += dy; - if (map[GridToCell(myX)][GridToCell(myY)] != THUAI6::PlaceType::Land) - return false; - } + if (newPlace == THUAI6::PlaceType::Grass && myPlace == THUAI6::PlaceType::Grass) // 都在草丛内,要另作判断 + for (int i = 0; i < divide; i++) + { + myX += dx; + myY += dy; + if (map[GridToCell(myX)][GridToCell(myY)] != THUAI6::PlaceType::Grass) + return false; + } + else // 不在草丛内,只需要没有墙即可 + for (int i = 0; i < divide; i++) + { + myX += dx; + myY += dy; + if (map[GridToCell(myX)][GridToCell(myY)] == THUAI6::PlaceType::Wall) + return false; + } return true; } else @@ -119,6 +130,11 @@ namespace Proto2THUAI6 {protobuf::StudentState::ADDICTED, THUAI6::StudentState::Addicted}, {protobuf::StudentState::QUIT, THUAI6::StudentState::Quit}, {protobuf::StudentState::GRADUATED, THUAI6::StudentState::Graduated}, + {protobuf::StudentState::RESCUED, THUAI6::StudentState::Rescued}, + {protobuf::StudentState::TREATED, THUAI6::StudentState::Treated}, + {protobuf::StudentState::STUNNED, THUAI6::StudentState::Stunned}, + {protobuf::StudentState::RESCUING, THUAI6::StudentState::Rescuing}, + {protobuf::StudentState::TREATING, THUAI6::StudentState::Treating}, }; inline std::map gameStateDict{ @@ -128,6 +144,15 @@ namespace Proto2THUAI6 {protobuf::GameState::GAME_END, THUAI6::GameState::GameEnd}, }; + inline std::map bulletTypeDict{ + {protobuf::BulletType::NULL_BULLET_TYPE, THUAI6::BulletType::NullBulletType}, + {protobuf::BulletType::COMMON_BULLET, THUAI6::BulletType::CommonBullet}, + {protobuf::BulletType::FAST_BULLET, THUAI6::BulletType::FastBullet}, + {protobuf::BulletType::LINE_BULLET, THUAI6::BulletType::LineBullet}, + {protobuf::BulletType::ORDINARY_BULLET, THUAI6::BulletType::OrdinaryBullet}, + {protobuf::BulletType::ATOM_BOMB, THUAI6::BulletType::AtomBomb}, + }; + // 用于将Protobuf中的类转换为THUAI6的类 inline std::shared_ptr Protobuf2THUAI6Tricker(const protobuf::MessageOfTricker& trickerMsg) { @@ -211,6 +236,32 @@ namespace Proto2THUAI6 return map; } + inline std::shared_ptr Protobuf2THUAI6Bullet(const protobuf::MessageOfBullet& bulletMsg) + { + auto bullet = std::make_shared(); + bullet->bulletType = bulletTypeDict[bulletMsg.type()]; + bullet->x = bulletMsg.x(); + bullet->y = bulletMsg.y(); + bullet->facingDirection = bulletMsg.facing_direction(); + bullet->guid = bulletMsg.guid(); + bullet->team = playerTypeDict[bulletMsg.team()]; + bullet->place = placeTypeDict[bulletMsg.place()]; + bullet->bombRange = bulletMsg.bomb_range(); + return bullet; + } + + inline std::shared_ptr Protobuf2THUAI6BombedBullet(const protobuf::MessageOfBombedBullet& bombedBulletMsg) + { + auto bombedBullet = std::make_shared(); + bombedBullet->bulletType = bulletTypeDict[bombedBulletMsg.type()]; + bombedBullet->x = bombedBulletMsg.x(); + bombedBullet->y = bombedBulletMsg.y(); + bombedBullet->facingDirection = bombedBulletMsg.facing_direction(); + bombedBullet->mappingID = bombedBulletMsg.mapping_id(); + bombedBullet->bombRange = bombedBulletMsg.bomb_range(); + return bombedBullet; + } + } // namespace Proto2THUAI6 namespace THUAI62Proto diff --git a/CAPI/API/src/logic.cpp b/CAPI/API/src/logic.cpp index 504035e..b4b0742 100644 --- a/CAPI/API/src/logic.cpp +++ b/CAPI/API/src/logic.cpp @@ -242,7 +242,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) } for (const auto& item : message.tricker_message()) { - if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.x(), item.y(), bufferState->gamemap)) + if (AssistFunction::HaveView(bufferState->studentSelf->viewRange, bufferState->studentSelf->x, bufferState->studentSelf->y, item.x(), item.y(), bufferState->studentSelf->place, Proto2THUAI6::placeTypeDict[item.place()], bufferState->gamemap)) { bufferState->trickers.push_back(Proto2THUAI6::Protobuf2THUAI6Tricker(item)); logger->debug("Add Tricker!"); @@ -261,7 +261,7 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) logger->debug("Add Tricker!"); } for (const auto& item : message.student_message()) - if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.x(), item.y(), bufferState->gamemap)) + if (AssistFunction::HaveView(bufferState->trickerSelf->viewRange, bufferState->trickerSelf->x, bufferState->trickerSelf->y, item.x(), item.y(), bufferState->trickerSelf->place, Proto2THUAI6::placeTypeDict[item.place()], bufferState->gamemap)) { bufferState->students.push_back(Proto2THUAI6::Protobuf2THUAI6Student(item)); logger->debug("Add Student!"); @@ -272,6 +272,16 @@ void Logic::LoadBuffer(protobuf::MessageToClient& message) bufferState->props.push_back(Proto2THUAI6::Protobuf2THUAI6Prop(item)); logger->debug("Add Prop!"); } + for (const auto& item : message.bullet_message()) + { + bufferState->bullets.push_back(Proto2THUAI6::Protobuf2THUAI6Bullet(item)); + logger->debug("Add Bullet!"); + } + for (const auto& item : message.bombed_bullet_message()) + { + bufferState->bombedBullets.push_back(Proto2THUAI6::Protobuf2THUAI6BombedBullet(item)); + logger->debug("Add BombedBullet!"); + } if (asynchronous) { {