diff --git a/server/gameserver/human.h b/server/gameserver/human.h index 9b1f085..0398b63 100644 --- a/server/gameserver/human.h +++ b/server/gameserver/human.h @@ -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 battling_items_; size_t normal_drop_times_ = 0; size_t box_drop_times_ = 0; + FindPathStatus* findpath_status_ = nullptr; std::array buff_effect_ = {}; std::array buff_attr_abs_ = {}; @@ -416,3 +419,4 @@ void InternalShot(Human* hum, int skill_id, float fly_distance, bool is_tank_skin); + diff --git a/server/gameserver/mapservice.cc b/server/gameserver/mapservice.cc index 7b7f5cf..fb1a009 100644 --- a/server/gameserver/mapservice.cc +++ b/server/gameserver/mapservice.cc @@ -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); } diff --git a/server/gameserver/mapservice.h b/server/gameserver/mapservice.h index c30ce69..f1c3186 100644 --- a/server/gameserver/mapservice.h +++ b/server/gameserver/mapservice.h @@ -25,6 +25,12 @@ struct FindPathStatus int curr_step = 0; int max_step_num = 0; std::vector 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& 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 findpath_requests_hash_; std::map node_hash_; }; diff --git a/server/gameserver/zombiemode.ai.cc b/server/gameserver/zombiemode.ai.cc index 3b11194..6faf655 100644 --- a/server/gameserver/zombiemode.ai.cc +++ b/server/gameserver/zombiemode.ai.cc @@ -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(); diff --git a/server/gameserver/zombiemode.ai.h b/server/gameserver/zombiemode.ai.h index c05e2eb..f1ed986 100644 --- a/server/gameserver/zombiemode.ai.h +++ b/server/gameserver/zombiemode.ai.h @@ -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();