From 87a7cef7706b8c1d4101051300eb45890c0494b4 Mon Sep 17 00:00:00 2001 From: songhao Date: Mon, 27 Aug 2018 02:31:58 -0400 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=A6=BB=E7=BA=BF=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=20=E8=B5=B7=E5=A7=8B=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cpp/tiledmap.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cpp/tiledmap.cc b/cpp/tiledmap.cc index 37c48ec..a59cea4 100644 --- a/cpp/tiledmap.cc +++ b/cpp/tiledmap.cc @@ -320,7 +320,7 @@ bool TiledMap::CalcCurrPos(std::vector& path_points, int old_pos_x, int old } std::vector grid_sort_list = SortGridList(grid_list,sp); - if (grid_sort_list.empty()){ + if (grid_sort_list.size() < 2) { return false; } if (exc_once) { @@ -336,8 +336,21 @@ bool TiledMap::CalcCurrPos(std::vector& path_points, int old_pos_x, int old return false; } { + bool has_index = false; + int index = 0; + for (auto& gc : grid_all_list) { + if (gc->x == old_pos_x && gc->y == old_pos_y) { + has_index = true; + break; + } + index++; + } + if (!has_index) { + return false; + } + int grid_all_count = grid_all_list.size(); - for (int i = 0; i < grid_all_count-1; ++i) { + for (int i = index; i < grid_all_count-1; ++i) { GridCell* gc_first = grid_all_list[i]; GridCell* gc_second = grid_all_list[i+1]; int speed = gc_first->speed;