This commit is contained in:
aozhiwei 2018-08-26 19:34:06 +08:00
parent 841fdde99e
commit 8e58095243

View File

@ -278,62 +278,66 @@ bool TiledMap::CalcCurrPos(std::vector<int>& path_points, int old_pos_x, int old
if (path_points.size() < 2) {
return false;
}
std::string path_point;
std::vector<std::string> stage_path_list;
bool path_start = true;
std::vector<GridCell*> grid_all_list;
for (auto& point : path_points) {
if (path_start) {
path_point = a8::XValue(point).GetString();
path_start = !path_start;
} else {
std::string point_str = a8::XValue(point).GetString();
path_point += "-" + point_str;
stage_path_list.push_back(path_point);
path_point = point_str;
}
}
bool exc_once = true;
for (auto& stage_path : stage_path_list) {
std::vector<GridCell*>* grid_list = nullptr;
std::string stage_path_reverse;
std::vector<std::string> split_list;
a8::Split(stage_path,split_list,'-');
if (split_list.size() != 2) {
return false;
}
StagePoint* sp = GetStageObject(a8::XValue(split_list.at(0)));
if (sp == nullptr) {
return false;
}
grid_list = GetStagePath(stage_path);
if (grid_list == nullptr) {
stage_path_reverse = split_list[1] + "-" + split_list[0];
grid_list = GetStagePath(stage_path_reverse);
if (grid_list == nullptr) {
return false;
{
std::string path_point;
bool path_start = true;
for (auto& point : path_points) {
if (path_start) {
path_point = a8::XValue(point).GetString();
path_start = !path_start;
} else {
std::string point_str = a8::XValue(point).GetString();
path_point += "-" + point_str;
stage_path_list.push_back(path_point);
path_point = point_str;
}
}
}
std::vector<GridCell*> grid_all_list;
{
bool exc_once = true;
for (auto& stage_path : stage_path_list) {
std::vector<GridCell*>* grid_list = nullptr;
std::vector<GridCell*> grid_sort_list = SortGridList(grid_list,sp);
if (grid_sort_list.empty()){
return false;
}
if (exc_once) {
grid_all_list.insert(grid_all_list.end(),grid_sort_list.begin(),grid_sort_list.end());
exc_once = false;
} else {
grid_all_list.insert(grid_all_list.end(),grid_sort_list.begin()+1,grid_sort_list.end());
std::string stage_path_reverse;
std::vector<std::string> split_list;
a8::Split(stage_path,split_list,'-');
if (split_list.size() != 2) {
return false;
}
StagePoint* sp = GetStageObject(a8::XValue(split_list.at(0)));
if (sp == nullptr) {
return false;
}
grid_list = GetStagePath(stage_path);
if (grid_list == nullptr) {
stage_path_reverse = split_list[1] + "-" + split_list[0];
grid_list = GetStagePath(stage_path_reverse);
if (grid_list == nullptr) {
return false;
}
}
std::vector<GridCell*> grid_sort_list = SortGridList(grid_list,sp);
if (grid_sort_list.empty()){
return false;
}
if (exc_once) {
grid_all_list.insert(grid_all_list.end(),grid_sort_list.begin(),grid_sort_list.end());
exc_once = false;
} else {
grid_all_list.insert(grid_all_list.end(),grid_sort_list.begin()+1,grid_sort_list.end());
}
}
}
if (grid_all_list.empty()) {
return false;
}
int grid_all_count = grid_all_list.size();
for (int i = 0; i < grid_all_count-1; ++i) {
{
int grid_all_count = grid_all_list.size();
for (int i = 0; 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;
@ -354,6 +358,7 @@ bool TiledMap::CalcCurrPos(std::vector<int>& path_points, int old_pos_x, int old
if (time_ms < 0) {
return true;
}
}
}
if (time_ms > 0) {
return true;