Skip to content

Commit

Permalink
Removed bunch of return commands in favor of the rust syntax of endin…
Browse files Browse the repository at this point in the history
…g method with return value
  • Loading branch information
DrInfy committed May 29, 2021
1 parent d5cf7a9 commit abcb06b
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 123 deletions.
2 changes: 1 addition & 1 deletion src/mapping/chokes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,5 +331,5 @@ fn distance(first: (usize, usize), second: (usize, usize)) -> f32 {
let pos1 = Pos(first.0, first.1);
let pos2 = Pos(second.0, second.1);

return pos1.euclidean_distance(&pos2) as f32 / MULTF32;
pos1.euclidean_distance(&pos2) as f32 / MULTF32
}
8 changes: 4 additions & 4 deletions src/mapping/influence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl Map {
maps.push(&mut self.reaper_pathing);
}

return maps;
maps
}

fn get_pure_ground_influence_maps(&mut self) -> Vec<&mut PathFind> {
Expand All @@ -162,7 +162,7 @@ impl Map {
maps.push(&mut self.reaper_pathing);
}

return maps;
maps
}

pub fn get_ground_influence_maps(&mut self) -> Vec<&mut PathFind> {
Expand All @@ -176,7 +176,7 @@ impl Map {
maps.push(&mut self.reaper_pathing);
}

return maps;
maps
}

pub fn get_air_influence_maps(&mut self) -> Vec<&mut PathFind> {
Expand All @@ -187,6 +187,6 @@ impl Map {
maps.push(&mut self.colossus_pathing);
}

return maps;
maps
}
}
46 changes: 22 additions & 24 deletions src/mapping/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,29 +150,29 @@ impl Map {
}
}

return result;
result
}

/// Returns current influence value
fn current_influence(&self, map_type: u8, position: (f32, f32)) -> f32 {
let map = self.get_map(map_type);
let position_int = round_point2(position);

return map.current_influence(position_int) as f32;
map.current_influence(position_int) as f32
}

/// Finds the first reachable position within specified walking distance from the center point with lowest value
fn lowest_influence_walk(&self, map_type: u8, center: (f32, f32), distance: f32) -> ((usize, usize), f32) {
let map = self.get_map(map_type);
let center_int = round_point2(center);

return map.lowest_influence_walk(center_int, distance);
map.lowest_influence_walk(center_int, distance)
}

/// Finds the first reachable position within specified distance from the center point with lowest value
pub fn lowest_influence(&self, map_type: u8, center: (f32, f32), distance: usize) -> ((usize, usize), f32) {
let map = self.get_map(map_type);
return map.inline_lowest_value(center, distance);
map.inline_lowest_value(center, distance)
}

/// Find the shortest path values without considering influence and returns the path and distance
Expand All @@ -186,7 +186,7 @@ impl Map {
let end_int = (end.0.round() as usize, end.1.round() as usize);

let map = self.get_map(map_type);
return map.find_path(start_int, end_int, possible_heuristic);
map.find_path(start_int, end_int, possible_heuristic)
}

/// Find the shortest path values without considering influence and returns the path and distance
Expand All @@ -200,7 +200,7 @@ impl Map {
let end_int = (end.0.round() as usize, end.1.round() as usize);

let map = self.get_map(map_type);
return map.find_path_large(start_int, end_int, possible_heuristic);
map.find_path_large(start_int, end_int, possible_heuristic)
}

/// Find the path using influence values and returns the path and distance
Expand All @@ -213,7 +213,7 @@ impl Map {
let start_int = (start.0.round() as usize, start.1.round() as usize);
let end_int = (end.0.round() as usize, end.1.round() as usize);
let map = self.get_map(map_type);
return map.find_path_influence(start_int, end_int, possible_heuristic);
map.find_path_influence(start_int, end_int, possible_heuristic)
}

/// Find the path using influence values and returns the path and distance
Expand All @@ -226,7 +226,7 @@ impl Map {
let start_int = (start.0.round() as usize, start.1.round() as usize);
let end_int = (end.0.round() as usize, end.1.round() as usize);
let map = self.get_map(map_type);
return map.find_path_influence_large(start_int, end_int, possible_heuristic);
map.find_path_influence_large(start_int, end_int, possible_heuristic)
}

/// Find the shortest path values without considering influence and returns the path and distance
Expand All @@ -241,7 +241,7 @@ impl Map {
let end_int = (end.0.round() as usize, end.1.round() as usize);

let map = self.get_map(map_type);
return map.find_path_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
map.find_path_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
}

/// Find the shortest path values without considering influence and returns the path and distance
Expand All @@ -256,7 +256,7 @@ impl Map {
let end_int = (end.0.round() as usize, end.1.round() as usize);

let map = self.get_map(map_type);
return map.find_path_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
map.find_path_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
}

/// Find the path using influence values and returns the path and distance
Expand All @@ -270,7 +270,7 @@ impl Map {
let start_int = (start.0.round() as usize, start.1.round() as usize);
let end_int = (end.0.round() as usize, end.1.round() as usize);
let map = self.get_map(map_type);
return map.find_path_influence_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
map.find_path_influence_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
}

