添加寻路基础接口

This commit is contained in:
aozhiwei 2020-08-05 20:13:08 +08:00
parent acd95739a6
commit 6e9cca9801
5 changed files with 63 additions and 20 deletions

View File

@ -26,6 +26,7 @@ enum HumanStatus
}; };
struct xtimer_list; struct xtimer_list;
struct FindPathStatus;
class CircleCollider; class CircleCollider;
class AabbCollider; class AabbCollider;
class Obstacle; class Obstacle;
@ -263,6 +264,7 @@ class Human : public MoveableEntity
void ProcBuffEffect(Human* caster, Buff* buff); void ProcBuffEffect(Human* caster, Buff* buff);
int GetLevel() {return level_;}; int GetLevel() {return level_;};
int GetExp() {return exp_;}; int GetExp() {return exp_;};
FindPathStatus* GetFindPathStatus() { return findpath_status_; }
void OnAttack() {}; void OnAttack() {};
void OnHit() {}; void OnHit() {};
int GetItemNum(int item_id); int GetItemNum(int item_id);
@ -389,6 +391,7 @@ private:
std::set<int> battling_items_; std::set<int> battling_items_;
size_t normal_drop_times_ = 0; size_t normal_drop_times_ = 0;
size_t box_drop_times_ = 0; size_t box_drop_times_ = 0;
FindPathStatus* findpath_status_ = nullptr;
std::array<Buff*, kBET_End> buff_effect_ = {}; std::array<Buff*, kBET_End> buff_effect_ = {};
std::array<float, kHAT_End> buff_attr_abs_ = {}; std::array<float, kHAT_End> buff_attr_abs_ = {};
@ -416,3 +419,4 @@ void InternalShot(Human* hum,
int skill_id, int skill_id,
float fly_distance, float fly_distance,
bool is_tank_skin); bool is_tank_skin);

View File

@ -6,11 +6,13 @@
#include "mapservice.h" #include "mapservice.h"
#include "collider.h" #include "collider.h"
#include "entity.h" #include "entity.h"
#include "human.h"
#include "room.h"
#include "roomobstacle.h" #include "roomobstacle.h"
MapService::MapService() MapService::MapService()
{ {
INIT_LIST_HEAD(&findpath_list_);
} }
MapService::~MapService() MapService::~MapService()
@ -231,20 +233,33 @@ int MapService::GetGridId(float world_x, float world_y)
return grid_id; return grid_id;
} }
int MapService::FindPathRequest(Human* hum, FindPathStatus* MapService::AddFindPathRequest(Human* hum,
const a8::Vec2& start_pos, const a8::Vec2& start_pos,
const a8::Vec2& end_pos, const a8::Vec2& end_pos,
int max_step_num) int max_step_num)
{ {
return 0; FindPathStatus* status = new FindPathStatus();
status->frameno = hum->room->GetFrameNo();
status->hum = hum;
status->start_pos = start_pos;
status->end_pos = end_pos;
status->curr_step = 0;
status->max_step_num = max_step_num;
list_add_tail(&status->entry, &findpath_list_);
findpath_requests_hash_[hum] = status;
return status;
} }
FindPathStatus* MapService::QueryFindPathStatus(int query_id) void MapService::DelFindPathRequest(Human* hum, FindPathStatus* status)
{ {
return nullptr; auto itr = findpath_requests_hash_.find(hum);
} if (itr == findpath_requests_hash_.end()) {
abort();
void MapService::RemoveFindPathRequest(Human* hum, int query_id) }
{ if (itr->second != status) {
abort();
}
list_del_init(&status->entry);
A8_SAFE_DELETE(status);
findpath_requests_hash_.erase(itr);
} }

View File

@ -25,6 +25,12 @@ struct FindPathStatus
int curr_step = 0; int curr_step = 0;
int max_step_num = 0; int max_step_num = 0;
std::vector<MovePathPoint> out_ponits; std::vector<MovePathPoint> out_ponits;
list_head entry;
FindPathStatus()
{
INIT_LIST_HEAD(&entry);
}
}; };
class Room; class Room;
@ -43,12 +49,11 @@ class MapService
float world_x, float world_x,
float world_y, float world_y,
std::set<ColliderComponent*>& colliders); std::set<ColliderComponent*>& colliders);
int FindPathRequest(Human* hum, FindPathStatus* AddFindPathRequest(Human* hum,
const a8::Vec2& start_pos, const a8::Vec2& start_pos,
const a8::Vec2& end_pos, const a8::Vec2& end_pos,
int max_step_num); int max_step_num);
FindPathStatus* QueryFindPathStatus(int query_id); void DelFindPathRequest(Human* hum, FindPathStatus* status);
void RemoveFindPathRequest(Human* hum, int query_id);
private: private:
int GetGridId(float world_x, float world_y); int GetGridId(float world_x, float world_y);
@ -60,6 +65,8 @@ class MapService
int cell_width_ = 0; int cell_width_ = 0;
int max_grid_id_ = 0; int max_grid_id_ = 0;
int grid_offset_arr_[9] = {0}; int grid_offset_arr_[9] = {0};
list_head findpath_list_;
std::map<Human*, FindPathStatus*> findpath_requests_hash_;
std::map<ColliderComponent*, CellNode*> node_hash_; std::map<ColliderComponent*, CellNode*> node_hash_;
}; };

View File

@ -120,6 +120,11 @@ void ZombieModeAI::UpdateAI()
UpdatePursuit(); UpdatePursuit();
} }
break; break;
case ZSE_FindPath:
{
UpdateFindPath();
}
break;
default: default:
{ {
abort(); abort();
@ -269,6 +274,11 @@ void ZombieModeAI::UpdatePursuit()
} }
} }
void ZombieModeAI::UpdateFindPath()
{
}
void ZombieModeAI::DoMove() void ZombieModeAI::DoMove()
{ {
Human* hum = (Human*)owner; Human* hum = (Human*)owner;
@ -361,6 +371,11 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
} }
} }
break; break;
case ZSE_FindPath:
{
}
break;
} }
node_->main_state = to_state; node_->main_state = to_state;
node_->frameno = hum->room->GetFrameNo(); node_->frameno = hum->room->GetFrameNo();

View File

@ -8,7 +8,8 @@ enum ZombieState_e
ZSE_Thinking = 1, ZSE_Thinking = 1,
ZSE_Attack = 2, ZSE_Attack = 2,
ZSE_RandomWalk = 3, ZSE_RandomWalk = 3,
ZSE_Pursuit = 4 ZSE_Pursuit = 4,
ZSE_FindPath = 5
}; };
class Human; class Human;
@ -30,6 +31,7 @@ private:
void UpdateAttack(); void UpdateAttack();
void UpdateRandomWalk(); void UpdateRandomWalk();
void UpdatePursuit(); void UpdatePursuit();
void UpdateFindPath();
void DoMove(); void DoMove();
void ChangeToState(ZombieState_e to_state); void ChangeToState(ZombieState_e to_state);
void DoShot(); void DoShot();