From e50fd3f1817c11b4aae510083a91173f16e4c6f9 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 5 Jul 2019 15:54:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A4=8D=E6=B4=BB=E7=9A=84?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/human.h | 1 + server/gameserver/metadata.cc | 35 ++++++---- server/gameserver/metadata.h | 1 + server/gameserver/room.cc | 87 ++++++++++++++++++++----- server/gameserver/room.h | 2 + server/tools/protobuild/metatable.proto | 1 + 6 files changed, 96 insertions(+), 31 deletions(-) diff --git a/server/gameserver/human.h b/server/gameserver/human.h index a012254..b7810f6 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -48,6 +48,7 @@ class Human : public Entity MetaData::Skill* skill_meta = nullptr; MetaData::Tank* skin_jlf_meta = nullptr; HumanAbility buff; + int born_point = 0; a8::Vec2 move_dir; a8::Vec2 attack_dir; diff --git a/server/gameserver/metadata.cc b/server/gameserver/metadata.cc index 6ff910a..b3ebd8a 100644 --- a/server/gameserver/metadata.cc +++ b/server/gameserver/metadata.cc @@ -314,19 +314,28 @@ namespace MetaData void MapTplThing::Init() { - rand_space = 0; - std::vector strings; - a8::Split(i->things(), strings, '\n'); - for (auto& str : strings) { - std::vector strings2; - a8::Split(str, strings2, ':'); - assert(strings2.size() == 2); - rand_space += a8::XValue(strings2[1]).GetInt(); - things.push_back(std::make_tuple( - a8::XValue(strings2[0]), - rand_space - ) - ); + { + rand_space = 0; + std::vector strings; + a8::Split(i->things(), strings, '\n'); + for (auto& str : strings) { + std::vector strings2; + a8::Split(str, strings2, ':'); + assert(strings2.size() == 2); + rand_space += a8::XValue(strings2[1]).GetInt(); + things.push_back(std::make_tuple( + a8::XValue(strings2[0]), + rand_space + ) + ); + } + } + { + std::vector strings; + a8::Split(i->born_angle(), strings, '\n'); + for (auto& str : strings) { + born_angle.push_back(a8::XValue(str).GetDouble()); + } } } diff --git a/server/gameserver/metadata.h b/server/gameserver/metadata.h index 1ddb43d..52bdb83 100755 --- a/server/gameserver/metadata.h +++ b/server/gameserver/metadata.h @@ -117,6 +117,7 @@ namespace MetaData int RandThing(); std::vector> things; + std::vector born_angle; int rand_space = 0; }; diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 259753b..4dc0946 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -36,10 +36,6 @@ Room::~Room() void Room::Init() { - born_points_ = MetaMgr::Instance()->GetMapBornPoints(map_tpl_name); - if (!born_points_ || born_points_->size() != ROOM_MAX_PLAYER_NUM) { - abort(); - } xtimer.Init(RoomXGetTickCount, this, 100, 100); xtimer_attacher.xtimer = &xtimer; grid_service.Init(MAP_WIDTH, MAP_HEIGHT, MAP_CELL_WIDTH * 8); @@ -57,6 +53,10 @@ void Room::Init() }, &xtimer_attacher.timer_list_); } + born_points_ = MetaMgr::Instance()->GetMapBornPoints(map_tpl_name); + if (!born_points_ || born_points_->size() != ROOM_MAX_PLAYER_NUM) { + abort(); + } ShuaAndroid(); } @@ -154,18 +154,29 @@ int Room::AliveCount() void Room::AddPlayer(Player* hum) { assert(gas_data.gas_mode == GasInactive); - { - hum->pos.x = 200 + rand() % 100; - hum->pos.y = 300 + rand() % 200; - hum->attack_dir = hum->pos; - hum->attack_dir.Normalize(); - hum->attack_dir.Rotate(a8::RandAngle()); - hum->move_dir = hum->attack_dir; + while (human_hash_.size() + 1 > ROOM_MAX_PLAYER_NUM) { + RandRemoveAndroid(); } hum->entity_uniid = AllocUniid(); + hum->born_point = AllocBornPoint(); + { + const MetaData::MapTplThing& thing_tpl = (*born_points_)[hum->born_point]; + hum->pos.x = thing_tpl.i->x(); + hum->pos.y = thing_tpl.i->y(); + hum->attack_dir = a8::Vec2::UP; + hum->attack_dir.Normalize(); + if (!thing_tpl.born_angle.empty()){ + float angle = thing_tpl.born_angle[rand() % thing_tpl.born_angle.size()]; + hum->attack_dir.Rotate(angle / 180.0f); + } else { + hum->attack_dir.Rotate(a8::RandAngle()); + } + hum->move_dir = hum->attack_dir; + } hum->room = this; hum->join_frameno = frame_no; hum->Initialize(); + born_point_human_hash_[hum->born_point] = hum; uniid_hash_[hum->entity_uniid] = hum; moveable_hash_[hum->entity_uniid] = hum; accountid_hash_[hum->account_id] = hum; @@ -175,9 +186,6 @@ void Room::AddPlayer(Player* hum) hum->FindLocation(); hum->RefreshView(); MatchTeam(hum); - while (human_hash_.size() > ROOM_MAX_PLAYER_NUM) { - RandRemoveAndroid(); - } NotifyUiUpdate(); } @@ -251,16 +259,24 @@ void Room::CreateAndroid(int robot_num) hum->meta = hum_meta; hum->robot_meta = robot_meta; hum->entity_uniid = AllocUniid(); + hum->born_point = AllocBornPoint(); { - hum->pos.x = 200 + rand() % 500; - hum->pos.y = 300 + rand() % 300; - hum->attack_dir = hum->pos; + const MetaData::MapTplThing& thing_tpl = (*born_points_)[hum->born_point]; + hum->pos.x = thing_tpl.i->x(); + hum->pos.y = thing_tpl.i->y(); + hum->attack_dir = a8::Vec2::UP; hum->attack_dir.Normalize(); - hum->attack_dir.Rotate(a8::RandAngle()); + if (!thing_tpl.born_angle.empty()){ + float angle = thing_tpl.born_angle[rand() % thing_tpl.born_angle.size()]; + hum->attack_dir.Rotate(angle / 180.0f); + } else { + hum->attack_dir.Rotate(a8::RandAngle()); + } hum->move_dir = hum->attack_dir; } hum->room = this; hum->Initialize(); + born_point_human_hash_[hum->born_point] = hum; uniid_hash_[hum->entity_uniid] = hum; moveable_hash_[hum->entity_uniid] = hum; human_hash_[hum->entity_uniid] = hum; @@ -627,6 +643,20 @@ void Room::OnHumanDie(Human* hum) void Room::OnHumanRevive(Human* hum) { + { + const MetaData::MapTplThing& thing_tpl = (*born_points_)[hum->born_point]; + hum->pos.x = thing_tpl.i->x(); + hum->pos.y = thing_tpl.i->y(); + hum->attack_dir = a8::Vec2::UP; + hum->attack_dir.Normalize(); + if (!thing_tpl.born_angle.empty()){ + float angle = thing_tpl.born_angle[rand() % thing_tpl.born_angle.size()]; + hum->attack_dir.Rotate(angle / 180.0f); + } else { + hum->attack_dir.Rotate(a8::RandAngle()); + } + hum->move_dir = hum->attack_dir; + } ++alive_count_; NotifyUiUpdate(); } @@ -954,6 +984,7 @@ void Room::RandRemoveAndroid() } cell->human_list.erase(hum); } + born_point_human_hash_.erase(hum->born_point); moveable_hash_.erase(hum->entity_uniid); uniid_hash_.erase(hum->entity_uniid); human_hash_.erase(hum->entity_uniid); @@ -1043,3 +1074,23 @@ void Room::BattleReport() game_over_frameno = frame_no; RoomMgr::Instance()->AddOverRoom(room_uuid); } + +int Room::AllocBornPoint() +{ + std::set points; + for (int i = 0; i < ROOM_MAX_PLAYER_NUM; ++i) { + points.insert(i); + } + for (auto& pair : born_point_human_hash_) { + points.erase(pair.first); + } + if (points.empty()) { + abort(); + return -1; + } + std::vector point_vec; + for (int point : points) { + point_vec.push_back(point); + } + return point_vec[rand() % point_vec.size()]; +} diff --git a/server/gameserver/room.h b/server/gameserver/room.h index 5ab6504..67a4468 100644 --- a/server/gameserver/room.h +++ b/server/gameserver/room.h @@ -108,6 +108,7 @@ private: void NotifyUiUpdate(); void NotifyWxVoip(); void BattleReport(); + int AllocBornPoint(); private: int elapsed_time_ = 0; @@ -117,6 +118,7 @@ private: int current_teamid = 0; int current_uniid = 0; + std::map born_point_human_hash_; std::vector* born_points_ = nullptr; xtimer_list* battle_report_timer_ = nullptr; diff --git a/server/tools/protobuild/metatable.proto b/server/tools/protobuild/metatable.proto index 90ca4a7..6007ef0 100755 --- a/server/tools/protobuild/metatable.proto +++ b/server/tools/protobuild/metatable.proto @@ -232,4 +232,5 @@ message MapTplThingJson optional float x = 5; optional float y = 6; optional int32 is_born_point = 7; + optional string born_angle = 8; } \ No newline at end of file