This commit is contained in:
aozhiwei 2019-07-25 21:01:48 +08:00
parent 5703d51dc6
commit c054a7008b
2 changed files with 0 additions and 105 deletions

View File

@ -105,9 +105,6 @@ void Room::Init(const cs::CMJoin& msg)
if (!born_points_ || born_points_->size() != kROOM_MAX_PLAYER_NUM) {
abort();
}
#if 0
ShuaAndroid();
#endif
}
void Room::UnInit()
@ -269,106 +266,6 @@ int Room::AllocUniid()
return current_uniid;
}
void Room::ShuaAndroid()
{
if (gas_data.gas_mode != kGasInactive) {
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);
if (robot_num > 0 && refresh_time > 0) {
CreateAndroid(robot_num);
xtimer.AddDeadLineTimerAndAttach(kSERVER_FRAME_RATE * refresh_time,
a8::XParams()
.SetSender(this),
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
room->ShuaAndroid();
},
&xtimer_attacher.timer_list_);
NotifyUiUpdate();
}
}
void Room::CreateAndroid(int robot_num)
{
std::vector<MetaData::Robot>* robot_list = MetaMgr::Instance()->GetRobotList();
if (!robot_list || robot_list->empty()) {
return;
}
MetaData::Player* hum_meta = MetaMgr::Instance()->GetPlayer(40002);
assert(hum_meta);
if (!hum_meta) {
abort();
}
for (int i = 0; i < robot_num; ++i) {
if (human_hash_.size() >= kROOM_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;
}
}
Android* hum = new Android();
hum->name = robot_meta->i->name();
hum->SetMeta(hum_meta);
#if 0
hum->robot_meta = robot_meta;
#endif
hum->entity_uniid = AllocUniid();
hum->born_point = AllocBornPoint();
{
const MetaData::MapTplThing& thing_tpl = (*born_points_)[hum->born_point];
hum->pos.x = thing_tpl.i->x();
hum->pos.y = thing_tpl.i->y();
hum->attack_dir = a8::Vec2::UP;
hum->attack_dir.Normalize();
if (!thing_tpl.born_angle.empty()){
float angle = thing_tpl.born_angle[rand() % thing_tpl.born_angle.size()];
hum->attack_dir.Rotate(angle / 180.0f);
} else {
hum->attack_dir.Rotate(a8::RandAngle());
}
hum->move_dir = hum->attack_dir;
}
hum->room = this;
hum->Initialize();
born_point_human_hash_[hum->born_point] = hum;
uniid_hash_[hum->entity_uniid] = hum;
moveable_hash_[hum->entity_uniid] = hum;
human_hash_[hum->entity_uniid] = hum;
++alive_count_;
grid_service.AddHuman(hum);
#if 0
hum->FindLocation();
#endif
hum->RefreshView();
{
hum->team_id = NewTeam();
hum->team_members = &team_hash_[hum->team_id];
hum->team_members->insert(hum);
}
refreshed_robot_set_.insert(robot_meta->i->id());
}
}
Human* Room::FindEnemy(Human* hum)
{
std::vector<Human*> enemys;

View File

@ -116,8 +116,6 @@ public:
private:
int AllocUniid();
void ShuaAndroid();
void CreateAndroid(int android_num);
void UpdateGas();
bool GenSmallCircle(a8::Vec2 big_circle_pos, float big_circle_rad, float small_circle_rad,
a8::Vec2& out_pos);