Browse Source

Merge pull request #116 from DragonAura/dev

feat(CAPI):  change have view func, add bullet
tags/0.1.0
Timothy Liu GitHub 2 years ago
parent
commit
6746790cbd
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 117 additions and 10 deletions
  1. +4
    -0
      CAPI/API/include/state.h
  2. +42
    -0
      CAPI/API/include/structures.h
  3. +59
    -8
      CAPI/API/include/utils.hpp
  4. +12
    -2
      CAPI/API/src/logic.cpp

+ 4
- 0
CAPI/API/include/state.h View File

@@ -20,6 +20,10 @@ struct State
std::vector<std::shared_ptr<THUAI6::Tricker>> trickers;
std::vector<std::shared_ptr<THUAI6::Prop>> props;

std::vector<std::shared_ptr<THUAI6::Bullet>> bullets;

std::vector<std::shared_ptr<THUAI6::BombedBullet>> bombedBullets;

std::vector<std::vector<THUAI6::PlaceType>> gamemap;

std::vector<int64_t> guids;


+ 42
- 0
CAPI/API/include/structures.h View File

@@ -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<TrickerBuffType> 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<PlayerType, std::string> playerTypeDict{


+ 59
- 8
CAPI/API/include/utils.hpp View File

@@ -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<std::vector<THUAI6::PlaceType>>& map)
inline bool HaveView(int viewRange, int x, int y, int newX, int newY, THUAI6::PlaceType myPlace, THUAI6::PlaceType newPlace, std::vector<std::vector<THUAI6::PlaceType>>& 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<protobuf::GameState, THUAI6::GameState> gameStateDict{
@@ -128,6 +144,15 @@ namespace Proto2THUAI6
{protobuf::GameState::GAME_END, THUAI6::GameState::GameEnd},
};

inline std::map<protobuf::BulletType, THUAI6::BulletType> 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<THUAI6::Tricker> Protobuf2THUAI6Tricker(const protobuf::MessageOfTricker& trickerMsg)
{
@@ -211,6 +236,32 @@ namespace Proto2THUAI6
return map;
}

inline std::shared_ptr<THUAI6::Bullet> Protobuf2THUAI6Bullet(const protobuf::MessageOfBullet& bulletMsg)
{
auto bullet = std::make_shared<THUAI6::Bullet>();
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<THUAI6::BombedBullet> Protobuf2THUAI6BombedBullet(const protobuf::MessageOfBombedBullet& bombedBulletMsg)
{
auto bombedBullet = std::make_shared<THUAI6::BombedBullet>();
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


+ 12
- 2
CAPI/API/src/logic.cpp View File

@@ -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)
{
{


Loading…
Cancel
Save