Better mugger AI

This commit is contained in:
Sam 2022-01-20 19:56:27 -05:00
parent e1f164d099
commit c15fb2b68f
5 changed files with 40 additions and 35 deletions

1
Cargo.lock generated
View File

@ -6439,6 +6439,7 @@ dependencies = [
"futures-util",
"hashbrown 0.11.2",
"humantime",
"inline_tweak",
"itertools",
"lazy_static",
"num_cpus",

View File

@ -23,7 +23,7 @@ common-net = { package = "veloren-common-net", path = "../common/net" }
world = { package = "veloren-world", path = "../world" }
network = { package = "veloren-network", path = "../network", features = ["metrics", "compression", "quic"], default-features = false }
# inline_tweak = "1.0.8"
inline_tweak = "1.0.8"
specs = { git = "https://github.com/amethyst/specs.git", features = ["shred-derive"], rev = "f985bec5d456f7b0dd8aae99848f9473c2cd9d46" }
specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "8be2abcddf8f524cb5876e8dd20a7e47cfaf7573" }

View File

@ -71,20 +71,23 @@ impl<'a> AgentData<'a> {
.and_then(|t| read_data.orientations.get(t.target))
.map(|ori| ori.look_vec())
.unwrap_or_default();
let vec_to_target = (tgt_data.pos.0 - self.pos.0).xy();
let dist = attack_data.dist_sqrd.sqrt();
let in_front_of_target = target_ori.dot(self.pos.0 - tgt_data.pos.0) > 0.0;
if attack_data.dist_sqrd < MAX_PATH_DIST.powi(2) {
// If in front of the target, circle to try and get behind, else just make a
// beeline for the back of the agent
let vec_to_target = (tgt_data.pos.0 - self.pos.0).xy();
if in_front_of_target {
let theta = (PI / 2. - dist * 0.1).max(0.0);
// Checks both CW and CCW rotation
let potential_move_dirs = [
vec_to_target
.rotated_z(PI / 2.)
.rotated_z(theta)
.try_normalized()
.unwrap_or_default(),
vec_to_target
.rotated_z(-PI / 2.)
.rotated_z(-theta)
.try_normalized()
.unwrap_or_default(),
];
@ -96,7 +99,12 @@ impl<'a> AgentData<'a> {
controller.inputs.move_dir = *move_dir;
}
} else {
controller.inputs.move_dir = vec_to_target.try_normalized().unwrap_or_default();
// Aim for a point a given distance behind the target to prevent sideways
// movement
let move_target = tgt_data.pos.0.xy() - dist / 2. * target_ori.xy();
controller.inputs.move_dir = (move_target - self.pos.0)
.try_normalized()
.unwrap_or_default();
}
} else {
self.path_toward_target(agent, controller, tgt_data, read_data, false, true, None);

View File

@ -197,36 +197,31 @@ impl Civs {
let mut rng = ctx.reseed().rng;
let site = index.sites.insert(match &sim_site.kind {
//SiteKind::Settlement => {
// WorldSite::settlement(Settlement::generate(wpos, Some(ctx.sim), &mut rng))
//},
//SiteKind::Dungeon => WorldSite::dungeon(site2::Site::generate_dungeon(
// &Land::from_sim(ctx.sim),
// &mut rng,
// wpos,
//)),
//SiteKind::Castle => {
// WorldSite::castle(Castle::generate(wpos, Some(ctx.sim), &mut rng))
//},
//SiteKind::Refactor => WorldSite::refactor(site2::Site::generate_city(
// &Land::from_sim(ctx.sim),
// &mut rng,
// wpos,
//)),
//SiteKind::Tree => {
// WorldSite::tree(Tree::generate(wpos, &Land::from_sim(ctx.sim), &mut rng))
//},
//SiteKind::GiantTree => WorldSite::giant_tree(site2::Site::generate_giant_tree(
// &Land::from_sim(ctx.sim),
// &mut rng,
// wpos,
//)),
//SiteKind::Gnarling => WorldSite::gnarling(site2::Site::generate_gnarling(
// &Land::from_sim(ctx.sim),
// &mut rng,
// wpos,
//)),
_ => WorldSite::gnarling(site2::Site::generate_gnarling(
SiteKind::Settlement => {
WorldSite::settlement(Settlement::generate(wpos, Some(ctx.sim), &mut rng))
},
SiteKind::Dungeon => WorldSite::dungeon(site2::Site::generate_dungeon(
&Land::from_sim(ctx.sim),
&mut rng,
wpos,
)),
SiteKind::Castle => {
WorldSite::castle(Castle::generate(wpos, Some(ctx.sim), &mut rng))
},
SiteKind::Refactor => WorldSite::refactor(site2::Site::generate_city(
&Land::from_sim(ctx.sim),
&mut rng,
wpos,
)),
SiteKind::Tree => {
WorldSite::tree(Tree::generate(wpos, &Land::from_sim(ctx.sim), &mut rng))
},
SiteKind::GiantTree => WorldSite::giant_tree(site2::Site::generate_giant_tree(
&Land::from_sim(ctx.sim),
&mut rng,
wpos,
)),
SiteKind::Gnarling => WorldSite::gnarling(site2::Site::generate_gnarling(
&Land::from_sim(ctx.sim),
&mut rng,
wpos,

View File

@ -1963,6 +1963,7 @@ fn harvester_boss<R: Rng>(pos: Vec3<i32>, rng: &mut R) -> EntityInfo {
.with_asset_expect("common.entity.dungeon.gnarling.harvester", rng)
}
#[allow(clippy::type_complexity)]
fn rrt<F>(
start: Vec3<i32>,
end: Vec3<i32>,