From dbcbd43b8f45c3fd803e60f2cc65cc12f1c22865 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 24 May 2023 12:54:29 +0100 Subject: [PATCH] Added body kind argument to /airship and /ship --- common/src/cmd.rs | 24 ++++++++++++++++++++++-- server/src/cmd.rs | 24 ++++++++++++++++++------ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/common/src/cmd.rs b/common/src/cmd.rs index 83bb096b71..9e1523bdf6 100644 --- a/common/src/cmd.rs +++ b/common/src/cmd.rs @@ -352,7 +352,17 @@ impl ServerChatCommand { Some(Admin), ), ServerChatCommand::Airship => cmd( - vec![Float("destination_degrees_ccw_of_east", 90.0, Optional)], + vec![ + Enum( + "kind", + comp::ship::ALL_AIRSHIPS + .iter() + .map(|b| format!("{b:?}")) + .collect(), + Optional, + ), + Float("destination_degrees_ccw_of_east", 90.0, Optional), + ], "Spawns an airship", Some(Admin), ), @@ -649,7 +659,17 @@ impl ServerChatCommand { Some(Admin), ), ServerChatCommand::Ship => cmd( - vec![Float("destination_degrees_ccw_of_east", 90.0, Optional)], + vec![ + Enum( + "kind", + comp::ship::ALL_SHIPS + .iter() + .map(|b| format!("{b:?}")) + .collect(), + Optional, + ), + Float("destination_degrees_ccw_of_east", 90.0, Optional), + ], "Spawns a ship", Some(Admin), ), diff --git a/server/src/cmd.rs b/server/src/cmd.rs index aa471b9f7e..eecc4f06da 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1639,15 +1639,21 @@ fn handle_spawn_airship( args: Vec, _action: &ServerChatCommand, ) -> CmdResult<()> { - let angle = parse_cmd_args!(args, f32); + let (body_name, angle) = parse_cmd_args!(args, String, f32); let mut pos = position(server, target, "target")?; pos.0.z += 50.0; const DESTINATION_RADIUS: f32 = 2000.0; let angle = angle.map(|a| a * std::f32::consts::PI / 180.0); let dir = angle.map(|a| Vec3::new(a.cos(), a.sin(), 0.0)); let destination = dir.map(|dir| pos.0 + dir * DESTINATION_RADIUS + Vec3::new(0.0, 0.0, 200.0)); - let mut rng = thread_rng(); - let ship = comp::ship::Body::random_airship_with(&mut rng); + let ship = if let Some(body_name) = body_name { + *comp::ship::ALL_AIRSHIPS + .iter() + .find(|body| format!("{body:?}") == body_name) + .ok_or_else(|| format!("No such airship '{body_name}'."))? + } else { + comp::ship::Body::random_airship_with(&mut thread_rng()) + }; let ori = comp::Ori::from(common::util::Dir::new(dir.unwrap_or(Vec3::unit_y()))); let mut builder = server .state @@ -1677,15 +1683,21 @@ fn handle_spawn_ship( args: Vec, _action: &ServerChatCommand, ) -> CmdResult<()> { - let angle = parse_cmd_args!(args, f32); + let (body_name, angle) = parse_cmd_args!(args, String, f32); let mut pos = position(server, target, "target")?; pos.0.z += 2.0; const DESTINATION_RADIUS: f32 = 2000.0; let angle = angle.map(|a| a * std::f32::consts::PI / 180.0); let dir = angle.map(|a| Vec3::new(a.cos(), a.sin(), 0.0)); let destination = dir.map(|dir| pos.0 + dir * DESTINATION_RADIUS + Vec3::new(0.0, 0.0, 200.0)); - let mut rng = thread_rng(); - let ship = comp::ship::Body::random_ship_with(&mut rng); + let ship = if let Some(body_name) = body_name { + *comp::ship::ALL_SHIPS + .iter() + .find(|body| format!("{body:?}") == body_name) + .ok_or_else(|| format!("No such airship '{body_name}'."))? + } else { + comp::ship::Body::random_airship_with(&mut thread_rng()) + }; let ori = comp::Ori::from(common::util::Dir::new(dir.unwrap_or(Vec3::unit_y()))); let mut builder = server .state