implemented collision detection

This commit is contained in:
Christopher
2023-03-05 15:30:17 +13:00
parent 8c1e725716
commit 9f4f045826
4 changed files with 29 additions and 56 deletions

View File

@@ -40,7 +40,7 @@ pub fn gather_dir_and_speed_then_move(galaxy: &mut Galaxy, provided: Vec<String>
let course = input::param_or_prompt_value(&provided, 0, view::prompts::COURSE, 1.0, 9.0);
if course.is_none() {
view::bad_nav();
view::bad_course_data();
return;
}
@@ -53,7 +53,7 @@ pub fn gather_dir_and_speed_then_move(galaxy: &mut Galaxy, provided: Vec<String>
let speed = input::param_or_prompt_value(&provided, 1, &view::prompts::warp_factor(max_warp), 0.0, 8.0);
if speed.is_none() {
view::bad_nav();
view::bad_course_data();
return;
}
@@ -130,9 +130,27 @@ fn move_enterprise(course: f32, warp_speed: f32, galaxy: &mut Galaxy) {
let ship = &mut galaxy.enterprise;
// todo account for being blocked
let (mut path, mut hit_edge) = find_nav_path(ship.quadrant, ship.sector, course, warp_speed);
for i in 0..path.len() {
let (quadrant, sector) = path[i].to_local_quadrant_sector();
if quadrant != ship.quadrant {
break; // have left current quadrant, so collision checks removed. if there is a collision at the dest... /shrug?
}
let quadrant = &galaxy.quadrants[quadrant.as_index()];
if quadrant.sector_status(sector) != SectorStatus::Empty {
path = path[..i].into();
hit_edge = false;
if i > 0 {
let (_, last_sector) = path[path.len() - 1].to_local_quadrant_sector();
view::bad_nav(last_sector);
} else {
view::bad_nav(ship.sector);
return;
}
break;
}
}
let (path, hit_edge) = find_nav_path(ship.quadrant, ship.sector, course, warp_speed);
let energy_cost = path.len() as u16 + 10;
if energy_cost > ship.total_energy {

View File

@@ -56,7 +56,7 @@ impl Enterprise {
return;
}
view::enterprise_hit(&hit_strength, &sector);
view::enterprise_hit(&hit_strength, sector);
if self.shields <= hit_strength {
view::enterprise_destroyed();

View File

@@ -310,15 +310,19 @@ pub fn enterprise_destroyed() {
println!("The Enterprise has been destroyed. The Federation will be conquered.");
}
pub fn bad_nav() {
pub fn bad_course_data() {
println!(" Lt. Sulu reports, 'Incorrect course data, sir!'")
}
pub fn bad_nav(current_sector: Pos) {
println!("Warp engines shut down at sector {current_sector} dues to bad navigation")
}
pub fn bad_torpedo_course() {
println!(" Ensign Chekov reports, 'Incorrect course data, sir!'")
}
pub fn enterprise_hit(hit_strength: &u16, from_sector: &Pos) {
pub fn enterprise_hit(hit_strength: &u16, from_sector: Pos) {
println!("{hit_strength} unit hit on Enterprise from sector {from_sector}");
}

View File

@@ -1,49 +0,0 @@
# Tasks
Started after movement and display of stats was finished (no energy management or collision detection or anything).
- [x] klingon movement
- [x] klingon firing, game over etc
- [x] add intro
- [x] add entering (and starting in) sector headers
- [x] conditions and danger messages
- [x] remove energy on move
- [x] shields
- [x] shield control
- [x] shield hit absorption
- [x] subsystem damage
- [x] and support for reports
- [x] random system damage or repairs on move
- [x] lrs?
- [x] stranded...
- [ ] 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)
- [x] starbases
- [x] proximity detection for docking
- [x] repair on damage control
- [x] protection from shots
- [x] weapons
- [x] phasers
- [x] torpedoes
- [x] computer
- [x] 0 - output of all short and long range scans (requires tracking if a system has been scanned)
- [x] 1 - klingons, starbases, stardate and damage control
- [x] 2 - photon torpedo data: direction and distance to all local klingons
- [x] 3 - starbase distance and dir locally
- [x] 4 - direction/distance calculator (useful for nav actions I guess)
- [x] 5 - galactic name map
- [x] restarting the game
- [x] after defeat
- [x] and by resigning
- [x] time progression
- [x] check all areas where time should move, and adjust accordingly
- looks to only be on nav and repair
- [x] defeat due to time expired
- [x] intro instructions
- [x] victory
- [x] switch from x,y to y,x
- [ ] uppercase prompts?