From 871a1ccbfc79f5b45bced94a7efd16dc0df5a91f Mon Sep 17 00:00:00 2001 From: Khalid Ali Date: Sun, 5 Sep 2021 17:07:09 -0500 Subject: [PATCH 1/3] Set direction using character state --- server/src/sys/agent.rs | 130 +++++++++++++--------------------------- 1 file changed, 43 insertions(+), 87 deletions(-) diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index b61620ca71..1cead46d4d 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1814,44 +1814,24 @@ impl<'a> AgentData<'a> { // Not all attacks may want their direction overwritten. // And this is quite hard to debug when you don't see it in actual // attack handler. - if let Some(dir) = match tactic { - // FIXME: this code make Staff flamethrower aim flamethrower - // like a projectile. - Tactic::Bow - | Tactic::FixedTurret - | Tactic::QuadLowRanged - | Tactic::QuadMedJump - | Tactic::RotatingTurret - | Tactic::Staff - | Tactic::Turret - if dist_sqrd > 0.0 => - { - if matches!(self.char_state, CharacterState::ChargedRanged(_)) { + if let Some(dir) = match self.char_state { + CharacterState::ChargedRanged(c) + if dist_sqrd > 0.0 => { + let projectile_speed = c.static_data.initial_projectile_speed + 0.5 * c.static_data.scaled_projectile_speed; aim_projectile( - 175.0, - Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), + projectile_speed, + Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), Vec3::new( tgt_data.pos.0.x, tgt_data.pos.0.y, tgt_data.pos.0.z + tgt_eye_offset, ), ) - } else { - aim_projectile( - 90.0, // + self.vel.0.magnitude(), - Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), - Vec3::new( - tgt_data.pos.0.x, - tgt_data.pos.0.y, - tgt_data.pos.0.z + tgt_eye_offset, - ), - ) - } - } - Tactic::ClayGolem if matches!(self.char_state, CharacterState::BasicRanged(_)) => { - const ROCKET_SPEED: f32 = 30.0; + }, + CharacterState::BasicRanged(c) => { + let projectile_speed = c.static_data.projectile_speed; aim_projectile( - ROCKET_SPEED, + projectile_speed, Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), Vec3::new( tgt_data.pos.0.x, @@ -1860,64 +1840,31 @@ impl<'a> AgentData<'a> { ), ) }, - Tactic::Yeti if matches!(self.char_state, CharacterState::BasicRanged(_)) => { - const SNOWBALL_SPEED: f32 = 60.0; - aim_projectile( - SNOWBALL_SPEED, - Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), - Vec3::new( - tgt_data.pos.0.x, - tgt_data.pos.0.y, - tgt_data.pos.0.z + tgt_eye_offset, - ), - ) - }, - Tactic::Harvester if matches!(self.char_state, CharacterState::BasicRanged(_)) => { - const PUMPKIN_SPEED: f32 = 30.0; - aim_projectile( - PUMPKIN_SPEED, - Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), - Vec3::new( - tgt_data.pos.0.x, - tgt_data.pos.0.y, - tgt_data.pos.0.z + tgt_eye_offset, - ), - ) - }, - // Leap into direction of the target - // TODO: test with different weapons/tactics - Tactic::Hammer if matches!(self.char_state, CharacterState::LeapMelee(_)) => { - let tgt_pos = tgt_data.pos.0; - let self_pos = self.pos.0; - - let direction_weight = 0.1; - let delta_x = (tgt_pos.x - self_pos.x) * direction_weight; - let delta_y = (tgt_pos.y - self_pos.y) * direction_weight; - - Dir::from_unnormalized(Vec3::new(delta_x, delta_y, -1.0)) - }, - Tactic::Axe if matches!(self.char_state, CharacterState::LeapMelee(_)) => { - let tgt_pos = tgt_data.pos.0; - let self_pos = self.pos.0; - - let direction_weight = 0.3; - let delta_x = (tgt_pos.x - self_pos.x) * direction_weight; - let delta_y = (tgt_pos.y - self_pos.y) * direction_weight; - - Dir::from_unnormalized(Vec3::new(delta_x, delta_y, -1.0)) - }, - _ => { - let aim_from = match self.char_state { - CharacterState::BasicBeam(_) => self.body.map_or(self.pos.0, |body| { - self.pos.0 - + basic_beam::beam_offsets( - body, - controller.inputs.look_dir, - self.ori.look_vec(), - ) - }), - _ => Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), + CharacterState::LeapMelee(_) + if matches!(tactic, Tactic::Hammer) || matches!(tactic, Tactic::Axe) => { + let direction_weight = match tactic { + Tactic::Hammer => 0.1, + Tactic::Axe => 0.3, + _ => 0.0, // should not be called }; + + let tgt_pos = tgt_data.pos.0; + let self_pos = self.pos.0; + + let delta_x = (tgt_pos.x - self_pos.x) * direction_weight; + let delta_y = (tgt_pos.y - self_pos.y) * direction_weight; + + Dir::from_unnormalized(Vec3::new(delta_x, delta_y, -1.0)) + }, + CharacterState::BasicBeam(_) => { + let aim_from = self.body.map_or(self.pos.0, |body| { + self.pos.0 + + basic_beam::beam_offsets( + body, + controller.inputs.look_dir, + self.ori.look_vec(), + ) + }); let aim_to = Vec3::new( tgt_data.pos.0.x, tgt_data.pos.0.y, @@ -1925,6 +1872,15 @@ impl<'a> AgentData<'a> { ); Dir::from_unnormalized(aim_to - aim_from) }, + _ => { + let aim_from = Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset); + let aim_to = Vec3::new( + tgt_data.pos.0.x, + tgt_data.pos.0.y, + tgt_data.pos.0.z + tgt_eye_offset, + ); + Dir::from_unnormalized(aim_to - aim_from) + } } { controller.inputs.look_dir = dir; } From a0b78ffd162021430ac6f5ac1318747b1b5d32d8 Mon Sep 17 00:00:00 2001 From: Khalid Ali Date: Sun, 5 Sep 2021 18:03:54 -0500 Subject: [PATCH 2/3] Add RepeaterRanged and fix scaling ChargedRange --- server/src/sys/agent.rs | 47 ++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 1cead46d4d..9f7a896f12 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1815,19 +1815,21 @@ impl<'a> AgentData<'a> { // And this is quite hard to debug when you don't see it in actual // attack handler. if let Some(dir) = match self.char_state { - CharacterState::ChargedRanged(c) - if dist_sqrd > 0.0 => { - let projectile_speed = c.static_data.initial_projectile_speed + 0.5 * c.static_data.scaled_projectile_speed; - aim_projectile( - projectile_speed, - Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), - Vec3::new( - tgt_data.pos.0.x, - tgt_data.pos.0.y, - tgt_data.pos.0.z + tgt_eye_offset, - ), - ) - }, + CharacterState::ChargedRanged(c) if dist_sqrd > 0.0 => { + let charge_factor = + c.timer.as_secs_f32() / c.static_data.charge_duration.as_secs_f32(); + let projectile_speed = c.static_data.initial_projectile_speed + + charge_factor * c.static_data.scaled_projectile_speed; + aim_projectile( + projectile_speed, + Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), + Vec3::new( + tgt_data.pos.0.x, + tgt_data.pos.0.y, + tgt_data.pos.0.z + tgt_eye_offset, + ), + ) + }, CharacterState::BasicRanged(c) => { let projectile_speed = c.static_data.projectile_speed; aim_projectile( @@ -1840,12 +1842,23 @@ impl<'a> AgentData<'a> { ), ) }, - CharacterState::LeapMelee(_) - if matches!(tactic, Tactic::Hammer) || matches!(tactic, Tactic::Axe) => { + CharacterState::RepeaterRanged(c) => { + let projectile_speed = c.static_data.projectile_speed; + aim_projectile( + projectile_speed, + Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset), + Vec3::new( + tgt_data.pos.0.x, + tgt_data.pos.0.y, + tgt_data.pos.0.z + tgt_eye_offset, + ), + ) + }, + CharacterState::LeapMelee(_) if matches!(tactic, Tactic::Hammer | Tactic::Axe) => { let direction_weight = match tactic { Tactic::Hammer => 0.1, Tactic::Axe => 0.3, - _ => 0.0, // should not be called + _ => panic!("Direction weight called on unknown tactic."), }; let tgt_pos = tgt_data.pos.0; @@ -1880,7 +1893,7 @@ impl<'a> AgentData<'a> { tgt_data.pos.0.z + tgt_eye_offset, ); Dir::from_unnormalized(aim_to - aim_from) - } + }, } { controller.inputs.look_dir = dir; } From cbc6cdfad1976a2cb01a9eff3f20156b66e535b7 Mon Sep 17 00:00:00 2001 From: Khalid Ali Date: Sun, 5 Sep 2021 18:13:20 -0500 Subject: [PATCH 3/3] Use unreachable instead of panic --- server/src/sys/agent.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/sys/agent.rs b/server/src/sys/agent.rs index 9f7a896f12..896f917dfe 100644 --- a/server/src/sys/agent.rs +++ b/server/src/sys/agent.rs @@ -1858,7 +1858,7 @@ impl<'a> AgentData<'a> { let direction_weight = match tactic { Tactic::Hammer => 0.1, Tactic::Axe => 0.3, - _ => panic!("Direction weight called on unknown tactic."), + _ => unreachable!("Direction weight called on incorrect tactic."), }; let tgt_pos = tgt_data.pos.0;