优化目标选取
This commit is contained in:
parent
79e771455a
commit
9dc816e77b
@ -892,6 +892,18 @@ void Creature::ResetAction()
|
||||
|
||||
bool Creature::IsProperTarget(Creature* target)
|
||||
{
|
||||
if (target->dead) {
|
||||
return false;
|
||||
}
|
||||
if (a8::HasBitFlag(target->status, HS_Disable)) {
|
||||
return false;
|
||||
}
|
||||
if (team_id == target->team_id) {
|
||||
return false;
|
||||
}
|
||||
if (room->GetRoomMode() == kZombieMode && GetRace() == target->GetRace()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -903,3 +915,17 @@ bool Creature::IsEnemy(Creature* target)
|
||||
return team_id != target->team_id;
|
||||
}
|
||||
}
|
||||
|
||||
void Creature::TouchProperTargets(std::function<void (Creature*, bool&)> func)
|
||||
{
|
||||
auto callback =
|
||||
[this, func] (Creature* c, bool& stop)
|
||||
{
|
||||
if (IsProperTarget(c)) {
|
||||
func(c, stop);
|
||||
}
|
||||
};
|
||||
room->grid_service->TouchCreatures(room->GetRoomIdx(),
|
||||
GetGridList(),
|
||||
callback);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ class Creature : public MoveableEntity
|
||||
{
|
||||
public:
|
||||
|
||||
int status = 0;
|
||||
bool dead = false;
|
||||
int team_id = 0;
|
||||
bool aiming = false;
|
||||
@ -90,6 +91,8 @@ class Creature : public MoveableEntity
|
||||
int GetActionType() { return action_type; }
|
||||
int GetActionTargetId() { return action_target_id; }
|
||||
|
||||
void TouchProperTargets(std::function<void (Creature*, bool&)> func);
|
||||
|
||||
private:
|
||||
|
||||
virtual void AddBuffPostProc(Creature* caster, Buff* buff);
|
||||
|
@ -29,7 +29,7 @@ void GridCell::ClearRoomData(Room* room)
|
||||
creatures_[room->GetRoomIdx()].clear();
|
||||
}
|
||||
|
||||
void GridCell::TouchHumanList(std::function<void (Human*, bool&)>& func,
|
||||
void GridCell::TouchHumanList(std::function<void (Human*, bool&)> func,
|
||||
int room_idx,
|
||||
bool& stop)
|
||||
{
|
||||
@ -45,11 +45,16 @@ void GridCell::TouchHumanList(std::function<void (Human*, bool&)>& func,
|
||||
}
|
||||
}
|
||||
|
||||
void GridCell::TouchHumanListEx(std::function<void (Human*, bool&)> func,
|
||||
int room_idx,
|
||||
bool& stop)
|
||||
void GridCell::TouchCreatures(std::function<void (Creature*, bool&)>& func,
|
||||
int room_idx,
|
||||
bool& stop)
|
||||
{
|
||||
TouchHumanList(func, room_idx, stop);
|
||||
for (Creature* c : creatures_[room_idx]) {
|
||||
func(c, stop);
|
||||
if (stop) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GridCell::AddBullet(Bullet* bullet)
|
||||
|
@ -13,12 +13,12 @@ public:
|
||||
GridCell();
|
||||
void ClearRoomData(Room* room);
|
||||
|
||||
void TouchHumanList(std::function<void (Human*, bool&)>& func,
|
||||
void TouchHumanList(std::function<void (Human*, bool&)> func,
|
||||
int room_idx,
|
||||
bool& stop);
|
||||
void TouchCreatures(std::function<void (Creature*, bool&)>& func,
|
||||
int room_idx,
|
||||
bool& stop);
|
||||
void TouchHumanListEx(std::function<void (Human*, bool&)> func,
|
||||
int room_idx,
|
||||
bool& stop);
|
||||
|
||||
void AddCreature(Creature* c);
|
||||
void RemoveCreature(Creature* c);
|
||||
|
@ -378,11 +378,24 @@ void GridService::TouchAllLayerHumanList(int room_idx,
|
||||
}
|
||||
}
|
||||
|
||||
void GridService::TouchCreatures(int room_idx,
|
||||
std::set<GridCell*>& grid_list,
|
||||
std::function<void (Creature*, bool&)> func)
|
||||
{
|
||||
bool stop = false;
|
||||
for (auto& cell : grid_list) {
|
||||
cell->TouchHumanList(func, room_idx, stop);
|
||||
if (stop) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GridService::DeatchHuman(Human* target)
|
||||
{
|
||||
for (auto& cell : target->GetGridList()) {
|
||||
bool stop = false;
|
||||
cell->TouchHumanListEx
|
||||
cell->TouchHumanList
|
||||
(
|
||||
[target] (Human* hum, bool& stop)
|
||||
{
|
||||
|
@ -49,6 +49,9 @@ class GridService
|
||||
void TouchAllLayerHumanList(int room_idx,
|
||||
std::set<GridCell*>& grid_list,
|
||||
std::function<void (Human*, bool&)> func);
|
||||
void TouchCreatures(int room_idx,
|
||||
std::set<GridCell*>& grid_list,
|
||||
std::function<void (Creature*, bool&)> func);
|
||||
void DeatchHuman(Human* hum);
|
||||
|
||||
private:
|
||||
|
@ -82,7 +82,6 @@ class Human : public Creature
|
||||
int lethal_weapon = 0;
|
||||
long long join_frameno = 0;
|
||||
long long enable_frameno = 0;
|
||||
int status = 0;
|
||||
float atk_add = 0.0f;
|
||||
int emoji1 = 0;
|
||||
int emoji2 = 0;
|
||||
|
@ -155,7 +155,7 @@ void ZombieModeAI::UpdateThinking()
|
||||
ChangeToState(ZSE_RandomWalk);
|
||||
}
|
||||
} else {
|
||||
Human* target = GetTarget();
|
||||
Creature* target = GetTarget();
|
||||
if (target) {
|
||||
node_->target = target;
|
||||
ChangeToState(ZSE_Attack);
|
||||
@ -369,7 +369,7 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
|
||||
node_->exec_frame_num = 0;
|
||||
}
|
||||
|
||||
Human* ZombieModeAI::GetTarget()
|
||||
Creature* ZombieModeAI::GetTarget()
|
||||
{
|
||||
if (GetAiLevel() <= 1) {
|
||||
return nullptr;
|
||||
@ -379,30 +379,18 @@ Human* ZombieModeAI::GetTarget()
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Human* target = nullptr;
|
||||
myself->TouchAllLayerHumanList
|
||||
Creature* target = nullptr;
|
||||
myself->TouchProperTargets
|
||||
(
|
||||
[myself, &target] (Human* hum, bool& stop)
|
||||
[myself, &target] (Creature* c, bool& stop)
|
||||
{
|
||||
if (hum->dead) {
|
||||
return;
|
||||
}
|
||||
if (a8::HasBitFlag(hum->status, HS_Disable)) {
|
||||
return;
|
||||
}
|
||||
if (myself->team_id == hum->team_id) {
|
||||
return;
|
||||
}
|
||||
if (myself->GetRace() == hum->GetRace()) {
|
||||
return;
|
||||
}
|
||||
if (target) {
|
||||
if (myself->GetPos().ManhattanDistance(target->GetPos()) >
|
||||
myself->GetPos().ManhattanDistance(hum->GetPos())) {
|
||||
target = hum;
|
||||
myself->GetPos().ManhattanDistance(c->GetPos())) {
|
||||
target = c;
|
||||
}
|
||||
} else {
|
||||
target = hum;
|
||||
target = c;
|
||||
}
|
||||
});
|
||||
if (target) {
|
||||
|
@ -12,6 +12,7 @@ enum ZombieState_e
|
||||
};
|
||||
|
||||
class Human;
|
||||
class Creature;
|
||||
class ZombieAINode;
|
||||
class ZombieModeAI : public AIComponent
|
||||
{
|
||||
@ -35,7 +36,7 @@ private:
|
||||
void DoShot();
|
||||
void DoSkill(int skill_id);
|
||||
|
||||
Human* GetTarget();
|
||||
Creature* GetTarget();
|
||||
float GetAttackRange();
|
||||
int GetAttackTimes();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user