优化CreateAndroid
This commit is contained in:
parent
dc3e9b9b2b
commit
337648d008
@ -212,6 +212,11 @@ public:
|
||||
METAMGR_READ(level1room_robot_water, 8);
|
||||
METAMGR_READ(level1room_robot_autodie_time, 10);
|
||||
METAMGR_READ(level1room_robot_autodie_distance, 500);
|
||||
|
||||
METAMGR_READ(refresh_robot_min_num, 5);
|
||||
METAMGR_READ(refresh_robot_max_num, 10);
|
||||
METAMGR_READ(refresh_robot_min_time, 5);
|
||||
METAMGR_READ(refresh_robot_max_time, 10);
|
||||
}
|
||||
if (MetaMgr::Instance()->K < 0.01f) {
|
||||
abort();
|
||||
@ -274,6 +279,16 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
if (MetaMgr::Instance()->refresh_robot_min_num >
|
||||
MetaMgr::Instance()->refresh_robot_max_num) {
|
||||
abort();
|
||||
}
|
||||
if (MetaMgr::Instance()->refresh_robot_min_time >
|
||||
MetaMgr::Instance()->refresh_robot_max_time) {
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BindToMetaData()
|
||||
@ -667,13 +682,17 @@ int MetaMgr::GetKillPointParam2(int kill_num)
|
||||
return itr != loader_->killpoint_hash.end() ? itr->second->i->parameter2() : 0;
|
||||
}
|
||||
|
||||
std::vector<MetaData::Robot>* MetaMgr::GetRobotList()
|
||||
MetaData::Robot* MetaMgr::RandRobot(std::set<int>& refreshed_robot_set)
|
||||
{
|
||||
return &loader_->robot_list;
|
||||
}
|
||||
|
||||
MetaData::Robot* MetaMgr::GetRobot(int robot_id)
|
||||
{
|
||||
auto itr = loader_->robot_hash.find(robot_id);
|
||||
return itr != loader_->robot_hash.end() ? itr->second : nullptr;
|
||||
int try_count = 0;
|
||||
while (true) {
|
||||
MetaData::Robot& tmp_robot_meta = loader_->robot_list[rand() % loader_->robot_list.size()];
|
||||
if (refreshed_robot_set.find(tmp_robot_meta.i->id()) == refreshed_robot_set.end()) {
|
||||
return &tmp_robot_meta;
|
||||
}
|
||||
++try_count;
|
||||
if (try_count > 3000) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -44,8 +44,7 @@ class MetaMgr : public a8::Singleton<MetaMgr>
|
||||
int GetRankPointParam2(int rank);
|
||||
int GetKillPointParam1(int kill_num);
|
||||
int GetKillPointParam2(int kill_num);
|
||||
std::vector<MetaData::Robot>* GetRobotList();
|
||||
MetaData::Robot* GetRobot(int robot_id);
|
||||
MetaData::Robot* RandRobot(std::set<int>& refreshed_robot_set);
|
||||
|
||||
int gas_inactive_time = 10;
|
||||
int newbie_gas_inactive_time = 10;
|
||||
@ -101,6 +100,11 @@ class MetaMgr : public a8::Singleton<MetaMgr>
|
||||
int level1room_robot_autodie_time = 0;
|
||||
int level1room_robot_autodie_distance = 0;
|
||||
|
||||
int refresh_robot_min_num = 0;
|
||||
int refresh_robot_max_num = 0;
|
||||
int refresh_robot_min_time = 0;
|
||||
int refresh_robot_max_time = 0;
|
||||
|
||||
int other_fill_interval = 0;
|
||||
float android_attack_range = 0;
|
||||
float android_pursuit_range = 0;
|
||||
|
@ -73,7 +73,6 @@ void Room::UnInit()
|
||||
#ifdef DEBUG
|
||||
UnInitDebugInfo();
|
||||
#endif
|
||||
App::Instance()->perf.alive_count -= alive_count_;
|
||||
timer_attacher.ClearTimerList();
|
||||
xtimer_attacher_.ClearTimerList();
|
||||
for (auto& pair : accountid_hash_) {
|
||||
@ -92,6 +91,7 @@ void Room::UnInit()
|
||||
}
|
||||
removed_robot_hash_.clear();
|
||||
grid_service->ClearRoomData(this);
|
||||
App::Instance()->perf.alive_count -= alive_count_;
|
||||
}
|
||||
|
||||
void Room::Update(int delta_time)
|
||||
@ -148,12 +148,12 @@ int Room::AliveCount()
|
||||
|
||||
void Room::AddPlayer(Player* hum)
|
||||
{
|
||||
assert(gas_data_.gas_mode == GasInactive);
|
||||
if (gas_data_.gas_mode == GasInactive) {
|
||||
abort();
|
||||
}
|
||||
hum->born_point = AllocBornPoint(hum);
|
||||
if (!hum->born_point) {
|
||||
hum->SetPos(a8::Vec2(DEFAULT_BORN_POINT_X + rand() % 100,
|
||||
DEFAULT_BORN_POINT_Y + rand() % 200)
|
||||
);
|
||||
hum->SetPos(GetDefaultBornPoint());
|
||||
} else {
|
||||
hum->SetPos(hum->born_point->RandPoint());
|
||||
}
|
||||
@ -179,17 +179,18 @@ void Room::AddPlayer(Player* hum)
|
||||
notifymsg.set_map_height(map_meta_->i->map_height());
|
||||
GGListener::Instance()->SendToClient(hum->socket_handle, 0, notifymsg);
|
||||
}
|
||||
uniid_hash_[hum->entity_uniid] = hum;
|
||||
moveable_hash_[hum->entity_uniid] = hum;
|
||||
accountid_hash_[hum->account_id] = hum;
|
||||
human_hash_[hum->entity_uniid] = hum;
|
||||
alive_human_hash_[hum->entity_uniid] = hum;
|
||||
AddToEntityHash(hum);
|
||||
AddToMoveableHash(hum);
|
||||
AddToAccountHash(hum);
|
||||
AddToHumanHash(hum);
|
||||
AddToAliveHumanHash(hum);
|
||||
++alive_count_;
|
||||
++App::Instance()->perf.alive_count;
|
||||
MatchTeam(hum);
|
||||
|
||||
grid_service->AddHuman(hum);
|
||||
hum->FindLocation();
|
||||
hum->RefreshView();
|
||||
MatchTeam(hum);
|
||||
if (room_type_ == RT_NewBrid) {
|
||||
if (force_shua_android_times_ < 1) {
|
||||
CreateAndroid(20 + rand() % 10);
|
||||
@ -264,14 +265,13 @@ void Room::ShuaAndroid()
|
||||
if (gas_data_.gas_mode != GasInactive) {
|
||||
return;
|
||||
}
|
||||
int robot_min_num = MetaMgr::Instance()->GetSysParamAsInt("refresh_robot_min_num", 5);
|
||||
int robot_max_num = MetaMgr::Instance()->GetSysParamAsInt("refresh_robot_max_num", 10);
|
||||
int refresh_min_time = MetaMgr::Instance()->GetSysParamAsInt("refresh_robot_min_time", 5);
|
||||
int refresh_max_time = MetaMgr::Instance()->GetSysParamAsInt("refresh_robot_max_time", 10);
|
||||
int robot_num = a8::RandEx(robot_min_num, robot_max_num);
|
||||
int refresh_time = a8::RandEx(refresh_min_time, refresh_max_time);
|
||||
int robot_num = a8::RandEx(MetaMgr::Instance()->refresh_robot_min_num,
|
||||
MetaMgr::Instance()->refresh_robot_max_num);
|
||||
int refresh_time = a8::RandEx(MetaMgr::Instance()->refresh_robot_min_time,
|
||||
MetaMgr::Instance()->refresh_robot_max_time);
|
||||
if (robot_num > 0 && refresh_time > 0) {
|
||||
CreateAndroid(robot_num);
|
||||
NotifyUiUpdate();
|
||||
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * refresh_time,
|
||||
a8::XParams()
|
||||
.SetSender(this),
|
||||
@ -281,7 +281,6 @@ void Room::ShuaAndroid()
|
||||
room->ShuaAndroid();
|
||||
},
|
||||
&xtimer_attacher_.timer_list_);
|
||||
NotifyUiUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@ -312,32 +311,13 @@ void Room::ShowAndroid(Human* target, int num)
|
||||
|
||||
void Room::CreateAndroid(int robot_num)
|
||||
{
|
||||
std::vector<MetaData::Robot>* robot_list = MetaMgr::Instance()->GetRobotList();
|
||||
if (!robot_list || robot_list->empty()) {
|
||||
return;
|
||||
}
|
||||
if (robot_num <= 0) {
|
||||
return;
|
||||
}
|
||||
int rnd_skin_robot_idx = rand() % robot_num;
|
||||
for (int i = 0; i < robot_num; ++i) {
|
||||
if (human_hash_.size() >= ROOM_MAX_PLAYER_NUM) {
|
||||
return;
|
||||
}
|
||||
|
||||
MetaData::Robot* robot_meta = nullptr;
|
||||
int try_count = 0;
|
||||
while (true) {
|
||||
MetaData::Robot& tmp_robot_meta = (*robot_list)[rand() % robot_list->size()];
|
||||
if (refreshed_robot_set_.find(tmp_robot_meta.i->id()) ==
|
||||
refreshed_robot_set_.end()) {
|
||||
robot_meta = &tmp_robot_meta;
|
||||
break;
|
||||
}
|
||||
++try_count;
|
||||
if (try_count > 3000) {
|
||||
return;
|
||||
}
|
||||
MetaData::Robot* robot_meta = MetaMgr::Instance()->RandRobot(refreshed_robot_set_);
|
||||
if (!robot_meta) {
|
||||
abort();
|
||||
}
|
||||
|
||||
Android* hum = new Android();
|
||||
@ -347,9 +327,7 @@ void Room::CreateAndroid(int robot_num)
|
||||
hum->entity_uniid = AllocUniid();
|
||||
hum->born_point = AllocBornPoint(hum);
|
||||
if (!hum->born_point) {
|
||||
hum->SetPos(a8::Vec2(DEFAULT_BORN_POINT_X + rand() % 1400,
|
||||
DEFAULT_BORN_POINT_Y + rand() % 1500)
|
||||
);
|
||||
hum->SetPos(GetDefaultBornPoint());
|
||||
} else {
|
||||
hum->SetPos(hum->born_point->RandPoint());
|
||||
}
|
||||
@ -357,34 +335,20 @@ DEFAULT_BORN_POINT_Y + rand() % 1500)
|
||||
hum->attack_dir.Normalize();
|
||||
hum->attack_dir.Rotate(a8::RandAngle());
|
||||
hum->move_dir = hum->attack_dir;
|
||||
|
||||
hum->room = this;
|
||||
hum->Initialize();
|
||||
if (rnd_skin_robot_idx == i) {
|
||||
MetaData::Dress* skin_meta = MetaMgr::Instance()->RandDress();
|
||||
if (skin_meta) {
|
||||
#if 0
|
||||
hum->skin_meta = skin_meta;
|
||||
hum->SetSkinInfo(skin_meta->i->id());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
uniid_hash_[hum->entity_uniid] = hum;
|
||||
human_hash_[hum->entity_uniid] = hum;
|
||||
AddToEntityHash(hum);
|
||||
AddToHumanHash(hum);
|
||||
MatchTeam(hum);
|
||||
++alive_count_;
|
||||
{
|
||||
hum->team_id = NewTeam();
|
||||
hum->team_members = &team_hash_[hum->team_id];
|
||||
hum->team_members->insert(hum);
|
||||
}
|
||||
++App::Instance()->perf.alive_count;
|
||||
refreshed_robot_set_.insert(robot_meta->i->id());
|
||||
|
||||
if (room_type_ == RT_NewBrid) {
|
||||
a8::SetBitFlag(hum->status, HS_Disable);
|
||||
} else {
|
||||
alive_human_hash_[hum->entity_uniid] = hum;
|
||||
moveable_hash_[hum->entity_uniid] = hum;
|
||||
AddToAliveHumanHash(hum);
|
||||
AddToMoveableHash(hum);
|
||||
grid_service->AddHuman(hum);
|
||||
hum->FindLocation();
|
||||
hum->RefreshView();
|
||||
@ -1021,6 +985,7 @@ bool Room::GenSmallCircle(a8::Vec2 big_circle_pos, float big_circle_rad, float s
|
||||
|
||||
void Room::MatchTeam(Human* hum)
|
||||
{
|
||||
if (!hum->team_uuid.empty()) {
|
||||
for (auto& pair : human_hash_) {
|
||||
if (pair.second != hum) {
|
||||
if (!hum->team_uuid.empty() && pair.second->team_uuid == hum->team_uuid) {
|
||||
@ -1038,6 +1003,7 @@ void Room::MatchTeam(Human* hum)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hum->team_id == 0) {
|
||||
hum->team_id = NewTeam();
|
||||
hum->team_members = &team_hash_[hum->team_id];
|
||||
@ -2431,3 +2397,35 @@ void Room::UnInitDebugInfo()
|
||||
});
|
||||
}
|
||||
#endif
|
||||
|
||||
a8::Vec2 Room::GetDefaultBornPoint()
|
||||
{
|
||||
a8::Vec2 pos = a8::Vec2(DEFAULT_BORN_POINT_X + rand() % 1400,
|
||||
DEFAULT_BORN_POINT_Y + rand() % 1500);
|
||||
return pos;
|
||||
}
|
||||
|
||||
void Room::AddToEntityHash(Entity* entity)
|
||||
{
|
||||
uniid_hash_[entity->entity_uniid] = entity;
|
||||
}
|
||||
|
||||
void Room::AddToHumanHash(Human* hum)
|
||||
{
|
||||
human_hash_[hum->entity_uniid] = hum;
|
||||
}
|
||||
|
||||
void Room::AddToAliveHumanHash(Human* hum)
|
||||
{
|
||||
alive_human_hash_[hum->entity_uniid] = hum;
|
||||
}
|
||||
|
||||
void Room::AddToMoveableHash(MoveableEntity* entity)
|
||||
{
|
||||
moveable_hash_[entity->entity_uniid] = entity;
|
||||
}
|
||||
|
||||
void Room::AddToAccountHash(Player* hum)
|
||||
{
|
||||
accountid_hash_[hum->account_id] = hum;
|
||||
}
|
||||
|
@ -160,6 +160,14 @@ private:
|
||||
void OnHumanGridChg(Human* target);
|
||||
void ShuaGridRound(Human* target);
|
||||
void CheckAliveHuman(Human* hum, std::vector<Human*>& alive_humans);
|
||||
a8::Vec2 GetDefaultBornPoint();
|
||||
|
||||
void AddToEntityHash(Entity* entity);
|
||||
void AddToHumanHash(Human* hum);
|
||||
void AddToAliveHumanHash(Human* hum);
|
||||
void AddToMoveableHash(MoveableEntity* entity);
|
||||
void AddToAccountHash(Player* hum);
|
||||
|
||||
#ifdef DEBUG
|
||||
void InitDebugInfo();
|
||||
void UnInitDebugInfo();
|
||||
|
Loading…
x
Reference in New Issue
Block a user