完成a星版本
This commit is contained in:
parent
6af635e301
commit
e40397fa60
@ -11,7 +11,11 @@
|
|||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "entityfactory.h"
|
#include "entityfactory.h"
|
||||||
|
|
||||||
|
#ifdef FIND_PATH_TEST
|
||||||
|
const int MAP_GRID_WIDTH = 40;
|
||||||
|
#else
|
||||||
const int MAP_GRID_WIDTH = 64;
|
const int MAP_GRID_WIDTH = 64;
|
||||||
|
#endif
|
||||||
|
|
||||||
void MapInstance::Init()
|
void MapInstance::Init()
|
||||||
{
|
{
|
||||||
|
@ -130,6 +130,10 @@ void MapService::AddCollider(ColliderComponent* collider)
|
|||||||
node->collider = collider;
|
node->collider = collider;
|
||||||
list_add_tail(&node->entry, head);
|
list_add_tail(&node->entry, head);
|
||||||
node->next = top_node;
|
node->next = top_node;
|
||||||
|
#ifdef DEBUG
|
||||||
|
node->x = x;
|
||||||
|
node->y = y;
|
||||||
|
#endif
|
||||||
top_node = node;
|
top_node = node;
|
||||||
if (!bot_node) {
|
if (!bot_node) {
|
||||||
bot_node = node;
|
bot_node = node;
|
||||||
@ -235,10 +239,25 @@ int MapService::GetMap(int x, int y)
|
|||||||
#endif
|
#endif
|
||||||
return TILE_STATE_CLOSED;
|
return TILE_STATE_CLOSED;
|
||||||
}
|
}
|
||||||
list_head* head = &map_cells_[x * y];
|
list_head* head = &map_cells_[x + map_width_ * y];
|
||||||
if (list_empty(head)) {
|
if (list_empty(head)) {
|
||||||
return TILE_STATE_OPENED_COST1;
|
return TILE_STATE_OPENED_COST1;
|
||||||
} else {
|
} 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;
|
return TILE_STATE_CLOSED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -323,7 +342,10 @@ void MapService::FindPathUpdate(FindPathStatus* find_status)
|
|||||||
|
|
||||||
steps++;
|
steps++;
|
||||||
MovePathPoint point;
|
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);
|
find_status->out_points.push_back(point);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -382,5 +404,11 @@ void MapService::DoMove(FindPathStatus* find_status)
|
|||||||
if (target_distance < 1.0001f) {
|
if (target_distance < 1.0001f) {
|
||||||
myself->SetPos(point->pos);
|
myself->SetPos(point->pos);
|
||||||
++find_status->path_index;
|
++find_status->path_index;
|
||||||
|
#ifdef DEBUG
|
||||||
|
if (myself->IsCollisionInMapService()) {
|
||||||
|
myself->IsCollisionInMapService();
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,10 @@ struct CellNode
|
|||||||
ColliderComponent* collider;
|
ColliderComponent* collider;
|
||||||
list_head entry;
|
list_head entry;
|
||||||
CellNode* next = nullptr;
|
CellNode* next = nullptr;
|
||||||
|
#ifdef DEBUG
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MovePathPoint
|
struct MovePathPoint
|
||||||
|
@ -22,3 +22,6 @@ namespace google
|
|||||||
#include "framework/cpp/types.h"
|
#include "framework/cpp/types.h"
|
||||||
#include "framework/cpp/protoutils.h"
|
#include "framework/cpp/protoutils.h"
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#define FIND_PATH_TEST 1
|
||||||
|
#endif
|
||||||
|
@ -2913,12 +2913,24 @@ void Room::ZombieModeStart()
|
|||||||
#endif
|
#endif
|
||||||
std::vector<Human*> human_list;
|
std::vector<Human*> human_list;
|
||||||
for (auto& pair : human_hash_) {
|
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);
|
human_list.push_back(pair.second);
|
||||||
|
#endif
|
||||||
if (RoomMgr::Instance()->IsGM(pair.second->account_id)) {
|
if (RoomMgr::Instance()->IsGM(pair.second->account_id)) {
|
||||||
debug_trace = true;
|
debug_trace = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::random_shuffle(human_list.begin(), human_list.end());
|
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) {
|
for (size_t i = 0; i < 2; ++i) {
|
||||||
Human* hum = human_list[i];
|
Human* hum = human_list[i];
|
||||||
hum->ChangeToRace(kZombieRace, 1);
|
hum->ChangeToRace(kZombieRace, 1);
|
||||||
@ -2948,6 +2960,7 @@ void Room::ZombieModeStart()
|
|||||||
room->battle_report_timer_ = nullptr;
|
room->battle_report_timer_ = nullptr;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Human* Room::GetOneCanEnableAndroid()
|
Human* Room::GetOneCanEnableAndroid()
|
||||||
@ -3285,7 +3298,11 @@ int Room::GetAliveCountByRace(RaceType_e race)
|
|||||||
size_t Room::GetRoomMaxPlayerNum()
|
size_t Room::GetRoomMaxPlayerNum()
|
||||||
{
|
{
|
||||||
if (room_mode_ == kZombieMode) {
|
if (room_mode_ == kZombieMode) {
|
||||||
|
#ifdef FIND_PATH_TEST
|
||||||
|
return 2;
|
||||||
|
#else
|
||||||
return MetaMgr::Instance()->zbmode_player_num;
|
return MetaMgr::Instance()->zbmode_player_num;
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if (IsMiniRoom()) {
|
if (IsMiniRoom()) {
|
||||||
return MINI_ROOM_MAX_PLAYER_NUM;
|
return MINI_ROOM_MAX_PLAYER_NUM;
|
||||||
|
@ -291,8 +291,11 @@ void ZombieModeAI::UpdateFindPath()
|
|||||||
} else {
|
} else {
|
||||||
myself->room->map_service->FindPathUpdate(find_status);
|
myself->room->map_service->FindPathUpdate(find_status);
|
||||||
if (myself->room->map_service->FindFailed(find_status)) {
|
if (myself->room->map_service->FindFailed(find_status)) {
|
||||||
|
#ifdef DEBUG
|
||||||
|
a8::XPrintf("寻路失败 step:%d\n", {find_status->search_step});
|
||||||
|
#endif
|
||||||
myself->ClearFindPathStatus();
|
myself->ClearFindPathStatus();
|
||||||
ChangeToState(ZSE_Thinking);
|
ChangeToState(ZSE_RandomWalk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -424,13 +427,18 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
|
|||||||
break;
|
break;
|
||||||
case ZSE_FindPathMoving:
|
case ZSE_FindPathMoving:
|
||||||
{
|
{
|
||||||
|
#ifdef DEBUG
|
||||||
|
a8::XPrintf("寻路成功\n", {});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
node_->main_state = to_state;
|
node_->main_state = to_state;
|
||||||
node_->frameno = hum->room->GetFrameNo();
|
node_->frameno = hum->room->GetFrameNo();
|
||||||
node_->exec_frame_num = 0;
|
node_->exec_frame_num = 0;
|
||||||
|
#ifdef DEBUG1
|
||||||
|
a8::XPrintf("changetostate %d\n", {to_state});
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Human* ZombieModeAI::GetTarget()
|
Human* ZombieModeAI::GetTarget()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user