moved where system keys are defined

This commit is contained in:
Christopher
2023-03-02 13:39:12 +13:00
parent 0581fe38f8
commit f253ff7155
4 changed files with 17 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
use crate::{model::{Galaxy, Pos, COURSES, EndPosition}, view, input};
use crate::{model::{Galaxy, Pos, COURSES, EndPosition, self}, view, input};
pub fn perform_short_range_scan(galaxy: &Galaxy) {
if galaxy.enterprise.damaged.contains_key(view::keys::SHORT_RANGE_SCAN) {
if galaxy.enterprise.damaged.contains_key(model::systems::SHORT_RANGE_SCAN) {
view::scanners_out();
return;
}
@@ -11,7 +11,7 @@ pub fn perform_short_range_scan(galaxy: &Galaxy) {
pub fn get_amount_and_set_shields(galaxy: &mut Galaxy, provided: Vec<String>) {
if galaxy.enterprise.damaged.contains_key(view::keys::SHIELD_CONTROL) {
if galaxy.enterprise.damaged.contains_key(model::systems::SHIELD_CONTROL) {
view::inoperable("Shield Control");
return;
}
@@ -45,7 +45,7 @@ pub fn gather_dir_and_speed_then_move(galaxy: &mut Galaxy, provided: Vec<String>
let course = course.unwrap();
let mut max_warp = 8.0;
if galaxy.enterprise.damaged.contains_key(view::keys::NAVIGATION) {
if galaxy.enterprise.damaged.contains_key(model::systems::WARP_ENGINES) {
max_warp = 0.2;
}
@@ -77,8 +77,6 @@ fn move_enterprise(course: u8, warp_speed: f32, galaxy: &mut Galaxy) {
let end = find_end_quadrant_sector(ship.quadrant, ship.sector, course, warp_speed);
// todo account for engine damage
if end.energy_cost > ship.total_energy {
view::insuffient_warp_energy(warp_speed);
return

View File

@@ -26,9 +26,9 @@ fn main() {
continue;
}
match command[0].to_uppercase().as_str() {
view::keys::SHORT_RANGE_SCAN => commands::perform_short_range_scan(&galaxy),
view::keys::NAVIGATION => commands::gather_dir_and_speed_then_move(&mut galaxy, command[1..].into()),
view::keys::SHIELD_CONTROL => commands::get_amount_and_set_shields(&mut galaxy, command[1..].into()),
model::systems::SHORT_RANGE_SCAN => commands::perform_short_range_scan(&galaxy),
model::systems::WARP_ENGINES => commands::gather_dir_and_speed_then_move(&mut galaxy, command[1..].into()),
model::systems::SHIELD_CONTROL => commands::get_amount_and_set_shields(&mut galaxy, command[1..].into()),
_ => view::print_command_help()
}

View File

@@ -64,6 +64,16 @@ impl Enterprise {
}
}
pub mod systems {
pub const SHORT_RANGE_SCAN: &str = "SRS";
pub const WARP_ENGINES: &str = "NAV";
pub const SHIELD_CONTROL: &str = "SHE";
pub const ALL: [&str; 3] = [
SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL
];
}
pub struct EndPosition {
pub quadrant: Pos,
pub sector: Pos,

View File

@@ -1,15 +1,5 @@
use crate::model::{Galaxy, Pos, EndPosition, SectorStatus};
pub mod keys {
pub const SHORT_RANGE_SCAN: &str = "SRS";
pub const NAVIGATION: &str = "NAV";
pub const SHIELD_CONTROL: &str = "SHE";
pub const ALL_SYSTEMS: [&str; 3] = [
SHORT_RANGE_SCAN, NAVIGATION, SHIELD_CONTROL
];
}
pub fn enterprise() {
println!("