添加寻路基础接口
This commit is contained in:
parent
acd95739a6
commit
6e9cca9801
@ -26,6 +26,7 @@ enum HumanStatus
|
||||
};
|
||||
|
||||
struct xtimer_list;
|
||||
struct FindPathStatus;
|
||||
class CircleCollider;
|
||||
class AabbCollider;
|
||||
class Obstacle;
|
||||
@ -263,6 +264,7 @@ class Human : public MoveableEntity
|
||||
void ProcBuffEffect(Human* caster, Buff* buff);
|
||||
int GetLevel() {return level_;};
|
||||
int GetExp() {return exp_;};
|
||||
FindPathStatus* GetFindPathStatus() { return findpath_status_; }
|
||||
void OnAttack() {};
|
||||
void OnHit() {};
|
||||
int GetItemNum(int item_id);
|
||||
@ -389,6 +391,7 @@ private:
|
||||
std::set<int> battling_items_;
|
||||
size_t normal_drop_times_ = 0;
|
||||
size_t box_drop_times_ = 0;
|
||||
FindPathStatus* findpath_status_ = nullptr;
|
||||
std::array<Buff*, kBET_End> buff_effect_ = {};
|
||||
|
||||
std::array<float, kHAT_End> buff_attr_abs_ = {};
|
||||
@ -416,3 +419,4 @@ void InternalShot(Human* hum,
|
||||
int skill_id,
|
||||
float fly_distance,
|
||||
bool is_tank_skin);
|
||||
|
||||
|
@ -6,11 +6,13 @@
|
||||
#include "mapservice.h"
|
||||
#include "collider.h"
|
||||
#include "entity.h"
|
||||
#include "human.h"
|
||||
#include "room.h"
|
||||
#include "roomobstacle.h"
|
||||
|
||||
MapService::MapService()
|
||||
{
|
||||
|
||||
INIT_LIST_HEAD(&findpath_list_);
|
||||
}
|
||||
|
||||
MapService::~MapService()
|
||||
@ -231,20 +233,33 @@ int MapService::GetGridId(float world_x, float world_y)
|
||||
return grid_id;
|
||||
}
|
||||
|
||||
int MapService::FindPathRequest(Human* hum,
|
||||
const a8::Vec2& start_pos,
|
||||
const a8::Vec2& end_pos,
|
||||
int max_step_num)
|
||||
FindPathStatus* MapService::AddFindPathRequest(Human* hum,
|
||||
const a8::Vec2& start_pos,
|
||||
const a8::Vec2& end_pos,
|
||||
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;
|
||||
}
|
||||
|
||||
void MapService::RemoveFindPathRequest(Human* hum, int query_id)
|
||||
{
|
||||
|
||||
auto itr = findpath_requests_hash_.find(hum);
|
||||
if (itr == findpath_requests_hash_.end()) {
|
||||
abort();
|
||||
}
|
||||
if (itr->second != status) {
|
||||
abort();
|
||||
}
|
||||
list_del_init(&status->entry);
|
||||
A8_SAFE_DELETE(status);
|
||||
findpath_requests_hash_.erase(itr);
|
||||
}
|
||||
|
@ -25,6 +25,12 @@ struct FindPathStatus
|
||||
int curr_step = 0;
|
||||
int max_step_num = 0;
|
||||
std::vector<MovePathPoint> out_ponits;
|
||||
list_head entry;
|
||||
|
||||
FindPathStatus()
|
||||
{
|
||||
INIT_LIST_HEAD(&entry);
|
||||
}
|
||||
};
|
||||
|
||||
class Room;
|
||||
@ -43,12 +49,11 @@ class MapService
|
||||
float world_x,
|
||||
float world_y,
|
||||
std::set<ColliderComponent*>& colliders);
|
||||
int FindPathRequest(Human* hum,
|
||||
const a8::Vec2& start_pos,
|
||||
const a8::Vec2& end_pos,
|
||||
int max_step_num);
|
||||
FindPathStatus* QueryFindPathStatus(int query_id);
|
||||
void RemoveFindPathRequest(Human* hum, int query_id);
|
||||
FindPathStatus* AddFindPathRequest(Human* hum,
|
||||
const a8::Vec2& start_pos,
|
||||
const a8::Vec2& end_pos,
|
||||
int max_step_num);
|
||||
void DelFindPathRequest(Human* hum, FindPathStatus* status);
|
||||
|
||||
private:
|
||||
int GetGridId(float world_x, float world_y);
|
||||
@ -60,6 +65,8 @@ class MapService
|
||||
int cell_width_ = 0;
|
||||
int max_grid_id_ = 0;
|
||||
int grid_offset_arr_[9] = {0};
|
||||
list_head findpath_list_;
|
||||
std::map<Human*, FindPathStatus*> findpath_requests_hash_;
|
||||
std::map<ColliderComponent*, CellNode*> node_hash_;
|
||||
|
||||
};
|
||||
|
@ -120,6 +120,11 @@ void ZombieModeAI::UpdateAI()
|
||||
UpdatePursuit();
|
||||
}
|
||||
break;
|
||||
case ZSE_FindPath:
|
||||
{
|
||||
UpdateFindPath();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
abort();
|
||||
@ -269,6 +274,11 @@ void ZombieModeAI::UpdatePursuit()
|
||||
}
|
||||
}
|
||||
|
||||
void ZombieModeAI::UpdateFindPath()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ZombieModeAI::DoMove()
|
||||
{
|
||||
Human* hum = (Human*)owner;
|
||||
@ -361,6 +371,11 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ZSE_FindPath:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
node_->main_state = to_state;
|
||||
node_->frameno = hum->room->GetFrameNo();
|
||||
|
@ -8,7 +8,8 @@ enum ZombieState_e
|
||||
ZSE_Thinking = 1,
|
||||
ZSE_Attack = 2,
|
||||
ZSE_RandomWalk = 3,
|
||||
ZSE_Pursuit = 4
|
||||
ZSE_Pursuit = 4,
|
||||
ZSE_FindPath = 5
|
||||
};
|
||||
|
||||
class Human;
|
||||
@ -30,6 +31,7 @@ private:
|
||||
void UpdateAttack();
|
||||
void UpdateRandomWalk();
|
||||
void UpdatePursuit();
|
||||
void UpdateFindPath();
|
||||
void DoMove();
|
||||
void ChangeToState(ZombieState_e to_state);
|
||||
void DoShot();
|
||||
|
Loading…
x
Reference in New Issue
Block a user