You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.hpp 21 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. // 杂项函数
  2. #pragma once
  3. #ifndef UTILS_HPP
  4. #define UTILS_HPP
  5. #include <cstdint>
  6. #include "Message2Clients.pb.h"
  7. #include "Message2Server.pb.h"
  8. #include "MessageType.pb.h"
  9. #include "structures.h"
  10. namespace AssistFunction
  11. {
  12. constexpr int numOfGridPerCell = 100;
  13. [[nodiscard]] constexpr inline int GridToCell(int grid) noexcept
  14. {
  15. return grid / numOfGridPerCell;
  16. }
  17. 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)
  18. {
  19. int deltaX = newX - x;
  20. int deltaY = newY - y;
  21. double distance = deltaX * deltaX + deltaY * deltaY;
  22. if (newPlace == THUAI6::PlaceType::Grass && myPlace != THUAI6::PlaceType::Grass) // 草丛外必不可能看到草丛内
  23. return false;
  24. if (distance < viewRange * viewRange)
  25. {
  26. int divide = std::max(std::abs(deltaX), std::abs(deltaY)) / 100;
  27. double dx = deltaX / divide;
  28. double dy = deltaY / divide;
  29. double myX = double(x);
  30. double myY = double(y);
  31. if (newPlace == THUAI6::PlaceType::Grass && myPlace == THUAI6::PlaceType::Grass) // 都在草丛内,要另作判断
  32. for (int i = 0; i < divide; i++)
  33. {
  34. myX += dx;
  35. myY += dy;
  36. if (map[GridToCell(myX)][GridToCell(myY)] != THUAI6::PlaceType::Grass)
  37. return false;
  38. }
  39. else // 不在草丛内,只需要没有墙即可
  40. for (int i = 0; i < divide; i++)
  41. {
  42. myX += dx;
  43. myY += dy;
  44. if (map[GridToCell(myX)][GridToCell(myY)] == THUAI6::PlaceType::Wall)
  45. return false;
  46. }
  47. return true;
  48. }
  49. else
  50. return false;
  51. }
  52. } // namespace AssistFunction
  53. // 辅助函数,用于将proto信息转换为THUAI6信息
  54. namespace Proto2THUAI6
  55. {
  56. // 用于将Protobuf中的枚举转换为THUAI6的枚举
  57. inline std::map<protobuf::PlaceType, THUAI6::PlaceType> placeTypeDict{
  58. {protobuf::PlaceType::NULL_PLACE_TYPE, THUAI6::PlaceType::NullPlaceType},
  59. {protobuf::PlaceType::LAND, THUAI6::PlaceType::Land},
  60. {protobuf::PlaceType::WALL, THUAI6::PlaceType::Wall},
  61. {protobuf::PlaceType::GRASS, THUAI6::PlaceType::Grass},
  62. {protobuf::PlaceType::CLASSROOM, THUAI6::PlaceType::ClassRoom},
  63. {protobuf::PlaceType::GATE, THUAI6::PlaceType::Gate},
  64. {protobuf::PlaceType::HIDDEN_GATE, THUAI6::PlaceType::HiddenGate},
  65. {protobuf::PlaceType::WINDOW, THUAI6::PlaceType::Window},
  66. {protobuf::PlaceType::DOOR, THUAI6::PlaceType::Door},
  67. {protobuf::PlaceType::CHEST, THUAI6::PlaceType::Chest},
  68. };
  69. inline std::map<protobuf::ShapeType, THUAI6::ShapeType> shapeTypeDict{
  70. {protobuf::ShapeType::NULL_SHAPE_TYPE, THUAI6::ShapeType::NullShapeType},
  71. {protobuf::ShapeType::CIRCLE, THUAI6::ShapeType::Circle},
  72. {protobuf::ShapeType::SQUARE, THUAI6::ShapeType::Square},
  73. };
  74. inline std::map<protobuf::PropType, THUAI6::PropType> propTypeDict{
  75. {protobuf::PropType::NULL_PROP_TYPE, THUAI6::PropType::NullPropType},
  76. {protobuf::PropType::PTYPE1, THUAI6::PropType::PropType1},
  77. {protobuf::PropType::PTYPE2, THUAI6::PropType::PropType2},
  78. {protobuf::PropType::PTYPE3, THUAI6::PropType::PropType3},
  79. {protobuf::PropType::PTYPE4, THUAI6::PropType::PropType4},
  80. };
  81. inline std::map<protobuf::PlayerType, THUAI6::PlayerType> playerTypeDict{
  82. {protobuf::PlayerType::NULL_PLAYER_TYPE, THUAI6::PlayerType::NullPlayerType},
  83. {protobuf::PlayerType::STUDENT_PLAYER, THUAI6::PlayerType::StudentPlayer},
  84. {protobuf::PlayerType::TRICKER_PLAYER, THUAI6::PlayerType::TrickerPlayer},
  85. };
  86. inline std::map<protobuf::StudentType, THUAI6::StudentType> studentTypeDict{
  87. {protobuf::StudentType::NULL_STUDENT_TYPE, THUAI6::StudentType::NullStudentType},
  88. {protobuf::StudentType::STUDENTTYPE1, THUAI6::StudentType::StudentType1},
  89. {protobuf::StudentType::STUDENTTYPE2, THUAI6::StudentType::StudentType2},
  90. {protobuf::StudentType::STUDENTTYPE3, THUAI6::StudentType::StudentType3},
  91. {protobuf::StudentType::STUDENTTYPE4, THUAI6::StudentType::StudentType4},
  92. };
  93. inline std::map<protobuf::TrickerType, THUAI6::TrickerType> trickerTypeDict{
  94. {protobuf::TrickerType::NULL_TRICKER_TYPE, THUAI6::TrickerType::NullTrickerType},
  95. {protobuf::TrickerType::TRICKERTYPE1, THUAI6::TrickerType::TrickerType1},
  96. {protobuf::TrickerType::TRICKERTYPE2, THUAI6::TrickerType::TrickerType2},
  97. {protobuf::TrickerType::TRICKERTYPE3, THUAI6::TrickerType::TrickerType3},
  98. {protobuf::TrickerType::TRICKERTYPE4, THUAI6::TrickerType::TrickerType4},
  99. };
  100. inline std::map<protobuf::StudentBuffType, THUAI6::StudentBuffType> studentBuffTypeDict{
  101. {protobuf::StudentBuffType::NULL_SBUFF_TYPE, THUAI6::StudentBuffType::NullStudentBuffType},
  102. {protobuf::StudentBuffType::SBUFFTYPE1, THUAI6::StudentBuffType::StudentBuffType1},
  103. {protobuf::StudentBuffType::SBUFFTYPE2, THUAI6::StudentBuffType::StudentBuffType2},
  104. {protobuf::StudentBuffType::SBUFFTYPE3, THUAI6::StudentBuffType::StudentBuffType3},
  105. {protobuf::StudentBuffType::SBUFFTYPE4, THUAI6::StudentBuffType::StudentBuffType4},
  106. };
  107. inline std::map<protobuf::TrickerBuffType, THUAI6::TrickerBuffType> trickerBuffTypeDict{
  108. {protobuf::TrickerBuffType::NULL_TBUFF_TYPE, THUAI6::TrickerBuffType::NullTrickerBuffType},
  109. {protobuf::TrickerBuffType::TBUFFTYPE1, THUAI6::TrickerBuffType::TrickerBuffType1},
  110. {protobuf::TrickerBuffType::TBUFFTYPE2, THUAI6::TrickerBuffType::TrickerBuffType2},
  111. {protobuf::TrickerBuffType::TBUFFTYPE3, THUAI6::TrickerBuffType::TrickerBuffType3},
  112. {protobuf::TrickerBuffType::TBUFFTYPE4, THUAI6::TrickerBuffType::TrickerBuffType4},
  113. };
  114. inline std::map<protobuf::PlayerState, THUAI6::PlayerState> playerStateDict{
  115. {protobuf::PlayerState::NULL_STATUS, THUAI6::PlayerState::NullState},
  116. {protobuf::PlayerState::IDLE, THUAI6::PlayerState::Idle},
  117. {protobuf::PlayerState::LEARNING, THUAI6::PlayerState::Learning},
  118. {protobuf::PlayerState::ADDICTED, THUAI6::PlayerState::Addicted},
  119. {protobuf::PlayerState::QUIT, THUAI6::PlayerState::Quit},
  120. {protobuf::PlayerState::GRADUATED, THUAI6::PlayerState::Graduated},
  121. {protobuf::PlayerState::RESCUED, THUAI6::PlayerState::Rescued},
  122. {protobuf::PlayerState::TREATED, THUAI6::PlayerState::Treated},
  123. {protobuf::PlayerState::STUNNED, THUAI6::PlayerState::Stunned},
  124. {protobuf::PlayerState::RESCUING, THUAI6::PlayerState::Rescuing},
  125. {protobuf::PlayerState::TREATING, THUAI6::PlayerState::Treating},
  126. };
  127. inline std::map<protobuf::GameState, THUAI6::GameState> gameStateDict{
  128. {protobuf::GameState::NULL_GAME_STATE, THUAI6::GameState::NullGameState},
  129. {protobuf::GameState::GAME_START, THUAI6::GameState::GameStart},
  130. {protobuf::GameState::GAME_RUNNING, THUAI6::GameState::GameRunning},
  131. {protobuf::GameState::GAME_END, THUAI6::GameState::GameEnd},
  132. };
  133. inline std::map<protobuf::BulletType, THUAI6::BulletType> bulletTypeDict{
  134. {protobuf::BulletType::NULL_BULLET_TYPE, THUAI6::BulletType::NullBulletType},
  135. {protobuf::BulletType::COMMON_BULLET, THUAI6::BulletType::CommonBullet},
  136. {protobuf::BulletType::FAST_BULLET, THUAI6::BulletType::FastBullet},
  137. {protobuf::BulletType::LINE_BULLET, THUAI6::BulletType::LineBullet},
  138. {protobuf::BulletType::ORDINARY_BULLET, THUAI6::BulletType::OrdinaryBullet},
  139. {protobuf::BulletType::ATOM_BOMB, THUAI6::BulletType::AtomBomb},
  140. };
  141. inline std::map<protobuf::MessageOfObj::MessageOfObjCase, THUAI6::MessageOfObj> messageOfObjDict{
  142. {protobuf::MessageOfObj::MessageOfObjCase::kStudentMessage, THUAI6::MessageOfObj::StudentMessage},
  143. {protobuf::MessageOfObj::MessageOfObjCase::kTrickerMessage, THUAI6::MessageOfObj::TrickerMessage},
  144. {protobuf::MessageOfObj::MessageOfObjCase::kPropMessage, THUAI6::MessageOfObj::PropMessage},
  145. {protobuf::MessageOfObj::MessageOfObjCase::kBulletMessage, THUAI6::MessageOfObj::BulletMessage},
  146. {protobuf::MessageOfObj::MessageOfObjCase::kBombedBulletMessage, THUAI6::MessageOfObj::BombedBulletMessage},
  147. {protobuf::MessageOfObj::MessageOfObjCase::kClassroomMessage, THUAI6::MessageOfObj::ClassroomMessage},
  148. {protobuf::MessageOfObj::MessageOfObjCase::kDoorMessage, THUAI6::MessageOfObj::DoorMessage},
  149. {protobuf::MessageOfObj::MessageOfObjCase::kGateMessage, THUAI6::MessageOfObj::GateMessage},
  150. {protobuf::MessageOfObj::MessageOfObjCase::kChestMessage, THUAI6::MessageOfObj::ChestMessage},
  151. {protobuf::MessageOfObj::MessageOfObjCase::MESSAGE_OF_OBJ_NOT_SET, THUAI6::MessageOfObj::NullMessageOfObj},
  152. };
  153. // 用于将Protobuf中的类转换为THUAI6的类
  154. inline std::shared_ptr<THUAI6::Tricker> Protobuf2THUAI6Tricker(const protobuf::MessageOfTricker& trickerMsg)
  155. {
  156. auto tricker = std::make_shared<THUAI6::Tricker>();
  157. tricker->x = trickerMsg.x();
  158. tricker->y = trickerMsg.y();
  159. tricker->speed = trickerMsg.speed();
  160. tricker->damage = trickerMsg.damage();
  161. for (int i = 0; i < trickerMsg.time_until_skill_available().size(); i++)
  162. tricker->timeUntilSkillAvailable.push_back(trickerMsg.time_until_skill_available(i));
  163. tricker->place = placeTypeDict[trickerMsg.place()];
  164. tricker->playerState = playerStateDict[trickerMsg.player_state()];
  165. for (int i = 0; i < trickerMsg.prop().size(); i++)
  166. tricker->props.push_back(propTypeDict[trickerMsg.prop(i)]);
  167. tricker->trickerType = trickerTypeDict[trickerMsg.tricker_type()];
  168. tricker->guid = trickerMsg.guid();
  169. tricker->playerID = trickerMsg.player_id();
  170. tricker->viewRange = trickerMsg.view_range();
  171. tricker->radius = trickerMsg.radius();
  172. tricker->buff.clear();
  173. for (int i = 0; i < trickerMsg.buff().size(); i++)
  174. tricker->buff.push_back(trickerBuffTypeDict[trickerMsg.buff(i)]);
  175. return tricker;
  176. }
  177. inline std::shared_ptr<THUAI6::Student> Protobuf2THUAI6Student(const protobuf::MessageOfStudent& studentMsg)
  178. {
  179. auto student = std::make_shared<THUAI6::Student>();
  180. student->x = studentMsg.x();
  181. student->y = studentMsg.y();
  182. student->speed = studentMsg.speed();
  183. student->viewRange = studentMsg.view_range();
  184. student->playerID = studentMsg.player_id();
  185. student->guid = studentMsg.guid();
  186. student->radius = studentMsg.radius();
  187. for (int i = 0; i < studentMsg.time_until_skill_available().size(); i++)
  188. student->timeUntilSkillAvailable.push_back(studentMsg.time_until_skill_available(i));
  189. student->damage = studentMsg.damage();
  190. student->playerType = THUAI6::PlayerType::StudentPlayer;
  191. for (int i = 0; i < studentMsg.prop().size(); i++)
  192. student->props.push_back(propTypeDict[studentMsg.prop(i)]);
  193. student->place = placeTypeDict[studentMsg.place()];
  194. student->playerState = playerStateDict[studentMsg.state()];
  195. student->determination = studentMsg.determination();
  196. student->addiction = studentMsg.addiction();
  197. student->studentType = studentTypeDict[studentMsg.student_type()];
  198. student->buff.clear();
  199. for (int i = 0; i < studentMsg.buff_size(); i++)
  200. student->buff.push_back(studentBuffTypeDict[studentMsg.buff(i)]);
  201. return student;
  202. }
  203. inline std::shared_ptr<THUAI6::Prop> Protobuf2THUAI6Prop(const protobuf::MessageOfProp& propMsg)
  204. {
  205. auto prop = std::make_shared<THUAI6::Prop>();
  206. prop->x = propMsg.x();
  207. prop->y = propMsg.y();
  208. prop->type = propTypeDict[propMsg.type()];
  209. prop->place = placeTypeDict[propMsg.place()];
  210. prop->guid = propMsg.guid();
  211. prop->size = propMsg.size();
  212. prop->facingDirection = propMsg.facing_direction();
  213. prop->isMoving = propMsg.is_moving();
  214. return prop;
  215. }
  216. inline std::shared_ptr<THUAI6::GameInfo> Protobuf2THUAI6GameInfo(const protobuf::MessageOfAll& allMsg)
  217. {
  218. auto gameInfo = std::make_shared<THUAI6::GameInfo>();
  219. gameInfo->gameTime = allMsg.game_time();
  220. gameInfo->subjectLeft = allMsg.subject_left();
  221. gameInfo->studentGraduated = allMsg.student_graduated();
  222. gameInfo->studentQuited = allMsg.student_quited();
  223. gameInfo->studentScore = allMsg.student_score();
  224. gameInfo->trickerScore = allMsg.tricker_score();
  225. gameInfo->gateOpened = allMsg.gate_opened();
  226. gameInfo->hiddenGateOpened = allMsg.hidden_gate_opened();
  227. gameInfo->hiddenGateRefreshed = allMsg.hidden_gate_refreshed();
  228. return gameInfo;
  229. }
  230. inline std::shared_ptr<THUAI6::Bullet> Protobuf2THUAI6Bullet(const protobuf::MessageOfBullet& bulletMsg)
  231. {
  232. auto bullet = std::make_shared<THUAI6::Bullet>();
  233. bullet->bulletType = bulletTypeDict[bulletMsg.type()];
  234. bullet->x = bulletMsg.x();
  235. bullet->y = bulletMsg.y();
  236. bullet->facingDirection = bulletMsg.facing_direction();
  237. bullet->guid = bulletMsg.guid();
  238. bullet->team = playerTypeDict[bulletMsg.team()];
  239. bullet->place = placeTypeDict[bulletMsg.place()];
  240. bullet->bombRange = bulletMsg.bomb_range();
  241. return bullet;
  242. }
  243. inline std::shared_ptr<THUAI6::BombedBullet> Protobuf2THUAI6BombedBullet(const protobuf::MessageOfBombedBullet& bombedBulletMsg)
  244. {
  245. auto bombedBullet = std::make_shared<THUAI6::BombedBullet>();
  246. bombedBullet->bulletType = bulletTypeDict[bombedBulletMsg.type()];
  247. bombedBullet->x = bombedBulletMsg.x();
  248. bombedBullet->y = bombedBulletMsg.y();
  249. bombedBullet->facingDirection = bombedBulletMsg.facing_direction();
  250. bombedBullet->mappingID = bombedBulletMsg.mapping_id();
  251. bombedBullet->bombRange = bombedBulletMsg.bomb_range();
  252. return bombedBullet;
  253. }
  254. } // namespace Proto2THUAI6
  255. namespace THUAI62Proto
  256. {
  257. // 用于将THUAI6的枚举转换为Protobuf的枚举
  258. inline std::map<THUAI6::PlaceType, protobuf::PlaceType> placeTypeDict{
  259. {THUAI6::PlaceType::NullPlaceType, protobuf::PlaceType::NULL_PLACE_TYPE},
  260. {THUAI6::PlaceType::Land, protobuf::PlaceType::LAND},
  261. {THUAI6::PlaceType::Wall, protobuf::PlaceType::WALL},
  262. {THUAI6::PlaceType::Grass, protobuf::PlaceType::GRASS},
  263. {THUAI6::PlaceType::ClassRoom, protobuf::PlaceType::CLASSROOM},
  264. {THUAI6::PlaceType::Gate, protobuf::PlaceType::GATE},
  265. {THUAI6::PlaceType::HiddenGate, protobuf::PlaceType::HIDDEN_GATE},
  266. {THUAI6::PlaceType::Door, protobuf::PlaceType::DOOR},
  267. {THUAI6::PlaceType::Window, protobuf::PlaceType::WINDOW},
  268. };
  269. inline std::map<THUAI6::ShapeType, protobuf::ShapeType> shapeTypeDict{
  270. {THUAI6::ShapeType::NullShapeType, protobuf::ShapeType::NULL_SHAPE_TYPE},
  271. {THUAI6::ShapeType::Circle, protobuf::ShapeType::CIRCLE},
  272. {THUAI6::ShapeType::Square, protobuf::ShapeType::SQUARE},
  273. };
  274. inline std::map<THUAI6::PropType, protobuf::PropType> propTypeDict{
  275. {THUAI6::PropType::NullPropType, protobuf::PropType::NULL_PROP_TYPE},
  276. {THUAI6::PropType::PropType1, protobuf::PropType::PTYPE1},
  277. {THUAI6::PropType::PropType2, protobuf::PropType::PTYPE2},
  278. {THUAI6::PropType::PropType3, protobuf::PropType::PTYPE3},
  279. {THUAI6::PropType::PropType4, protobuf::PropType::PTYPE4},
  280. };
  281. inline std::map<THUAI6::PlayerType, protobuf::PlayerType> playerTypeDict{
  282. {THUAI6::PlayerType::NullPlayerType, protobuf::PlayerType::NULL_PLAYER_TYPE},
  283. {THUAI6::PlayerType::StudentPlayer, protobuf::PlayerType::STUDENT_PLAYER},
  284. {THUAI6::PlayerType::TrickerPlayer, protobuf::PlayerType::TRICKER_PLAYER},
  285. };
  286. inline std::map<THUAI6::StudentType, protobuf::StudentType> studentTypeDict{
  287. {THUAI6::StudentType::NullStudentType, protobuf::StudentType::NULL_STUDENT_TYPE},
  288. {THUAI6::StudentType::StudentType1, protobuf::StudentType::STUDENTTYPE1},
  289. {THUAI6::StudentType::StudentType2, protobuf::StudentType::STUDENTTYPE2},
  290. {THUAI6::StudentType::StudentType3, protobuf::StudentType::STUDENTTYPE3},
  291. {THUAI6::StudentType::StudentType4, protobuf::StudentType::STUDENTTYPE4},
  292. };
  293. inline std::map<THUAI6::StudentBuffType, protobuf::StudentBuffType> studentBuffTypeDict{
  294. {THUAI6::StudentBuffType::NullStudentBuffType, protobuf::StudentBuffType::NULL_SBUFF_TYPE},
  295. {THUAI6::StudentBuffType::StudentBuffType1, protobuf::StudentBuffType::SBUFFTYPE1},
  296. {THUAI6::StudentBuffType::StudentBuffType2, protobuf::StudentBuffType::SBUFFTYPE2},
  297. {THUAI6::StudentBuffType::StudentBuffType3, protobuf::StudentBuffType::SBUFFTYPE3},
  298. {THUAI6::StudentBuffType::StudentBuffType4, protobuf::StudentBuffType::SBUFFTYPE4},
  299. };
  300. inline std::map<THUAI6::TrickerType, protobuf::TrickerType> trickerTypeDict{
  301. {THUAI6::TrickerType::NullTrickerType, protobuf::TrickerType::NULL_TRICKER_TYPE},
  302. {THUAI6::TrickerType::TrickerType1, protobuf::TrickerType::TRICKERTYPE1},
  303. {THUAI6::TrickerType::TrickerType2, protobuf::TrickerType::TRICKERTYPE2},
  304. {THUAI6::TrickerType::TrickerType3, protobuf::TrickerType::TRICKERTYPE3},
  305. {THUAI6::TrickerType::TrickerType4, protobuf::TrickerType::TRICKERTYPE4},
  306. };
  307. inline std::map<THUAI6::TrickerBuffType, protobuf::TrickerBuffType> trickerBuffTypeDict{
  308. {THUAI6::TrickerBuffType::NullTrickerBuffType, protobuf::TrickerBuffType::NULL_TBUFF_TYPE},
  309. {THUAI6::TrickerBuffType::TrickerBuffType1, protobuf::TrickerBuffType::TBUFFTYPE1},
  310. {THUAI6::TrickerBuffType::TrickerBuffType2, protobuf::TrickerBuffType::TBUFFTYPE2},
  311. {THUAI6::TrickerBuffType::TrickerBuffType3, protobuf::TrickerBuffType::TBUFFTYPE3},
  312. {THUAI6::TrickerBuffType::TrickerBuffType4, protobuf::TrickerBuffType::TBUFFTYPE4},
  313. };
  314. // 用于将THUAI6的类转换为Protobuf的消息
  315. inline protobuf::PlayerMsg THUAI62ProtobufPlayer(int64_t playerID, THUAI6::PlayerType playerType, THUAI6::StudentType studentType, THUAI6::TrickerType trickerType)
  316. {
  317. protobuf::PlayerMsg playerMsg;
  318. playerMsg.set_player_id(playerID);
  319. playerMsg.set_player_type(playerTypeDict[playerType]);
  320. if (playerType == THUAI6::PlayerType::StudentPlayer)
  321. {
  322. playerMsg.set_student_type(studentTypeDict[studentType]);
  323. }
  324. else if (playerType == THUAI6::PlayerType::TrickerPlayer)
  325. {
  326. playerMsg.set_tricker_type(trickerTypeDict[trickerType]);
  327. }
  328. return playerMsg;
  329. }
  330. inline protobuf::IDMsg THUAI62ProtobufID(int playerID)
  331. {
  332. protobuf::IDMsg idMsg;
  333. idMsg.set_player_id(playerID);
  334. return idMsg;
  335. }
  336. inline protobuf::MoveMsg THUAI62ProtobufMove(int64_t time, double angle, int64_t id)
  337. {
  338. protobuf::MoveMsg moveMsg;
  339. moveMsg.set_time_in_milliseconds(time);
  340. moveMsg.set_angle(angle);
  341. moveMsg.set_player_id(id);
  342. return moveMsg;
  343. }
  344. inline protobuf::PropMsg THUAI62ProtobufProp(THUAI6::PropType prop, int64_t id)
  345. {
  346. protobuf::PropMsg pickMsg;
  347. pickMsg.set_prop_type(propTypeDict[prop]);
  348. pickMsg.set_player_id(id);
  349. return pickMsg;
  350. }
  351. inline protobuf::SendMsg THUAI62ProtobufSend(std::string msg, int64_t toID, int64_t id)
  352. {
  353. protobuf::SendMsg sendMsg;
  354. sendMsg.set_message(msg);
  355. sendMsg.set_to_player_id(toID);
  356. sendMsg.set_player_id(id);
  357. return sendMsg;
  358. }
  359. inline protobuf::AttackMsg THUAI62ProtobufAttack(double angle, int64_t id)
  360. {
  361. protobuf::AttackMsg attackMsg;
  362. attackMsg.set_angle(angle);
  363. attackMsg.set_player_id(id);
  364. return attackMsg;
  365. }
  366. inline protobuf::SkillMsg THUAI62ProtobufSkill(int32_t skillID, int64_t id)
  367. {
  368. protobuf::SkillMsg skillMsg;
  369. skillMsg.set_skill_id(skillID);
  370. skillMsg.set_player_id(id);
  371. return skillMsg;
  372. }
  373. } // namespace THUAI62Proto
  374. namespace Time
  375. {
  376. inline double TimeSinceStart(const std::chrono::system_clock::time_point& sp)
  377. {
  378. std::chrono::system_clock::time_point tp = std::chrono::system_clock::now();
  379. std::chrono::duration<double, std::milli> time_span = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(tp - sp);
  380. return time_span.count();
  381. }
  382. } // namespace Time
  383. #endif