重构move_dir

This commit is contained in:
aozhiwei 2021-04-08 10:44:58 +08:00
parent 4d82f76a4c
commit ade68bd729
10 changed files with 100 additions and 81 deletions

View File

@ -139,10 +139,11 @@ void AndroidNewAI::ChangeToStateOldAI(AndroidState_e to_state)
case AS_moving: case AS_moving:
{ {
Human* hum = (Human*)owner; Human* hum = (Human*)owner;
hum->move_dir = a8::Vec2(1.0f, 0); a8::Vec2 move_dir = a8::Vec2(1.0f, 0);
hum->move_dir.Rotate(a8::RandAngle()); move_dir.Rotate(a8::RandAngle());
hum->move_dir.Normalize(); move_dir.Normalize();
hum->attack_dir = hum->move_dir; hum->SetMoveDir(move_dir);
hum->attack_dir = hum->GetMoveDir();
} }
break; break;
default: default:
@ -164,12 +165,13 @@ void AndroidNewAI::DoMoveOldAI()
int speed = std::max(1, (int)hum->GetSpeed()); int speed = std::max(1, (int)hum->GetSpeed());
if (a8::HasBitFlag(hum->status, HS_NewBieGuideAndroid) && if (a8::HasBitFlag(hum->status, HS_NewBieGuideAndroid) &&
hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 8) { hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 8) {
hum->move_dir = hum->room->GetFirstNewBie()->GetPos() - hum->GetPos(); a8::Vec2 move_dir = hum->room->GetFirstNewBie()->GetPos() - hum->GetPos();
hum->move_dir.Normalize(); move_dir.Normalize();
hum->SetMoveDir(move_dir);
} }
for (int i = 0; i < speed; ++i) { for (int i = 0; i < speed; ++i) {
a8::Vec2 old_pos = hum->GetPos(); a8::Vec2 old_pos = hum->GetPos();
hum->SetPos(hum->GetPos() + hum->move_dir); hum->SetPos(hum->GetPos() + hum->GetMoveDir());
if (hum->IsCollisionInMapService()) { if (hum->IsCollisionInMapService()) {
hum->SetPos(old_pos); hum->SetPos(old_pos);
if (i == 0) { if (i == 0) {
@ -217,17 +219,18 @@ void AndroidNewAI::UpdateNewBieNpc()
Human* hum = (Human*)owner; Human* hum = (Human*)owner;
if (hum->room->GetFrameNo() - hum->enable_frameno < 2) { if (hum->room->GetFrameNo() - hum->enable_frameno < 2) {
if (hum->GetPos().ManhattanDistance(hum->room->GetFirstNewBie()->GetPos()) > 100) { if (hum->GetPos().ManhattanDistance(hum->room->GetFirstNewBie()->GetPos()) > 100) {
hum->move_dir = hum->room->GetFirstNewBie()->GetPos() - hum->GetPos(); a8::Vec2 move_dir = hum->room->GetFirstNewBie()->GetPos() - hum->GetPos();
hum->move_dir.Normalize(); move_dir.Normalize();
hum->SetMoveDir(move_dir);
} }
hum->attack_dir = hum->move_dir; hum->attack_dir = hum->GetMoveDir();
if (hum->curr_weapon->weapon_idx != 0) { if (hum->curr_weapon->weapon_idx != 0) {
hum->curr_weapon->ammo = MetaMgr::Instance()->newbie_first_robot_ammo; hum->curr_weapon->ammo = MetaMgr::Instance()->newbie_first_robot_ammo;
} }
} else if (hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 1.5) { } else if (hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 1.5) {
int speed = std::max(1, (int)hum->GetSpeed()); int speed = std::max(1, (int)hum->GetSpeed());
for (int i = 0; i < speed; ++i) { for (int i = 0; i < speed; ++i) {
hum->SetPos(hum->GetPos() + hum->move_dir); hum->SetPos(hum->GetPos() + hum->GetMoveDir());
hum->room->grid_service->MoveCreature(hum); hum->room->grid_service->MoveCreature(hum);
} }
} else if (hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 3) { } else if (hum->room->GetFrameNo() - hum->enable_frameno < SERVER_FRAME_RATE * 3) {
@ -252,10 +255,11 @@ void AndroidNewAI::UpdateLastNpc()
Human* hum = (Human*)owner; Human* hum = (Human*)owner;
if (hum->room->GetFrameNo() - hum->enable_frameno < 2) { if (hum->room->GetFrameNo() - hum->enable_frameno < 2) {
if (hum->GetPos().ManhattanDistance(hum->last_human_target->GetPos()) > 100) { if (hum->GetPos().ManhattanDistance(hum->last_human_target->GetPos()) > 100) {
hum->move_dir = hum->last_human_target->GetPos() - hum->GetPos(); a8::Vec2 move_dir = hum->last_human_target->GetPos() - hum->GetPos();
hum->move_dir.Normalize(); move_dir.Normalize();
hum->SetMoveDir(move_dir);
} }
hum->attack_dir = hum->move_dir; hum->attack_dir = hum->GetMoveDir();
if (hum->curr_weapon->weapon_idx != 0) { if (hum->curr_weapon->weapon_idx != 0) {
hum->curr_weapon->ammo = MetaMgr::Instance()->newbie_first_robot_ammo * 2; hum->curr_weapon->ammo = MetaMgr::Instance()->newbie_first_robot_ammo * 2;
} }
@ -263,7 +267,7 @@ void AndroidNewAI::UpdateLastNpc()
int speed = std::max(1, (int)hum->GetSpeed()); int speed = std::max(1, (int)hum->GetSpeed());
for (int i = 0; i < speed; ++i) { for (int i = 0; i < speed; ++i) {
a8::Vec2 old_pos = hum->GetPos(); a8::Vec2 old_pos = hum->GetPos();
hum->SetPos(hum->GetPos() + hum->move_dir); hum->SetPos(hum->GetPos() + hum->GetMoveDir());
if (!hum->room->OverBorder(hum->GetPos(), hum->meta->i->radius())) { if (!hum->room->OverBorder(hum->GetPos(), hum->meta->i->radius())) {
hum->room->grid_service->MoveCreature(hum); hum->room->grid_service->MoveCreature(hum);
} else { } else {
@ -347,7 +351,7 @@ void AndroidNewAI::UpdateNewBieRoomLogic()
if (hum->room->AliveCount() < 15) { if (hum->room->AliveCount() < 15) {
if (hum->GetPos().ManhattanDistance(target->GetPos()) > 1000) { if (hum->GetPos().ManhattanDistance(target->GetPos()) > 1000) {
a8::Vec2 pos = target->GetPos(); a8::Vec2 pos = target->GetPos();
a8::Vec2 dir = target->move_dir; a8::Vec2 dir = target->GetMoveDir();
dir = a8::Vec2::UP; dir = a8::Vec2::UP;
if (rand() % 100 < 1) { if (rand() % 100 < 1) {
dir.Rotate(a8::RandAngle() / 2.0f); dir.Rotate(a8::RandAngle() / 2.0f);
@ -375,12 +379,13 @@ void AndroidNewAI::UpdateNewBieRoomLogic()
old_ai_data_.last_target.Reset(); old_ai_data_.last_target.Reset();
} else { } else {
int speed = std::max(1, (int)hum->GetSpeed()); int speed = std::max(1, (int)hum->GetSpeed());
hum->move_dir = target->GetPos() - hum->GetPos(); a8::Vec2 move_dir = target->GetPos() - hum->GetPos();
hum->move_dir.Normalize(); move_dir.Normalize();
hum->attack_dir = hum->move_dir; hum->SetMoveDir(move_dir);
hum->attack_dir = hum->GetMoveDir();
speed *= 0.7; speed *= 0.7;
for (int i = 0; i < speed; ++i) { for (int i = 0; i < speed; ++i) {
hum->SetPos(hum->GetPos() + hum->move_dir); hum->SetPos(hum->GetPos() + hum->GetMoveDir());
hum->room->grid_service->MoveCreature(hum); hum->room->grid_service->MoveCreature(hum);
} }
} }
@ -585,8 +590,8 @@ void AndroidNewAI::UpdatePursuit()
void AndroidNewAI::DoMoveNewAI() void AndroidNewAI::DoMoveNewAI()
{ {
Human* hum = (Human*)owner; Human* hum = (Human*)owner;
if (std::abs(hum->move_dir.x) > FLT_EPSILON || if (std::abs(hum->GetMoveDir().x) > FLT_EPSILON ||
std::abs(hum->move_dir.y) > FLT_EPSILON) { std::abs(hum->GetMoveDir().y) > FLT_EPSILON) {
hum->on_move_collision = hum->on_move_collision =
[this] () { [this] () {
ChangeToStateNewAI(ASE_RandomWalk); ChangeToStateNewAI(ASE_RandomWalk);
@ -657,10 +662,11 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
node_.shot_times = 0; node_.shot_times = 0;
node_.next_random_move_frameno = hum->room->GetFrameNo() + node_.next_random_move_frameno = hum->room->GetFrameNo() +
SERVER_FRAME_RATE * ai_meta->GetMoveIdleTime(); SERVER_FRAME_RATE * ai_meta->GetMoveIdleTime();
hum->move_dir = a8::Vec2(1.0f, 0); a8::Vec2 move_dir = a8::Vec2(1.0f, 0);
hum->move_dir.Rotate(a8::RandAngle()); move_dir.Rotate(a8::RandAngle());
hum->move_dir.Normalize(); move_dir.Normalize();
hum->attack_dir = hum->move_dir; hum->SetMoveDir(move_dir);
hum->attack_dir = hum->GetMoveDir();
if (node_.param1 <= 1) { if (node_.param1 <= 1) {
moving_ = false; moving_ = false;
} }
@ -670,9 +676,10 @@ void AndroidNewAI::ChangeToStateNewAI(AndroidStateEx_e to_state)
{ {
moving_ = true; moving_ = true;
if (node_.target.Get()) { if (node_.target.Get()) {
hum->move_dir = node_.target.Get()->GetPos() - hum->GetPos(); a8::Vec2 move_dir = node_.target.Get()->GetPos() - hum->GetPos();
hum->move_dir.Normalize(); move_dir.Normalize();
hum->attack_dir = hum->move_dir; hum->SetMoveDir(move_dir);
hum->attack_dir = hum->GetMoveDir();
} }
} }
break; break;

View File

@ -33,7 +33,7 @@ void Car::FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data)
cs::MFCarPart* p = part_data->mutable_union_obj_11(); cs::MFCarPart* p = part_data->mutable_union_obj_11();
p->set_obj_uniid(GetEntityUniId()); p->set_obj_uniid(GetEntityUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos()); TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(move_dir, p->mutable_dir()); TypeConvert::ToPb(GetMoveDir(), p->mutable_dir());
} }
void Car::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) void Car::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
@ -42,7 +42,7 @@ void Car::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
cs::MFCarFull* p = full_data->mutable_union_obj_11(); cs::MFCarFull* p = full_data->mutable_union_obj_11();
p->set_obj_uniid(GetEntityUniId()); p->set_obj_uniid(GetEntityUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos()); TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(move_dir, p->mutable_dir()); TypeConvert::ToPb(GetMoveDir(), p->mutable_dir());
p->set_car_id(meta->i->id()); p->set_car_id(meta->i->id());
p->set_driver(driver_ ? driver_->GetEntityUniId() : 0); p->set_driver(driver_ ? driver_->GetEntityUniId() : 0);
for (auto hum : passengers_) { for (auto hum : passengers_) {
@ -167,11 +167,11 @@ void Car::SyncPos()
{ {
if (driver_) { if (driver_) {
SetPos(driver_->GetPos()); SetPos(driver_->GetPos());
move_dir = driver_->move_dir; SetMoveDir(driver_->GetMoveDir());
for (auto hum : passengers_) { for (auto hum : passengers_) {
if (hum != driver_) { if (hum != driver_) {
hum->SetPos(GetPos()); hum->SetPos(GetPos());
hum->move_dir = move_dir; hum->SetMoveDir(GetMoveDir());
room->grid_service->MoveCreature(hum); room->grid_service->MoveCreature(hum);
} }
} }

View File

@ -78,11 +78,11 @@ void InternalShot(Creature* c,
} }
} }
if (weapon_meta->i->recoil_force() > 0.000001) { if (weapon_meta->i->recoil_force() > 0.000001) {
a8::Vec2 old_move_dir = c->move_dir; a8::Vec2 old_move_dir = c->GetMoveDir();
c->MustBeAddBuff(c, kRecoilBuffId); c->MustBeAddBuff(c, kRecoilBuffId);
c->move_dir = c->attack_dir * -1; c->SetMoveDir(c->attack_dir * -1);
c->_UpdateMove(weapon_meta->i->recoil_force()); c->_UpdateMove(weapon_meta->i->recoil_force());
c->move_dir = old_move_dir; c->SetMoveDir(old_move_dir);
} }
} }
@ -727,16 +727,18 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
SetPos(caster->GetPos()); SetPos(caster->GetPos());
target_pos = caster->GetPos(); target_pos = caster->GetPos();
} else { } else {
move_dir = caster->GetPos() - GetPos(); a8::Vec2 move_dir = caster->GetPos() - GetPos();
move_dir.Normalize(); move_dir.Normalize();
target_pos = GetPos() + move_dir * (target_distance - buff->meta->param3); SetMoveDir(move_dir);
target_pos = GetPos() + GetMoveDir() * (target_distance - buff->meta->param3);
} }
} }
} else { } else {
caster->skill_dir_.Normalize(); caster->skill_dir_.Normalize();
target_pos = caster->GetPos() + caster->skill_dir_ * caster->skill_distance_; target_pos = caster->GetPos() + caster->skill_dir_ * caster->skill_distance_;
move_dir = target_pos - GetPos(); a8::Vec2 move_dir = target_pos - GetPos();
move_dir.Normalize(); move_dir.Normalize();
SetMoveDir(move_dir);
} }
} }
break; break;
@ -753,10 +755,11 @@ void Creature::ProcBuffEffect(Creature* caster, Buff* buff)
SetPos(entity->GetPos()); SetPos(entity->GetPos());
skill_target_pos_ = entity->GetPos(); skill_target_pos_ = entity->GetPos();
} else { } else {
move_dir = entity->GetPos() - GetPos(); a8::Vec2 move_dir = entity->GetPos() - GetPos();
move_dir.Normalize(); move_dir.Normalize();
skill_dir_ = move_dir; SetMoveDir(move_dir);
skill_target_pos_ = GetPos() + move_dir * (target_distance - buff->meta->param3); skill_dir_ = GetMoveDir();
skill_target_pos_ = GetPos() + GetMoveDir() * (target_distance - buff->meta->param3);
} }
} }
} }

View File

@ -230,8 +230,8 @@ void HeroAI::UpdatePursuit()
void HeroAI::DoMoveAI() void HeroAI::DoMoveAI()
{ {
Hero* hero = (Hero*)owner; Hero* hero = (Hero*)owner;
if (std::abs(hero->move_dir.x) > FLT_EPSILON || if (std::abs(hero->GetMoveDir().x) > FLT_EPSILON ||
std::abs(hero->move_dir.y) > FLT_EPSILON) { std::abs(hero->GetMoveDir().y) > FLT_EPSILON) {
hero->on_move_collision = hero->on_move_collision =
[this] () { [this] () {
ChangeToStateAI(HSE_RandomWalk); ChangeToStateAI(HSE_RandomWalk);
@ -294,10 +294,11 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state)
node_.shot_times = 0; node_.shot_times = 0;
node_.next_random_move_frameno = hero->room->GetFrameNo() + node_.next_random_move_frameno = hero->room->GetFrameNo() +
SERVER_FRAME_RATE * ai_meta->GetMoveIdleTime(); SERVER_FRAME_RATE * ai_meta->GetMoveIdleTime();
hero->move_dir = a8::Vec2(1.0f, 0); a8::Vec2 move_dir = a8::Vec2(1.0f, 0);
hero->move_dir.Rotate(a8::RandAngle()); move_dir.Rotate(a8::RandAngle());
hero->move_dir.Normalize(); move_dir.Normalize();
hero->attack_dir = hero->move_dir; hero->SetMoveDir(move_dir);
hero->attack_dir = hero->GetMoveDir();
if (node_.param1 <= 1) { if (node_.param1 <= 1) {
moving_ = false; moving_ = false;
} }
@ -307,9 +308,10 @@ void HeroAI::ChangeToStateAI(HeroState_e to_state)
{ {
moving_ = true; moving_ = true;
if (node_.target.Get()) { if (node_.target.Get()) {
hero->move_dir = node_.target.Get()->GetPos() - hero->GetPos(); a8::Vec2 move_dir = node_.target.Get()->GetPos() - hero->GetPos();
hero->move_dir.Normalize(); move_dir.Normalize();
hero->attack_dir = hero->move_dir; hero->SetMoveDir(move_dir);
hero->attack_dir = hero->GetMoveDir();
} }
} }
break; break;

View File

@ -36,7 +36,7 @@ void Hero::FillMFObjectPart(Room* room, Human* hum, cs::MFObjectPart* part_data)
cs::MFHeroPart* p = part_data->mutable_union_obj_10(); cs::MFHeroPart* p = part_data->mutable_union_obj_10();
p->set_obj_uniid(GetEntityUniId()); p->set_obj_uniid(GetEntityUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos()); TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(move_dir, p->mutable_dir()); TypeConvert::ToPb(GetMoveDir(), p->mutable_dir());
} }
void Hero::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data) void Hero::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
@ -45,7 +45,7 @@ void Hero::FillMFObjectFull(Room* room, Human* hum, cs::MFObjectFull* full_data)
cs::MFHeroFull* p = full_data->mutable_union_obj_10(); cs::MFHeroFull* p = full_data->mutable_union_obj_10();
p->set_obj_uniid(GetEntityUniId()); p->set_obj_uniid(GetEntityUniId());
TypeConvert::ToPb(GetPos(), p->mutable_pos()); TypeConvert::ToPb(GetPos(), p->mutable_pos());
TypeConvert::ToPb(move_dir, p->mutable_dir()); TypeConvert::ToPb(GetMoveDir(), p->mutable_dir());
p->set_heroid(meta->i->id()); p->set_heroid(meta->i->id());
p->set_master_uniid(master ? master->GetEntityUniId() : 0); p->set_master_uniid(master ? master->GetEntityUniId() : 0);
} }
@ -74,7 +74,7 @@ void Hero::_UpdateMove(int speed)
void Hero::InternalUpdateMove(float speed) void Hero::InternalUpdateMove(float speed)
{ {
a8::Vec2 old_pos = GetPos(); a8::Vec2 old_pos = GetPos();
a8::Vec2 new_pos = GetPos() + move_dir * speed; a8::Vec2 new_pos = GetPos() + GetMoveDir() * speed;
SetPos(new_pos); SetPos(new_pos);
if (!IsCollisionInMapService()) { if (!IsCollisionInMapService()) {

View File

@ -588,8 +588,8 @@ void Human::FindPathInMapService()
} }
} }
{ {
float up_dot = a8::Vec2::UP.Dot(move_dir); float up_dot = a8::Vec2::UP.Dot(GetMoveDir());
bool at_left_side = a8::Vec2::LEFT.Dot(move_dir) > 0.0001f; bool at_left_side = a8::Vec2::LEFT.Dot(GetMoveDir()) > 0.0001f;
if (std::abs(up_dot) <= 0.001f) { //相互垂直 if (std::abs(up_dot) <= 0.001f) { //相互垂直
//向上 //向上
SetPos(old_pos + a8::Vec2::UP); SetPos(old_pos + a8::Vec2::UP);
@ -1391,7 +1391,7 @@ void Human::SummonHero(int heroid)
(this, (this,
hero_meta, hero_meta,
GetPos(), GetPos(),
move_dir, GetMoveDir(),
team_id team_id
); );
} }
@ -1711,9 +1711,10 @@ void Human::_UpdateSpecMove()
if (target_distance <= 0.000001f) { if (target_distance <= 0.000001f) {
move_end = true; move_end = true;
} else { } else {
a8::Vec2 old_move_dir = move_dir; a8::Vec2 old_move_dir = GetMoveDir();
move_dir = target_pos - GetPos(); a8::Vec2 move_dir = target_pos - GetPos();
move_dir.Normalize(); move_dir.Normalize();
SetMoveDir(move_dir);
bool is_collision = false; bool is_collision = false;
std::function<bool ()> old_on_move_collision = on_move_collision; std::function<bool ()> old_on_move_collision = on_move_collision;
on_move_collision = on_move_collision =
@ -1875,8 +1876,8 @@ void Human::WinExp(Human* sender, int exp)
void Human::_InternalUpdateMove(float speed) void Human::_InternalUpdateMove(float speed)
{ {
float nx = move_dir.x * speed; float nx = GetMoveDir().x * speed;
float ny = move_dir.y * speed; float ny = GetMoveDir().y * speed;
a8::Vec2 old_pos = GetPos(); a8::Vec2 old_pos = GetPos();
#if 1 #if 1

View File

@ -7,7 +7,6 @@ class AIComponent;
class MoveableEntity : public RoomEntity class MoveableEntity : public RoomEntity
{ {
public: public:
a8::Vec2 move_dir;
AIComponent* ai = nullptr; AIComponent* ai = nullptr;
virtual void Update(int delta_time) {}; virtual void Update(int delta_time) {};
@ -25,9 +24,12 @@ class MoveableEntity : public RoomEntity
std::set<GridCell*>& dec_grids std::set<GridCell*>& dec_grids
); );
virtual void SyncAroundPlayers(const char* file, int line, const char* func); virtual void SyncAroundPlayers(const char* file, int line, const char* func);
virtual const a8::Vec2& GetMoveDir() { return move_dir_; };
virtual void SetMoveDir(const a8::Vec2& move_dir) { move_dir_ = move_dir; };
protected: protected:
int updated_times_ = 0; int updated_times_ = 0;
a8::Vec2 move_dir_;
private: private:
std::set<GridCell*> grid_list_; std::set<GridCell*> grid_list_;

View File

@ -1060,12 +1060,14 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
std::abs(msg.move_dir().y()) > FLT_EPSILON std::abs(msg.move_dir().y()) > FLT_EPSILON
) { ) {
a8::Vec2 old_move_dir; a8::Vec2 old_move_dir;
TypeConvert::FromPb(move_dir, &msg.move_dir()); a8::Vec2 new_move_dir;
move_dir.Normalize(); TypeConvert::FromPb(new_move_dir, &msg.move_dir());
new_move_dir.Normalize();
SetMoveDir(new_move_dir);
moving = true; moving = true;
} }
} }
assert(!isnan(move_dir.x) && !isnan(move_dir.y)); assert(!isnan(GetMoveDir().x) && !isnan(GetMoveDir().y));
if (msg.has_attack_dir()) { if (msg.has_attack_dir()) {
if (std::isfinite(msg.attack_dir().x()) && if (std::isfinite(msg.attack_dir().x()) &&
std::isfinite(msg.attack_dir().y()) && std::isfinite(msg.attack_dir().y()) &&
@ -1079,7 +1081,7 @@ void Player::_CMMove(f8::MsgHdr& hdr, const cs::CMMove& msg)
} }
} else { } else {
if (moving) { if (moving) {
attack_dir = move_dir; attack_dir = GetMoveDir();
} }
} }
if (moving) { if (moving) {

View File

@ -221,7 +221,7 @@ void Room::AddPlayer(Player* hum)
hum->attack_dir = hum->GetPos(); hum->attack_dir = hum->GetPos();
hum->attack_dir.Normalize(); hum->attack_dir.Normalize();
hum->attack_dir.Rotate(a8::RandAngle()); hum->attack_dir.Rotate(a8::RandAngle());
hum->move_dir = hum->attack_dir; hum->SetMoveDir(hum->attack_dir);
hum->room = this; hum->room = this;
hum->join_frameno = GetFrameNo(); hum->join_frameno = GetFrameNo();
@ -333,7 +333,7 @@ void Room::CreateAndroid(int robot_num)
hum->attack_dir = hum->GetPos(); hum->attack_dir = hum->GetPos();
hum->attack_dir.Normalize(); hum->attack_dir.Normalize();
hum->attack_dir.Rotate(a8::RandAngle()); hum->attack_dir.Rotate(a8::RandAngle());
hum->move_dir = hum->attack_dir; hum->SetMoveDir(hum->attack_dir);
hum->room = this; hum->room = this;
hum->Initialize(); hum->Initialize();
AddToEntityHash(hum); AddToEntityHash(hum);
@ -596,7 +596,7 @@ Hero* Room::CreateHero(Creature* master,
hero->master = master; hero->master = master;
hero->room = this; hero->room = this;
hero->SetPos(pos); hero->SetPos(pos);
hero->move_dir = dir; hero->SetMoveDir(dir);
hero->attack_dir = dir; hero->attack_dir = dir;
hero->team_id = team_id; hero->team_id = team_id;
hero->Initialize(); hero->Initialize();
@ -1702,7 +1702,7 @@ void Room::ShuaPlane()
pair.second->MustBeAddBuff(pair.second, FLY_BUFFID); pair.second->MustBeAddBuff(pair.second, FLY_BUFFID);
pair.second->SetPos(plane.curr_pos); pair.second->SetPos(plane.curr_pos);
pair.second->attack_dir = plane.dir; pair.second->attack_dir = plane.dir;
pair.second->move_dir = plane.dir; pair.second->SetMoveDir(plane.dir);
grid_service->MoveCreature(pair.second); grid_service->MoveCreature(pair.second);
pair.second->AddToNewObjects(pair.second); pair.second->AddToNewObjects(pair.second);
} }
@ -2495,7 +2495,7 @@ void Room::ProcShuaAndroid(int shua_time, int shua_num)
GetCanEnableAndroids(humans, real_shua_num); GetCanEnableAndroids(humans, real_shua_num);
for (auto& hum : humans) { for (auto& hum : humans) {
a8::Vec2 pos = target->GetPos(); a8::Vec2 pos = target->GetPos();
a8::Vec2 dir = target->move_dir; a8::Vec2 dir = target->GetMoveDir();
dir = a8::Vec2::UP; dir = a8::Vec2::UP;
if (rand() % 100 < 1) { if (rand() % 100 < 1) {
dir.Rotate(a8::RandAngle() / 2.0f); dir.Rotate(a8::RandAngle() / 2.0f);
@ -3400,7 +3400,7 @@ void Room::ShowHand()
Human* hum = androids[i]; Human* hum = androids[i];
{ {
a8::Vec2 pos = target->GetPos(); a8::Vec2 pos = target->GetPos();
a8::Vec2 dir = target->move_dir; a8::Vec2 dir = target->GetMoveDir();
if (rand() % 100 < 80) { if (rand() % 100 < 80) {
dir.Rotate(a8::RandAngle() / 2.0f); dir.Rotate(a8::RandAngle() / 2.0f);
} else { } else {

View File

@ -277,8 +277,8 @@ void ZombieModeAI::DoMove()
if (hum->HasBuffEffect(kBET_Vertigo)) { if (hum->HasBuffEffect(kBET_Vertigo)) {
return; return;
} }
if (std::abs(hum->move_dir.x) > FLT_EPSILON || if (std::abs(hum->GetMoveDir().x) > FLT_EPSILON ||
std::abs(hum->move_dir.y) > FLT_EPSILON) { std::abs(hum->GetMoveDir().y) > FLT_EPSILON) {
hum->on_move_collision = hum->on_move_collision =
[this] () { [this] () {
ChangeToState(ZSE_RandomWalk); ChangeToState(ZSE_RandomWalk);
@ -344,10 +344,11 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
node_->shot_times = 0; node_->shot_times = 0;
node_->next_random_move_frameno = hum->room->GetFrameNo() + node_->next_random_move_frameno = hum->room->GetFrameNo() +
SERVER_FRAME_RATE * node_->ai_meta->GetMoveIdleTime(); SERVER_FRAME_RATE * node_->ai_meta->GetMoveIdleTime();
hum->move_dir = a8::Vec2(1.0f, 0); a8::Vec2 move_dir = a8::Vec2(1.0f, 0);
hum->move_dir.Rotate(a8::RandAngle()); move_dir.Rotate(a8::RandAngle());
hum->move_dir.Normalize(); move_dir.Normalize();
hum->attack_dir = hum->move_dir; hum->SetMoveDir(move_dir);
hum->attack_dir = hum->GetMoveDir();
if (node_->param1 <= 1) { if (node_->param1 <= 1) {
node_->moving = false; node_->moving = false;
} }
@ -357,9 +358,10 @@ void ZombieModeAI::ChangeToState(ZombieState_e to_state)
{ {
node_->moving = true; node_->moving = true;
if (node_->target.Get()) { if (node_->target.Get()) {
hum->move_dir = node_->target.Get()->GetPos() - hum->GetPos(); a8::Vec2 move_dir = node_->target.Get()->GetPos() - hum->GetPos();
hum->move_dir.Normalize(); move_dir.Normalize();
hum->attack_dir = hum->move_dir; hum->SetMoveDir(move_dir);
hum->attack_dir = hum->GetMoveDir();
} }
} }
break; break;