From ffa7f0982a7b4b22a3fc641f9346dfd662562b8c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 9 Sep 2019 18:00:45 +0800 Subject: [PATCH] 1 --- server/gameserver/constant.h | 3 +++ server/gameserver/human.h | 1 + server/gameserver/room.cc | 41 ++++++++++++++++++++++++------------ server/gameserver/room.h | 2 ++ server/gameserver/types.cc | 6 ++++++ server/gameserver/types.h | 12 +++++++++++ 6 files changed, 51 insertions(+), 14 deletions(-) diff --git a/server/gameserver/constant.h b/server/gameserver/constant.h index 10d7458..35dc211 100755 --- a/server/gameserver/constant.h +++ b/server/gameserver/constant.h @@ -206,3 +206,6 @@ const int MAX_TEAM_NUM = 4; const int MAX_SYS_HTTP_NUM = 2; const int MAX_USER_HTTP_NUM = 8; const int MAX_ALL_HTTP_NUM = MAX_SYS_HTTP_NUM + MAX_USER_HTTP_NUM; + +const int DEFAULT_BORN_POINT_X = 3000; +const int DEFAULT_BORN_POINT_Y = 3000; diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 9f7e8e2..73abc10 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -116,6 +116,7 @@ class Human : public Entity std::set kill_humans; Human* last_tank_attacker = nullptr; long long last_tank_attack_idx = 0; + const BornPoint* born_point = nullptr; bool shot_start = false; bool shot_hold = false; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 091e5fe..b9d8c67 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -166,14 +166,18 @@ int Room::AliveCount() void Room::AddPlayer(Player* hum) { assert(gas_data.gas_mode == GasInactive); - { - hum->pos.x = 3000 + rand() % 100; - hum->pos.y = 3000 + rand() % 200; - hum->attack_dir = hum->pos; - hum->attack_dir.Normalize(); - hum->attack_dir.Rotate(a8::RandAngle()); - hum->move_dir = hum->attack_dir; + hum->born_point = AllocBornPoint(); + if (!hum->born_point) { + hum->pos.x = DEFAULT_BORN_POINT_X + rand() % 100; + hum->pos.y = DEFAULT_BORN_POINT_Y + rand() % 200; + } else { + hum->pos = hum->born_point->RandPoint(); } + hum->attack_dir = hum->pos; + hum->attack_dir.Normalize(); + hum->attack_dir.Rotate(a8::RandAngle()); + hum->move_dir = hum->attack_dir; + hum->entity_uniid = AllocUniid(); hum->room = this; hum->join_frameno = frame_no; @@ -264,14 +268,18 @@ void Room::CreateAndroid(int robot_num) hum->meta = hum_meta; hum->robot_meta = robot_meta; hum->entity_uniid = AllocUniid(); - { - hum->pos.x = 3000 + rand() % 1400; - hum->pos.y = 3000 + rand() % 1500; - hum->attack_dir = hum->pos; - hum->attack_dir.Normalize(); - hum->attack_dir.Rotate(a8::RandAngle()); - hum->move_dir = hum->attack_dir; + hum->born_point = AllocBornPoint(); + if (!hum->born_point) { + hum->pos.x = DEFAULT_BORN_POINT_X + rand() % 1400; + hum->pos.y = DEFAULT_BORN_POINT_Y + rand() % 1500; + } else { + hum->pos = hum->born_point->RandPoint(); } + hum->attack_dir = hum->pos; + hum->attack_dir.Normalize(); + hum->attack_dir.Rotate(a8::RandAngle()); + hum->move_dir = hum->attack_dir; + hum->room = this; hum->Initialize(); uniid_hash_[hum->entity_uniid] = hum; @@ -1474,3 +1482,8 @@ void Room::NotifyWxVoip() }, &xtimer_attacher.timer_list_); } + +BornPoint* Room::AllocBornPoint() +{ + return nullptr; +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index ff107d8..6f6313f 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -120,6 +120,7 @@ private: void OnGameOver(); void RandRemoveAndroid(); void NotifyWxVoip(); + BornPoint* AllocBornPoint(); private: int elapsed_time_ = 0; @@ -138,6 +139,7 @@ private: std::map uniid_hash_; std::map later_add_hash_; std::map human_hash_; + std::map born_point_hash_; std::map car_hash_; std::map removed_robot_hash_; diff --git a/server/gameserver/types.cc b/server/gameserver/types.cc index 9bca8ed..a2251ff 100644 --- a/server/gameserver/types.cc +++ b/server/gameserver/types.cc @@ -30,3 +30,9 @@ void Skin::ToPB(cs::MFSkin* pb_obj) pb_obj->set_skin_id(skin_id); pb_obj->set_skin_lv(skin_lv); } + +a8::Vec2 BornPoint::RandPoint() const +{ + a8::Vec2 born_point = pos; + return born_point; +} diff --git a/server/gameserver/types.h b/server/gameserver/types.h index e3a317c..6428d41 100755 --- a/server/gameserver/types.h +++ b/server/gameserver/types.h @@ -118,3 +118,15 @@ struct CarObject a8::Vec2 pos; bool taken = false; }; + +struct BornPoint +{ + int born_point_id = 0; + a8::Vec2 pos; + float rad = 0.0f; + + int player_num = 0; + int android_num = 0; + + a8::Vec2 RandPoint() const; +};