diff --git a/server/gameserver/android.ai.cc b/server/gameserver/android.ai.cc index 66b9e93..440b162 100644 --- a/server/gameserver/android.ai.cc +++ b/server/gameserver/android.ai.cc @@ -177,7 +177,7 @@ void AndroidNewAI::DoMoveOldAI() } break; } - hum->room->grid_service->MoveHuman(hum); + hum->room->grid_service->MoveCreature(hum); } } } @@ -228,7 +228,7 @@ void AndroidNewAI::UpdateNewBieNpc() int speed = std::max(1, (int)hum->GetSpeed()); for (int i = 0; i < speed; ++i) { hum->SetPos(hum->GetPos() + hum->move_dir); - hum->room->grid_service->MoveHuman(hum); + hum->room->grid_service->MoveCreature(hum); } } else if (hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 3) { Human* enemy = hum->room->GetFirstNewBie(); @@ -265,7 +265,7 @@ void AndroidNewAI::UpdateLastNpc() a8::Vec2 old_pos = hum->GetPos(); hum->SetPos(hum->GetPos() + hum->move_dir); if (!hum->room->OverBorder(hum->GetPos(), hum->meta->i->radius())) { - hum->room->grid_service->MoveHuman(hum); + hum->room->grid_service->MoveCreature(hum); } else { hum->SetPos(old_pos); break; @@ -361,7 +361,7 @@ void AndroidNewAI::UpdateNewBieRoomLogic() } } hum->SetPos(pos); - hum->room->grid_service->MoveHuman(hum); + hum->room->grid_service->MoveCreature(hum); hum->FindLocation(); hum->RefreshView(); } @@ -380,7 +380,7 @@ void AndroidNewAI::UpdateNewBieRoomLogic() speed *= 0.7; for (int i = 0; i < speed; ++i) { hum->SetPos(hum->GetPos() + hum->move_dir); - hum->room->grid_service->MoveHuman(hum); + hum->room->grid_service->MoveCreature(hum); } } } else { diff --git a/server/gameserver/android.cc b/server/gameserver/android.cc index 6e4a157..f3f70f6 100644 --- a/server/gameserver/android.cc +++ b/server/gameserver/android.cc @@ -62,7 +62,7 @@ void Android::InternalUpdate(int delta_time) } if (HasBuffEffect(kBET_Fly)) { SetPos(room->plane.curr_pos); - room->grid_service->MoveHuman(this); + room->grid_service->MoveCreature(this); return; } ai->Update(delta_time); diff --git a/server/gameserver/car.cc b/server/gameserver/car.cc index 20be5e3..569e86d 100644 --- a/server/gameserver/car.cc +++ b/server/gameserver/car.cc @@ -8,7 +8,7 @@ #include "perfmonitor.h" #include "typeconvert.h" -Car::Car():MoveableEntity() +Car::Car():Creature() { ++PerfMonitor::Instance()->entity_num[ET_Car]; } @@ -20,7 +20,7 @@ Car::~Car() void Car::Initialize() { - MoveableEntity::Initialize(); + Creature::Initialize(); hero_meta_ = MetaMgr::Instance()->GetPlayer(meta->i->heroid()); if (!hero_meta_) { abort(); @@ -172,9 +172,9 @@ void Car::SyncPos() if (hum != driver_) { hum->SetPos(GetPos()); hum->move_dir = move_dir; - room->grid_service->MoveHuman(hum); + room->grid_service->MoveCreature(hum); } } - room->grid_service->MoveCar(this); + room->grid_service->MoveCreature(this); } } diff --git a/server/gameserver/car.h b/server/gameserver/car.h index fab9ff2..1feacd8 100644 --- a/server/gameserver/car.h +++ b/server/gameserver/car.h @@ -1,6 +1,6 @@ #pragma once -#include "moveableentity.h" +#include "creature.h" #include "cs_proto.pb.h" @@ -12,7 +12,7 @@ namespace MetaData class Human; class Room; -class Car : public MoveableEntity +class Car : public Creature { public: int car_uniid = 0; diff --git a/server/gameserver/creature.cc b/server/gameserver/creature.cc index a42c3a3..5f691c8 100644 --- a/server/gameserver/creature.cc +++ b/server/gameserver/creature.cc @@ -832,3 +832,18 @@ float Creature::GetAttrRate(int attr_id) float attr_rate_val = GetBuffAttrRate(attr_id); return attr_rate_val; } + +bool Creature::IsPlayer() const +{ + return IsHuman() && IsEntitySubType(EST_Player); +} + +bool Creature::IsAndroid() const +{ + return IsHuman() && IsEntitySubType(EST_Android); +} + +bool Creature::IsHuman() const +{ + return IsEntityType(ET_Player); +} diff --git a/server/gameserver/creature.h b/server/gameserver/creature.h index 0637339..05ace61 100644 --- a/server/gameserver/creature.h +++ b/server/gameserver/creature.h @@ -71,8 +71,9 @@ class Creature : public MoveableEntity virtual std::string GetName() { return "";}; virtual void SendDebugMsg(const std::string& debug_msg); virtual void DropItems(Obstacle* obstacle) {}; - virtual bool IsPlayer() const { return false;}; - virtual bool IsAndroid() const { return false;}; + bool IsPlayer() const; + bool IsAndroid() const; + bool IsHuman() const; virtual void DecHP(float dec_hp, int killer_id, const std::string& killer_name, int weapon_id) {}; RaceType_e GetRace() { return race_; } diff --git a/server/gameserver/gridcell.cc b/server/gameserver/gridcell.cc index e0b1d7a..94a64e9 100644 --- a/server/gameserver/gridcell.cc +++ b/server/gameserver/gridcell.cc @@ -7,50 +7,37 @@ #include "room.h" #include "car.h" #include "hero.h" +#include "creature.h" GridCell::GridCell() { - human_list_.reserve(MAX_ROOM_IDX); - entity_list_.reserve(MAX_ROOM_IDX); - bullet_list_.reserve(MAX_ROOM_IDX); + entitys_.reserve(MAX_ROOM_IDX); + bullets_.reserve(MAX_ROOM_IDX); + creatures_.reserve(MAX_ROOM_IDX); for (int i = 0; i < MAX_ROOM_IDX; ++i) { - human_list_.push_back(std::set()); - entity_list_.push_back(std::set()); - bullet_list_.push_back(std::set()); - car_list_.push_back(std::set()); - hero_list_.push_back(std::set()); + entitys_.push_back(std::set()); + bullets_.push_back(std::set()); + creatures_.push_back(std::set()); } } void GridCell::ClearRoomData(Room* room) { - human_list_[room->GetRoomIdx()].clear(); - entity_list_[room->GetRoomIdx()].clear(); - bullet_list_[room->GetRoomIdx()].clear(); - bullet_list_[room->GetRoomIdx()].clear(); -} - -void GridCell::AddHuman(Human* hum) -{ - human_list_[hum->room->GetRoomIdx()].insert(hum); -} - -void GridCell::RemoveHuman(Human* hum) -{ - human_list_[hum->room->GetRoomIdx()].erase(hum); -} - -bool GridCell::ExistsHuman(Human* hum) -{ - return human_list_[hum->room->GetRoomIdx()].find(hum) != human_list_[hum->room->GetRoomIdx()].end(); + entitys_[room->GetRoomIdx()].clear(); + bullets_[room->GetRoomIdx()].clear(); + creatures_[room->GetRoomIdx()].clear(); } void GridCell::TouchHumanList(std::function& func, int room_idx, bool& stop) { - for (Human* hum : human_list_[room_idx]) { + for (Creature* c : creatures_[room_idx]) { + if (!c->IsHuman()) { + continue; + } + Human* hum = (Human*)c; func(hum, stop); if (stop) { return; @@ -67,62 +54,42 @@ void GridCell::TouchHumanListEx(std::function func, void GridCell::AddBullet(Bullet* bullet) { - bullet_list_[bullet->room->GetRoomIdx()].insert(bullet); + bullets_[bullet->room->GetRoomIdx()].insert(bullet); } void GridCell::RemoveBullet(Bullet* bullet) { - bullet_list_[bullet->room->GetRoomIdx()].erase(bullet); -} - -void GridCell::AddCar(Car* car) -{ - car_list_[car->room->GetRoomIdx()].insert(car); -} - -void GridCell::RemoveCar(Car* car) -{ - car_list_[car->room->GetRoomIdx()].erase(car); -} - -void GridCell::AddHero(Hero* hero) -{ - hero_list_[hero->room->GetRoomIdx()].insert(hero); -} - -void GridCell::RemoveHero(Hero* hero) -{ - hero_list_[hero->room->GetRoomIdx()].erase(hero); + bullets_[bullet->room->GetRoomIdx()].erase(bullet); } void GridCell::AddPermanentEntity(Entity* entity) { - entity_list_[0].insert(entity); + entitys_[0].insert(entity); } void GridCell::AddRoomEntity(Room* room, Entity* entity) { - entity_list_[room->GetRoomIdx()].insert(entity); + entitys_[room->GetRoomIdx()].insert(entity); } void GridCell::RemoveRoomEntity(Room* room, Entity* entity) { - entity_list_[room->GetRoomIdx()].erase(entity); + entitys_[room->GetRoomIdx()].erase(entity); } -bool GridCell::ExistsEntity(Room* room, Entity* entity) +bool GridCell::EntityExists(Room* room, Entity* entity) { - if (entity_list_[0].find(entity) != entity_list_[0].end()) { + if (entitys_[0].find(entity) != entitys_[0].end()) { return true; } - return entity_list_[room->GetRoomIdx()].find(entity) != - entity_list_[room->GetRoomIdx()].end(); + return entitys_[room->GetRoomIdx()].find(entity) != + entitys_[room->GetRoomIdx()].end(); } void GridCell::TouchLayer0EntityList(std::function& func, bool& stop) { - for (Entity* entity : entity_list_[0]) { + for (Entity* entity : entitys_[0]) { func(entity, stop); if (stop) { return; @@ -134,7 +101,7 @@ void GridCell::TouchLayer1EntityList(std::function& func, int room_idx, bool& stop) { - for (Entity* entity : entity_list_[room_idx]) { + for (Entity* entity : entitys_[room_idx]) { func(entity, stop); if (stop) { return; @@ -151,3 +118,18 @@ void GridCell::TouchAllLayerEntityList(std::function& fun TouchLayer1EntityList(func, room_idx, stop); } } + +void GridCell::AddCreature(Creature* c) +{ + creatures_[c->room->GetRoomIdx()].insert(c); +} + +void GridCell::RemoveCreature(Creature* c) +{ + creatures_[c->room->GetRoomIdx()].erase(c); +} + +bool GridCell::CreatureExists(Creature* c) +{ + return creatures_[c->room->GetRoomIdx()].find(c) != creatures_[c->room->GetRoomIdx()].end(); +} diff --git a/server/gameserver/gridcell.h b/server/gameserver/gridcell.h index 3c56d08..8c3f1b0 100644 --- a/server/gameserver/gridcell.h +++ b/server/gameserver/gridcell.h @@ -4,8 +4,7 @@ class Entity; class Human; class Bullet; class Room; -class Car; -class Hero; +class Creature; class GridCell { @@ -13,9 +12,7 @@ public: GridCell(); void ClearRoomData(Room* room); - void AddHuman(Human* hum); - void RemoveHuman(Human* hum); - bool ExistsHuman(Human* hum); + void TouchHumanList(std::function& func, int room_idx, bool& stop); @@ -23,16 +20,15 @@ public: int room_idx, bool& stop); + void AddCreature(Creature* c); + void RemoveCreature(Creature* c); + bool CreatureExists(Creature* c); void AddBullet(Bullet* bullet); void RemoveBullet(Bullet* bullet); - void AddCar(Car* car); - void RemoveCar(Car* car); - void AddHero(Hero* hero); - void RemoveHero(Hero* hero); void AddPermanentEntity(Entity* entity); void AddRoomEntity(Room* room, Entity* entity); void RemoveRoomEntity(Room* room, Entity* entity); - bool ExistsEntity(Room* room, Entity* Entity); + bool EntityExists(Room* room, Entity* Entity); void TouchLayer0EntityList(std::function& func, bool& stop); void TouchLayer1EntityList(std::function& func, @@ -43,9 +39,7 @@ public: bool& stop); private: - std::vector> human_list_; - std::vector> entity_list_; - std::vector> bullet_list_; - std::vector> car_list_; - std::vector> hero_list_; + std::vector> entitys_; + std::vector> bullets_; + std::vector> creatures_; }; diff --git a/server/gameserver/gridservice.cc b/server/gameserver/gridservice.cc index c455592..2014a85 100644 --- a/server/gameserver/gridservice.cc +++ b/server/gameserver/gridservice.cc @@ -5,8 +5,6 @@ #include "bullet.h" #include "room.h" #include "gridcell.h" -#include "car.h" -#include "hero.h" /* 1 2 3 @@ -102,25 +100,31 @@ void GridService::ClearRoomData(Room* room) } } -void GridService::AddHuman(Human* hum) +void GridService::AddCreature(Creature* c) { - int x = (int)hum->GetX() + cell_width_; - int y = (int)hum->GetY() + cell_width_; + int x = (int)c->GetX() + cell_width_; + int y = (int)c->GetY() + cell_width_; if (BroderOverFlow(x, y)) { abort(); } - hum->SetGridId(x/cell_width_ + (y/cell_width_) * cell_count_per_row_); - if (hum->GetGridId() == 0 || hum->GetGridId() > max_grid_id_) { + c->SetGridId(x/cell_width_ + (y/cell_width_) * cell_count_per_row_); + if (c->GetGridId() == 0 || c->GetGridId() > max_grid_id_) { abort(); } - cells_[hum->GetGridId()].AddHuman(hum); - GetAllCells(hum->room, hum->GetGridId(), hum->GetGridList()); + cells_[c->GetGridId()].AddCreature(c); + GetAllCells(c->room, c->GetGridId(), c->GetGridList()); } -void GridService::MoveHuman(Human* hum) +void GridService::RemoveCreature(Creature* c) { - int new_x = (int)hum->GetX() + cell_width_; - int new_y = (int)hum->GetY() + cell_width_; + GridCell& cell = cells_[c->GetGridId()]; + cell.RemoveCreature(c); +} + +void GridService::MoveCreature(Creature* c) +{ + int new_x = (int)c->GetX() + cell_width_; + int new_y = (int)c->GetY() + cell_width_; int new_grid_id = new_x/cell_width_ + (new_y/cell_width_) * cell_count_per_row_; if (BroderOverFlow(new_x, new_y)) { abort(); @@ -128,20 +132,20 @@ void GridService::MoveHuman(Human* hum) if (new_grid_id == 0 || new_grid_id > max_grid_id_) { abort(); } - if (new_grid_id != hum->GetGridId()) { + if (new_grid_id != c->GetGridId()) { std::set inc_grid_list; std::set dec_grid_list; - std::set old_grid_list = hum->GetGridList(); - ComputeDiff(hum->room, - hum->GetGridId(), + std::set old_grid_list = c->GetGridList(); + ComputeDiff(c->room, + c->GetGridId(), new_grid_id, - hum->GetGridList(), + c->GetGridList(), inc_grid_list, dec_grid_list); - cells_[hum->GetGridId()].RemoveHuman(hum); - cells_[new_grid_id].AddHuman(hum); - hum->SetGridId(new_grid_id); - hum->OnGridListChange(old_grid_list, inc_grid_list, dec_grid_list); + cells_[c->GetGridId()].RemoveCreature(c); + cells_[new_grid_id].AddCreature(c); + c->SetGridId(new_grid_id); + c->OnGridListChange(old_grid_list, inc_grid_list, dec_grid_list); } } @@ -193,104 +197,6 @@ void GridService::DelBullet(Bullet* bullet) cell.RemoveBullet(bullet); } -void GridService::AddCar(Car* car) -{ - int x = (int)car->GetX() + cell_width_; - int y = (int)car->GetY() + cell_width_; - if (BroderOverFlow(x, y)) { - abort(); - } - car->SetGridId(x/cell_width_ + (y/cell_width_) * cell_count_per_row_); - if (car->GetGridId() == 0 || car->GetGridId() > max_grid_id_) { - abort(); - } - cells_[car->GetGridId()].AddCar(car); - GetAllCells(car->room, car->GetGridId(), car->GetGridList()); -} - -void GridService::MoveCar(Car* car) -{ - int new_x = (int)car->GetX() + cell_width_; - int new_y = (int)car->GetY() + cell_width_; - int new_grid_id = new_x/cell_width_ + (new_y/cell_width_) * cell_count_per_row_; - if (BroderOverFlow(new_x, new_y)) { - abort(); - } - if (new_grid_id == 0 || new_grid_id > max_grid_id_) { - abort(); - } - if (new_grid_id != car->GetGridId()) { - std::set inc_grid_list; - std::set dec_grid_list; - std::set old_grid_list = car->GetGridList(); - ComputeDiff(car->room, - car->GetGridId(), - new_grid_id, - car->GetGridList(), - inc_grid_list, - dec_grid_list); - cells_[car->GetGridId()].RemoveCar(car); - cells_[new_grid_id].AddCar(car); - car->SetGridId(new_grid_id); - car->OnGridListChange(old_grid_list, inc_grid_list, dec_grid_list); - } -} - -void GridService::DelCar(Car* car) -{ - GridCell& cell = cells_[car->GetGridId()]; - cell.RemoveCar(car); -} - -void GridService::AddHero(Hero* hero) -{ - int x = (int)hero->GetX() + cell_width_; - int y = (int)hero->GetY() + cell_width_; - if (BroderOverFlow(x, y)) { - abort(); - } - hero->SetGridId(x/cell_width_ + (y/cell_width_) * cell_count_per_row_); - if (hero->GetGridId() == 0 || hero->GetGridId() > max_grid_id_) { - abort(); - } - cells_[hero->GetGridId()].AddHero(hero); - GetAllCells(hero->room, hero->GetGridId(), hero->GetGridList()); -} - -void GridService::MoveHero(Hero* hero) -{ - int new_x = (int)hero->GetX() + cell_width_; - int new_y = (int)hero->GetY() + cell_width_; - int new_grid_id = new_x/cell_width_ + (new_y/cell_width_) * cell_count_per_row_; - if (BroderOverFlow(new_x, new_y)) { - abort(); - } - if (new_grid_id == 0 || new_grid_id > max_grid_id_) { - abort(); - } - if (new_grid_id != hero->GetGridId()) { - std::set inc_grid_list; - std::set dec_grid_list; - std::set old_grid_list = hero->GetGridList(); - ComputeDiff(hero->room, - hero->GetGridId(), - new_grid_id, - hero->GetGridList(), - inc_grid_list, - dec_grid_list); - cells_[hero->GetGridId()].RemoveHero(hero); - cells_[new_grid_id].AddHero(hero); - hero->SetGridId(new_grid_id); - hero->OnGridListChange(old_grid_list, inc_grid_list, dec_grid_list); - } -} - -void GridService::DelHero(Hero* hero) -{ - GridCell& cell = cells_[hero->GetGridId()]; - cell.RemoveHero(hero); -} - void GridService::AddRoomEntity(Room* room, Entity* entity) { assert(!entity->IsEntityType(ET_Player)); @@ -327,10 +233,10 @@ void GridService::AddPermanentEntity(Entity* entity) cells_[entity->GetGridId()].AddPermanentEntity(entity); } -bool GridService::HumanInGridList(Human* hum, std::set& grid_list) +bool GridService::CreatureInGridList(Creature* c, std::set& grid_list) { for (auto& cell : grid_list) { - if (cell->ExistsHuman(hum)) { + if (cell->CreatureExists(c)) { return true; } } @@ -340,7 +246,7 @@ bool GridService::HumanInGridList(Human* hum, std::set& grid_list) bool GridService::EntityInGridList(Room* room, Entity* entity, std::set& grid_list) { for (auto& cell : grid_list) { - if (cell->ExistsEntity(room, entity)) { + if (cell->EntityExists(room, entity)) { return true; } } @@ -484,7 +390,7 @@ void GridService::DeatchHuman(Human* target) }, target->room->GetRoomIdx(), stop); - cell->RemoveHuman(target); + cell->RemoveCreature(target); } target->SetGridId(0); target->GetGridList().clear(); diff --git a/server/gameserver/gridservice.h b/server/gameserver/gridservice.h index 7c03830..6533fdd 100644 --- a/server/gameserver/gridservice.h +++ b/server/gameserver/gridservice.h @@ -4,8 +4,7 @@ class Human; class Entity; class Room; class Bullet; -class Car; -class Hero; +class Creature; class GridCell; class GridService { @@ -21,27 +20,20 @@ class GridService bool CanAdd(float x, float y); void ClearRoomData(Room* room); - void AddHuman(Human* hum); - void MoveHuman(Human* hum); + void AddCreature(Creature* c); + void RemoveCreature(Creature* c); + void MoveCreature(Creature* c); void AddBullet(Bullet* bullet); void MoveBullet(Bullet* bullet); void DelBullet(Bullet* bullet); - void AddCar(Car* car); - void MoveCar(Car* car); - void DelCar(Car* car); - - void AddHero(Hero* hero); - void MoveHero(Hero* hero); - void DelHero(Hero* hero); - void AddRoomEntity(Room* room, Entity* entity); void DelRoomEntity(Room* room, Entity* entity); void AddPermanentEntity(Entity* entity); - bool HumanInGridList(Human* hum, std::set& grid_list); + bool CreatureInGridList(Creature* c, std::set& grid_list); bool EntityInGridList(Room* room, Entity* entity, std::set& grid_list); bool InView(int a_grid, int b_grid); bool InView(int grid_id, float x, float y); diff --git a/server/gameserver/hero.cc b/server/gameserver/hero.cc index ea6c9ab..073eefd 100644 --- a/server/gameserver/hero.cc +++ b/server/gameserver/hero.cc @@ -91,7 +91,7 @@ void Hero::InternalUpdateMove(float speed) SetPos(new_pos); if (!IsCollisionInMapService()) { - room->grid_service->MoveHero(this); + room->grid_service->MoveCreature(this); } else { if (on_move_collision && !on_move_collision()) { SetPos(old_pos); diff --git a/server/gameserver/human.cc b/server/gameserver/human.cc index c12cdb4..10cf9e3 100644 --- a/server/gameserver/human.cc +++ b/server/gameserver/human.cc @@ -2133,7 +2133,7 @@ void Human::_InternalUpdateMove(float speed) #if 1 SetPos(old_pos + a8::Vec2(nx, ny)); if (!IsCollisionInMapService()) { - room->grid_service->MoveHuman(this); + room->grid_service->MoveCreature(this); return; } else { if (Global::last_collider && Global::last_collider->type == CT_Circle) { @@ -2148,7 +2148,7 @@ void Human::_InternalUpdateMove(float speed) SetPos(GetPos() + new_dir); } if (!IsCollisionInMapService()) { - room->grid_service->MoveHuman(this); + room->grid_service->MoveCreature(this); return; } } @@ -2174,7 +2174,7 @@ void Human::_InternalUpdateMove(float speed) } SetPos(old_pos + a8::Vec2(nx, ny)); - room->grid_service->MoveHuman(this); + room->grid_service->MoveCreature(this); } void Human::ClearFrameData() @@ -2730,7 +2730,7 @@ void Human::FindLocationWithTarget(Entity* target) float distance = (new_pos - old_pos).Norm(); for (int i = distance; i < 10000000; i += 5) { SetPos(old_pos + new_pos_dir * i); - room->grid_service->MoveHuman(this); + room->grid_service->MoveCreature(this); Entity* building = nullptr; std::set tmp_grids; @@ -2915,16 +2915,6 @@ void Human::DecItem(int item_id, int item_num) } } -bool Human::IsPlayer() const -{ - return IsEntitySubType(EST_Player); -} - -bool Human::IsAndroid() const -{ - return IsEntitySubType(EST_Android); -} - void Human::DropItems(Obstacle* obstacle) { bool is_treasure_box = false; @@ -3101,7 +3091,7 @@ void Human::OnEnable() { a8::UnSetBitFlag(status, HS_Disable); enable_frameno = room->GetFrameNo(); - room->grid_service->AddHuman(this); + room->grid_service->MoveCreature(this); FindLocation(); RefreshView(); } @@ -3191,7 +3181,7 @@ void Human::ProcIncGridList(std::set& old_grids, inc_grids, [this, &old_grids] (Human* hum, bool& stop) { - if (!room->grid_service->HumanInGridList(hum, old_grids)) { + if (!room->grid_service->CreatureInGridList(hum, old_grids)) { hum->AddToNewObjects(this); hum->AddToPartObjects(this); hum->RemoveOutObjects(this); @@ -3233,7 +3223,7 @@ void Human::ProcDecGridList(std::set& old_grids, dec_grids, [this] (Human* hum, bool& stop) { - if (!room->grid_service->HumanInGridList(hum, GetGridList())) { + if (!room->grid_service->CreatureInGridList(hum, GetGridList())) { AddOutObjects(hum); hum->AddOutObjects(this); #ifdef DEBUG @@ -3476,7 +3466,7 @@ void Human::OnLand() for (const a8::Vec2& dir : dirs) { SetPos(old_pos + dir * i); if (!IsCollisionInMapService()) { - room->grid_service->MoveHuman(this); + room->grid_service->MoveCreature(this); return; } } diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 986204a..5704526 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -240,8 +240,6 @@ class Human : public Creature int GetItemNum(int item_id); void AddItem(int item_id, int item_num); void DecItem(int item_id, int item_num); - virtual bool IsPlayer() const override; - virtual bool IsAndroid() const override; virtual void DropItems(Obstacle* obstacle) override; void ProcNewBieLogic(); void OnEnable(); diff --git a/server/gameserver/moveableentity.cc b/server/gameserver/moveableentity.cc index c615aa0..c8c75db 100644 --- a/server/gameserver/moveableentity.cc +++ b/server/gameserver/moveableentity.cc @@ -46,7 +46,7 @@ void MoveableEntity::OnGridListChange(std::set& old_grids, inc_grids, [this, &old_grids] (Human* hum, bool& stop) { - if (!room->grid_service->HumanInGridList(hum, old_grids)) { + if (!room->grid_service->CreatureInGridList(hum, old_grids)) { hum->AddToNewObjects(this); hum->AddToPartObjects(this); hum->RemoveOutObjects(this); @@ -60,7 +60,7 @@ void MoveableEntity::OnGridListChange(std::set& old_grids, dec_grids, [this] (Human* hum, bool& stop) { - if (!room->grid_service->HumanInGridList(hum, GetGridList())) { + if (!room->grid_service->CreatureInGridList(hum, GetGridList())) { hum->AddOutObjects(this); } }); diff --git a/server/gameserver/player.cc b/server/gameserver/player.cc index 4a1e2cf..e6b6d3d 100644 --- a/server/gameserver/player.cc +++ b/server/gameserver/player.cc @@ -58,7 +58,7 @@ void Player::InternalUpdate(int delta_time) } if (HasBuffEffect(kBET_Fly)) { SetPos(room->plane.curr_pos); - room->grid_service->MoveHuman(this); + room->grid_service->MoveCreature(this); #ifdef DEBUG if (GetCar() && GetCar()->IsDriver(this)) { GetCar()->SyncPos(); diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 40e4235..edbfb70 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -237,7 +237,7 @@ void Room::AddPlayer(Player* hum) alive_count_chged_frameno_ = GetFrameNo(); ++PerfMonitor::Instance()->alive_count; - grid_service->AddHuman(hum); + grid_service->AddCreature(hum); hum->FindLocation(); hum->RefreshView(); AddPlayerPostProc(hum); @@ -352,7 +352,7 @@ void Room::CreateAndroid(int robot_num) } else { AddToAliveHumanHash(hum); AddToMoveableHash(hum); - grid_service->AddHuman(hum); + grid_service->AddCreature(hum); hum->FindLocation(); hum->RefreshView(); } @@ -564,7 +564,7 @@ Car* Room::CreateCar(Human* driver, } car->Initialize(); AddToEntityHash(car); - grid_service->AddCar(car); + grid_service->AddCreature(car); car->RefreshView(); car->BroadcastFullState(this); return car; @@ -584,7 +584,7 @@ Hero* Room::CreateHero(Creature* master, hero->Initialize(); AddToEntityHash(hero); AddToMoveableHash(hero); - grid_service->AddHero(hero); + grid_service->AddCreature(hero); hero->RefreshView(); return hero; } @@ -618,7 +618,7 @@ void Room::RemoveObjectLater(RoomEntity* entity) { entity->RemoveFromAroundPlayers(entity->room); entity->BroadcastDeleteState(entity->room); - entity->room->grid_service->DelCar((Car*)entity); + entity->room->grid_service->RemoveCreature((Car*)entity); entity->room->RemoveFromMoveableHash((Car*)entity); } break; @@ -1685,7 +1685,7 @@ void Room::ShuaPlane() pair.second->SetPos(plane.curr_pos); pair.second->attack_dir = plane.dir; pair.second->move_dir = plane.dir; - grid_service->MoveHuman(pair.second); + grid_service->MoveCreature(pair.second); pair.second->AddToNewObjects(pair.second); } } @@ -3029,7 +3029,7 @@ void Room::CombineTeamBornPoint() if (!a8::HasBitFlag(hum->status, HS_Disable)) { hum->FindLocation(); hum->RefreshView(); - grid_service->MoveHuman(hum); + grid_service->MoveCreature(hum); } else if (room_type_ == RT_MidBrid && !hum->team_uuid.empty()){ EnableHuman(hum); } @@ -3050,7 +3050,7 @@ void Room::ForceSetBornPoint(Human* hum, BornPoint* born_point) } hum->FindLocation(); hum->RefreshView(); - grid_service->MoveHuman(hum); + grid_service->MoveCreature(hum); } }