This commit is contained in:
aozhiwei 2023-11-04 21:01:31 +08:00
parent b8661400a9
commit 488f7eada2
2 changed files with 23 additions and 30 deletions

View File

@ -177,9 +177,6 @@ void Room::UnInit()
delete pair.second;
}
removed_robot_hash_.clear();
for (auto& pair : team_hash_) {
delete pair.second;
}
f8::BtMgr::Instance()->BtDestory(room_agent_);
room_agent_ = nullptr;
team_hash_.clear();
@ -1010,7 +1007,7 @@ int Room::GetAliveTeamNum()
void Room::TraverseTeams(std::function<bool (Team*)> cb)
{
for (auto& pair : team_hash_) {
if (!pair.second->IsViewTeam() && !cb(pair.second)) {
if (!pair.second->IsViewTeam() && !cb(pair.second.get())) {
break;
}
}
@ -1177,15 +1174,15 @@ Team* Room::GetAliveTeam()
{
for (auto& pair : team_hash_) {
if (!pair.second->IsViewTeam() && pair.second->HasAliveMember()) {
return pair.second;
return pair.second.get();
}
}
return nullptr;
}
Team* Room::NewTeam()
std::shared_ptr<Team> Room::NewTeam()
{
Team* team = new Team();
auto team = std::make_shared<Team>();
team->room = this;
team->SetTeamId(++current_teamid_);
team_hash_[team->GetTeamId()] = team;
@ -1727,7 +1724,7 @@ void Room::MatchTeam(Human* hum)
if (mt::Param::s().prebattle_combine_team) {
if (!hum->GetTeam() && hum->auto_fill && combineable_team_hash_.size() > 1) {
for (auto& pair : combineable_team_hash_) {
Team* team = pair.second;
auto team = pair.second;
if (team->CanCombine(hum)) {
team->AddMember(hum);
team->AddCombineMemberNum(hum->init_team_member_num);
@ -1739,7 +1736,7 @@ void Room::MatchTeam(Human* hum)
}
if (!hum->GetTeam()) {
Team* new_team = NewTeam();
auto new_team = NewTeam();
new_team->SetInitTeamMemberNum(hum->init_team_member_num);
new_team->SetAutoFill(hum->auto_fill);
new_team->AddMember(hum);
@ -1760,7 +1757,7 @@ void Room::CombineTeam()
int first_team_id = 0;
int total_count = 0;
for (auto& pair : team_hash_) {
Team* team = pair.second;
auto team = pair.second;
if (!team->AllIsRunAway()) {
team->TraverseMembers
(
@ -1850,8 +1847,8 @@ void Room::CombineTeam()
if (pair1.second + pair2.second <= GetMaxTeamNum()) {
int new_team_num = pair1.second + pair2.second;
{
Team* team1 = team_hash_[team_id1];
Team* team2 = team_hash_[team_id2];
std::shared_ptr<Team> team1 = team_hash_[team_id1];
std::shared_ptr<Team> team2 = team_hash_[team_id2];
if (team1->GetMemberNum() + team2->GetMemberNum() > GetMaxTeamNum()) {
f8::UdpLog::Instance()->Warning("team_member > 4 :%d",
{
@ -1859,12 +1856,10 @@ void Room::CombineTeam()
});
}
if (pair1.first == first_team_id || pair1.second >= pair2.second) {
team1->CombineTeam(team2);
delete team2;
team1->CombineTeam(team2.get());
team_hash_.erase(pair2.first);
} else {
team2->CombineTeam(team1);
delete team1;
team2->CombineTeam(team1.get());
team_hash_.erase(pair1.first);
}
}
@ -1925,7 +1920,7 @@ void Room::CombineTeam()
void Room::FillTeam()
{
std::vector<Team*> free_team_list;
std::vector<std::shared_ptr<Team>> free_team_list;
for (auto& pair : team_hash_) {
if (pair.second->IsFreeTeam()) {
free_team_list.push_back(pair.second);
@ -1939,32 +1934,30 @@ void Room::FillTeam()
if (!pair.second->GetTeam()->IsFull()) {
for (int i = pair.second->GetTeam()->GetMemberNum(); i < GetMaxTeamNum(); ++i) {
if (!free_team_list.empty()) {
Team* b_team = free_team_list.at(free_team_list.size() - 1);
pair.second->GetTeam()->CombineTeam(b_team);
std::shared_ptr<Team> b_team = free_team_list.at(free_team_list.size() - 1);
pair.second->GetTeam()->CombineTeam(b_team.get());
free_team_list.erase(free_team_list.begin() + free_team_list.size() - 1);
team_hash_.erase(b_team->GetTeamId());
delete b_team;
}
}
}
}
while (free_team_list.size() > 1) {
Team* a_team = free_team_list[0];
std::shared_ptr<Team> a_team = free_team_list[0];
free_team_list.erase(free_team_list.begin());
for (int i = 1; i < 4; ++i) {
if (!free_team_list.empty()) {
Team* b_team = free_team_list[0];
a_team->CombineTeam(b_team);
std::shared_ptr<Team> b_team = free_team_list.at(0);
a_team->CombineTeam(b_team.get());
free_team_list.erase(free_team_list.begin());
team_hash_.erase(b_team->GetTeamId());
delete b_team;
}
}
}
for (auto& pair : team_hash_) {
pair.second->GenBattleUuid();
if (pair.second->HasPlayer()) {
batch_sync_->AddTeam(pair.second);
batch_sync_->AddTeam(pair.second.get());
}
}
}
@ -3023,7 +3016,7 @@ void Room::AddTeam(class MatchTeam* team)
return;
#endif
}
Team* new_team = NewTeam();
std::shared_ptr<Team> new_team = NewTeam();
{
new_team->SetInitTeamMemberNum(team->GetSlotNum());
#if 0
@ -3404,7 +3397,7 @@ void Room::CreateWorldObjects()
Team* Room::GetTeam(int team_id)
{
auto itr = team_hash_.find(team_id);
return itr != team_hash_.end() ? itr->second : nullptr;
return itr != team_hash_.end() ? itr->second.get() : nullptr;
}
Creature* Room::GetCreatureByUniId(int uniid)

View File

@ -295,7 +295,7 @@ private:
bool GenSmallCircle();
void MatchTeam(Human* hum);
void ShuaPlane();
Team* NewTeam();
std::shared_ptr<Team> NewTeam();
RoomObstacle* InternalCreateObstacle(int id, float x, float y, float z,
std::function<void (Obstacle*)> on_precreate,
std::shared_ptr<a8::Args> init_args = nullptr);
@ -386,8 +386,8 @@ private:
int current_uniid_ = FIXED_OBJECT_MAXID;
std::set<int> refreshed_robot_set_;
std::map<int, Team*> team_hash_;
std::map<int, Team*> combineable_team_hash_;
std::map<int, std::shared_ptr<Team>> team_hash_;
std::map<int, std::shared_ptr<Team>> combineable_team_hash_;
std::map<std::string, Player*> accountid_hash_;
std::map<int, MoveableEntity*> moveable_hash_;
std::map<int, Entity*> uniid_hash_;