1
This commit is contained in:
parent
b4fb10686c
commit
6af635e301
@ -42,6 +42,7 @@ bool MapSearchNode::GetSuccessors(AStarSearch<MapSearchNode> *astarsearch, MapSe
|
|||||||
}
|
}
|
||||||
if (hum->room->map_service->GetMap(cell_x, cell_y ) < TILE_STATE_CLOSED) {
|
if (hum->room->map_service->GetMap(cell_x, cell_y ) < TILE_STATE_CLOSED) {
|
||||||
new_node = MapSearchNode(cell_x, cell_y);
|
new_node = MapSearchNode(cell_x, cell_y);
|
||||||
|
new_node.hum = hum;
|
||||||
astarsearch->AddSuccessor(new_node);
|
astarsearch->AddSuccessor(new_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -230,6 +230,9 @@ void MapService::GetColliders(Room* room,
|
|||||||
int MapService::GetMap(int x, int y)
|
int MapService::GetMap(int x, int y)
|
||||||
{
|
{
|
||||||
if (!IsValidPos(x, y)) {
|
if (!IsValidPos(x, y)) {
|
||||||
|
#ifdef DEBUG1
|
||||||
|
abort();
|
||||||
|
#endif
|
||||||
return TILE_STATE_CLOSED;
|
return TILE_STATE_CLOSED;
|
||||||
}
|
}
|
||||||
list_head* head = &map_cells_[x * y];
|
list_head* head = &map_cells_[x * y];
|
||||||
@ -276,11 +279,11 @@ FindPathStatus* MapService::AddFindPathRequest(Human* hum,
|
|||||||
node_start.hum = hum;
|
node_start.hum = hum;
|
||||||
node_goal.hum = hum;
|
node_goal.hum = hum;
|
||||||
|
|
||||||
node_start.x = int(start_pos.x / map_width_);
|
node_start.x = int(start_pos.x / cell_width_);
|
||||||
node_start.y = int(start_pos.y / map_height_);
|
node_start.y = int(start_pos.y / cell_width_);
|
||||||
|
|
||||||
node_goal.x = int(end_pos.x / map_width_);
|
node_goal.x = int(end_pos.x / cell_width_);
|
||||||
node_goal.y = int(end_pos.y / map_height_);
|
node_goal.y = int(end_pos.y / cell_width_);
|
||||||
|
|
||||||
status->astar_search.SetStartAndGoalStates(node_start, node_goal);
|
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_state = find_status->astar_search.SearchStep();
|
||||||
++find_status->search_step;
|
++find_status->search_step;
|
||||||
} while (find_status->search_state == AStarSearch<MapSearchNode>::SEARCH_STATE_SEARCHING);
|
} while (find_status->search_state == AStarSearch<MapSearchNode>::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)
|
bool MapService::FindOk(FindPathStatus* find_status)
|
||||||
@ -315,8 +334,16 @@ bool MapService::FindOk(FindPathStatus* find_status)
|
|||||||
return find_status->search_state == AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED;
|
return find_status->search_state == AStarSearch<MapSearchNode>::SEARCH_STATE_SUCCEEDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MapService::FindFailed(FindPathStatus* find_status)
|
||||||
|
{
|
||||||
|
return find_status->search_state == AStarSearch<MapSearchNode>::SEARCH_STATE_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
bool MapService::MoveDone(FindPathStatus* find_status)
|
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() ||
|
if (find_status->path_index >= (int)find_status->out_points.size() ||
|
||||||
find_status->out_points.empty()) {
|
find_status->out_points.empty()) {
|
||||||
abort();
|
abort();
|
||||||
|
@ -74,6 +74,7 @@ class MapService
|
|||||||
void DelFindPathRequest(Human* hum, FindPathStatus* status);
|
void DelFindPathRequest(Human* hum, FindPathStatus* status);
|
||||||
void FindPathUpdate(FindPathStatus* find_status);
|
void FindPathUpdate(FindPathStatus* find_status);
|
||||||
bool FindOk(FindPathStatus* find_status);
|
bool FindOk(FindPathStatus* find_status);
|
||||||
|
bool FindFailed(FindPathStatus* find_status);
|
||||||
bool MoveDone(FindPathStatus* find_status);
|
bool MoveDone(FindPathStatus* find_status);
|
||||||
void DoMove(FindPathStatus* find_status);
|
void DoMove(FindPathStatus* find_status);
|
||||||
|
|
||||||
|
@ -290,6 +290,10 @@ void ZombieModeAI::UpdateFindPath()
|
|||||||
ChangeToState(ZSE_FindPathMoving);
|
ChangeToState(ZSE_FindPathMoving);
|
||||||
} else {
|
} else {
|
||||||
myself->room->map_service->FindPathUpdate(find_status);
|
myself->room->map_service->FindPathUpdate(find_status);
|
||||||
|
if (myself->room->map_service->FindFailed(find_status)) {
|
||||||
|
myself->ClearFindPathStatus();
|
||||||
|
ChangeToState(ZSE_Thinking);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user