修复随机出生点问题

This commit is contained in:
aozhiwei 2020-04-07 16:14:57 +08:00
parent dd9f855163
commit 95150f6cfe
2 changed files with 20 additions and 2 deletions

View File

@ -113,7 +113,7 @@ class Human : public Entity
std::set<Human*> kill_humans; std::set<Human*> kill_humans;
Human* last_tank_attacker = nullptr; Human* last_tank_attacker = nullptr;
long long last_tank_attack_idx = 0; long long last_tank_attack_idx = 0;
const BornPoint* born_point = nullptr; BornPoint* born_point = nullptr;
bool shot_start = false; bool shot_start = false;
bool shot_hold = false; bool shot_hold = false;

View File

@ -1500,6 +1500,9 @@ void Room::RandRemoveAndroid()
if (hum->team_id != 0) { if (hum->team_id != 0) {
team_hash_.erase(hum->team_id); team_hash_.erase(hum->team_id);
} }
if (hum->born_point) {
--hum->born_point->android_num;
}
for (auto& cell : hum->grid_list) { for (auto& cell : hum->grid_list) {
for (Human* target : cell->human_list) { for (Human* target : cell->human_list) {
target->AddOutObjects(hum); target->AddOutObjects(hum);
@ -1601,12 +1604,27 @@ BornPoint* Room::AllocBornPoint(Human* hum)
{ {
if (hum->born_point) { if (hum->born_point) {
std::vector<BornPoint*> point_list; std::vector<BornPoint*> point_list;
std::vector<BornPoint*> free_point_list;
BornPoint* pre_point = nullptr;
for (auto& pair : born_point_hash_) { for (auto& pair : born_point_hash_) {
if (&pair.second != hum->born_point) { if (&pair.second != hum->born_point) {
point_list.push_back(&pair.second); point_list.push_back(&pair.second);
if (pair.second.player_num + pair.second.android_num <
pair.second.thing_tpl->i->param1()) {
free_point_list.push_back(&pair.second);;
}
} else {
pre_point = &pair.second;
} }
} }
return !point_list.empty() ? point_list[rand() % point_list.size()] : nullptr; if (pre_point) {
--pre_point->player_num;
}
if (!free_point_list.empty()) {
return free_point_list[rand() % free_point_list.size()];
} else {
return !point_list.empty() ? point_list[rand() % point_list.size()] : nullptr;
}
} }
BornPoint* born_point = nullptr; BornPoint* born_point = nullptr;
for (auto& pair : born_point_hash_) { for (auto& pair : born_point_hash_) {