完成room重构

This commit is contained in:
aozhiwei 2020-05-29 15:37:20 +08:00
parent 6520fa4697
commit 7df7164307
16 changed files with 244 additions and 191 deletions

View File

@ -111,7 +111,7 @@ void AndroidAI::DoMove()
int speed = std::max(1, (int)hum->GetSpeed());
if (a8::HasBitFlag(hum->status, HS_NewBieNpc) &&
hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 8) {
hum->move_dir = hum->room->first_newbie->GetPos() - hum->GetPos();
hum->move_dir = hum->room->GetFirstNewBie()->GetPos() - hum->GetPos();
hum->move_dir.Normalize();
}
for (int i = 0; i < speed; ++i) {
@ -158,7 +158,7 @@ void AndroidAI::UpdateNewBieNpc()
{
Human* hum = (Human*)owner;
if (hum->room->GetFrameNo() - hum->enable_frameno < 2) {
hum->move_dir = hum->room->first_newbie->GetPos() - hum->GetPos();
hum->move_dir = hum->room->GetFirstNewBie()->GetPos() - hum->GetPos();
hum->move_dir.Normalize();
hum->attack_dir = hum->move_dir;
if (hum->curr_weapon->weapon_idx != 0) {
@ -179,7 +179,7 @@ void AndroidAI::UpdateNewBieNpc()
hum->room->grid_service->MoveHuman(hum);
}
} else if (hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 3) {
Human* enemy = hum->room->first_newbie;
Human* enemy = hum->room->GetFirstNewBie();
Human* sender = hum;
a8::Vec2 shot_dir = enemy->GetPos() - sender->GetPos();
if (std::abs(shot_dir.x) > FLT_EPSILON ||

View File

@ -110,7 +110,7 @@ void Bullet::ProcBomb()
self_collider_->rad = gun_meta->i->explosion_range();
std::set<Entity*> objects;
for (auto& grid : grid_list) {
for (Human* hum: grid->human_list[room->room_idx]) {
for (Human* hum: grid->human_list[room->GetRoomIdx()]) {
if (!is_tank_skin || player->team_id != hum->team_id) {
//友军火箭筒伤害取消
if ((meta->i->_inventory_slot() == 4 ||
@ -139,7 +139,7 @@ void Bullet::ProcBomb()
break;
}
}
for (Entity* entity : grid->entity_list[room->room_idx]) {
for (Entity* entity : grid->entity_list[room->GetRoomIdx()]) {
switch (entity->entity_type) {
case ET_Obstacle:
case ET_Building:
@ -207,7 +207,7 @@ void Bullet::MapServiceUpdate()
room->grid_service->MoveBullet(this);
std::set<Entity*> objects;
for (auto& grid : grid_list) {
for (Human* hum: grid->human_list[room->room_idx]) {
for (Human* hum: grid->human_list[room->GetRoomIdx()]) {
if (hum != player && !hum->dead && TestCollision(room, hum)) {
objects.insert(hum);
}

View File

@ -95,7 +95,7 @@ void Entity::BroadcastFullState(Room* room)
std::set<GridCell*> grid_list;
room->grid_service->GetAllCells(room, grid_id, grid_list);
for (auto& grid : grid_list) {
for (Human* hum : grid->human_list[room->room_idx]) {
for (Human* hum : grid->human_list[room->GetRoomIdx()]) {
hum->AddToNewObjects(this);
}
}
@ -106,7 +106,7 @@ void Entity::BroadcastDeleteState(Room* room)
std::set<GridCell*> grid_list;
room->grid_service->GetAllCells(room, grid_id, grid_list);
for (auto& grid : grid_list) {
for (Human* hum : grid->human_list[room->room_idx]) {
for (Human* hum : grid->human_list[room->GetRoomIdx()]) {
hum->RemoveObjects(this);
}
}

View File

@ -30,7 +30,7 @@ void FrameEvent::AddEmote(Human* sender, int emote_id)
{
int emote_idx = emotes_.size() - 1;
for (auto& cell : sender->grid_list) {
for (auto& hum : cell->human_list[sender->room->room_idx]) {
for (auto& hum : cell->human_list[sender->room->GetRoomIdx()]) {
hum->emotes_.push_back(emote_idx);
}
}
@ -56,7 +56,7 @@ void FrameEvent::AddShot(Human* sender)
{
int shot_idx = shots_.size() - 1;
for (auto& cell : sender->grid_list) {
for (auto& hum : cell->human_list[sender->room->room_idx]) {
for (auto& hum : cell->human_list[sender->room->GetRoomIdx()]) {
hum->shots_.push_back(shot_idx);
}
}
@ -91,7 +91,7 @@ void FrameEvent::AddBullet(Human* sender, a8::Vec2 born_pos, a8::Vec2 dir, float
{
int bullet_idx = bullets_.size() - 1;
for (auto& cell : sender->grid_list) {
for (auto& hum : cell->human_list[sender->room->room_idx]) {
for (auto& hum : cell->human_list[sender->room->GetRoomIdx()]) {
hum->bullets_.push_back(bullet_idx);
}
}
@ -112,7 +112,7 @@ void FrameEvent::AddExplosion(Bullet* bullet, int item_id, a8::Vec2 bomb_pos)
{
int explosion_idx = explosions_.size() - 1;
for (auto& cell : bullet->player->grid_list) {
for (auto& hum : cell->human_list[bullet->room->room_idx]){
for (auto& hum : cell->human_list[bullet->room->GetRoomIdx()]){
hum->explosions_.push_back(explosion_idx);
}
}
@ -134,7 +134,7 @@ void FrameEvent::AddExplosionEx(Human* sender, int item_id, a8::Vec2 bomb_pos, i
{
int explosion_idx = explosions_.size() - 1;
for (auto& cell : sender->grid_list) {
for (auto& hum : cell->human_list[sender->room->room_idx]) {
for (auto& hum : cell->human_list[sender->room->GetRoomIdx()]) {
hum->explosions_.push_back(explosion_idx);
}
}
@ -183,7 +183,7 @@ void FrameEvent::AddSmoke(Bullet* bullet, int item_id, a8::Vec2 pos)
{
int idx = smokes_.size() - 1;
for (auto& cell : bullet->player->grid_list) {
for (auto& hum : cell->human_list[bullet->room->room_idx]) {
for (auto& hum : cell->human_list[bullet->room->GetRoomIdx()]) {
hum->smokes_.push_back(idx);
}
}
@ -195,7 +195,7 @@ void FrameEvent::AddHpChg(Human* sender)
chged_hps_.push_back(sender);
int idx = chged_hps_.size() - 1;
for (auto& cell : sender->grid_list) {
for (auto& hum : cell->human_list[sender->room->room_idx]) {
for (auto& hum : cell->human_list[sender->room->GetRoomIdx()]) {
hum->chged_hps_.push_back(idx);
}
}
@ -213,7 +213,7 @@ void FrameEvent::AddBuff(Human* sender, Buff* buff)
{
int idx = chged_buffs_.size() - 1;
for (auto& cell : sender->grid_list) {
for (auto& hum : cell->human_list[sender->room->room_idx]) {
for (auto& hum : cell->human_list[sender->room->GetRoomIdx()]) {
hum->chged_buffs_.push_back(idx);
}
}
@ -232,7 +232,7 @@ void FrameEvent::RemoveBuff(Human* sender, int buff_id)
{
int idx = chged_buffs_.size() - 1;
for (auto& cell : sender->grid_list) {
for (auto& hum : cell->human_list[sender->room->room_idx]) {
for (auto& hum : cell->human_list[sender->room->GetRoomIdx()]) {
hum->chged_buffs_.push_back(idx);
}
}

View File

@ -23,7 +23,7 @@ void GameLog::GameStart(Player* hum)
prop->SetVal("account_id", hum->account_id);
prop->SetVal("account_register_utctime", hum->account_registertime);
prop->SetVal("account_register_date", a8::TimestampToDateTime(hum->account_registertime));
prop->SetVal("game_uniid", a8::XValue(hum->room->room_uuid).GetString());
prop->SetVal("game_uniid", a8::XValue(hum->room->GetRoomUuid()).GetString());
//prop->SetVal("game_param", "");
prop->SetVal("nickname", hum->name);
//prop->SetVal("localuuid", "");
@ -32,9 +32,9 @@ void GameLog::GameStart(Player* hum)
prop->SetVal("server_node_id", App::Instance()->node_id);
prop->SetVal("server_instance_id", App::Instance()->instance_id);
prop->SetVal("map_id", hum->room->map_meta->i->map_id());
prop->SetVal("map_name", hum->room->map_meta->i->map_name());
prop->SetVal("map_tpl_name", hum->room->map_tpl_name);
prop->SetVal("map_id", hum->room->GetMapMeta()->i->map_id());
prop->SetVal("map_name", hum->room->GetMapMeta()->i->map_name());
prop->SetVal("map_tpl_name", hum->room->GetMapTplName());
f8::TGLog::Instance()->AddTrackLog(game_id, hum->account_id, hum->ip_saddr, logclass1, logclass2, prop);
@ -57,7 +57,7 @@ void GameLog::GameEnd(Player* hum)
prop->SetVal("account_id", hum->account_id);
prop->SetVal("account_register_utctime", hum->account_registertime);
prop->SetVal("account_register_date", a8::TimestampToDateTime(hum->account_registertime));
prop->SetVal("game_uniid", a8::XValue(hum->room->room_uuid).GetString());
prop->SetVal("game_uniid", a8::XValue(hum->room->GetRoomUuid()).GetString());
//prop->SetVal("game_param", "");
prop->SetVal("game_gold", hum->stats.gold);
prop->SetVal("game_score", hum->stats.score);
@ -72,9 +72,9 @@ void GameLog::GameEnd(Player* hum)
prop->SetVal("server_node_id", App::Instance()->node_id);
prop->SetVal("server_instance_id", App::Instance()->instance_id);
prop->SetVal("map_id", hum->room->map_meta->i->map_id());
prop->SetVal("map_name", hum->room->map_meta->i->map_name());
prop->SetVal("map_tpl_name", hum->room->map_tpl_name);
prop->SetVal("map_id", hum->room->GetMapMeta()->i->map_id());
prop->SetVal("map_name", hum->room->GetMapMeta()->i->map_name());
prop->SetVal("map_tpl_name", hum->room->GetMapTplName());
if (!hum->dead) {
prop->SetVal("alive_time", hum->room->GetFrameNo() * 1000.0f / SERVER_FRAME_RATE);
} else {

View File

@ -102,14 +102,14 @@ bool GridService::CanAdd(float x, float y)
void GridService::ClearRoomData(Room* room)
{
if (room->room_idx <= 0) {
if (room->GetRoomIdx() <= 0) {
abort();
}
for (int i = 0; i < (max_grid_id_ + 1); ++i) {
GridCell& cell = cells_[i];
cell.human_list[room->room_idx].clear();
cell.entity_list[room->room_idx].clear();
cell.bullet_list[room->room_idx].clear();
cell.human_list[room->GetRoomIdx()].clear();
cell.entity_list[room->GetRoomIdx()].clear();
cell.bullet_list[room->GetRoomIdx()].clear();
}
}
@ -124,7 +124,7 @@ void GridService::AddHuman(Human* hum)
if (hum->grid_id == 0 || hum->grid_id > max_grid_id_) {
abort();
}
cells_[hum->grid_id].human_list[hum->room->room_idx].insert(hum);
cells_[hum->grid_id].human_list[hum->room->GetRoomIdx()].insert(hum);
GetAllCells(hum->room, hum->grid_id, hum->grid_list);
}
@ -149,8 +149,8 @@ void GridService::MoveHuman(Human* hum)
hum->grid_list,
inc_grid_list,
dec_grid_list);
cells_[hum->grid_id].human_list[hum->room->room_idx].erase(hum);
cells_[new_grid_id].human_list[hum->room->room_idx].insert(hum);
cells_[hum->grid_id].human_list[hum->room->GetRoomIdx()].erase(hum);
cells_[new_grid_id].human_list[hum->room->GetRoomIdx()].insert(hum);
hum->grid_id = new_grid_id;
hum->OnGridListChange(old_grid_list, inc_grid_list, dec_grid_list);
}
@ -167,7 +167,7 @@ void GridService::AddBullet(Bullet* bullet)
if (bullet->grid_id == 0 || bullet->grid_id > max_grid_id_) {
abort();
}
cells_[bullet->grid_id].bullet_list[bullet->room->room_idx].insert(bullet);
cells_[bullet->grid_id].bullet_list[bullet->room->GetRoomIdx()].insert(bullet);
GetAllCells(bullet->room, bullet->grid_id, bullet->grid_list);
}
@ -192,8 +192,8 @@ void GridService::MoveBullet(Bullet* bullet)
bullet->grid_list,
inc_grid_list,
dec_grid_list);
cells_[bullet->grid_id].bullet_list[bullet->room->room_idx].erase(bullet);
cells_[new_grid_id].bullet_list[bullet->room->room_idx].insert(bullet);
cells_[bullet->grid_id].bullet_list[bullet->room->GetRoomIdx()].erase(bullet);
cells_[new_grid_id].bullet_list[bullet->room->GetRoomIdx()].insert(bullet);
bullet->grid_id = new_grid_id;
}
}
@ -201,7 +201,7 @@ void GridService::MoveBullet(Bullet* bullet)
void GridService::DelBullet(Bullet* bullet)
{
GridCell& cell = cells_[bullet->grid_id];
cell.bullet_list[bullet->room->room_idx].erase(bullet);
cell.bullet_list[bullet->room->GetRoomIdx()].erase(bullet);
}
void GridService::AddRoomEntity(Room* room, Entity* entity)
@ -216,13 +216,13 @@ void GridService::AddRoomEntity(Room* room, Entity* entity)
if (entity->grid_id == 0 || entity->grid_id > max_grid_id_) {
abort();
}
cells_[entity->grid_id].entity_list[room->room_idx].insert(entity);
cells_[entity->grid_id].entity_list[room->GetRoomIdx()].insert(entity);
}
void GridService::DelRoomEntity(Room* room, Entity* entity)
{
GridCell& cell = cells_[entity->grid_id];
cell.entity_list[room->room_idx].erase(entity);
cell.entity_list[room->GetRoomIdx()].erase(entity);
}
void GridService::AddPermanentEntity(Entity* entity)
@ -243,8 +243,8 @@ void GridService::AddPermanentEntity(Entity* entity)
bool GridService::HumanInGridList(Human* hum, std::set<GridCell*>& grid_list)
{
for (auto& cell : grid_list) {
if (cell->human_list[hum->room->room_idx].find(hum) !=
cell->human_list[hum->room->room_idx].end()) {
if (cell->human_list[hum->room->GetRoomIdx()].find(hum) !=
cell->human_list[hum->room->GetRoomIdx()].end()) {
return true;
}
}
@ -257,8 +257,8 @@ bool GridService::EntityInGridList(Room* room, Entity* entity, std::set<GridCell
if (cell->entity_list[0].find(entity) != cell->entity_list[0].end()) {
return true;
}
if (cell->entity_list[room->room_idx].find(entity) !=
cell->entity_list[room->room_idx].end()) {
if (cell->entity_list[room->GetRoomIdx()].find(entity) !=
cell->entity_list[room->GetRoomIdx()].end()) {
return true;
}
}

View File

@ -675,7 +675,7 @@ void Human::SyncAroundPlayers(const char* file, int line, const char* func)
});
#endif
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
hum->AddToNewObjects(this);
#ifdef DEBUG
{
@ -842,7 +842,7 @@ void Human::FillSMGameOver(cs::SMGameOver& msg)
msg.set_team_allcnt(1);
msg.set_game_over(room->IsGameOver());
msg.set_victory(!dead);
msg.set_room_uuid(a8::XValue(room->room_uuid));
msg.set_room_uuid(a8::XValue(room->GetRoomUuid()));
cs::MFPlayerStats* p = msg.add_player_stats();
FillMFPlayerStats(p);
@ -1207,7 +1207,7 @@ void Human::FindLocation()
break;
}
}
for (Entity* entity : grid->entity_list[room->room_idx]) {
for (Entity* entity : grid->entity_list[room->GetRoomIdx()]) {
switch (entity->entity_type) {
case ET_Obstacle:
{
@ -1242,7 +1242,7 @@ void Human::FindLocation()
void Human::RefreshView()
{
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
hum->AddToNewObjects(this);
hum->AddToPartObjects(this);
AddToNewObjects(hum);
@ -1263,7 +1263,7 @@ void Human::RefreshView()
break;
}
}
for (Entity* entity : cell->entity_list[room->room_idx]) {
for (Entity* entity : cell->entity_list[room->GetRoomIdx()]) {
switch (entity->entity_type) {
case ET_Building:
case ET_Obstacle:
@ -1287,7 +1287,7 @@ void Human::OnGridListChange(std::set<GridCell*>& old_grid_list,
)
{
for (GridCell* cell : inc_grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
if (!room->grid_service->HumanInGridList(hum, old_grid_list)) {
hum->AddToNewObjects(this);
hum->AddToPartObjects(this);
@ -1315,7 +1315,7 @@ void Human::OnGridListChange(std::set<GridCell*>& old_grid_list,
}
}
}
for (Entity* entity : cell->entity_list[room->room_idx]) {
for (Entity* entity : cell->entity_list[room->GetRoomIdx()]) {
if (!room->grid_service->EntityInGridList(room, entity, old_grid_list)) {
switch (entity->entity_type) {
case ET_Building:
@ -1335,7 +1335,7 @@ void Human::OnGridListChange(std::set<GridCell*>& old_grid_list,
}
}
for (GridCell* cell : dec_grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
if (!room->grid_service->HumanInGridList(hum, grid_list)) {
AddOutObjects(hum);
hum->AddOutObjects(this);
@ -1365,7 +1365,7 @@ void Human::OnGridListChange(std::set<GridCell*>& old_grid_list,
}
}
}
for (Entity* entity : cell->entity_list[room->room_idx]) {
for (Entity* entity : cell->entity_list[room->GetRoomIdx()]) {
if (!room->grid_service->EntityInGridList(room, entity, grid_list)) {
switch (entity->entity_type) {
case ET_Building:
@ -1624,7 +1624,7 @@ void Human::SendUpdateMsg()
FillMFActivePlayerData(msg->mutable_active_player_data());
if (!refreshed_view) {
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
view_objects.insert(hum);
}
for (Entity* entity : cell->entity_list[0]) {
@ -1642,7 +1642,7 @@ void Human::SendUpdateMsg()
break;
}
}
for (Entity* entity : cell->entity_list[room->room_idx]) {
for (Entity* entity : cell->entity_list[room->GetRoomIdx()]) {
switch (entity->entity_type) {
case ET_Building:
case ET_Obstacle:
@ -1899,7 +1899,7 @@ void Human::SendWxVoip()
{
cs::SMWxVoip notifymsg;
if (!team_uuid.empty()) {
notifymsg.set_group_id(a8::XValue(room->room_uuid).GetString() + "_" + a8::XValue(team_id).GetString());
notifymsg.set_group_id(a8::XValue(room->GetRoomUuid()).GetString() + "_" + a8::XValue(team_id).GetString());
}
SendNotifyMsg(notifymsg);
}
@ -1959,7 +1959,7 @@ void Human::CheckSkinTank()
self_collider_->rad = skin_tank_meta->i->rad2();
std::set<Human*> objects;
for (auto& grid : grid_list) {
for (Human* hum: grid->human_list[room->room_idx]) {
for (Human* hum: grid->human_list[room->GetRoomIdx()]) {
if (hum != this &&
!hum->dead &&
!hum->tank_weapon.meta &&
@ -2196,9 +2196,9 @@ void Human::GenBattleReportData(a8::MutableXObject* params)
}
stats.rank = rank;
params->SetVal("account_id", account_id);
params->SetVal("map_id", room->map_meta->i->map_id());
params->SetVal("map_name", room->map_meta->i->map_name());
params->SetVal("map_tpl_name", room->map_tpl_name);
params->SetVal("map_id", room->GetMapMeta()->i->map_id());
params->SetVal("map_name", room->GetMapMeta()->i->map_name());
params->SetVal("map_tpl_name", room->GetMapTplName());
params->SetVal("game_time", time(nullptr));
params->SetVal("hurt", stats.damage_amount_in);
params->SetVal("rank", rank);
@ -2211,7 +2211,7 @@ void Human::GenBattleReportData(a8::MutableXObject* params)
params->SetVal("alive_time", dead_frameno * 1000.0f / SERVER_FRAME_RATE);
}
params->SetVal("team_status", team_members && team_members->size() > 1 ? 1 : 0);
params->SetVal("room_uuid", room->room_uuid);
params->SetVal("room_uuid", room->GetRoomUuid());
int snipe_kill = 0;
int rifle_kill = 0;
@ -2384,7 +2384,7 @@ void Human::SendBattleReport()
params->ToUrlEncodeStr(data);
f8::HttpClientPool::Instance()->HttpGet(
a8::XParams()
.SetSender(room->room_uuid)
.SetSender(room->GetRoomUuid())
.SetParam1(entity_uniid)
.SetParam2(data),
on_ok,
@ -2604,7 +2604,7 @@ void Human::FindLocationWithTarget(Entity* target)
break;
}
}
for (Entity* entity : grid->entity_list[room->room_idx]) {
for (Entity* entity : grid->entity_list[room->GetRoomIdx()]) {
switch (entity->entity_type) {
case ET_Building:
{
@ -3052,7 +3052,7 @@ void Human::DropItems(Obstacle* obstacle)
if (drop_id == 0) {
return;
}
if (room->room_type == RT_NewBrid && IsPlayer()) {
if (room->GetRoomType() == RT_NewBrid && IsPlayer()) {
if (is_treasure_box) {
if (box_drop_times_ < MetaMgr::Instance()->newbie_airdrop.size()) {
drop_id = MetaMgr::Instance()->newbie_airdrop[box_drop_times_];
@ -3162,7 +3162,7 @@ void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& ta
case kST_All:
{
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
if (hum->GetPos().Distance(target_pos) < skill_meta_->i->skill_distance()) {
target_list.insert(hum);
}
@ -3179,7 +3179,7 @@ void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& ta
{
target_list.insert(this);
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
if ((hum == this || hum->team_id == team_id) &&
hum->GetPos().Distance(target_pos) < skill_meta_->i->skill_distance()) {
target_list.insert(hum);
@ -3191,7 +3191,7 @@ void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& ta
case kST_FriendlyExcludeSelf:
{
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
if ((hum != this && hum->team_id == team_id) &&
hum->GetPos().Distance(target_pos) < skill_meta_->i->skill_distance()) {
target_list.insert(hum);
@ -3214,7 +3214,7 @@ void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& ta
case kST_EnemyGroup:
{
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
if ((hum->team_id != team_id) &&
hum->GetPos().Distance(target_pos) < skill_meta_->i->skill_distance()) {
target_list.insert(hum);
@ -3226,7 +3226,7 @@ void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& ta
case kST_EnemyAndObject:
{
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
if ((hum->team_id != team_id) &&
hum->GetPos().Distance(target_pos) < skill_meta_->i->skill_distance()) {
target_list.insert(hum);
@ -3238,7 +3238,7 @@ void Human::SelectSkillTargets(const a8::Vec2& target_pos, std::set<Entity*>& ta
case kST_EnemyAndSelf:
{
for (auto& cell : grid_list) {
for (Human* hum : cell->human_list[room->room_idx]) {
for (Human* hum : cell->human_list[room->GetRoomIdx()]) {
if ((hum == this || hum->team_id != team_id) &&
hum->GetPos().Distance(target_pos) < skill_meta_->i->skill_distance()) {
target_list.insert(hum);
@ -3354,7 +3354,7 @@ void Human::AdjustDecHp(float old_health, float& new_health)
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("触发新手保护buff %d %s %s %f %f",
{
room->room_idx,
room->GetRoomIdx(),
account_id,
name,
old_health,

View File

@ -51,22 +51,23 @@ void MapMgr::UnInit()
A8_SAFE_DELETE(grid_service_);
}
void MapMgr::AttachRoom(Room* room)
void MapMgr::AttachRoom(Room* room, RoomInitInfo& init_info)
{
room->grid_service = grid_service_;
room->map_service = map_service_;
room->spawn_points = &spawn_points_;
room->newbie_born_point_meta = newbie_born_point_;
room->loots = &loots_;
room->buildings = &buildings_;
room->map_meta = map_meta_;
init_info.map_tpl_name = map_tpl_name_;
init_info.map_meta = map_meta_;
init_info.grid_service = grid_service_;
init_info.map_service = map_service_;
init_info.spawn_points = &spawn_points_;
init_info.newbie_born_point_meta = newbie_born_point_;
init_info.loots = &loots_;
init_info.buildings = &buildings_;
}
void MapMgr::CreateThings()
{
std::string map_tpl_name = map_meta_->RandTemplate();
map_tpl_name_ = map_meta_->RandTemplate();
std::map<std::string, MetaData::MapTplThing*> spawn_points_hash;
std::vector<MetaData::MapTplThing>* things = MetaMgr::Instance()->GetMapTplThing(map_tpl_name);
std::vector<MetaData::MapTplThing>* things = MetaMgr::Instance()->GetMapTplThing(map_tpl_name_);
if (things) {
for (auto& thing_tpl : *things) {
switch (thing_tpl.i->_object_type()) {

View File

@ -22,7 +22,7 @@ class MapMgr : public a8::Singleton<MapMgr>
void Init();
void UnInit();
void AttachRoom(Room* room);
void AttachRoom(Room* room, RoomInitInfo& init_info);
private:
void CreateThings();
@ -36,9 +36,11 @@ class MapMgr : public a8::Singleton<MapMgr>
private:
int current_uniid_ = 0;
std::map<int, Entity*> uniid_hash_;
std::string map_tpl_name_;
MetaData::Map* map_meta_ = nullptr;
MapService* map_service_ = nullptr;
GridService* grid_service_ = nullptr;
MetaData::Map* map_meta_ = nullptr;
std::vector<MetaData::MapTplThing*> spawn_points_;
MetaData::MapTplThing* newbie_born_point_ = nullptr;
std::vector<MetaData::MapTplThing*> loots_;

View File

@ -230,7 +230,7 @@ void Obstacle::Explosion(Bullet* bullet)
std::set<GridCell*> grid_list;
room->grid_service->GetAllCellsByXy(room, GetX(), GetY(), grid_list);
for (auto& grid : grid_list) {
for (Human* hum: grid->human_list[room->room_idx]) {
for (Human* hum: grid->human_list[room->GetRoomIdx()]) {
if (TestCollision(room, hum)) {
objects.insert(hum);
}
@ -251,7 +251,7 @@ void Obstacle::Explosion(Bullet* bullet)
break;
}
}//end for
for (Entity* entity : grid->entity_list[room->room_idx]) {
for (Entity* entity : grid->entity_list[room->GetRoomIdx()]) {
switch (entity->entity_type) {
case ET_Obstacle:
case ET_Building:

View File

@ -583,7 +583,7 @@ void Player::LootInteraction(Loot* entity)
need_sync_active_player = true;
SyncAroundPlayers(__FILE__, __LINE__, __func__);
}
if (room->room_type == RT_NewBrid &&
if (room->GetRoomType() == RT_NewBrid &&
!a8::HasBitFlag(status, HS_AlreadyEquip)) {
a8::SetBitFlag(status, HS_AlreadyEquip);
ProcNewBieLogic();

View File

@ -37,6 +37,22 @@ Room::~Room()
}
void Room::InitData(RoomInitInfo& init_info)
{
room_idx_ = init_info.room_idx;
room_uuid_ = init_info.room_uuid;
room_type_ = init_info.room_type;
map_tpl_name_ = init_info.map_tpl_name;
grid_service = init_info.grid_service;
map_service = init_info.map_service;
map_meta_ = init_info.map_meta;
spawn_points_ = init_info.spawn_points;
newbie_born_point_meta_ = init_info.newbie_born_point_meta;
loots_ = init_info.loots;
buildings_ = init_info.buildings;
}
void Room::Init()
{
xtimer.Init(RoomXGetTickCount, this, 100, 100);
@ -158,9 +174,9 @@ void Room::AddPlayer(Player* hum)
}
{
cs::SMMapInfo notifymsg;
notifymsg.set_map_id(map_meta->i->map_id());
notifymsg.set_map_width(map_meta->i->map_width());
notifymsg.set_map_height(map_meta->i->map_height());
notifymsg.set_map_id(map_meta_->i->map_id());
notifymsg.set_map_width(map_meta_->i->map_width());
notifymsg.set_map_height(map_meta_->i->map_height());
GGListener::Instance()->SendToClient(hum->socket_handle, 0, notifymsg);
}
uniid_hash_[hum->entity_uniid] = hum;
@ -174,7 +190,7 @@ void Room::AddPlayer(Player* hum)
hum->FindLocation();
hum->RefreshView();
MatchTeam(hum);
if (room_type == RT_NewBrid) {
if (room_type_ == RT_NewBrid) {
if (force_shua_android_times_ < 1) {
CreateAndroid(20 + rand() % 10);
++force_shua_android_times_;
@ -189,7 +205,7 @@ void Room::AddPlayer(Player* hum)
},
&hum->xtimer_attacher.timer_list_);
}
if (room_type == RT_NewBrid || room_type == RT_MidBrid) {
if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) {
for (int buff_id : MetaMgr::Instance()->newbie_buff_list) {
MetaData::Buff* buff_meta = MetaMgr::Instance()->GetBuff(buff_id);
if (buff_meta) {
@ -198,7 +214,7 @@ void Room::AddPlayer(Player* hum)
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("room_idx:%d 添加新手buff %s %s %d",
{
room_idx,
GetRoomIdx(),
hum->account_id,
hum->name,
buff_id
@ -364,7 +380,7 @@ DEFAULT_BORN_POINT_Y + rand() % 1500)
++App::Instance()->perf.alive_count;
refreshed_robot_set_.insert(robot_meta->i->id());
if (room_type == RT_NewBrid) {
if (room_type_ == RT_NewBrid) {
a8::SetBitFlag(hum->status, HS_Disable);
} else {
alive_human_hash_[hum->entity_uniid] = hum;
@ -380,7 +396,7 @@ Human* Room::FindEnemy(Human* hum)
{
if (a8::HasBitFlag(hum->status, HS_NewBieNpc) &&
GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 8) {
return first_newbie;
return first_newbie_;
}
std::vector<Human*> enemys;
enemys.reserve(50);
@ -389,7 +405,7 @@ Human* Room::FindEnemy(Human* hum)
sub_type = EST_Android;
}
for (auto& cell : hum->grid_list) {
for (Human* target : cell->human_list[room_idx]) {
for (Human* target : cell->human_list[room_idx_]) {
if (target->entity_subtype == sub_type &&
!target->dead) {
if (hum->GetPos().Distance(target->GetPos()) < 300.0f) {
@ -415,7 +431,7 @@ void Room::FillSMJoinedNotify(Player* self_hum, cs::SMJoinedNotify& msg)
msg.set_team_mode(msg.team_mode());
msg.set_player_id(self_hum->entity_uniid);
msg.set_started(false);
msg.set_room_uuid(a8::XValue(room_uuid).GetString());
msg.set_room_uuid(a8::XValue(room_uuid_).GetString());
}
void Room::ScatterDrop(a8::Vec2 center, int drop_id)
@ -478,14 +494,14 @@ int Room::CreateLoot(int equip_id, a8::Vec2 pos, int count, int equip_lv)
entity->SetPos(pos);
#if 1
{
if (entity->GetX() >= map_meta->i->map_width()) {
entity->SetX(map_meta->i->map_width() - 1);
if (entity->GetX() >= map_meta_->i->map_width()) {
entity->SetX(map_meta_->i->map_width() - 1);
}
if (entity->GetX() < 1.0f) {
entity->SetX(1.0f);
}
if (entity->GetY() >= map_meta->i->map_height()) {
entity->SetY(map_meta->i->map_height() - 1);
if (entity->GetY() >= map_meta_->i->map_height()) {
entity->SetY(map_meta_->i->map_height() - 1);
}
if (entity->GetY() < 1.0f) {
entity->SetY(1.0f);
@ -585,14 +601,14 @@ bool Room::OverBorder(const a8::Vec2 pos, float radius)
return true;
}
int right_x = pos.x + radius;
if (right_x > map_meta->i->map_width()) {
if (right_x > map_meta_->i->map_width()) {
return true;
}
}
//检查y轴
{
int up_y = pos.y + radius;
if (up_y > map_meta->i->map_height()) {
if (up_y > map_meta_->i->map_height()) {
return true;
}
int down_y = pos.y - radius;
@ -652,13 +668,13 @@ bool Room::CanJoin(const std::string& accountid, RoomType_e self_room_type)
if (GetPlayerByAccountId(accountid)) {
return false;
}
if (room_type == RT_NewBrid) {
if (room_type != self_room_type || GetPlayerNum() > 0) {
if (room_type_ == RT_NewBrid) {
if (room_type_ != self_room_type || GetPlayerNum() > 0) {
return false;
}
}
if (room_type == RT_MidBrid) {
if (room_type != self_room_type || GetPlayerNum() > 4) {
if (room_type_ == RT_MidBrid) {
if (room_type_ != self_room_type || GetPlayerNum() > 4) {
return false;
}
}
@ -674,7 +690,7 @@ void Room::OnPlayerOffline(Player* hum)
}
}
if (!has_player) {
RoomMgr::Instance()->AddOverRoom(room_uuid);
RoomMgr::Instance()->AddOverRoom(room_uuid_);
}
}
@ -710,7 +726,7 @@ Entity* Room::FindFirstCollisonEntity(const a8::Vec2& aabb_pos, AabbCollider& aa
break;
}
}
for (Entity* entity : grid->entity_list[room_idx]) {
for (Entity* entity : grid->entity_list[room_idx_]) {
switch (entity->entity_type) {
case ET_Obstacle:
{
@ -904,8 +920,8 @@ void Room::UpdateGasInactive()
gas_data_.new_area_meta = MetaMgr::Instance()->GetSafeArea(30002);
gas_data_.gas_progress = gas_data_.old_area_meta->i->rad();
gas_data_.gas_start_frameno = GetFrameNo();
gas_data_.pos_old = a8::Vec2(map_meta->i->map_width() / 2.0f,
map_meta->i->map_height() / 2.0f);
gas_data_.pos_old = a8::Vec2(map_meta_->i->map_width() / 2.0f,
map_meta_->i->map_height() / 2.0f);
gas_data_.pos_old_bk = gas_data_.pos_old;
{
bool gen_ok = GenSmallCircle(gas_data_.pos_old,
@ -924,10 +940,10 @@ void Room::UpdateGasInactive()
CombineTeam();
NotifyGameStart();
NotifyWxVoip();
if (room_type != RT_NewBrid) {
if (room_type_ != RT_NewBrid) {
InitAirDrop();
}
RoomMgr::Instance()->ActiveRoom(room_uuid);
RoomMgr::Instance()->ActiveRoom(room_uuid_);
}
}
@ -1034,11 +1050,11 @@ void Room::CombineTeam()
std::map<int, size_t> need_combine_teams;
std::map<int, size_t> need_combine_teams_copy;
if (room_type == RT_MidBrid) {
if (room_type_ == RT_MidBrid) {
for (auto& pair : accountid_hash_) {
Human* hum = pair.second;
hum->auto_fill = true;
hum->team_uuid = a8::XValue(room_uuid).GetString();
hum->team_uuid = a8::XValue(room_uuid_).GetString();
}
for (size_t i = 0; i < 4 - accountid_hash_.size(); ++i) {
for (auto& pair : human_hash_) {
@ -1046,7 +1062,7 @@ void Room::CombineTeam()
if (hum->IsAndroid() &&
!hum->auto_fill) {
hum->auto_fill = true;
hum->team_uuid = a8::XValue(room_uuid).GetString();
hum->team_uuid = a8::XValue(room_uuid_).GetString();
break;
}
}
@ -1095,7 +1111,7 @@ void Room::CombineTeam()
break;
}
}
if (room_type == RT_MidBrid) {
if (room_type_ == RT_MidBrid) {
first_team_num = 4;
}
@ -1229,14 +1245,14 @@ void Room::AirDrop(int appear_time, int box_id)
if (box_pos.x < 1.0f) {
box_pos.x = 1.0f;
}
if (box_pos.x >= map_meta->i->map_width()) {
box_pos.x = map_meta->i->map_width() - 1;
if (box_pos.x >= map_meta_->i->map_width()) {
box_pos.x = map_meta_->i->map_width() - 1;
}
if (box_pos.y < 1.0f) {
box_pos.y = 1.0f;
}
if (box_pos.y >= map_meta->i->map_height()) {
box_pos.y = map_meta->i->map_height() - 1;
if (box_pos.y >= map_meta_->i->map_height()) {
box_pos.y = map_meta_->i->map_height() - 1;
}
AdjustAirDropPos(thing_meta, box_pos);
AabbCollider air_drop_aabb_box;
@ -1254,9 +1270,9 @@ void Room::AirDrop(int appear_time, int box_id)
box_pos.x = new_x;
box_pos.y = new_y;
}
if (box_pos.x + thing_meta->i->width()/2 + 2 > map_meta->i->map_width() ||
if (box_pos.x + thing_meta->i->width()/2 + 2 > map_meta_->i->map_width() ||
box_pos.x - thing_meta->i->width()/2 - 2 < 1 ||
box_pos.y + thing_meta->i->height()/2 + 2 > map_meta->i->map_height() ||
box_pos.y + thing_meta->i->height()/2 + 2 > map_meta_->i->map_height() ||
box_pos.y - thing_meta->i->height()/2 - 2 < 1
) {
return;
@ -1287,7 +1303,7 @@ void Room::AirDrop(int appear_time, int box_id)
void Room::AdjustAirDropPos(MetaData::MapThing* thing_meta, a8::Vec2& box_pos)
{
if (room_type == RT_NewBrid) {
if (room_type_ == RT_NewBrid) {
if (airdrop_times_ < MetaMgr::Instance()->newbie_airdrop.size()) {
for (auto& pair : accountid_hash_) {
if (pair.second) {
@ -1350,7 +1366,7 @@ void Room::OnGameOver()
pair.second->SendGameOver();
}
}
RoomMgr::Instance()->AddOverRoom(room_uuid);
RoomMgr::Instance()->AddOverRoom(room_uuid_);
}
void Room::RandRemoveAndroid()
@ -1370,10 +1386,10 @@ void Room::RandRemoveAndroid()
--hum->born_point->android_num;
}
for (auto& cell : hum->grid_list) {
for (Human* target : cell->human_list[room_idx]) {
for (Human* target : cell->human_list[room_idx_]) {
target->AddOutObjects(hum);
}
cell->human_list[room_idx].erase(hum);
cell->human_list[room_idx_].erase(hum);
}
moveable_hash_.erase(hum->entity_uniid);
uniid_hash_.erase(hum->entity_uniid);
@ -1527,15 +1543,15 @@ BornPoint* Room::GetBornPoint(int point_uniid)
void Room::CreateSpawnPoints()
{
if (!spawn_points || spawn_points->empty()) {
if (!spawn_points_ || spawn_points_->empty()) {
abort();
}
for (auto& thing_tpl : *spawn_points) {
for (auto& thing_tpl : *spawn_points_) {
int uniid = AllocUniid();
BornPoint born_point;
born_point.thing_tpl = thing_tpl;
born_point_hash_[uniid] = born_point;
if (thing_tpl == newbie_born_point_meta) {
if (thing_tpl == newbie_born_point_meta_) {
newbie_born_point_uniid_ = uniid;
}
}
@ -1543,8 +1559,8 @@ void Room::CreateSpawnPoints()
void Room::CreateLoots()
{
if (loots) {
for (auto& thing_tpl : *loots) {
if (loots_) {
for (auto& thing_tpl : *loots_) {
int thing_id = thing_tpl->RandThing();
MetaData::Equip* equip_meta = MetaMgr::Instance()->GetEquip(thing_id);
if (equip_meta) {
@ -1577,8 +1593,8 @@ void Room::CreateLoots()
void Room::CreateDropObjs()
{
if (buildings) {
for (auto& building : *buildings) {
if (buildings_) {
for (auto& building : *buildings_) {
for (auto& obj : building->meta->i->dropobj()) {
CreateLoot(obj.id(),
a8::Vec2(
@ -1669,7 +1685,7 @@ void Room::SecondRandPoint()
}
}
}
if (room_type == RT_NewBrid) {
if (room_type_ == RT_NewBrid) {
for (auto& pair : accountid_hash_) {
Human* hum = pair.second;
BornPoint* newbie_point = GetBornPoint(newbie_born_point_uniid_);
@ -1693,7 +1709,7 @@ void Room::SecondRandPoint()
CheckPartObjects();
#endif
for (auto& pair : accountid_hash_) {
if (room_type == RT_MidBrid) {
if (room_type_ == RT_MidBrid) {
pair.second->on_grid_chg = std::bind(&Room::OnHumanGridChg, this, std::placeholders::_1);
}
}
@ -1707,8 +1723,8 @@ void Room::NotifyGameStart()
cs::SMGameStart msg;
for (auto& pair : accountid_hash_) {
pair.second->SendNotifyMsg(msg);
if (room_type == RT_NewBrid) {
first_newbie = pair.second;
if (room_type_ == RT_NewBrid) {
first_newbie_ = pair.second;
}
}
xtimer.AddDeadLineTimerAndAttach(SERVER_FRAME_RATE * 1,
@ -1731,7 +1747,7 @@ void Room::NotifyGameStart()
room->waiting_start_ = false;
},
&xtimer_attacher_.timer_list_);
if (room_type == RT_NewBrid) {
if (room_type_ == RT_NewBrid) {
xtimer.AddDeadLineTimerAndAttach
(SERVER_FRAME_RATE * MetaMgr::Instance()->level0room_robot_protect_time,
a8::XParams()
@ -1739,13 +1755,13 @@ void Room::NotifyGameStart()
[] (const a8::XParams& param)
{
Room* room = (Room*)param.sender.GetUserData();
if (room->first_newbie) {
room->first_newbie->ProcNewBieLogic();
if (room->GetFirstNewBie()) {
room->GetFirstNewBie()->ProcNewBieLogic();
}
},
&xtimer_attacher_.timer_list_);
}
if (room_type == RT_MidBrid) {
if (room_type_ == RT_MidBrid) {
xtimer.AddDeadLineTimerAndAttach
(SERVER_FRAME_RATE * MetaMgr::Instance()->level1room_shua_robot_min_time,
a8::XParams()
@ -1779,7 +1795,7 @@ ObstacleData* Room::GetPermanentObstacleData(int entity_uniid)
long long Room::GetGasInactiveTime()
{
if (room_type == RT_NewBrid) {
if (room_type_ == RT_NewBrid) {
return MetaMgr::Instance()->newbie_gas_inactive_time;
} else {
return MetaMgr::Instance()->gas_inactive_time;
@ -1835,7 +1851,7 @@ void Room::DisableHuman(Human* target)
alive_human_hash_.erase(target->entity_uniid);
for (auto& cell : target->grid_list) {
bool has_target = false;
for (Human* hum : cell->human_list[room_idx]) {
for (Human* hum : cell->human_list[room_idx_]) {
if (hum == target) {
has_target = true;
} else {
@ -1843,7 +1859,7 @@ void Room::DisableHuman(Human* target)
}
}
if (has_target) {
cell->human_list[room_idx].erase(target);
cell->human_list[room_idx_].erase(target);
}
}
for (auto& pair : human_hash_) {
@ -1861,7 +1877,7 @@ void Room::ShuaNewBieAndroid(Human* target)
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("room_idx:%d ShuaNewBieAndroid %s %s",
{
room_idx,
GetRoomIdx(),
target->account_id,
target->name
});
@ -1921,7 +1937,7 @@ void Room::ShuaNewBieAndroid(Human* target)
void Room::ShuaAndroidTimerFunc()
{
if (room_type == RT_NewBrid || room_type == RT_MidBrid) {
if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) {
int shua_time = a8::RandEx(
MetaMgr::Instance()->level0room_shua_robot_min_time,
MetaMgr::Instance()->level0room_shua_robot_max_time
@ -1930,7 +1946,7 @@ void Room::ShuaAndroidTimerFunc()
MetaMgr::Instance()->level0room_shua_robot_min_num,
MetaMgr::Instance()->level0room_shua_robot_max_num
);
if (room_type == RT_MidBrid) {
if (room_type_ == RT_MidBrid) {
shua_time = a8::RandEx(
MetaMgr::Instance()->level1room_shua_robot_min_time,
MetaMgr::Instance()->level1room_shua_robot_max_time
@ -1963,7 +1979,7 @@ void Room::ShuaAndroidTimerFunc()
void Room::DieAndroidTimerFunc()
{
if (room_type == RT_NewBrid || room_type == RT_MidBrid) {
if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) {
int die_time = a8::RandEx(
MetaMgr::Instance()->level0room_die_robot_min_time,
MetaMgr::Instance()->level0room_die_robot_max_time
@ -1972,7 +1988,7 @@ void Room::DieAndroidTimerFunc()
MetaMgr::Instance()->level0room_die_robot_min_num,
MetaMgr::Instance()->level0room_die_robot_max_num
);
if (room_type == RT_MidBrid) {
if (room_type_ == RT_MidBrid) {
die_time = a8::RandEx(
MetaMgr::Instance()->level1room_die_robot_min_time,
MetaMgr::Instance()->level1room_die_robot_max_time
@ -2018,13 +2034,13 @@ void Room::ProcShuaAndroid(int shua_time, int shua_num)
int real_shua_num = shua_num;
int autodie_time = 10;
int autodie_distance = 500;
if (room_type == RT_NewBrid) {
if (room_type_ == RT_NewBrid) {
real_shua_num = std::max(0,
MetaMgr::Instance()->level0room_robot_water - RealAliveCount() +
(int)accountid_hash_.size());
autodie_time = MetaMgr::Instance()->level0room_robot_autodie_time;
autodie_distance = MetaMgr::Instance()->level0room_robot_autodie_distance;
} else if (room_type == RT_MidBrid) {
} else if (room_type_ == RT_MidBrid) {
real_shua_num = std::max(0,
MetaMgr::Instance()->level1room_robot_water - RealAliveCount() +
(int)accountid_hash_.size());
@ -2037,7 +2053,7 @@ void Room::ProcShuaAndroid(int shua_time, int shua_num)
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("ProcShuaAndroid room_idx:%d shua_time:%d shua_num%d real_shua_num:%d",
{
room_idx,
GetRoomIdx(),
shua_time,
shua_num,
real_shua_num
@ -2095,7 +2111,7 @@ void Room::ProcDieAndroid(int die_time, int die_num)
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("ProcDieAndroid room_idx:%d die_time:%d die_num:%d",
{
room_idx,
GetRoomIdx(),
die_time,
die_num
});
@ -2189,7 +2205,7 @@ void Room::CheckAutoDie(Human* target,
{
bool nodie = false;
for (auto& grid : target->grid_list) {
for (Human* hum: grid->human_list[room_idx]) {
for (Human* hum: grid->human_list[room_idx_]) {
if (!hum->real_dead &&
hum->entity_uniid != target->entity_uniid &&
hum->IsPlayer()) {
@ -2255,7 +2271,7 @@ bool Room::HasPlayerInRound(const a8::Vec2& pos, float rad)
void Room::ProcDisableHuman()
{
if (room_type == RT_NewBrid || room_type == RT_MidBrid) {
if (room_type_ == RT_NewBrid || room_type_ == RT_MidBrid) {
for (auto& pair : human_hash_) {
if (pair.second->IsAndroid() &&
pair.second->team_uuid.empty() &&
@ -2351,7 +2367,7 @@ void Room::CheckPartObjects(Human* testa, Human* testb)
for (auto& pair1 : human_hash_) {
Human* huma = pair1.second;
for (auto& cell : huma->grid_list) {
for (Human* humb : cell->human_list[room_idx]) {
for (Human* humb : cell->human_list[room_idx_]) {
if (testa && testb) {
if ((huma == testa && humb == testb) ||
(huma == testb && humb == testa)) {
@ -2401,7 +2417,7 @@ void Room::InitDebugInfo()
Room* room = (Room*)param.sender.GetUserData();
a8::UdpLog::Instance()->Debug("room_idx:%d real_alive_count:%d",
{
room->room_idx,
room->GetRoomIdx(),
room->RealAliveCount()
});
});
@ -2411,7 +2427,7 @@ void Room::UnInitDebugInfo()
{
a8::UdpLog::Instance()->Debug("destroy room_idx:%d",
{
room_idx
GetRoomIdx()
});
}
#endif

View File

@ -36,38 +36,37 @@ class Android;
class Room
{
public:
int room_idx = 0;
long long room_uuid = 0;
const MetaData::Map* map_meta = nullptr;
std::string map_tpl_name;
FrameEvent frame_event;
FrameMaker frame_maker;
a8::XTimer xtimer;
a8::TimerAttacher timer_attacher;
GridService* grid_service = nullptr;
MapService* map_service = nullptr;
RoomType_e room_type = RT_NewBrid;
const std::vector<MetaData::MapTplThing*>* spawn_points = nullptr;
const MetaData::MapTplThing* newbie_born_point_meta = nullptr;
const std::vector<MetaData::MapTplThing*>* loots = nullptr;
const std::vector<Building*>* buildings = nullptr;
Human* first_newbie = nullptr;
~Room();
void InitData(RoomInitInfo& init_info);
void Init();
void UnInit();
void Update(int delta_time);
inline long long GetFrameNo() { return frameno_; }
int GetPlayerNum();
int AliveCount();
inline int RealAliveCount() { return alive_human_hash_.size(); }
long long GetBattleStartFrameNo() { return battle_start_frameno_; }
bool IsGameOver() { return game_over_; }
const GasData& GetGasData() { return gas_data_; }
RoomType_e GetRoomType() { return room_type_; }
long long GetRoomUuid() { return room_uuid_; }
int GetRoomIdx() { return room_idx_; }
std::string GetMapTplName() { return map_tpl_name_; }
const MetaData::Map* GetMapMeta() { return map_meta_; }
bool IsWaitingStart() { return waiting_start_; }
int GetPlayerNum();
int AliveCount();
inline int RealAliveCount() { return alive_human_hash_.size(); }
Player* GetPlayerByAccountId(const std::string& accountid);
Player* GetPlayerByUniId(int uniid);
Entity* GetEntityByUniId(int uniid);
Human* GetFirstNewBie() { return first_newbie_; }
void AddPlayer(Player* hum);
Human* FindEnemy(Human* hum);
@ -167,6 +166,17 @@ private:
#endif
private:
int room_idx_ = 0;
long long room_uuid_ = 0;
const MetaData::Map* map_meta_ = nullptr;
std::string map_tpl_name_;
RoomType_e room_type_ = RT_NewBrid;
const std::vector<MetaData::MapTplThing*>* spawn_points_ = nullptr;
const MetaData::MapTplThing* newbie_born_point_meta_ = nullptr;
const std::vector<MetaData::MapTplThing*>* loots_ = nullptr;
const std::vector<Building*>* buildings_ = nullptr;
Human* first_newbie_ = nullptr;
bool waiting_start_ = false;
GasData gas_data_;
long long frameno_ = 0;

View File

@ -123,7 +123,7 @@ Room* RoomMgr::GetJoinableRoom(const cs::CMJoin& msg, const RoomType_e self_room
if (!msg.team_uuid().empty() && room->HaveMyTeam(msg.team_uuid())) {
return room;
}
group_rooms[room->room_type].push_back(room);
group_rooms[room->GetRoomType()].push_back(room);
}
}
@ -163,8 +163,8 @@ void RoomMgr::AddOverRoom(long long room_uuid)
{
Room* room = RoomMgr::Instance()->GetRoomByUuid(param.sender);
if (room) {
RoomMgr::Instance()->room_hash_.erase(room->room_uuid);
RoomMgr::Instance()->over_room_hash_[room->room_uuid] = room;
RoomMgr::Instance()->room_hash_.erase(room->GetRoomUuid());
RoomMgr::Instance()->over_room_hash_[room->GetRoomUuid()] = room;
RoomMgr::Instance()->FreeOverRoom(param.sender);
}
};
@ -258,7 +258,7 @@ void RoomMgr::FreeOverRoom(long long room_uuid)
auto itr = over_room_hash_.find(room_uuid);
if (itr != over_room_hash_.end()) {
itr->second->UnInit();
room_idx_hash_.erase(itr->second->room_idx);
room_idx_hash_.erase(itr->second->GetRoomIdx());
delete itr->second;
over_room_hash_.erase(itr);
}
@ -319,27 +319,31 @@ Room* RoomMgr::CreateRoom(RoomType_e room_type)
if (room_idx < 1) {
return nullptr;
}
RoomInitInfo init_info;
{
init_info.room_idx = room_idx;
init_info.room_uuid = App::Instance()->NewUuid();
init_info.room_type = room_type;
if (GetRoomByUuid(init_info.room_uuid)) {
abort();
}
if (GetRoomByIdx(init_info.room_idx)) {
abort();
}
}
Room* room = new Room();
room->room_type = room_type;
room->room_uuid = App::Instance()->NewUuid();
room->room_idx = room_idx;
MapMgr::Instance()->AttachRoom(room);
if (GetRoomByUuid(room->room_uuid)) {
abort();
}
if (GetRoomByIdx(room->room_idx)) {
abort();
}
room->InitData(init_info);
MapMgr::Instance()->AttachRoom(room, init_info);
room->Init();
inactive_room_hash_[room->room_uuid] = room;
room_hash_[room->room_uuid] = room;
room_idx_hash_[room->room_idx] = room;
inactive_room_hash_[room->GetRoomUuid()] = room;
room_hash_[room->GetRoomUuid()] = room;
room_idx_hash_[room->GetRoomIdx()] = room;
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("createroom room_idx:%d room_uuid:%d room_type:%d",
{
room->room_idx,
room->room_uuid,
room->room_type
room->GetRoomIdx(),
room->GetRoomUuid(),
room->GetRoomType()
});
#endif
return room;

View File

@ -23,7 +23,7 @@ RoomObstacle::~RoomObstacle()
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("OnRemoveCollider %d %d %d",
{
room->room_idx,
room->GetRoomIdx(),
entity_uniid,
(long long)collider
});
@ -72,7 +72,7 @@ void RoomObstacle::RecalcSelfCollider()
#ifdef DEBUG
a8::UdpLog::Instance()->Debug("OnAddCollider %d %d %d",
{
room->room_idx,
room->GetRoomIdx(),
entity_uniid,
(long long)self_collider_
});

View File

@ -18,6 +18,7 @@ struct PerfMonitor
namespace MetaData
{
struct Map;
struct SafeArea;
struct Equip;
struct EquipUpgrade;
@ -151,3 +152,22 @@ struct ObstacleData
int door_open_times = 0;
DoorState_e door_state = DoorStateClose;
};
class GridService;
class MapService;
class Building;
struct RoomInitInfo
{
int room_idx = 0;
long long room_uuid = 0;
RoomType_e room_type = RT_NewBrid;
const MetaData::Map* map_meta = nullptr;
std::string map_tpl_name;
GridService* grid_service = nullptr;
MapService* map_service = nullptr;
const std::vector<MetaData::MapTplThing*>* spawn_points = nullptr;
const MetaData::MapTplThing* newbie_born_point_meta = nullptr;
const std::vector<MetaData::MapTplThing*>* loots = nullptr;
const std::vector<Building*>* buildings = nullptr;
};