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