implemented long range scanners

This commit is contained in:
Christopher
2023-03-02 18:56:47 +13:00
parent 51663ea0b1
commit 4644a91024
5 changed files with 45 additions and 3 deletions

View File

@@ -206,3 +206,12 @@ pub fn display_damage_control(enterprise: &Enterprise) {
}
println!();
}
pub fn perform_long_range_scan(galaxy: &Galaxy) {
if galaxy.enterprise.damaged.contains_key(model::systems::SHORT_RANGE_SCAN) {
view::inoperable("Long Range Scanners");
return;
}
view::long_range_scan(galaxy);
}

View File

@@ -25,11 +25,12 @@ fn main() {
if command.len() == 0 {
continue;
}
match command[0].to_uppercase().as_str() {
match command[0].to_uppercase().as_str() { // order is weird because i built it in this order :)
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()),
model::systems::DAMAGE_CONTROL => commands::display_damage_control(&galaxy.enterprise),
model::systems::LONG_RANGE_SCAN => commands::perform_long_range_scan(&galaxy),
_ => view::print_command_help()
}

View File

@@ -101,9 +101,10 @@ pub mod systems {
pub const WARP_ENGINES: &str = "NAV";
pub const SHIELD_CONTROL: &str = "SHE";
pub const DAMAGE_CONTROL: &str = "DAM";
pub const LONG_RANGE_SCAN: &str = "LRS";
pub const KEYS: [&str; 4] = [
SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL, DAMAGE_CONTROL
pub const KEYS: [&str; 5] = [
SHORT_RANGE_SCAN, WARP_ENGINES, SHIELD_CONTROL, DAMAGE_CONTROL, LONG_RANGE_SCAN
];
pub fn name_for(key: &str) -> String {
@@ -112,6 +113,7 @@ pub mod systems {
WARP_ENGINES => "Warp Engines".into(),
SHIELD_CONTROL => "Shield Control".into(),
DAMAGE_CONTROL => "Damage Control".into(),
LONG_RANGE_SCAN => "Long Range Scanners".into(),
_ => "Unknown".into()
}
}

View File

@@ -224,3 +224,30 @@ pub fn random_repair_report_for(name: &str, damaged: bool) {
pub fn system_repair_completed(name: String) {
println!(" {name} repair completed.")
}
pub fn long_range_scan(galaxy: &Galaxy) {
let cx = galaxy.enterprise.quadrant.0 as i8;
let cy = galaxy.enterprise.quadrant.1 as i8;
println!("Long range scan for quadrant {}", galaxy.enterprise.quadrant);
println!("{:-^19}", "");
for y in cy - 1..=cy + 1 {
for x in cx - 1..=cx + 1 {
let mut klingons = "*".into();
let mut star_bases = "*".into();
let mut stars = "*".into();
if y >= 0 && y < 8 && x >= 0 && x < 8 {
let quadrant = &galaxy.quadrants[Pos(x as u8, y as u8).as_index()];
klingons = format!("{}", quadrant.klingons.len());
star_bases = quadrant.star_base.map_or("0", |_| "1");
stars = format!("{}", quadrant.stars.len());
}
print!(": {}{}{} ", klingons, stars, star_bases)
}
println!(":");
println!("{:-^19}", "");
}
}

View File

@@ -19,6 +19,7 @@ Started after movement and display of stats was finished (no energy management o
- [ ] stop before hitting an object
- when moving across a sector, the enterprise should stop before it runs into something
- the current move is a jump, which makes this problematic. would need to rewrite it
- also, movement courses could be floats, according to the instructions, allowing for more precise movement and aiming
- [x] better command reading - support entering multiple values on a line (e.g. nav 3 0.1)
- [ ] starbases
- [ ] repair
@@ -26,3 +27,5 @@ Started after movement and display of stats was finished (no energy management o
- [ ] phasers
- [ ] torpedoes
- [ ] restarting the game
- [ ] time progression
- check all areas where time should move, and adjust accordingly