diff --git a/src/actor.rs b/src/actor.rs index 8c0da7f..725389b 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -158,6 +158,8 @@ pub struct ActorEnteringVehicle; #[derive(Component)] pub struct ActorVehicleBeingEntered; #[derive(Component)] +pub struct MessageOnVehicleEntry(pub String); +#[derive(Component)] pub struct PlayersFlashLight; #[derive(Component)] pub struct WantsMaxRotation(pub f64); @@ -422,7 +424,7 @@ pub fn handle_input( q_camera: Query<&Transform, With>, mut q_flashlight: Query<&mut Visibility, With>, q_vehicles: Query< - (Entity, &Actor, &Transform), + (Entity, &Actor, &Transform, Option<&MessageOnVehicleEntry>), ( With, Without, @@ -432,6 +434,7 @@ pub fn handle_input( mut ew_conv: EventWriter, mut ew_vehicle: EventWriter, mut ew_sfx: EventWriter, + mut log: ResMut, q_player_drives: Query>, ) { if q_camera.is_empty() || player.is_empty() { @@ -457,12 +460,18 @@ pub fn handle_input( } // Entering Vehicles if q_player_drives.is_empty() { - let objects: Vec<((Entity, &Actor), &Transform)> = q_vehicles - .iter() - .map(|(entity, actor, transform)| ((entity, actor), transform)) - .collect(); - if let (Some((entity, actor)), dist) = - camera::find_closest_target::<(Entity, &Actor)>(objects, camtrans) + // Sort vehicles by their distance to the player + let objects: Vec<((Entity, &Actor, Option<&MessageOnVehicleEntry>), &Transform)> = + q_vehicles + .iter() + .map(|(entity, actor, transform, msg)| ((entity, actor, msg), transform)) + .collect(); + + // Get the vehicle with shortest distance + if let (Some((entity, actor, msg)), dist) = + camera::find_closest_target::<(Entity, &Actor, Option<&MessageOnVehicleEntry>)>( + objects, camtrans, + ) { if dist <= MAX_INTERACT_DISTANCE { commands.entity(entity).insert(ActorVehicleBeingEntered); @@ -474,6 +483,9 @@ pub fn handle_input( is_entering: q_player_drives.is_empty(), is_player: true, }); + if let Some(msg) = msg { + log.warning(msg.0.clone()); + } } } } diff --git a/src/cmd.rs b/src/cmd.rs index 4e5aa7e..0f944fa 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -79,6 +79,7 @@ struct ParserState { velocity: DVec3, angular_momentum: DVec3, pronoun: Option, + message_on_entry: Option, is_sphere: bool, is_player: bool, is_lifeform: bool, @@ -138,6 +139,7 @@ impl Default for ParserState { velocity: DVec3::splat(0.0), angular_momentum: DVec3::new(0.03, 0.3, 0.09), pronoun: None, + message_on_entry: None, is_sphere: false, is_player: false, is_lifeform: false, @@ -683,6 +685,9 @@ pub fn load_defs(mut ew_spawn: EventWriter) { continue; } } + ["message_on_entry", message] => { + state.message_on_entry = Some(message.to_string()); + } _ => { error!("No match for [{}]", parts.join(",")); } @@ -895,6 +900,9 @@ fn spawn_entities( if orbits_jupiter { actor.insert(actor::OrbitsJupiter); } + if let Some(message) = &state.message_on_entry { + actor.insert(actor::MessageOnVehicleEntry(message.clone())); + } actor.insert(world::DespawnOnPlayerDeath); actor.insert(actor::HitPoints::default()); actor.insert(Position::from(absolute_pos)); diff --git a/src/data/defs.txt b/src/data/defs.txt index d638594..3acbd69 100644 --- a/src/data/defs.txt +++ b/src/data/defs.txt @@ -298,7 +298,7 @@ actor 700 -100 -1100 suitv2 scene 22 0 0 workshop relativeto Luna actor -20 10 -23 MeteorAceGT - name "MeteorAceGTā„¢" + name "Luna's experimental MeteorAceGT" relativeto Luna scale 5 vehicle yes @@ -309,6 +309,7 @@ actor 700 -100 -1100 suitv2 density 500 angularmomentum 0 0 0.2 pointofinterest yes + message_on_entry "NOT DESIGNED FOR HUMAN USE" actor -9 4 11 lightorb relativeto Luna name "Light Orb" diff --git a/src/hud.rs b/src/hud.rs index 539e74c..89cb671 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -942,6 +942,7 @@ fn update_hud( } else { |msg: &&Message| match msg.level { LogLevel::Always => true, + LogLevel::Warning => true, LogLevel::Achievement => true, _ => false, }