优化机器人死亡逻辑

This commit is contained in:
aozhiwei 2020-05-28 20:10:38 +08:00
parent 45f95035e5
commit 15dc16633f
2 changed files with 28 additions and 11 deletions

View File

@ -2128,17 +2128,20 @@ void Room::ProcDieAndroid(int die_time, int die_num)
#endif
std::vector<Android*> alive_humans;
alive_humans.reserve(human_hash_.size());
for (auto& pair : human_hash_) {
if (pair.second->IsAndroid() &&
!pair.second->real_dead &&
pair.second->team_uuid.empty() &&
a8::HasBitFlag(pair.second->status, HS_Disable) &&
!HasPlayerInRound(pair.second->GetPos(), VIEW_RANGE))
{
Android* hum = (Android*)pair.second;
alive_humans.push_back(hum);
if (alive_humans.size() > 20) {
break;
{
if (frame_no % 8 < 5) {
for (auto itr = human_hash_.begin(); itr != human_hash_.end(); ++itr) {
CheckAliveHuman(itr->second, alive_humans);
if (alive_humans.size() > 16) {
break;
}
}
} else {
for (auto itr = human_hash_.rbegin(); itr != human_hash_.rend(); ++itr) {
CheckAliveHuman(itr->second, alive_humans);
if (alive_humans.size() > 16) {
break;
}
}
}
}
@ -2398,3 +2401,15 @@ void Room::CheckPartObjects(Human* testa, Human* testb)
}
}
}
void Room::CheckAliveHuman(Human* hum, std::vector<Android*>& alive_humans)
{
if (hum->IsAndroid() &&
!hum->real_dead &&
hum->team_uuid.empty() &&
a8::HasBitFlag(hum->status, HS_Disable) &&
!HasPlayerInRound(hum->GetPos(), VIEW_RANGE)) {
Android* hum = (Android*)hum;
alive_humans.push_back(hum);
}
}

View File

@ -36,6 +36,7 @@ class Player;
class Building;
class Hero;
class AabbCollider;
class Android;
class Room
{
public:
@ -169,6 +170,7 @@ private:
void ProcDisableHuman();
void OnHumanGridChg(Human* target);
void ShuaGridRound(Human* target);
void CheckAliveHuman(Human* hum, std::vector<Android*>& alive_humans);
private:
int elapsed_time_ = 0;