添加机器人数量
This commit is contained in:
parent
75e494b0f7
commit
f70fe3c598
@ -26,7 +26,7 @@ const int ROOM_MAX_PLAYER_NUM = 50;
|
||||
#if 0
|
||||
const int ANDROID_NUM = 0;
|
||||
#else
|
||||
const int ANDROID_NUM = 10;
|
||||
const int ANDROID_NUM = 49;
|
||||
#endif
|
||||
|
||||
static long long RoomXGetTickCount(void* context)
|
||||
@ -123,11 +123,6 @@ void Room::Update(int delta_time)
|
||||
}
|
||||
}
|
||||
|
||||
bool Room::IsFull()
|
||||
{
|
||||
return accountid_hash_.size() >= ROOM_MAX_PLAYER_NUM;
|
||||
}
|
||||
|
||||
int Room::GetPlayerNum()
|
||||
{
|
||||
return accountid_hash_.size();
|
||||
@ -158,6 +153,7 @@ 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;
|
||||
@ -179,6 +175,7 @@ void Room::AddPlayer(Player* hum)
|
||||
hum->FindLocation();
|
||||
hum->RefreshView();
|
||||
MatchTeam(hum);
|
||||
RandRemoveAndroid();
|
||||
}
|
||||
|
||||
unsigned short Room::AllocUniid()
|
||||
@ -526,6 +523,12 @@ void Room::RemoveObjectLater(Entity* entity)
|
||||
entity->room->grid_service.DelEntity(entity);
|
||||
}
|
||||
break;
|
||||
case ET_Player:
|
||||
{
|
||||
entity->room->moveable_hash_.erase(entity->entity_uniid);
|
||||
entity->room->human_hash_.erase(entity->entity_uniid);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
abort();
|
||||
@ -638,6 +641,14 @@ int Room::GetAliveTeamNum()
|
||||
return num;
|
||||
}
|
||||
|
||||
bool Room::CanJoin(const std::string& accountid)
|
||||
{
|
||||
if (gas_data.gas_mode != GasInactive) {
|
||||
return false;
|
||||
}
|
||||
return accountid_hash_.size() < ROOM_MAX_PLAYER_NUM;
|
||||
}
|
||||
|
||||
std::set<Human*>* Room::GetAliveTeam()
|
||||
{
|
||||
for (auto& pair : team_hash_) {
|
||||
@ -1117,3 +1128,30 @@ void Room::OnGameOver()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Room::RandRemoveAndroid()
|
||||
{
|
||||
Human* hum = nullptr;
|
||||
for (auto& pair : human_hash_) {
|
||||
if (pair.second->entity_subtype == EST_Android) {
|
||||
hum = pair.second;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hum) {
|
||||
if (hum->team_id != 0) {
|
||||
team_hash_.erase(hum->team_id);
|
||||
}
|
||||
for (auto& cell : hum->grid_list) {
|
||||
for (Human* target : cell->human_list) {
|
||||
target->AddOutObjects(hum);
|
||||
}
|
||||
cell->human_list.erase(hum);
|
||||
}
|
||||
moveable_hash_.erase(hum->entity_uniid);
|
||||
uniid_hash_.erase(hum->entity_uniid);
|
||||
human_hash_.erase(hum->entity_uniid);
|
||||
removed_robot_hash_[hum->entity_uniid] = hum;
|
||||
--alive_count_;
|
||||
}
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ public:
|
||||
void Init();
|
||||
void UnInit();
|
||||
void Update(int delta_time);
|
||||
bool IsFull();
|
||||
int GetPlayerNum();
|
||||
int AliveCount();
|
||||
Player* GetPlayerByAccountId(const std::string& accountid);
|
||||
@ -88,6 +87,7 @@ public:
|
||||
bool BattleStarted();
|
||||
int GetAliveTeamNum();
|
||||
std::set<Human*>* GetAliveTeam();
|
||||
bool CanJoin(const std::string& accountid);
|
||||
|
||||
private:
|
||||
unsigned short AllocUniid();
|
||||
@ -109,6 +109,7 @@ private:
|
||||
std::function<void (Obstacle*)> on_precreate);
|
||||
void AddObjectLater(Entity* entity);
|
||||
void OnGameOver();
|
||||
void RandRemoveAndroid();
|
||||
|
||||
private:
|
||||
timer_list* stats_timer_ = nullptr;
|
||||
@ -127,4 +128,6 @@ private:
|
||||
std::map<unsigned short, Entity*> uniid_hash_;
|
||||
std::map<unsigned short, Entity*> later_add_hash_;
|
||||
std::map<unsigned short, Human*> human_hash_;
|
||||
|
||||
std::map<unsigned short, Human*> removed_robot_hash_;
|
||||
};
|
||||
|
@ -106,7 +106,7 @@ int RoomMgr::RoomNum()
|
||||
Room* RoomMgr::GetJoinableRoom(const std::string& account_id)
|
||||
{
|
||||
for (auto& pair : inactive_room_hash_) {
|
||||
if (!pair.second->IsFull() && !pair.second->GetPlayerByAccountId(account_id)) {
|
||||
if (pair.second->CanJoin(account_id)) {
|
||||
return pair.second;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user