/// Find the path using influence values and returns the path and distance
Expand All @@ -284,7 +284,7 @@ impl Map {
let start_int = (start.0.round() as usize, start.1.round() as usize);
let end_int = (end.0.round() as usize, end.1.round() as usize);
let map = self.get_map(map_type);
return map.find_path_influence_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target);
map.find_path_influence_large_closer_than(start_int, end_int, possible_heuristic, distance_from_target)
}

/// Finds a compromise where low influence matches with close position to the start position.
Expand All @@ -295,7 +295,7 @@ impl Map {
distance: f32)
-> ((f32, f32), f32) {
let map = self.get_map(map_type);
return map.find_low_inside_walk(start, target, distance);
map.find_low_inside_walk(start, target, distance)
}
}

Expand Down Expand Up @@ -402,14 +402,13 @@ impl Map {

let c = points[x][y].cliff_type;

if c != Cliff::None {
if points[x + 1][y].cliff_type != c
&& points[x - 1][y].cliff_type != c
&& points[x][y + 1].cliff_type != c
&& points[x][y - 1].cliff_type != c
{
points[x][y].cliff_type = Cliff::None;
}
if c != Cliff::None
&& points[x + 1][y].cliff_type != c
&& points[x - 1][y].cliff_type != c
&& points[x][y + 1].cliff_type != c
&& points[x][y - 1].cliff_type != c
{
points[x][y].cliff_type = Cliff::None;
}

if !set_handled_overlord_spots.contains(&point_hash) && points[x][y].overlord_spot {
Expand Down Expand Up @@ -515,7 +514,7 @@ fn flood_fill_overlord(points: &mut Vec<Vec<map_point::MapPoint>>,

let mut result = true;
points[x][y].overlord_spot = replacement;
// if points[x][y].overlord_spot == target {

if y > 0 {
result &= flood_fill_overlord(points, x, ((y as u32) - 1) as usize, target_height, replacement, set);
}
Expand All @@ -528,7 +527,6 @@ fn flood_fill_overlord(points: &mut Vec<Vec<map_point::MapPoint>>,
if x < points.len() - 1 {
result &= flood_fill_overlord(points, x + 1, y, target_height, replacement, set);
}
// }

return result;
result
}
11 changes: 3 additions & 8 deletions src/mapping/zones.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ impl Map {

pub fn get_zone(&self, position: (f32, f32)) -> i8 {
let u_position = round_point2(position);
let index = self.points[u_position.0][u_position.1].zone_index;
index
self.points[u_position.0][u_position.1].zone_index
}
}

impl Map {
fn borrow(&mut self, x: usize, y: usize) -> &mut MapPoint { return &mut self.points[x][y]; }
fn zone_index(&mut self, x: usize, y: usize) -> i8 { return self.points[x][y].zone_index; }
fn borrow(&mut self, x: usize, y: usize) -> &mut MapPoint { &mut self.points[x][y] }
fn zone_index(&mut self, x: usize, y: usize) -> i8 { self.points[x][y].zone_index }
}

fn flood_fill(map: &mut Map,
Expand Down Expand Up @@ -128,7 +127,6 @@ fn flood_fill(map: &mut Map,
return;
}

// if points[x][y].overlord_spot == target {
if y > 0 {
flood_fill(map, x, ((y as u32) - 1) as usize, target_height, zone_index, origin, sorted_base_locations);
}
Expand All @@ -141,7 +139,4 @@ fn flood_fill(map: &mut Map,
if x < map.points.len() - 1 {
flood_fill(map, x + 1, y, target_height, zone_index, origin, sorted_base_locations);
}
// }

return;
}
12 changes: 5 additions & 7 deletions src/path_find/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::f32::MAX;

use pathfinding::prelude::{absdiff, astar, dijkstra_all, dijkstra_partial};
use pyo3::prelude::*;

Expand Down Expand Up @@ -911,8 +909,8 @@ impl PathFind {
if distance_from_target > distance {
continue;
}
let distance_from_start= octile_distance_f32(corrected_start, destination.0);

let distance_from_start = octile_distance_f32(corrected_start, destination.0);
// Use magic distance constant here to not move without reason.
// Let's take the distance into account so that same influence value is better when it's closer.
let distance_value = distance_from_start;
Expand All @@ -924,7 +922,7 @@ impl PathFind {
}
}

return best_target;
best_target
}

pub fn invert_djiktra(&self, start: (f32, f32), distance: f32) -> Vec<((usize, usize), f32)> {
Expand All @@ -946,7 +944,7 @@ impl PathFind {
destination_collection.push(((x, y), d));
}

return destination_collection;
destination_collection
}

pub fn djiktra(&self, start: (f32, f32), distance: f32) -> Vec<((usize, usize), f32)> {
Expand All @@ -968,6 +966,6 @@ impl PathFind {
destination_collection.push(((x, y), d));
}

return destination_collection;
destination_collection
}
}
Loading

0 comments on commit abcb06b

Please sign in to comment.