diff --git a/server/gameserver/mapsearchnode.cc b/server/gameserver/mapsearchnode.cc index 5088d04..597c824 100644 --- a/server/gameserver/mapsearchnode.cc +++ b/server/gameserver/mapsearchnode.cc @@ -42,6 +42,7 @@ bool MapSearchNode::GetSuccessors(AStarSearch *astarsearch, MapSe } if (hum->room->map_service->GetMap(cell_x, cell_y ) < TILE_STATE_CLOSED) { new_node = MapSearchNode(cell_x, cell_y); + new_node.hum = hum; astarsearch->AddSuccessor(new_node); } } diff --git a/server/gameserver/mapservice.cc b/server/gameserver/mapservice.cc index f6273b3..5edb5ba 100644 --- a/server/gameserver/mapservice.cc +++ b/server/gameserver/mapservice.cc @@ -230,6 +230,9 @@ void MapService::GetColliders(Room* room, int MapService::GetMap(int x, int y) { if (!IsValidPos(x, y)) { +#ifdef DEBUG1 + abort(); +#endif return TILE_STATE_CLOSED; } list_head* head = &map_cells_[x * y]; @@ -276,11 +279,11 @@ FindPathStatus* MapService::AddFindPathRequest(Human* hum, node_start.hum = hum; node_goal.hum = hum; - node_start.x = int(start_pos.x / map_width_); - node_start.y = int(start_pos.y / map_height_); + node_start.x = int(start_pos.x / cell_width_); + node_start.y = int(start_pos.y / cell_width_); - node_goal.x = int(end_pos.x / map_width_); - node_goal.y = int(end_pos.y / map_height_); + node_goal.x = int(end_pos.x / cell_width_); + node_goal.y = int(end_pos.y / cell_width_); status->astar_search.SetStartAndGoalStates(node_start, node_goal); } @@ -308,6 +311,22 @@ void MapService::FindPathUpdate(FindPathStatus* find_status) find_status->search_state = find_status->astar_search.SearchStep(); ++find_status->search_step; } while (find_status->search_state == AStarSearch::SEARCH_STATE_SEARCHING); + + if (FindOk(find_status)) { + MapSearchNode *node = find_status->astar_search.GetSolutionStart(); + int steps = 0; + for( ;; ) { + node = find_status->astar_search.GetSolutionNext(); + if (!node) { + break; + } + + steps++; + MovePathPoint point; + point.pos = a8::Vec2(node->x * cell_width_, node->y * cell_width_); + find_status->out_points.push_back(point); + }; + } } bool MapService::FindOk(FindPathStatus* find_status) @@ -315,8 +334,16 @@ bool MapService::FindOk(FindPathStatus* find_status) return find_status->search_state == AStarSearch::SEARCH_STATE_SUCCEEDED; } +bool MapService::FindFailed(FindPathStatus* find_status) +{ + return find_status->search_state == AStarSearch::SEARCH_STATE_FAILED; +} + bool MapService::MoveDone(FindPathStatus* find_status) { + if (find_status->path_index >= (int)find_status->out_points.size()) { + return true; + } if (find_status->path_index >= (int)find_status->out_points.size() || find_status->out_points.empty()) { abort(); diff --git a/server/gameserver/mapservice.h b/server/gameserver/mapservice.h index 6a52884..e8ab212 100644 --- a/server/gameserver/mapservice.h +++ b/server/gameserver/mapservice.h @@ -74,6 +74,7 @@ class MapService void DelFindPathRequest(Human* hum, FindPathStatus* status); void FindPathUpdate(FindPathStatus* find_status); bool FindOk(FindPathStatus* find_status); + bool FindFailed(FindPathStatus* find_status); bool MoveDone(FindPathStatus* find_status); void DoMove(FindPathStatus* find_status); diff --git a/server/gameserver/zombiemode.ai.cc b/server/gameserver/zombiemode.ai.cc index f19bb7f..9dfba37 100644 --- a/server/gameserver/zombiemode.ai.cc +++ b/server/gameserver/zombiemode.ai.cc @@ -290,6 +290,10 @@ void ZombieModeAI::UpdateFindPath() ChangeToState(ZSE_FindPathMoving); } else { myself->room->map_service->FindPathUpdate(find_status); + if (myself->room->map_service->FindFailed(find_status)) { + myself->ClearFindPathStatus(); + ChangeToState(ZSE_Thinking); + } } } }