mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Better mugger AI
This commit is contained in:
parent
e1f164d099
commit
c15fb2b68f
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -6439,6 +6439,7 @@ dependencies = [
|
|||||||
"futures-util",
|
"futures-util",
|
||||||
"hashbrown 0.11.2",
|
"hashbrown 0.11.2",
|
||||||
"humantime",
|
"humantime",
|
||||||
|
"inline_tweak",
|
||||||
"itertools",
|
"itertools",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
|
@ -23,7 +23,7 @@ common-net = { package = "veloren-common-net", path = "../common/net" }
|
|||||||
world = { package = "veloren-world", path = "../world" }
|
world = { package = "veloren-world", path = "../world" }
|
||||||
network = { package = "veloren-network", path = "../network", features = ["metrics", "compression", "quic"], default-features = false }
|
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 = { git = "https://github.com/amethyst/specs.git", features = ["shred-derive"], rev = "f985bec5d456f7b0dd8aae99848f9473c2cd9d46" }
|
||||||
specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "8be2abcddf8f524cb5876e8dd20a7e47cfaf7573" }
|
specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "8be2abcddf8f524cb5876e8dd20a7e47cfaf7573" }
|
||||||
|
@ -71,20 +71,23 @@ impl<'a> AgentData<'a> {
|
|||||||
.and_then(|t| read_data.orientations.get(t.target))
|
.and_then(|t| read_data.orientations.get(t.target))
|
||||||
.map(|ori| ori.look_vec())
|
.map(|ori| ori.look_vec())
|
||||||
.unwrap_or_default();
|
.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;
|
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 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
|
// If in front of the target, circle to try and get behind, else just make a
|
||||||
// beeline for the back of the agent
|
// beeline for the back of the agent
|
||||||
|
let vec_to_target = (tgt_data.pos.0 - self.pos.0).xy();
|
||||||
if in_front_of_target {
|
if in_front_of_target {
|
||||||
|
let theta = (PI / 2. - dist * 0.1).max(0.0);
|
||||||
// Checks both CW and CCW rotation
|
// Checks both CW and CCW rotation
|
||||||
let potential_move_dirs = [
|
let potential_move_dirs = [
|
||||||
vec_to_target
|
vec_to_target
|
||||||
.rotated_z(PI / 2.)
|
.rotated_z(theta)
|
||||||
.try_normalized()
|
.try_normalized()
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
vec_to_target
|
vec_to_target
|
||||||
.rotated_z(-PI / 2.)
|
.rotated_z(-theta)
|
||||||
.try_normalized()
|
.try_normalized()
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
];
|
];
|
||||||
@ -96,7 +99,12 @@ impl<'a> AgentData<'a> {
|
|||||||
controller.inputs.move_dir = *move_dir;
|
controller.inputs.move_dir = *move_dir;
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
self.path_toward_target(agent, controller, tgt_data, read_data, false, true, None);
|
self.path_toward_target(agent, controller, tgt_data, read_data, false, true, None);
|
||||||
|
@ -197,36 +197,31 @@ impl Civs {
|
|||||||
|
|
||||||
let mut rng = ctx.reseed().rng;
|
let mut rng = ctx.reseed().rng;
|
||||||
let site = index.sites.insert(match &sim_site.kind {
|
let site = index.sites.insert(match &sim_site.kind {
|
||||||
//SiteKind::Settlement => {
|
SiteKind::Settlement => {
|
||||||
// WorldSite::settlement(Settlement::generate(wpos, Some(ctx.sim), &mut rng))
|
WorldSite::settlement(Settlement::generate(wpos, Some(ctx.sim), &mut rng))
|
||||||
//},
|
},
|
||||||
//SiteKind::Dungeon => WorldSite::dungeon(site2::Site::generate_dungeon(
|
SiteKind::Dungeon => WorldSite::dungeon(site2::Site::generate_dungeon(
|
||||||
// &Land::from_sim(ctx.sim),
|
&Land::from_sim(ctx.sim),
|
||||||
// &mut rng,
|
&mut rng,
|
||||||
// wpos,
|
wpos,
|
||||||
//)),
|
)),
|
||||||
//SiteKind::Castle => {
|
SiteKind::Castle => {
|
||||||
// WorldSite::castle(Castle::generate(wpos, Some(ctx.sim), &mut rng))
|
WorldSite::castle(Castle::generate(wpos, Some(ctx.sim), &mut rng))
|
||||||
//},
|
},
|
||||||
//SiteKind::Refactor => WorldSite::refactor(site2::Site::generate_city(
|
SiteKind::Refactor => WorldSite::refactor(site2::Site::generate_city(
|
||||||
// &Land::from_sim(ctx.sim),
|
&Land::from_sim(ctx.sim),
|
||||||
// &mut rng,
|
&mut rng,
|
||||||
// wpos,
|
wpos,
|
||||||
//)),
|
)),
|
||||||
//SiteKind::Tree => {
|
SiteKind::Tree => {
|
||||||
// WorldSite::tree(Tree::generate(wpos, &Land::from_sim(ctx.sim), &mut rng))
|
WorldSite::tree(Tree::generate(wpos, &Land::from_sim(ctx.sim), &mut rng))
|
||||||
//},
|
},
|
||||||
//SiteKind::GiantTree => WorldSite::giant_tree(site2::Site::generate_giant_tree(
|
SiteKind::GiantTree => WorldSite::giant_tree(site2::Site::generate_giant_tree(
|
||||||
// &Land::from_sim(ctx.sim),
|
&Land::from_sim(ctx.sim),
|
||||||
// &mut rng,
|
&mut rng,
|
||||||
// wpos,
|
wpos,
|
||||||
//)),
|
)),
|
||||||
//SiteKind::Gnarling => WorldSite::gnarling(site2::Site::generate_gnarling(
|
SiteKind::Gnarling => WorldSite::gnarling(site2::Site::generate_gnarling(
|
||||||
// &Land::from_sim(ctx.sim),
|
|
||||||
// &mut rng,
|
|
||||||
// wpos,
|
|
||||||
//)),
|
|
||||||
_ => WorldSite::gnarling(site2::Site::generate_gnarling(
|
|
||||||
&Land::from_sim(ctx.sim),
|
&Land::from_sim(ctx.sim),
|
||||||
&mut rng,
|
&mut rng,
|
||||||
wpos,
|
wpos,
|
||||||
|
@ -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)
|
.with_asset_expect("common.entity.dungeon.gnarling.harvester", rng)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(clippy::type_complexity)]
|
||||||
fn rrt<F>(
|
fn rrt<F>(
|
||||||
start: Vec3<i32>,
|
start: Vec3<i32>,
|
||||||
end: Vec3<i32>,
|
end: Vec3<i32>,
|
||||||
|
Loading…
Reference in New Issue
Block a user