mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Address code review.
This commit is contained in:
parent
995504be26
commit
455cab0ee7
@ -1589,7 +1589,6 @@ impl<'a> AgentData<'a> {
|
||||
!health.is_dead && !is_invulnerable(entity, read_data)
|
||||
})
|
||||
};
|
||||
let lost_target = |target: Option<EcsEntity>| agent.target.is_none() && target.is_some();
|
||||
|
||||
// Search the area.
|
||||
// TODO: choose target by more than just distance
|
||||
@ -1598,8 +1597,8 @@ impl<'a> AgentData<'a> {
|
||||
let target = grid
|
||||
.in_circle_aabr(self.pos.0.xy(), agent.psyche.search_dist())
|
||||
.filter(|entity| {
|
||||
does_entity_see_other(agent, *self.entity, *entity, controller, read_data)
|
||||
&& is_valid(*entity)
|
||||
is_valid(*entity)
|
||||
&& does_entity_see_other(agent, *self.entity, *entity, controller, read_data)
|
||||
})
|
||||
.filter_map(get_enemy)
|
||||
.min_by_key(|entity| {
|
||||
@ -1607,7 +1606,7 @@ impl<'a> AgentData<'a> {
|
||||
get_pos(*entity).map(|pos| (pos.0.distance_squared(self.pos.0) * 100.0) as i32)
|
||||
});
|
||||
|
||||
if lost_target(target) {
|
||||
if agent.target.is_none() && target.is_some() {
|
||||
if aggro_on {
|
||||
controller.push_utterance(UtteranceKind::Angry);
|
||||
} else {
|
||||
@ -2385,7 +2384,7 @@ impl<'a> AgentData<'a> {
|
||||
(entity != *self.entity)
|
||||
&& (are_our_owners_hostile(self.alignment, alignment, read_data)
|
||||
|| self.remembers_fight_with(entity, read_data)
|
||||
|| self.is_villager_and_is_entity_dressed_as_cultist(entity, read_data))
|
||||
|| (is_villager(self.alignment) && is_dressed_as_cultist(entity, read_data)))
|
||||
}
|
||||
|
||||
fn should_defend(&self, entity: EcsEntity, read_data: &ReadData) -> bool {
|
||||
@ -2409,12 +2408,4 @@ impl<'a> AgentData<'a> {
|
||||
|| (is_village_guard(*self.entity, read_data) && is_villager(entity_alignment))
|
||||
|| self_owns_entity
|
||||
}
|
||||
|
||||
fn is_villager_and_is_entity_dressed_as_cultist(
|
||||
&self,
|
||||
entity: EcsEntity,
|
||||
read_data: &ReadData,
|
||||
) -> bool {
|
||||
is_villager(self.alignment) && is_dressed_as_cultist(entity, read_data)
|
||||
}
|
||||
}
|
||||
|
@ -130,15 +130,17 @@ impl<'a> AgentData<'a> {
|
||||
tgt_data: &TargetData,
|
||||
read_data: &ReadData,
|
||||
) {
|
||||
let line_of_sight_with_target = agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
});
|
||||
let line_of_sight_with_target = || {
|
||||
agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
})
|
||||
};
|
||||
|
||||
let elevation = self.pos.0.z - tgt_data.pos.0.z;
|
||||
const PREF_DIST: f32 = 30_f32;
|
||||
if attack_data.angle_xy < 30.0
|
||||
&& (elevation > 10.0 || attack_data.dist_sqrd > PREF_DIST.powi(2))
|
||||
&& line_of_sight_with_target
|
||||
&& line_of_sight_with_target()
|
||||
{
|
||||
controller.push_basic_input(InputKind::Primary);
|
||||
} else if attack_data.dist_sqrd < (PREF_DIST / 2.).powi(2) {
|
||||
@ -185,7 +187,7 @@ impl<'a> AgentData<'a> {
|
||||
..self.traversal_config
|
||||
},
|
||||
) {
|
||||
if line_of_sight_with_target {
|
||||
if line_of_sight_with_target() {
|
||||
controller.push_basic_input(InputKind::Primary);
|
||||
}
|
||||
controller.inputs.move_dir =
|
||||
@ -398,9 +400,11 @@ impl<'a> AgentData<'a> {
|
||||
const OPTIMAL_TARGET_VELOCITY: f32 = 5.0;
|
||||
const DESIRED_ENERGY_LEVEL: f32 = 50.0;
|
||||
|
||||
let line_of_sight_with_target = agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
});
|
||||
let line_of_sight_with_target = |agent: &Agent| {
|
||||
agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
})
|
||||
};
|
||||
|
||||
// Logic to use abilities
|
||||
if let CharacterState::ChargedRanged(c) = self.char_state {
|
||||
@ -426,7 +430,7 @@ impl<'a> AgentData<'a> {
|
||||
// If in repeater ranged, have enough energy, and aren't in recovery, try to
|
||||
// keep firing
|
||||
if attack_data.dist_sqrd > attack_data.min_attack_dist.powi(2)
|
||||
&& line_of_sight_with_target
|
||||
&& line_of_sight_with_target(agent)
|
||||
{
|
||||
// Only keep firing if not in melee range or if can see target
|
||||
controller.push_basic_input(InputKind::Secondary);
|
||||
@ -460,7 +464,8 @@ impl<'a> AgentData<'a> {
|
||||
controller.push_basic_input(InputKind::Primary);
|
||||
}
|
||||
}
|
||||
} else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) && line_of_sight_with_target {
|
||||
} else if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) && line_of_sight_with_target(agent)
|
||||
{
|
||||
// If not really far, and can see target, attempt to shoot bow
|
||||
if self.energy.current() < DESIRED_ENERGY_LEVEL {
|
||||
// If low on energy, use primary to attempt to regen energy
|
||||
@ -499,7 +504,7 @@ impl<'a> AgentData<'a> {
|
||||
..self.traversal_config
|
||||
},
|
||||
) {
|
||||
if line_of_sight_with_target && attack_data.angle < 45.0 {
|
||||
if line_of_sight_with_target(agent) && attack_data.angle < 45.0 {
|
||||
controller.inputs.move_dir = bearing
|
||||
.xy()
|
||||
.rotated_z(rng.gen_range(0.5..1.57))
|
||||
@ -682,12 +687,15 @@ impl<'a> AgentData<'a> {
|
||||
const DESIRED_ENERGY_LEVEL: f32 = 50.0;
|
||||
const DESIRED_COMBO_LEVEL: u32 = 8;
|
||||
|
||||
let line_of_sight_with_target = agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
});
|
||||
let line_of_sight_with_target = |agent: &Agent| {
|
||||
agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
})
|
||||
};
|
||||
|
||||
// Logic to use abilities
|
||||
if attack_data.dist_sqrd > attack_data.min_attack_dist.powi(2) && line_of_sight_with_target
|
||||
if attack_data.dist_sqrd > attack_data.min_attack_dist.powi(2)
|
||||
&& line_of_sight_with_target(agent)
|
||||
{
|
||||
// If far enough away, and can see target, check which skill is appropriate to
|
||||
// use
|
||||
@ -765,7 +773,7 @@ impl<'a> AgentData<'a> {
|
||||
..self.traversal_config
|
||||
},
|
||||
) {
|
||||
if line_of_sight_with_target && attack_data.angle < 45.0 {
|
||||
if line_of_sight_with_target(agent) && attack_data.angle < 45.0 {
|
||||
controller.inputs.move_dir = bearing
|
||||
.xy()
|
||||
.rotated_z(rng.gen_range(0.5..1.57))
|
||||
@ -2038,9 +2046,11 @@ impl<'a> AgentData<'a> {
|
||||
.map(|t| t.target)
|
||||
.and_then(|e| read_data.velocities.get(e))
|
||||
.map_or(0.0, |v| v.0.cross(self.ori.look_vec()).magnitude_squared());
|
||||
let line_of_sight_with_target = agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
});
|
||||
let line_of_sight_with_target = |agent: &Agent| {
|
||||
agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
})
|
||||
};
|
||||
|
||||
if attack_data.dist_sqrd < golem_melee_range.powi(2) {
|
||||
if agent.action_state.counter < 7.5 {
|
||||
@ -2058,7 +2068,7 @@ impl<'a> AgentData<'a> {
|
||||
} else if attack_data.dist_sqrd < GOLEM_LASER_RANGE.powi(2) {
|
||||
if matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs(5))
|
||||
|| target_speed_cross_sqd < GOLEM_TARGET_SPEED.powi(2)
|
||||
&& line_of_sight_with_target
|
||||
&& line_of_sight_with_target(agent)
|
||||
&& attack_data.angle < 45.0
|
||||
{
|
||||
// If target in range threshold and haven't been lasering for more than 5
|
||||
@ -2070,7 +2080,9 @@ impl<'a> AgentData<'a> {
|
||||
controller.push_basic_input(InputKind::Ability(0));
|
||||
}
|
||||
} else if attack_data.dist_sqrd < GOLEM_LONG_RANGE.powi(2) {
|
||||
if target_speed_cross_sqd < GOLEM_TARGET_SPEED.powi(2) && line_of_sight_with_target {
|
||||
if target_speed_cross_sqd < GOLEM_TARGET_SPEED.powi(2)
|
||||
&& line_of_sight_with_target(agent)
|
||||
{
|
||||
// If target is far-ish and moving slow-ish, rocket them
|
||||
controller.push_basic_input(InputKind::Ability(1));
|
||||
} else if health_fraction < 0.7 {
|
||||
@ -2102,9 +2114,11 @@ impl<'a> AgentData<'a> {
|
||||
const BUBBLE_RANGE: f32 = 20.0;
|
||||
const MINION_SUMMON_THRESHOLD: f32 = 0.20;
|
||||
let health_fraction = self.health.map_or(0.5, |h| h.fraction());
|
||||
let line_of_sight_with_target = agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
});
|
||||
let line_of_sight_with_target = |agent: &Agent| {
|
||||
agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
})
|
||||
};
|
||||
|
||||
// Sets counter at start of combat, using `condition` to keep track of whether
|
||||
// it was already intitialized
|
||||
@ -2135,12 +2149,12 @@ impl<'a> AgentData<'a> {
|
||||
} else if attack_data.in_min_range() && attack_data.angle < 60.0 {
|
||||
// Pincer them if they're in range and angle
|
||||
controller.push_basic_input(InputKind::Primary);
|
||||
} else if attack_data.angle < 30.0 && line_of_sight_with_target {
|
||||
} else if attack_data.angle < 30.0 && line_of_sight_with_target(agent) {
|
||||
// Start bubbling them if not close enough to do something else and in angle and
|
||||
// can see target
|
||||
controller.push_basic_input(InputKind::Ability(0));
|
||||
}
|
||||
} else if attack_data.angle < 90.0 && line_of_sight_with_target {
|
||||
} else if attack_data.angle < 90.0 && line_of_sight_with_target(agent) {
|
||||
// Start scuttling if not close enough to do something else and in angle and can
|
||||
// see target
|
||||
controller.push_basic_input(InputKind::Secondary);
|
||||
@ -2223,9 +2237,11 @@ impl<'a> AgentData<'a> {
|
||||
const FIRE_BREATH_RANGE: f32 = 20.0;
|
||||
const MAX_PUMPKIN_RANGE: f32 = 50.0;
|
||||
let health_fraction = self.health.map_or(0.5, |h| h.fraction());
|
||||
let line_of_sight_with_target = agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
});
|
||||
let line_of_sight_with_target = |agent: &Agent| {
|
||||
agent.target.map_or(false, |target| {
|
||||
entities_have_line_of_sight(*self.entity, target.target, read_data)
|
||||
})
|
||||
};
|
||||
|
||||
if health_fraction < VINE_CREATION_THRESHOLD && !agent.action_state.condition {
|
||||
// Summon vines when reach threshold of health
|
||||
@ -2237,7 +2253,7 @@ impl<'a> AgentData<'a> {
|
||||
}
|
||||
} else if attack_data.dist_sqrd < FIRE_BREATH_RANGE.powi(2) {
|
||||
if matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs(5))
|
||||
&& line_of_sight_with_target
|
||||
&& line_of_sight_with_target(agent)
|
||||
{
|
||||
// Keep breathing fire if close enough, can see target, and have not been
|
||||
// breathing for more than 5 seconds
|
||||
@ -2245,11 +2261,13 @@ impl<'a> AgentData<'a> {
|
||||
} else if attack_data.in_min_range() && attack_data.angle < 60.0 {
|
||||
// Scythe them if they're in range and angle
|
||||
controller.push_basic_input(InputKind::Primary);
|
||||
} else if attack_data.angle < 30.0 && line_of_sight_with_target {
|
||||
} else if attack_data.angle < 30.0 && line_of_sight_with_target(agent) {
|
||||
// Start breathing fire at them if close enough, in angle, and can see target
|
||||
controller.push_basic_input(InputKind::Secondary);
|
||||
}
|
||||
} else if attack_data.dist_sqrd < MAX_PUMPKIN_RANGE.powi(2) && line_of_sight_with_target {
|
||||
} else if attack_data.dist_sqrd < MAX_PUMPKIN_RANGE.powi(2)
|
||||
&& line_of_sight_with_target(agent)
|
||||
{
|
||||
// Throw a pumpkin at them if close enough and can see them
|
||||
controller.push_basic_input(InputKind::Ability(1));
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ pub fn does_entity_see_other(
|
||||
.try_normalized()
|
||||
.map_or(false, |v| v.dot(*controller.inputs.look_dir) > 0.15);
|
||||
|
||||
within_sight_dist && entities_have_line_of_sight(entity, other, read_data) && within_fov
|
||||
within_sight_dist && within_fov && entities_have_line_of_sight(entity, other, read_data)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user