11use clap:: Parser ;
2- use cli:: { BuildNavpointMatrixArgs , Cli , Command , ConnectedNodesFromNavigationDataArgs , ConnectedNodesFromNavpointMatrixArgs } ;
2+ use cli:: { BuildNavpointMatrixArgs , Cli , Command , ConnectedNodesFromNavigationDataArgs , ConnectedNodesFromNavpointMatrixArgs , ShowPathArgs } ;
33use connected_nodes:: ConnectedNodes ;
44use p3_api:: data:: { navigation_matrix:: NavigationMatrix , navigation_vector:: NavigationVector , navpoint_matrix:: NavpointMatrix } ;
55use pathfinding:: prelude:: { build_path, dijkstra_all} ;
@@ -18,6 +18,7 @@ fn main() {
1818 Command :: ConnectedNodesFromNavpointMatrix ( args) => build_connected_nodes_from_navpoint_matrix ( args) ,
1919 Command :: ConnectedNodesFromNavigationData ( args) => build_connected_nodes_from_navigation_data ( args) ,
2020 Command :: Test => test ( ) ,
21+ Command :: ShowPath ( show_path_args) => show_path ( show_path_args) ,
2122 }
2223}
2324
@@ -56,10 +57,26 @@ fn build_connected_nodes_from_navigation_data(args: ConnectedNodesFromNavigation
5657 fs:: write ( args. output_file , connected_nodes. serialize ( ) ) . unwrap ( ) ;
5758}
5859
60+ fn show_path ( args : ShowPathArgs ) {
61+ let navpoint_matrix = NavpointMatrix :: deserialize ( & fs:: read ( r"C:\Users\Benni\Patrician 3_workbench\navdata\matrix_int.dat.orig" ) . unwrap ( ) ) ;
62+ let navigation_vector = NavigationVector :: deserialize ( & fs:: read ( r"C:\Users\Benni\Patrician 3_workbench\navdata\nav_vec.dat.orig" ) . unwrap ( ) ) ;
63+ let mut current = args. source_index ;
64+ let current_point = navigation_vector. points [ current as usize ] ;
65+ let mut buf = format ! ( "{current} {current_point:x?}" ) ;
66+ let distance = navpoint_matrix. get ( current, args. destination_index , 350 ) . distance ;
67+ while current != args. destination_index {
68+ let cell = navpoint_matrix. get ( current, args. destination_index , 350 ) ;
69+ current = cell. next ;
70+ let current_point = navigation_vector. points [ current as usize ] ;
71+ buf. push_str ( & format ! ( " -> {current} {current_point:x?}" ) ) ;
72+ }
73+ println ! ( "{buf} (declared distance: {distance})" ) ;
74+ }
75+
5976fn test ( ) {
6077 let start = Instant :: now ( ) ;
61- let navigation_vector = NavigationVector :: deserialize ( & fs:: read ( r"C:\Users\Benni\Patrician 3_workbench\navdata\nav_vec.dat" ) . unwrap ( ) ) ;
62- let original_navpoint_matrix = NavpointMatrix :: deserialize ( & fs:: read ( r"C:\Users\Benni\Patrician 3_workbench\navdata\matrix_int.dat" ) . unwrap ( ) ) ;
78+ let navigation_vector = NavigationVector :: deserialize ( & fs:: read ( r"C:\Users\Benni\Patrician 3_workbench\navdata\nav_vec.dat.orig " ) . unwrap ( ) ) ;
79+ let original_navpoint_matrix = NavpointMatrix :: deserialize ( & fs:: read ( r"C:\Users\Benni\Patrician 3_workbench\navdata\matrix_int.dat.orig " ) . unwrap ( ) ) ;
6380 let connected_nodes = ConnectedNodes :: from_navpoint_matrix ( & original_navpoint_matrix) ;
6481 let mut new_navpoint_matrix = NavpointMatrix :: new ( navigation_vector. length ) ;
6582
@@ -99,7 +116,8 @@ fn test() {
99116 let orig_distance = original_navpoint_matrix. matrix [ i] . distance ;
100117 let calculated_distance = new_navpoint_matrix. matrix [ i] . distance ;
101118 if orig_distance != calculated_distance {
102- println ! ( "cell {i}: distance {orig_distance} != {calculated_distance}" ) ;
119+ let ( source, destination) = new_navpoint_matrix. get_source_and_destination ( i, navigation_vector. length ) ;
120+ println ! ( "cell {i}: distance {orig_distance} != {calculated_distance} ({source} -> {destination})" ) ;
103121 bad_distance_cells += 1 ;
104122 }
105123 }
0 commit comments