From e40397fa602d494cb484801aafe62cfd79f2f640 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Fri, 7 Aug 2020 15:09:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90a=E6=98=9F=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/gameserver/mapinstance.cc | 4 ++++ server/gameserver/mapservice.cc | 32 ++++++++++++++++++++++++++++-- server/gameserver/mapservice.h | 4 ++++ server/gameserver/precompile.h | 3 +++ server/gameserver/room.cc | 17 ++++++++++++++++ server/gameserver/zombiemode.ai.cc | 12 +++++++++-- 6 files changed, 68 insertions(+), 4 deletions(-) diff --git a/server/gameserver/mapinstance.cc b/server/gameserver/mapinstance.cc index ed46cc4..52405f1 100644 --- a/server/gameserver/mapinstance.cc +++ b/server/gameserver/mapinstance.cc @@ -11,7 +11,11 @@ #include "room.h" #include "entityfactory.h" +#ifdef FIND_PATH_TEST +const int MAP_GRID_WIDTH = 40; +#else const int MAP_GRID_WIDTH = 64; +#endif void MapInstance::Init() { diff --git a/server/gameserver/mapservice.cc b/server/gameserver/mapservice.cc index 5edb5ba..6e3483b 100644 --- a/server/gameserver/mapservice.cc +++ b/server/gameserver/mapservice.cc @@ -130,6 +130,10 @@ void MapService::AddCollider(ColliderComponent* collider) node->collider = collider; list_add_tail(&node->entry, head); node->next = top_node; + #ifdef DEBUG + node->x = x; + node->y = y; + #endif top_node = node; if (!bot_node) { bot_node = node; @@ -235,10 +239,25 @@ int MapService::GetMap(int x, int y) #endif return TILE_STATE_CLOSED; } - list_head* head = &map_cells_[x * y]; + list_head* head = &map_cells_[x + map_width_ * y]; if (list_empty(head)) { return TILE_STATE_OPENED_COST1; } else { + CellNode* node = list_first_entry(head, CellNode, entry); + switch (node->collider->owner->GetEntityType()) { + case ET_Obstacle: + { + Obstacle* obstacle = (Obstacle*)node->collider->owner; + if (!obstacle->IsPermanent()) { + return TILE_STATE_OPENED_COST1; + } + } + break; + default: + { + } + break; + } return TILE_STATE_CLOSED; } } @@ -323,7 +342,10 @@ void MapService::FindPathUpdate(FindPathStatus* find_status) steps++; MovePathPoint point; - point.pos = a8::Vec2(node->x * cell_width_, node->y * cell_width_); + point.pos = a8::Vec2( + node->x * cell_width_ + cell_width_ / 2, + node->y * cell_width_ + cell_width_ / 2 + ); find_status->out_points.push_back(point); }; } @@ -382,5 +404,11 @@ void MapService::DoMove(FindPathStatus* find_status) if (target_distance < 1.0001f) { myself->SetPos(point->pos); ++find_status->path_index; +#ifdef DEBUG + if (myself->IsCollisionInMapService()) { + myself->IsCollisionInMapService(); + abort(); + } +#endif } } diff --git a/server/gameserver/mapservice.h b/server/gameserver/mapservice.h index e8ab212..27e48e5 100644 --- a/server/gameserver/mapservice.h +++ b/server/gameserver/mapservice.h @@ -21,6 +21,10 @@ struct CellNode ColliderComponent* collider; list_head entry; CellNode* next = nullptr; + #ifdef DEBUG + int x = 0; + int y = 0; + #endif }; struct MovePathPoint diff --git a/server/gameserver/precompile.h b/server/gameserver/precompile.h index 726d0f7..b030712 100644 --- a/server/gameserver/precompile.h +++ b/server/gameserver/precompile.h @@ -22,3 +22,6 @@ namespace google #include "framework/cpp/types.h" #include "framework/cpp/protoutils.h" +#ifdef DEBUG +#define FIND_PATH_TEST 1 +#endif diff --git a/server/gameserver/room.cc b/server/gameserver/room.cc index 8554b25..6eed87e 100644 --- a/server/gameserver/room.cc +++ b/server/gameserver/room.cc @@ -2913,12 +2913,24 @@ void Room::ZombieModeStart() #endif std::vector human_list; for (auto& pair : human_hash_) { + #ifdef FIND_PATH_TEST + if (pair.second->IsAndroid()) { + human_list.push_back(pair.second); + } + #else human_list.push_back(pair.second); + #endif if (RoomMgr::Instance()->IsGM(pair.second->account_id)) { debug_trace = true; } } std::random_shuffle(human_list.begin(), human_list.end()); + #ifdef FIND_PATH_TEST + for (size_t i = 0; i < 1; ++i) { + Human* hum = human_list[i]; + hum->ChangeToRace(kZombieRace, 1); + } + #else for (size_t i = 0; i < 2; ++i) { Human* hum = human_list[i]; hum->ChangeToRace(kZombieRace, 1); @@ -2948,6 +2960,7 @@ void Room::ZombieModeStart() room->battle_report_timer_ = nullptr; } ); + #endif } Human* Room::GetOneCanEnableAndroid() @@ -3285,7 +3298,11 @@ int Room::GetAliveCountByRace(RaceType_e race) size_t Room::GetRoomMaxPlayerNum() { if (room_mode_ == kZombieMode) { + #ifdef FIND_PATH_TEST + return 2; + #else return MetaMgr::Instance()->zbmode_player_num; + #endif } else { if (IsMiniRoom()) { return MINI_ROOM_MAX_PLAYER_NUM; diff --git a/server/gameserver/zombiemode.ai.cc b/server/gameserver/zombiemode.ai.cc index 9dfba37..312d561 100644 --- a/server/gameserver/zombiemode.ai.cc +++ b/server/gameserver/zombiemode.ai.cc @@ -291,8 +291,11 @@ void ZombieModeAI::UpdateFindPath() } else { myself->room->map_service->FindPathUpdate(find_status); if (myself->room->map_service->FindFailed(find_status)) { +#ifdef DEBUG + a8::XPrintf("寻路失败 step:%d\n", {find_status->search_step}); +#endif myself->ClearFindPathStatus(); - ChangeToState(ZSE_Thinking); + ChangeToState(ZSE_RandomWalk); } } } @@ -424,13 +427,18 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state) break; case ZSE_FindPathMoving: { - + #ifdef DEBUG + a8::XPrintf("寻路成功\n", {}); + #endif } break; } node_->main_state = to_state; node_->frameno = hum->room->GetFrameNo(); node_->exec_frame_num = 0; + #ifdef DEBUG1 + a8::XPrintf("changetostate %d\n", {to_state}); + #endif } Human* ZombieModeAI::GetTarget()